@tetacom/svg-charts 1.4.3 → 1.4.6
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 -2
- package/chart/model/i-chart-config.d.ts +6 -0
- package/esm2020/chart/chart-container/gridlines/gridlines.component.mjs +9 -6
- package/esm2020/chart/chart-container/plotline/plotline.component.mjs +7 -1
- package/esm2020/chart/core/utils/generate-ticks.mjs +3 -4
- package/esm2020/chart/directives/zoomable.directive.mjs +23 -13
- package/esm2020/chart/model/i-broadcast-message.mjs +1 -1
- package/esm2020/chart/model/i-chart-config.mjs +1 -1
- package/fesm2015/tetacom-svg-charts.mjs +40 -23
- package/fesm2015/tetacom-svg-charts.mjs.map +1 -1
- package/fesm2020/tetacom-svg-charts.mjs +36 -19
- 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));
|
|
@@ -1705,6 +1706,12 @@ class PlotlineComponent {
|
|
|
1705
1706
|
const drag = this.dragElements
|
|
1706
1707
|
.on('start drag end', (event, d) => {
|
|
1707
1708
|
d.value = this.scale.invert(event[AxisOrientation[this.axis.orientation]]);
|
|
1709
|
+
if (d.max !== null && d.max !== undefined && d.value >= d.max) {
|
|
1710
|
+
d.value = d.max;
|
|
1711
|
+
}
|
|
1712
|
+
if (d.min !== null && d.min !== undefined && d.value <= d.min) {
|
|
1713
|
+
d.value = d.min;
|
|
1714
|
+
}
|
|
1708
1715
|
this.emit({
|
|
1709
1716
|
event,
|
|
1710
1717
|
target: d,
|
|
@@ -2020,7 +2027,10 @@ class ZoomableDirective {
|
|
|
2020
2027
|
if (event.sourceEvent) {
|
|
2021
2028
|
if (Object.keys(event.sourceEvent).length !== 0) {
|
|
2022
2029
|
const origin = this.axis.scale.copy().domain(this.axis.originDomain);
|
|
2023
|
-
|
|
2030
|
+
if (this.axis.options.scaleType.type === ScaleType.band) {
|
|
2031
|
+
return;
|
|
2032
|
+
}
|
|
2033
|
+
const domain = this.axis.orientation === AxisOrientation.y
|
|
2024
2034
|
? event.transform.rescaleY(origin).domain()
|
|
2025
2035
|
: event.transform.rescaleX(origin).domain();
|
|
2026
2036
|
const message = new ZoomMessage({
|
|
@@ -2030,7 +2040,7 @@ class ZoomableDirective {
|
|
|
2030
2040
|
orientation: this.axis.orientation,
|
|
2031
2041
|
},
|
|
2032
2042
|
element: this.elementRef,
|
|
2033
|
-
domain
|
|
2043
|
+
domain,
|
|
2034
2044
|
chartId: this.config.id
|
|
2035
2045
|
});
|
|
2036
2046
|
this.zoomService.fireZoom(message);
|
|
@@ -2051,7 +2061,7 @@ class ZoomableDirective {
|
|
|
2051
2061
|
this.initZoomSync();
|
|
2052
2062
|
}
|
|
2053
2063
|
ngOnDestroy() {
|
|
2054
|
-
this.zoom?.on('
|
|
2064
|
+
this.zoom?.on('zoom end', null);
|
|
2055
2065
|
this._element?.on('wheel', null);
|
|
2056
2066
|
this.alive = false;
|
|
2057
2067
|
}
|
|
@@ -2085,28 +2095,28 @@ class ZoomableDirective {
|
|
|
2085
2095
|
[0, 0],
|
|
2086
2096
|
[this.size.width, this.size.height],
|
|
2087
2097
|
]);
|
|
2088
|
-
const min = this.config?.zoom?.minTranslate
|
|
2098
|
+
const min = this.config?.zoom?.minTranslate != null
|
|
2089
2099
|
? this.axis.scale(this.config?.zoom?.minTranslate)
|
|
2090
2100
|
: -Infinity;
|
|
2091
|
-
const max = (this.config?.zoom?.maxTranslate
|
|
2092
|
-
? this.axis.scale(this.config?.zoom?.maxTranslate)
|
|
2101
|
+
const max = (this.config?.zoom?.maxTranslate != null
|
|
2102
|
+
? this.axis.scale(this.config?.zoom?.maxTranslate)
|
|
2093
2103
|
: Infinity);
|
|
2094
2104
|
if (this.axis.orientation === AxisOrientation.x && this.config.zoom.type === ZoomType.x) {
|
|
2095
2105
|
this.zoom.translateExtent([
|
|
2096
|
-
[min, -Infinity],
|
|
2097
|
-
[max, Infinity],
|
|
2106
|
+
[Math.min(min, max), -Infinity],
|
|
2107
|
+
[Math.max(min, max), Infinity],
|
|
2098
2108
|
]);
|
|
2099
2109
|
}
|
|
2100
2110
|
if (this.axis.orientation === AxisOrientation.y && this.config.zoom.type === ZoomType.y) {
|
|
2101
2111
|
this.zoom.translateExtent([
|
|
2102
|
-
[-Infinity, min],
|
|
2103
|
-
[Infinity, max],
|
|
2112
|
+
[-Infinity, Math.min(min, max)],
|
|
2113
|
+
[Infinity, Math.max(min, max)],
|
|
2104
2114
|
]);
|
|
2105
2115
|
}
|
|
2106
2116
|
if (this.config.zoom?.wheelDelta) {
|
|
2107
2117
|
this.zoom.wheelDelta(this.config.zoom?.wheelDelta);
|
|
2108
2118
|
}
|
|
2109
|
-
if (this.axis.options.scaleType.type
|
|
2119
|
+
if (this.axis.options.scaleType.type !== ScaleType.band) {
|
|
2110
2120
|
const extremes = this.axis.extremes;
|
|
2111
2121
|
const maxZoom = this.config.zoom?.max
|
|
2112
2122
|
? (extremes[1] - extremes[0]) /
|
|
@@ -2120,7 +2130,7 @@ class ZoomableDirective {
|
|
|
2120
2130
|
: Infinity;
|
|
2121
2131
|
this.zoom.scaleExtent([maxZoom, minZoom]);
|
|
2122
2132
|
}
|
|
2123
|
-
this.zoom.on('zoom end', this.zoomed);
|
|
2133
|
+
this.zoom.on('start zoom end', this.zoomed);
|
|
2124
2134
|
this._element.call(this.zoom).on('dblclick.zoom', null);
|
|
2125
2135
|
if (this.config?.zoom?.zoomBehavior === ZoomBehaviorType.wheel) {
|
|
2126
2136
|
this.runWheelTranslate();
|
|
@@ -2158,6 +2168,13 @@ class ZoomableDirective {
|
|
|
2158
2168
|
let domain = this.axis.orientation === AxisOrientation.y
|
|
2159
2169
|
? transform.rescaleY(origin).domain()
|
|
2160
2170
|
: transform.rescaleX(origin).domain();
|
|
2171
|
+
const extent = this.axis.options?.inverted ? domain : [...domain].reverse();
|
|
2172
|
+
if (extent[0] <= this.config.zoom?.minTranslate) {
|
|
2173
|
+
return;
|
|
2174
|
+
}
|
|
2175
|
+
if (extent[1] >= this.config.zoom?.maxTranslate) {
|
|
2176
|
+
return;
|
|
2177
|
+
}
|
|
2161
2178
|
const message = new ZoomMessage({
|
|
2162
2179
|
eventType: type,
|
|
2163
2180
|
element: this.elementRef,
|