@tetacom/svg-charts 1.4.2 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chart/core/utils/generate-ticks.d.ts +1 -1
- package/chart/model/i-broadcast-message.d.ts +2 -0
- package/chart/model/i-chart-config.d.ts +6 -0
- package/esm2020/chart/chart-container/gridlines/gridlines.component.mjs +9 -6
- package/esm2020/chart/core/utils/generate-ticks.mjs +3 -4
- package/esm2020/chart/directives/brushable.directive.mjs +4 -2
- package/esm2020/chart/directives/zoomable.directive.mjs +23 -13
- package/esm2020/chart/model/i-broadcast-message.mjs +2 -1
- package/esm2020/chart/model/i-chart-config.mjs +1 -1
- package/fesm2015/tetacom-svg-charts.mjs +38 -24
- package/fesm2015/tetacom-svg-charts.mjs.map +1 -1
- package/fesm2020/tetacom-svg-charts.mjs +34 -20
- package/fesm2020/tetacom-svg-charts.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -459,10 +459,9 @@ const getTextWidth = (inputText, backupRatio = 0.5, fontSize = 10) => {
|
|
|
459
459
|
return fontSize * backupRatio * text.length;
|
|
460
460
|
};
|
|
461
461
|
|
|
462
|
-
function generateTicks(extremes) {
|
|
462
|
+
function generateTicks(extremes, count = 10) {
|
|
463
463
|
const [min, max] = extremes;
|
|
464
|
-
const
|
|
465
|
-
const tickStep = (max - min) / tickCount;
|
|
464
|
+
const tickStep = (max - min) / count;
|
|
466
465
|
const ticks = d3
|
|
467
466
|
.range(min, max + tickStep, tickStep)
|
|
468
467
|
.filter((step) => step <= max);
|
|
@@ -1581,13 +1580,15 @@ class GridlinesComponent {
|
|
|
1581
1580
|
this.svc = svc;
|
|
1582
1581
|
this.chartService = chartService;
|
|
1583
1582
|
this.config = this.chartService.config;
|
|
1584
|
-
this.tickYValues = this.svc.scales.pipe(map((_) => {
|
|
1583
|
+
this.tickYValues = this.svc.scales.pipe(withLatestFrom(this.config), map((_) => {
|
|
1584
|
+
const [scales, config] = _;
|
|
1585
1585
|
const ratio = this.size.height / 40;
|
|
1586
|
-
return
|
|
1586
|
+
return config.gridLines?.y?.ticksCount != null ? generateTicks(scales.y.get(0).scale.domain(), config.gridLines?.y?.ticksCount) : scales.y.get(0)?.scale.ticks(ratio);
|
|
1587
1587
|
}));
|
|
1588
|
-
this.tickXValues = this.svc.scales.pipe(map((_) => {
|
|
1588
|
+
this.tickXValues = this.svc.scales.pipe(withLatestFrom(this.config), map((_) => {
|
|
1589
|
+
const [scales, config] = _;
|
|
1589
1590
|
const ratio = this.size.width / 40;
|
|
1590
|
-
return
|
|
1591
|
+
return config.gridLines?.x?.ticksCount != null ? generateTicks(scales.x.get(0).originDomain, config.gridLines?.x?.ticksCount) : scales.x.get(0)?.scale.ticks(ratio);
|
|
1591
1592
|
}));
|
|
1592
1593
|
this.y = this.svc.scales.pipe(map((_) => _.y.get(0)?.scale));
|
|
1593
1594
|
this.x = this.svc.scales.pipe(map((_) => _.x.get(0)?.scale));
|
|
@@ -2002,6 +2003,7 @@ class BrushMessage {
|
|
|
2002
2003
|
constructor(options) {
|
|
2003
2004
|
this.chartId = options?.chartId;
|
|
2004
2005
|
this.selection = options?.selection;
|
|
2006
|
+
this.mode = options?.mode;
|
|
2005
2007
|
}
|
|
2006
2008
|
}
|
|
2007
2009
|
|
|
@@ -2019,7 +2021,10 @@ class ZoomableDirective {
|
|
|
2019
2021
|
if (event.sourceEvent) {
|
|
2020
2022
|
if (Object.keys(event.sourceEvent).length !== 0) {
|
|
2021
2023
|
const origin = this.axis.scale.copy().domain(this.axis.originDomain);
|
|
2022
|
-
|
|
2024
|
+
if (this.axis.options.scaleType.type === ScaleType.band) {
|
|
2025
|
+
return;
|
|
2026
|
+
}
|
|
2027
|
+
const domain = this.axis.orientation === AxisOrientation.y
|
|
2023
2028
|
? event.transform.rescaleY(origin).domain()
|
|
2024
2029
|
: event.transform.rescaleX(origin).domain();
|
|
2025
2030
|
const message = new ZoomMessage({
|
|
@@ -2029,7 +2034,7 @@ class ZoomableDirective {
|
|
|
2029
2034
|
orientation: this.axis.orientation,
|
|
2030
2035
|
},
|
|
2031
2036
|
element: this.elementRef,
|
|
2032
|
-
domain
|
|
2037
|
+
domain,
|
|
2033
2038
|
chartId: this.config.id
|
|
2034
2039
|
});
|
|
2035
2040
|
this.zoomService.fireZoom(message);
|
|
@@ -2050,7 +2055,7 @@ class ZoomableDirective {
|
|
|
2050
2055
|
this.initZoomSync();
|
|
2051
2056
|
}
|
|
2052
2057
|
ngOnDestroy() {
|
|
2053
|
-
this.zoom?.on('
|
|
2058
|
+
this.zoom?.on('zoom end', null);
|
|
2054
2059
|
this._element?.on('wheel', null);
|
|
2055
2060
|
this.alive = false;
|
|
2056
2061
|
}
|
|
@@ -2084,28 +2089,28 @@ class ZoomableDirective {
|
|
|
2084
2089
|
[0, 0],
|
|
2085
2090
|
[this.size.width, this.size.height],
|
|
2086
2091
|
]);
|
|
2087
|
-
const min = this.config?.zoom?.minTranslate
|
|
2092
|
+
const min = this.config?.zoom?.minTranslate != null
|
|
2088
2093
|
? this.axis.scale(this.config?.zoom?.minTranslate)
|
|
2089
2094
|
: -Infinity;
|
|
2090
|
-
const max = (this.config?.zoom?.maxTranslate
|
|
2091
|
-
? this.axis.scale(this.config?.zoom?.maxTranslate)
|
|
2095
|
+
const max = (this.config?.zoom?.maxTranslate != null
|
|
2096
|
+
? this.axis.scale(this.config?.zoom?.maxTranslate)
|
|
2092
2097
|
: Infinity);
|
|
2093
2098
|
if (this.axis.orientation === AxisOrientation.x && this.config.zoom.type === ZoomType.x) {
|
|
2094
2099
|
this.zoom.translateExtent([
|
|
2095
|
-
[min, -Infinity],
|
|
2096
|
-
[max, Infinity],
|
|
2100
|
+
[Math.min(min, max), -Infinity],
|
|
2101
|
+
[Math.max(min, max), Infinity],
|
|
2097
2102
|
]);
|
|
2098
2103
|
}
|
|
2099
2104
|
if (this.axis.orientation === AxisOrientation.y && this.config.zoom.type === ZoomType.y) {
|
|
2100
2105
|
this.zoom.translateExtent([
|
|
2101
|
-
[-Infinity, min],
|
|
2102
|
-
[Infinity, max],
|
|
2106
|
+
[-Infinity, Math.min(min, max)],
|
|
2107
|
+
[Infinity, Math.max(min, max)],
|
|
2103
2108
|
]);
|
|
2104
2109
|
}
|
|
2105
2110
|
if (this.config.zoom?.wheelDelta) {
|
|
2106
2111
|
this.zoom.wheelDelta(this.config.zoom?.wheelDelta);
|
|
2107
2112
|
}
|
|
2108
|
-
if (this.axis.options.scaleType.type
|
|
2113
|
+
if (this.axis.options.scaleType.type !== ScaleType.band) {
|
|
2109
2114
|
const extremes = this.axis.extremes;
|
|
2110
2115
|
const maxZoom = this.config.zoom?.max
|
|
2111
2116
|
? (extremes[1] - extremes[0]) /
|
|
@@ -2119,7 +2124,7 @@ class ZoomableDirective {
|
|
|
2119
2124
|
: Infinity;
|
|
2120
2125
|
this.zoom.scaleExtent([maxZoom, minZoom]);
|
|
2121
2126
|
}
|
|
2122
|
-
this.zoom.on('zoom end', this.zoomed);
|
|
2127
|
+
this.zoom.on('start zoom end', this.zoomed);
|
|
2123
2128
|
this._element.call(this.zoom).on('dblclick.zoom', null);
|
|
2124
2129
|
if (this.config?.zoom?.zoomBehavior === ZoomBehaviorType.wheel) {
|
|
2125
2130
|
this.runWheelTranslate();
|
|
@@ -2157,6 +2162,13 @@ class ZoomableDirective {
|
|
|
2157
2162
|
let domain = this.axis.orientation === AxisOrientation.y
|
|
2158
2163
|
? transform.rescaleY(origin).domain()
|
|
2159
2164
|
: transform.rescaleX(origin).domain();
|
|
2165
|
+
const extent = this.axis.options?.inverted ? domain : [...domain].reverse();
|
|
2166
|
+
if (extent[0] <= this.config.zoom?.minTranslate) {
|
|
2167
|
+
return;
|
|
2168
|
+
}
|
|
2169
|
+
if (extent[1] >= this.config.zoom?.maxTranslate) {
|
|
2170
|
+
return;
|
|
2171
|
+
}
|
|
2160
2172
|
const message = new ZoomMessage({
|
|
2161
2173
|
eventType: type,
|
|
2162
2174
|
element: this.elementRef,
|
|
@@ -2238,6 +2250,7 @@ class BrushableDirective {
|
|
|
2238
2250
|
const brushMessage = new BrushMessage({
|
|
2239
2251
|
chartId: this.config.id,
|
|
2240
2252
|
selection: [this.config?.brush?.from, this.config?.brush?.to],
|
|
2253
|
+
mode: 'init'
|
|
2241
2254
|
});
|
|
2242
2255
|
this.brushService.setBrush(brushMessage);
|
|
2243
2256
|
}
|
|
@@ -2315,6 +2328,7 @@ class BrushableDirective {
|
|
|
2315
2328
|
const brushMessage = new BrushMessage({
|
|
2316
2329
|
chartId: this.config.id,
|
|
2317
2330
|
selection: [brushScale.invert(from), brushScale.invert(to)],
|
|
2331
|
+
mode: _.mode
|
|
2318
2332
|
});
|
|
2319
2333
|
this.brushService.setBrush(brushMessage);
|
|
2320
2334
|
}
|
|
@@ -2331,7 +2345,7 @@ class BrushableDirective {
|
|
|
2331
2345
|
}
|
|
2332
2346
|
this._container.call(this.brush.move, this.selection
|
|
2333
2347
|
? this.selection.map(brushScale)
|
|
2334
|
-
: domain.map(brushScale));
|
|
2348
|
+
: domain.map(brushScale), {});
|
|
2335
2349
|
}, 0);
|
|
2336
2350
|
});
|
|
2337
2351
|
}
|