mdt-charts 1.27.4 → 1.28.1

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.
@@ -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";
@@ -25,6 +25,8 @@ export class ChartValueLabels {
25
25
  if (this.chart.isSegmented) {
26
26
  const preparedData = getStackedData(data, this.chart);
27
27
  preparedData.forEach((segment, segmentIndex) => {
28
+ if (!segment[0])
29
+ return;
28
30
  this.renderByGroupIndex(scales, segmentIndex, segment, segment[0].fieldName, "1", (d) => d.data);
29
31
  });
30
32
  }
@@ -40,13 +42,14 @@ export class ChartValueLabels {
40
42
  if (this.chart.isSegmented) {
41
43
  const preparedData = getStackedData(newData, this.chart);
42
44
  preparedData.forEach((segment, segmentIndex) => {
43
- const promise = this.updateByGroupIndex(scales, segmentIndex, segment, segment[0].fieldName, "1", (d) => d.data);
45
+ var _a;
46
+ const promise = this.updateByGroupIndex(scales, segmentIndex, segment, "1", (d) => d.data, (_a = segment[0]) === null || _a === void 0 ? void 0 : _a.fieldName);
44
47
  updatePromises.push(promise);
45
48
  });
46
49
  }
47
50
  else {
48
51
  this.chart.data.valueFields.forEach((valueField, vfIndex) => {
49
- const promise = this.updateByGroupIndex(scales, vfIndex, newData, valueField.name, valueField.name, (d) => d);
52
+ const promise = this.updateByGroupIndex(scales, vfIndex, newData, valueField.name, (d) => d, valueField.name);
50
53
  updatePromises.push(promise);
51
54
  });
52
55
  }
@@ -59,11 +62,15 @@ export class ChartValueLabels {
59
62
  this.setAttrs(valueLabels, attrs, valueFieldName, this.options.format, dataRowAccessor);
60
63
  this.setClasses(valueLabels, this.chart.cssClasses, groupIndex);
61
64
  }
62
- updateByGroupIndex(scales, groupIndex, data, valueFieldName, datumField, dataRowAccessor) {
65
+ updateByGroupIndex(scales, groupIndex, data, datumField, dataRowAccessor, valueFieldName) {
63
66
  return new Promise((resolve) => {
64
67
  const valueLabels = this.getAllValueLabelsOfChart(groupIndex).data(data);
65
68
  valueLabels.exit().remove();
66
69
  const attrs = this.attrsProvider.getAttrs(this.globalOptions, this.options, scales, datumField, dataRowAccessor);
70
+ if (!valueFieldName) {
71
+ resolve();
72
+ return;
73
+ }
67
74
  let newValueLabels = valueLabels.enter().append("text");
68
75
  newValueLabels = this.renderPipeline.execute(newValueLabels, { style: this.globalOptions.canvas.style });
69
76
  const mergedValueLabels = newValueLabels.merge(valueLabels);
@@ -78,23 +85,42 @@ export class ChartValueLabels {
78
85
  }
79
86
  setAttrs(valueLabels, attrs, valueFieldName, formatter, dataRowAccessor, animate = false, onEndAnimation) {
80
87
  const animationName = "labels-updating";
81
- valueLabels
88
+ let selection = valueLabels
82
89
  .text((d) => formatter(dataRowAccessor(d)[valueFieldName]))
83
90
  .attr("dominant-baseline", attrs.dominantBaseline)
84
91
  .attr("text-anchor", attrs.textAnchor);
85
92
  if (animate) {
86
- const transition = valueLabels
93
+ selection = selection
87
94
  .interrupt(animationName)
88
95
  .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));
96
+ .duration(this.globalOptions.elementAccessors.getBlock().transitionManager.durations.chartUpdate);
97
97
  }
98
+ selection
99
+ .attr("x", (d) => attrs.x(d))
100
+ .attr("y", (d) => attrs.y(d))
101
+ .attr("transform", (d) => {
102
+ var _a;
103
+ 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)})`
104
+ : null;
105
+ });
106
+ const handleElements = () => {
107
+ if (this.chart.valueLabels.handleElement) {
108
+ const thisClass = this;
109
+ selection.each(function (d) {
110
+ thisClass.chart.valueLabels.handleElement({
111
+ element: this,
112
+ value: dataRowAccessor(d)[valueFieldName]
113
+ });
114
+ });
115
+ }
116
+ };
117
+ if (animate)
118
+ selection.on("end", () => {
119
+ onEndAnimation();
120
+ handleElements();
121
+ });
122
+ else
123
+ handleElements();
98
124
  }
99
125
  setClasses(textLabels, cssClasses, vfIndex) {
100
126
  textLabels.classed(ChartValueLabels.valueLabelClass, true);
@@ -134,8 +160,7 @@ export class CanvasValueLabels {
134
160
  return this.chartsValueLabels[index].update(chartScales, data[dataOptions.dataSource], chart.valueLabels);
135
161
  });
136
162
  Promise.all(chartsUpdatePromises).then(() => {
137
- const newValueLabels = this.getAllValueLabels();
138
- ValueLabelsCollision.resolveValueLabelsCollisions(newValueLabels, valueLabelsSettings);
163
+ ValueLabelsCollision.resolveValueLabelsCollisions(this.getAllValueLabels(), valueLabelsSettings);
139
164
  });
140
165
  }
141
166
  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.getBBox();
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 (!positionMode || positionMode === "after") {
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
- labelClientRect.x -= labelClientRect.width / 2 + BORDER_OFFSET_SIZE_PX;
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 += labelClientRect.width / 2 + BORDER_OFFSET_SIZE_PX;
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.shiftRight
73
+ shiftCoordinate: blockSidesOptions.shiftToRight
74
74
  },
75
75
  right: {
76
76
  mode: "shift",
77
77
  hasCollision: blockSidesOptions.hasCollisionRight,
78
- shiftCoordinate: blockSidesOptions.shiftLeft
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
- shiftLeft: (labelClientRect) => shiftCoordinateXLeft(labelClientRect),
119
+ shiftToLeft: (labelClientRect) => shiftCoordinateXLeft(labelClientRect, canvasModel.getBlockSize(), canvasModel.getMargin()),
120
120
  hasCollisionRight: (labelClientRect) => hasCollisionRightSide(labelClientRect, canvasModel.getBlockSize(), canvasModel.getMargin()),
121
- shiftRight: (labelClientRect) => shiftCoordinateXRight(labelClientRect),
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()),
@@ -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: (_e = (_d = (_c = designerConfig.canvas.markers) === null || _c === void 0 ? void 0 : _c.highlighted) === null || _d === void 0 ? void 0 : _d.radius) !== null && _e !== void 0 ? _e : 4,
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: (_h = (_g = (_f = designerConfig.canvas.markers) === null || _f === void 0 ? void 0 : _f.normal) === null || _g === void 0 ? void 0 : _g.radius) !== null && _h !== void 0 ? _h : 3,
100
- borderSize: `${(_l = (_k = (_j = designerConfig.canvas.markers) === null || _j === void 0 ? void 0 : _j.normal) === null || _k === void 0 ? void 0 : _k.borderSize) !== null && _l !== void 0 ? _l : 2}px`
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((_m = chart.lineStyles) === null || _m === void 0 ? void 0 : _m.dash),
107
- strokeWidth: (_p = (_o = chart.lineStyles) === null || _o === void 0 ? void 0 : _o.width) !== null && _p !== void 0 ? _p : LINE_CHART_DEFAULT_WIDTH,
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: (_r = (_q = chart.valueLabels) === null || _q === void 0 ? void 0 : _q.on) !== null && _r !== void 0 ? _r : false,
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: calculateValueLabelAlignment(keyAxisOrient, (_t = (_s = chart.valueLabels) === null || _s === void 0 ? void 0 : _s.position) === null || _t === void 0 ? void 0 : _t.mode)
127
- .textAnchor,
128
- dominantBaseline: calculateValueLabelAlignment(keyAxisOrient, (_v = (_u = chart.valueLabels) === null || _u === void 0 ? void 0 : _u.position) === null || _v === void 0 ? void 0 : _v.mode)
129
- .dominantBaseline,
130
- format: configReader.getValueLabelFormatterForChart(index)
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: (_y = (_x = (_w = chart.dotLikeStyles) === null || _w === void 0 ? void 0 : _w.shape) === null || _x === void 0 ? void 0 : _x.width) !== null && _y !== void 0 ? _y : LINE_CHART_DEFAULT_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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdt-charts",
3
- "version": "1.27.4",
3
+ "version": "1.28.1",
4
4
  "description": "",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {