mdt-charts 1.27.4 → 1.28.0
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/lib/config/config.d.ts +8 -0
- package/lib/engine/features/valueLabels/valueLabels.js +30 -12
- package/lib/engine/features/valueLabelsCollision/valueLabelsCollision.js +1 -1
- package/lib/model/featuresModel/valueLabelsModel/valueLabelsModel.d.ts +4 -4
- package/lib/model/featuresModel/valueLabelsModel/valueLabelsModel.js +9 -6
- package/lib/model/helpers/twoDimensionalModelHelper.js +4 -4
- package/lib/model/model.d.ts +6 -1
- package/lib/model/notations/twoDimensionalModel.js +14 -13
- package/package.json +1 -1
package/lib/config/config.d.ts
CHANGED
|
@@ -297,6 +297,14 @@ export interface TwoDimensionalChartValueLabels {
|
|
|
297
297
|
mode?: ValueLabelsPositionMode;
|
|
298
298
|
};
|
|
299
299
|
format?: ValueLabelsFormatter;
|
|
300
|
+
rotation?: ValueLabelsRotationOptions;
|
|
301
|
+
handleElement?: (elInfo: {
|
|
302
|
+
element: SVGTextElement;
|
|
303
|
+
value: number;
|
|
304
|
+
}) => void;
|
|
305
|
+
}
|
|
306
|
+
export interface ValueLabelsRotationOptions {
|
|
307
|
+
angle?: number;
|
|
300
308
|
}
|
|
301
309
|
export declare type ValueLabelsFormatter = (value: number) => string;
|
|
302
310
|
export declare type TwoDimensionalValueGroup = "main" | "secondary";
|
|
@@ -78,23 +78,42 @@ export class ChartValueLabels {
|
|
|
78
78
|
}
|
|
79
79
|
setAttrs(valueLabels, attrs, valueFieldName, formatter, dataRowAccessor, animate = false, onEndAnimation) {
|
|
80
80
|
const animationName = "labels-updating";
|
|
81
|
-
valueLabels
|
|
81
|
+
let selection = valueLabels
|
|
82
82
|
.text((d) => formatter(dataRowAccessor(d)[valueFieldName]))
|
|
83
83
|
.attr("dominant-baseline", attrs.dominantBaseline)
|
|
84
84
|
.attr("text-anchor", attrs.textAnchor);
|
|
85
85
|
if (animate) {
|
|
86
|
-
|
|
86
|
+
selection = selection
|
|
87
87
|
.interrupt(animationName)
|
|
88
88
|
.transition(animationName)
|
|
89
|
-
.duration(this.globalOptions.elementAccessors.getBlock().transitionManager.durations.chartUpdate)
|
|
90
|
-
.attr("x", (d) => attrs.x(d))
|
|
91
|
-
.attr("y", (d) => attrs.y(d));
|
|
92
|
-
if (onEndAnimation)
|
|
93
|
-
transition.on("end", onEndAnimation);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
valueLabels.attr("x", (d) => attrs.x(d)).attr("y", (d) => attrs.y(d));
|
|
89
|
+
.duration(this.globalOptions.elementAccessors.getBlock().transitionManager.durations.chartUpdate);
|
|
97
90
|
}
|
|
91
|
+
selection
|
|
92
|
+
.attr("x", (d) => attrs.x(d))
|
|
93
|
+
.attr("y", (d) => attrs.y(d))
|
|
94
|
+
.attr("transform", (d) => {
|
|
95
|
+
var _a;
|
|
96
|
+
return ((_a = this.chart.valueLabels.rotation) === null || _a === void 0 ? void 0 : _a.angle) ? `rotate(${this.chart.valueLabels.rotation.angle}, ${attrs.x(d)}, ${attrs.y(d)})`
|
|
97
|
+
: null;
|
|
98
|
+
});
|
|
99
|
+
const handleElements = () => {
|
|
100
|
+
if (this.chart.valueLabels.handleElement) {
|
|
101
|
+
const thisClass = this;
|
|
102
|
+
selection.each(function (d) {
|
|
103
|
+
thisClass.chart.valueLabels.handleElement({
|
|
104
|
+
element: this,
|
|
105
|
+
value: dataRowAccessor(d)[valueFieldName]
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
if (animate)
|
|
111
|
+
selection.on("end", () => {
|
|
112
|
+
onEndAnimation();
|
|
113
|
+
handleElements();
|
|
114
|
+
});
|
|
115
|
+
else
|
|
116
|
+
handleElements();
|
|
98
117
|
}
|
|
99
118
|
setClasses(textLabels, cssClasses, vfIndex) {
|
|
100
119
|
textLabels.classed(ChartValueLabels.valueLabelClass, true);
|
|
@@ -134,8 +153,7 @@ export class CanvasValueLabels {
|
|
|
134
153
|
return this.chartsValueLabels[index].update(chartScales, data[dataOptions.dataSource], chart.valueLabels);
|
|
135
154
|
});
|
|
136
155
|
Promise.all(chartsUpdatePromises).then(() => {
|
|
137
|
-
|
|
138
|
-
ValueLabelsCollision.resolveValueLabelsCollisions(newValueLabels, valueLabelsSettings);
|
|
156
|
+
ValueLabelsCollision.resolveValueLabelsCollisions(this.getAllValueLabels(), valueLabelsSettings);
|
|
139
157
|
});
|
|
140
158
|
}
|
|
141
159
|
toggleOldValueLabelsVisibility() {
|
|
@@ -10,7 +10,7 @@ export class ValueLabelsCollision {
|
|
|
10
10
|
static getValueLabelElementsRectInfo(valueLabels) {
|
|
11
11
|
let ValueLabelElementsReactInfo = [];
|
|
12
12
|
valueLabels.each(function (_, index) {
|
|
13
|
-
const { height, width } = this.
|
|
13
|
+
const { height, width } = this.getBoundingClientRect();
|
|
14
14
|
const x = +this.getAttribute("x");
|
|
15
15
|
const y = +this.getAttribute("y");
|
|
16
16
|
ValueLabelElementsReactInfo.push({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BlockMargin, Orient, ValueLabelAnchor, ValueLabelDominantBaseline } from "../../model";
|
|
2
2
|
import { BoundingRect } from "../../../engine/features/valueLabelsCollision/valueLabelsCollision";
|
|
3
|
-
import { Size, ValueLabelsPositionMode } from "../../../config/config";
|
|
3
|
+
import { Size, ValueLabelsPositionMode, ValueLabelsRotationOptions } from "../../../config/config";
|
|
4
4
|
interface ValueLabelAlignment {
|
|
5
5
|
dominantBaseline: ValueLabelDominantBaseline;
|
|
6
6
|
textAnchor: ValueLabelAnchor;
|
|
@@ -15,13 +15,13 @@ export declare class ValueLabelCoordinateCalculator {
|
|
|
15
15
|
getValueLabelY(scaledValue: number): number;
|
|
16
16
|
getValueLabelX(scaledValue: number): number;
|
|
17
17
|
}
|
|
18
|
-
export declare function calculateValueLabelAlignment(keyAxisOrient: Orient, positionMode?: ValueLabelsPositionMode): ValueLabelAlignment;
|
|
18
|
+
export declare function calculateValueLabelAlignment(keyAxisOrient: Orient, positionMode?: ValueLabelsPositionMode, rotation?: ValueLabelsRotationOptions): ValueLabelAlignment;
|
|
19
19
|
export declare function hasCollisionLeftSide(labelClientRect: BoundingRect, margin: BlockMargin): boolean;
|
|
20
20
|
export declare function hasCollisionRightSide(labelClientRect: BoundingRect, blockSize: Size, margin: BlockMargin): boolean;
|
|
21
21
|
export declare function hasCollisionTopSide(labelClientRect: BoundingRect, margin: BlockMargin): boolean;
|
|
22
22
|
export declare function hasCollisionBottomSide(labelClientRect: BoundingRect, blockSize: Size, margin: BlockMargin): boolean;
|
|
23
|
-
export declare function shiftCoordinateXLeft(labelClientRect: BoundingRect): void;
|
|
24
|
-
export declare function shiftCoordinateXRight(labelClientRect: BoundingRect): void;
|
|
23
|
+
export declare function shiftCoordinateXLeft(labelClientRect: BoundingRect, blockSize: Size, margin: BlockMargin): void;
|
|
24
|
+
export declare function shiftCoordinateXRight(labelClientRect: BoundingRect, margin: BlockMargin): void;
|
|
25
25
|
export declare function shiftCoordinateYTop(labelClientRect: BoundingRect): void;
|
|
26
26
|
export declare function shiftCoordinateYBottom(labelClientRect: BoundingRect): void;
|
|
27
27
|
export {};
|
|
@@ -27,8 +27,8 @@ export class ValueLabelCoordinateCalculator {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
export function calculateValueLabelAlignment(keyAxisOrient, positionMode) {
|
|
31
|
-
if (
|
|
30
|
+
export function calculateValueLabelAlignment(keyAxisOrient, positionMode, rotation) {
|
|
31
|
+
if ((positionMode !== null && positionMode !== void 0 ? positionMode : "after") === "after" && !(rotation === null || rotation === void 0 ? void 0 : rotation.angle)) {
|
|
32
32
|
switch (keyAxisOrient) {
|
|
33
33
|
case "top":
|
|
34
34
|
return { dominantBaseline: "hanging", textAnchor: "middle" };
|
|
@@ -56,11 +56,14 @@ export function hasCollisionTopSide(labelClientRect, margin) {
|
|
|
56
56
|
export function hasCollisionBottomSide(labelClientRect, blockSize, margin) {
|
|
57
57
|
return labelClientRect.y + labelClientRect.height / 2 >= blockSize.height - margin.bottom;
|
|
58
58
|
}
|
|
59
|
-
export function shiftCoordinateXLeft(labelClientRect) {
|
|
60
|
-
|
|
59
|
+
export function shiftCoordinateXLeft(labelClientRect, blockSize, margin) {
|
|
60
|
+
const blockRightSide = blockSize.width - margin.right;
|
|
61
|
+
const labelRightSide = labelClientRect.x + labelClientRect.width / 2;
|
|
62
|
+
labelClientRect.x -= labelRightSide - blockRightSide + BORDER_OFFSET_SIZE_PX;
|
|
61
63
|
}
|
|
62
|
-
export function shiftCoordinateXRight(labelClientRect) {
|
|
63
|
-
labelClientRect.x
|
|
64
|
+
export function shiftCoordinateXRight(labelClientRect, margin) {
|
|
65
|
+
const labelLeftSide = labelClientRect.x - labelClientRect.width / 2;
|
|
66
|
+
labelClientRect.x += margin.left - labelLeftSide + BORDER_OFFSET_SIZE_PX;
|
|
64
67
|
}
|
|
65
68
|
export function shiftCoordinateYTop(labelClientRect) {
|
|
66
69
|
labelClientRect.y -= labelClientRect.height / 2 + BORDER_OFFSET_SIZE_PX;
|
|
@@ -70,12 +70,12 @@ export class TwoDimensionalModelHelper {
|
|
|
70
70
|
left: {
|
|
71
71
|
mode: "shift",
|
|
72
72
|
hasCollision: blockSidesOptions.hasCollisionLeft,
|
|
73
|
-
shiftCoordinate: blockSidesOptions.
|
|
73
|
+
shiftCoordinate: blockSidesOptions.shiftToRight
|
|
74
74
|
},
|
|
75
75
|
right: {
|
|
76
76
|
mode: "shift",
|
|
77
77
|
hasCollision: blockSidesOptions.hasCollisionRight,
|
|
78
|
-
shiftCoordinate: blockSidesOptions.
|
|
78
|
+
shiftCoordinate: blockSidesOptions.shiftToLeft
|
|
79
79
|
},
|
|
80
80
|
top: {
|
|
81
81
|
mode: "none"
|
|
@@ -116,9 +116,9 @@ export class TwoDimensionalModelHelper {
|
|
|
116
116
|
static getChartBlockSidesOptions(canvasModel) {
|
|
117
117
|
return {
|
|
118
118
|
hasCollisionLeft: (labelClientRect) => hasCollisionLeftSide(labelClientRect, canvasModel.getMargin()),
|
|
119
|
-
|
|
119
|
+
shiftToLeft: (labelClientRect) => shiftCoordinateXLeft(labelClientRect, canvasModel.getBlockSize(), canvasModel.getMargin()),
|
|
120
120
|
hasCollisionRight: (labelClientRect) => hasCollisionRightSide(labelClientRect, canvasModel.getBlockSize(), canvasModel.getMargin()),
|
|
121
|
-
|
|
121
|
+
shiftToRight: (labelClientRect) => shiftCoordinateXRight(labelClientRect, canvasModel.getMargin()),
|
|
122
122
|
hasCollisionTop: (labelClientRect) => hasCollisionTopSide(labelClientRect, canvasModel.getMargin()),
|
|
123
123
|
shiftTop: (labelClientRect) => shiftCoordinateYTop(labelClientRect),
|
|
124
124
|
hasCollisionBottom: (labelClientRect) => hasCollisionBottomSide(labelClientRect, canvasModel.getBlockSize(), canvasModel.getMargin()),
|
package/lib/model/model.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChartOrientation, MdtChartsColorField, IntervalChartType, PolarChartType, Size, TooltipOptions, TwoDimensionalChartType, AxisLabelPosition, ShowTickFn, MdtChartsDataRow, TwoDimensionalValueGroup, ValueLabelsCollisionMode } from "../config/config";
|
|
1
|
+
import { ChartOrientation, MdtChartsColorField, IntervalChartType, PolarChartType, Size, TooltipOptions, TwoDimensionalChartType, AxisLabelPosition, ShowTickFn, MdtChartsDataRow, TwoDimensionalValueGroup, ValueLabelsCollisionMode, ValueLabelsRotationOptions } from "../config/config";
|
|
2
2
|
import { DataType, DonutOptionsCanvas, Formatter, StaticLegendBlockCanvas, TooltipSettings, Transitions } from "../designer/designerConfig";
|
|
3
3
|
import { BoundingRect } from "../engine/features/valueLabelsCollision/valueLabelsCollision";
|
|
4
4
|
declare type AxisType = "key" | "value";
|
|
@@ -394,6 +394,11 @@ export interface TwoDimChartValueLabelsOptions {
|
|
|
394
394
|
dominantBaseline: ValueLabelDominantBaseline;
|
|
395
395
|
format: ValueLabelsFormatter;
|
|
396
396
|
handleScaledValue: (dataRow: MdtChartsDataRow, datumField: string) => number;
|
|
397
|
+
rotation?: ValueLabelsRotationOptions;
|
|
398
|
+
handleElement?: (elInfo: {
|
|
399
|
+
element: SVGTextElement;
|
|
400
|
+
value: number;
|
|
401
|
+
}) => void;
|
|
397
402
|
}
|
|
398
403
|
export declare type ValueLabelsFormatter = (value: number) => string;
|
|
399
404
|
export interface MarkersOptions {
|
|
@@ -74,9 +74,10 @@ export class TwoDimensionalModel {
|
|
|
74
74
|
const styleModel = new TwoDimensionalChartStyleModel(charts, designerConfig.chartStyle);
|
|
75
75
|
const chartsModel = [];
|
|
76
76
|
charts.forEach((chart, index) => {
|
|
77
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
77
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
78
78
|
const style = styleModel.getChartStyle(chart, index);
|
|
79
79
|
const valueLabelsCoordinateCalculator = new ValueLabelCoordinateCalculator((_b = (_a = chart.valueLabels) === null || _a === void 0 ? void 0 : _a.position) === null || _b === void 0 ? void 0 : _b.mode, keyAxisOrient, canvasModel.getMargin());
|
|
80
|
+
const valueLabelsAlignment = calculateValueLabelAlignment(keyAxisOrient, (_d = (_c = chart.valueLabels) === null || _c === void 0 ? void 0 : _c.position) === null || _d === void 0 ? void 0 : _d.mode, (_e = chart.valueLabels) === null || _e === void 0 ? void 0 : _e.rotation);
|
|
80
81
|
chartsModel.push({
|
|
81
82
|
type: chart.type,
|
|
82
83
|
isSegmented: chart.isSegmented,
|
|
@@ -90,28 +91,28 @@ export class TwoDimensionalModel {
|
|
|
90
91
|
styles: {
|
|
91
92
|
highlighted: {
|
|
92
93
|
size: {
|
|
93
|
-
radius: (
|
|
94
|
+
radius: (_h = (_g = (_f = designerConfig.canvas.markers) === null || _f === void 0 ? void 0 : _f.highlighted) === null || _g === void 0 ? void 0 : _g.radius) !== null && _h !== void 0 ? _h : 4,
|
|
94
95
|
borderSize: "3.5px"
|
|
95
96
|
}
|
|
96
97
|
},
|
|
97
98
|
normal: {
|
|
98
99
|
size: {
|
|
99
|
-
radius: (
|
|
100
|
-
borderSize: `${(
|
|
100
|
+
radius: (_l = (_k = (_j = designerConfig.canvas.markers) === null || _j === void 0 ? void 0 : _j.normal) === null || _k === void 0 ? void 0 : _k.radius) !== null && _l !== void 0 ? _l : 3,
|
|
101
|
+
borderSize: `${(_p = (_o = (_m = designerConfig.canvas.markers) === null || _m === void 0 ? void 0 : _m.normal) === null || _o === void 0 ? void 0 : _o.borderSize) !== null && _p !== void 0 ? _p : 2}px`
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
105
|
},
|
|
105
106
|
lineLikeViewOptions: {
|
|
106
|
-
dashedStyles: parseDashStyles((
|
|
107
|
-
strokeWidth: (
|
|
107
|
+
dashedStyles: parseDashStyles((_q = chart.lineStyles) === null || _q === void 0 ? void 0 : _q.dash),
|
|
108
|
+
strokeWidth: (_s = (_r = chart.lineStyles) === null || _r === void 0 ? void 0 : _r.width) !== null && _s !== void 0 ? _s : LINE_CHART_DEFAULT_WIDTH,
|
|
108
109
|
renderForKey: (dataRow, valueFieldName) => dataRow[valueFieldName] !== null && dataRow[valueFieldName] !== undefined
|
|
109
110
|
},
|
|
110
111
|
barViewOptions: getBarViewOptions(chart, keyAxisOrient, calculateBarIndexes(charts, chart, index)),
|
|
111
112
|
legend: getLegendMarkerOptions(chart),
|
|
112
113
|
index,
|
|
113
114
|
valueLabels: {
|
|
114
|
-
show: (
|
|
115
|
+
show: (_u = (_t = chart.valueLabels) === null || _t === void 0 ? void 0 : _t.on) !== null && _u !== void 0 ? _u : false,
|
|
115
116
|
handleX: (scaledValue) => valueLabelsCoordinateCalculator.getValueLabelX(scaledValue),
|
|
116
117
|
handleY: (scaledValue) => valueLabelsCoordinateCalculator.getValueLabelY(scaledValue),
|
|
117
118
|
handleScaledValue: (dataRow, datumField) => {
|
|
@@ -123,11 +124,11 @@ export class TwoDimensionalModel {
|
|
|
123
124
|
else
|
|
124
125
|
return dataRow[datumField] / 2;
|
|
125
126
|
},
|
|
126
|
-
textAnchor:
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
textAnchor: valueLabelsAlignment.textAnchor,
|
|
128
|
+
dominantBaseline: valueLabelsAlignment.dominantBaseline,
|
|
129
|
+
format: configReader.getValueLabelFormatterForChart(index),
|
|
130
|
+
rotation: (_v = chart.valueLabels) === null || _v === void 0 ? void 0 : _v.rotation,
|
|
131
|
+
handleElement: (_w = chart.valueLabels) === null || _w === void 0 ? void 0 : _w.handleElement
|
|
131
132
|
},
|
|
132
133
|
areaViewOptions: getAreaViewOptions(chart, index, style, modelInstance.version.getVersionNumber()),
|
|
133
134
|
dotViewOptions: {
|
|
@@ -135,7 +136,7 @@ export class TwoDimensionalModel {
|
|
|
135
136
|
type: "line",
|
|
136
137
|
handleEndCoordinate: (v) => v + 2,
|
|
137
138
|
handleStartCoordinate: (v) => v - 2,
|
|
138
|
-
width: (
|
|
139
|
+
width: (_z = (_y = (_x = chart.dotLikeStyles) === null || _x === void 0 ? void 0 : _x.shape) === null || _y === void 0 ? void 0 : _y.width) !== null && _z !== void 0 ? _z : LINE_CHART_DEFAULT_WIDTH
|
|
139
140
|
}
|
|
140
141
|
}
|
|
141
142
|
});
|