mdt-charts 1.21.2 → 1.23.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.
Files changed (50) hide show
  1. package/lib/config/config.d.ts +51 -15
  2. package/lib/engine/features/axis/axis.js +2 -0
  3. package/lib/engine/features/gridLine/gridLine.d.ts +3 -5
  4. package/lib/engine/features/gridLine/gridLine.js +15 -32
  5. package/lib/engine/features/legend/legend.d.ts +3 -0
  6. package/lib/engine/features/legend/legend.js +3 -0
  7. package/lib/engine/features/legend/legendHelper.d.ts +1 -0
  8. package/lib/engine/features/legend/legendHelper.js +11 -2
  9. package/lib/engine/features/legend/legendHelperService.d.ts +0 -1
  10. package/lib/engine/features/legend/legendHelperService.js +0 -3
  11. package/lib/engine/features/legend/legendMarkerCreator.js +7 -4
  12. package/lib/engine/features/valueLabels/valueLabels.d.ts +0 -1
  13. package/lib/engine/features/valueLabels/valueLabels.js +9 -14
  14. package/lib/engine/features/valueLabelsCollision/valueLabelsCollision.d.ts +7 -2
  15. package/lib/engine/features/valueLabelsCollision/valueLabelsCollision.js +25 -1
  16. package/lib/engine/twoDimensionalNotation/bar/bar.d.ts +1 -0
  17. package/lib/engine/twoDimensionalNotation/bar/bar.js +14 -9
  18. package/lib/engine/twoDimensionalNotation/bar/barHelper.d.ts +38 -6
  19. package/lib/engine/twoDimensionalNotation/bar/barHelper.js +67 -22
  20. package/lib/engine/twoDimensionalNotation/dot/dotChart.d.ts +36 -0
  21. package/lib/engine/twoDimensionalNotation/dot/dotChart.js +106 -0
  22. package/lib/engine/twoDimensionalNotation/line/lineHelper.js +4 -0
  23. package/lib/engine/twoDimensionalNotation/twoDimensionalManager.d.ts +1 -0
  24. package/lib/engine/twoDimensionalNotation/twoDimensionalManager.js +22 -2
  25. package/lib/model/dataManagerModel/dataManagerModel.d.ts +1 -2
  26. package/lib/model/dataManagerModel/dataManagerModel.js +15 -33
  27. package/lib/model/featuresModel/axisModel.d.ts +0 -1
  28. package/lib/model/featuresModel/axisModel.js +12 -32
  29. package/lib/model/featuresModel/legendModel/legendCanvasModel.d.ts +0 -1
  30. package/lib/model/featuresModel/legendModel/legendCanvasModel.js +0 -18
  31. package/lib/model/featuresModel/legendModel/legendModel.js +1 -1
  32. package/lib/model/featuresModel/legendModel/twoDimLegendModel.d.ts +2 -2
  33. package/lib/model/featuresModel/legendModel/twoDimLegendModel.js +3 -1
  34. package/lib/model/featuresModel/scaleModel/scaleModel.d.ts +1 -1
  35. package/lib/model/featuresModel/scaleModel/scaleModel.js +5 -5
  36. package/lib/model/featuresModel/scaleModel/scaleModelServices.d.ts +1 -1
  37. package/lib/model/featuresModel/scaleModel/scaleModelServices.js +15 -9
  38. package/lib/model/featuresModel/valueLabelsModel/valueLabelsModel.d.ts +6 -0
  39. package/lib/model/featuresModel/valueLabelsModel/valueLabelsModel.js +13 -0
  40. package/lib/model/model.d.ts +66 -6
  41. package/lib/model/modelBuilder.js +1 -3
  42. package/lib/model/modelInstance/configReader.js +5 -5
  43. package/lib/model/notations/polar/polarModel.js +11 -3
  44. package/lib/model/notations/twoDimensional/styles.d.ts +4 -1
  45. package/lib/model/notations/twoDimensional/styles.js +61 -4
  46. package/lib/model/notations/twoDimensionalModel.d.ts +2 -1
  47. package/lib/model/notations/twoDimensionalModel.js +66 -16
  48. package/lib/style/charts-main.css +9 -8
  49. package/lib/style/charts-main.less +9 -8
  50. package/package.json +1 -1
@@ -4,11 +4,12 @@ export declare type AxisPosition = 'start' | 'end';
4
4
  export declare type ChartOrientation = 'vertical' | 'horizontal';
5
5
  export declare type ChartNotation = '2d' | 'polar' | 'interval';
6
6
  export declare type ChartType = 'bar' | 'line' | 'area' | 'donut' | 'gantt';
7
- export declare type TwoDimensionalChartType = 'line' | 'bar' | 'area';
7
+ export declare type TwoDimensionalChartType = 'line' | 'bar' | 'area' | 'dot';
8
8
  export declare type PolarChartType = 'donut';
9
9
  export declare type IntervalChartType = 'gantt';
10
10
  export declare type EmbeddedLabelType = 'none' | 'key' | 'value';
11
11
  export declare type ValueLabelsCollisionMode = "none" | "hide";
12
+ export declare type TwoDimLegendPosition = "top" | "bottom";
12
13
  export declare type MdtChartsDataRow = {
13
14
  [field: string]: any;
14
15
  };
@@ -44,7 +45,7 @@ interface BasicOptions {
44
45
  }
45
46
  interface GraphicNotationOptions extends BasicOptions {
46
47
  data: DataOptions;
47
- legend: Legend;
48
+ legend: MdtChartsTwoDimLegend;
48
49
  title?: Title;
49
50
  selectable: boolean;
50
51
  }
@@ -54,7 +55,7 @@ export interface MdtChartsTwoDimensionalOptions extends GraphicNotationOptions {
54
55
  additionalElements: AdditionalElements;
55
56
  charts: MdtChartsTwoDimensionalChart[];
56
57
  orientation: ChartOrientation;
57
- valueLabels?: TwoDimensionalValueLabels;
58
+ valueLabels?: MdtChartsTwoDimensionalValueLabels;
58
59
  }
59
60
  export interface MdtChartsPolarOptions extends GraphicNotationOptions {
60
61
  type: 'polar';
@@ -70,6 +71,9 @@ export interface MdtChartsIntervalOptions extends GraphicNotationOptions {
70
71
  export interface Legend {
71
72
  show: boolean;
72
73
  }
74
+ export interface MdtChartsTwoDimLegend extends Legend {
75
+ position?: TwoDimLegendPosition;
76
+ }
73
77
  export interface TitleFunctionParams {
74
78
  data: MdtChartsDataRow[];
75
79
  }
@@ -125,11 +129,18 @@ export interface AdditionalElements {
125
129
  }
126
130
  interface GridLineOptions {
127
131
  flag: GridLineFlag;
132
+ styles?: GridLineStyles;
128
133
  }
129
134
  interface GridLineFlag {
130
135
  key: boolean;
131
136
  value: boolean;
132
137
  }
138
+ interface GridLineStyles {
139
+ dash?: GridLineStylesDash;
140
+ }
141
+ interface GridLineStylesDash {
142
+ on?: boolean;
143
+ }
133
144
  export interface TwoDimensionalAxis {
134
145
  key: DiscreteAxisOptions;
135
146
  value: NumberAxisOptions;
@@ -140,10 +151,15 @@ export interface AxisOptions {
140
151
  visibility: boolean;
141
152
  position: AxisPosition;
142
153
  ticks: AxisTicks;
154
+ line?: AxisLineOptions;
143
155
  }
144
156
  interface AxisTicks {
145
157
  flag: boolean;
146
158
  }
159
+ interface AxisLineOptions {
160
+ /** @default true */
161
+ visible?: boolean;
162
+ }
147
163
  export interface NumberAxisOptions extends AxisOptions {
148
164
  domain: AxisNumberDomain;
149
165
  labels?: NumberAxisLabel;
@@ -174,10 +190,13 @@ export interface MdtChartsShowAxisLabelRule {
174
190
  spaceForOneLabel?: number;
175
191
  showTickFn?: ShowTickFn;
176
192
  }
177
- export interface TwoDimensionalValueLabels {
193
+ export interface MdtChartsTwoDimensionalValueLabels {
178
194
  collision: ValueLabelsCollision;
179
195
  }
180
196
  export interface ValueLabelsCollision {
197
+ otherValueLabels: OtherValueLabels;
198
+ }
199
+ export interface OtherValueLabels {
181
200
  mode: ValueLabelsCollisionMode;
182
201
  }
183
202
  export interface IntervalAxis {
@@ -186,12 +205,6 @@ export interface IntervalAxis {
186
205
  }
187
206
  interface DateAxisOptions extends AxisOptions {
188
207
  }
189
- interface ChartSettings {
190
- tooltip: Tooltip;
191
- }
192
- interface Tooltip {
193
- show: boolean;
194
- }
195
208
  interface MdtChartsLineLikeChart {
196
209
  markers: MarkersOptions;
197
210
  lineStyles?: MdtChartsLineLikeChartStyles;
@@ -199,6 +212,10 @@ interface MdtChartsLineLikeChart {
199
212
  }
200
213
  export interface MdtChartsLineLikeChartStyles {
201
214
  dash?: MdtChartsLineLikeChartDashedStyles;
215
+ /**
216
+ * @default 2
217
+ */
218
+ width?: number;
202
219
  }
203
220
  export interface MdtChartsLineLikeChartDashedStyles {
204
221
  on: boolean;
@@ -217,26 +234,45 @@ export interface AreaStylesBorderLine {
217
234
  }
218
235
  interface MdtChartsBarLikeChart {
219
236
  barStyles?: MdtChartsBarLikeChartStyles;
237
+ embeddedLabels: EmbeddedLabelType;
220
238
  }
221
- interface MdtChartsBarLikeChartStyles {
239
+ export interface MdtChartsBarLikeChartStyles {
222
240
  hatch?: MdtChartsBarLikeChartHatchedStyles;
241
+ borderRadius?: MdtChartsBarLikeChartBorderRadius;
242
+ }
243
+ interface MdtChartsBarLikeChartBorderRadius {
244
+ /**
245
+ * @default 2
246
+ */
247
+ value?: number;
223
248
  }
224
249
  interface MdtChartsBarLikeChartHatchedStyles {
225
250
  on: boolean;
226
251
  }
227
- export interface MdtChartsTwoDimensionalChart extends ChartSettings, MdtChartsLineLikeChart, MdtChartsBarLikeChart {
252
+ interface MdtChartsDotChart {
253
+ /** @alpha */
254
+ dotLikeStyles?: MdtChartsDotLikeChartStyles;
255
+ }
256
+ interface MdtChartsDotLikeChartStyles {
257
+ shape?: MdtChartsDotLikeChartShape;
258
+ }
259
+ interface MdtChartsDotLikeChartShape {
260
+ type: "line";
261
+ width?: number;
262
+ }
263
+ export interface MdtChartsTwoDimensionalChart extends MdtChartsLineLikeChart, MdtChartsBarLikeChart, MdtChartsDotChart {
264
+ /** @alpha dot type has no full support */
228
265
  type: TwoDimensionalChartType;
229
266
  data: TwoDimensionalChartData;
230
- embeddedLabels: EmbeddedLabelType;
231
267
  isSegmented: boolean;
232
268
  valueLabels?: TwoDimensionalChartValueLabels;
233
269
  }
234
- export interface PolarChart extends ChartSettings {
270
+ export interface PolarChart {
235
271
  type: PolarChartType;
236
272
  data: PolarChartData;
237
273
  aggregator?: MdtChartsDonutAggregator;
238
274
  }
239
- export interface IntervalChart extends ChartSettings {
275
+ export interface IntervalChart {
240
276
  type: IntervalChartType;
241
277
  data: IntervalChartData;
242
278
  }
@@ -44,6 +44,8 @@ export class Axis {
44
44
  .append('g')
45
45
  .attr('class', `${this.axesClass} ${axisOptions.cssClass} data-label`);
46
46
  AxisDomHelper.updateAxisElement(axisGenerator, axisElement, axisOptions.translate);
47
+ if (!axisOptions.line.visible)
48
+ axisElement.select('.domain').style('display', 'none');
47
49
  if (!axisOptions.labels.visible) {
48
50
  AxisLabelHelper.hideLabels(axisElement);
49
51
  return;
@@ -1,13 +1,11 @@
1
1
  import { Size } from "../../../config/config";
2
- import { BlockMargin, GridLineFlag, IAxisModel } from "../../../model/model";
2
+ import { BlockMargin, GridLineOptions, IAxisModel } from "../../../model/model";
3
3
  import { Block } from "../../block/block";
4
4
  import { Scales } from "../scale/scale";
5
5
  export declare class GridLine {
6
6
  private static readonly gridLineClass;
7
- static render(block: Block, gridLineFlag: GridLineFlag, axes: IAxisModel, blockSize: Size, margin: BlockMargin, scales: Scales): void;
8
- static update(block: Block, gridLineFlag: GridLineFlag, axes: IAxisModel, blockSize: Size, margin: BlockMargin, scales: Scales): void;
7
+ static render(block: Block, options: GridLineOptions, axes: IAxisModel, blockSize: Size, margin: BlockMargin, scales: Scales): void;
8
+ static update(block: Block, options: GridLineOptions, axes: IAxisModel, blockSize: Size, margin: BlockMargin, scales: Scales): void;
9
9
  private static renderLine;
10
10
  private static clear;
11
- private static removeGridLinesOnAxes;
12
- private static rmGridLineOnTick;
13
11
  }
@@ -1,23 +1,25 @@
1
1
  import { GridLineHelper } from "./gidLineHelper";
2
2
  export class GridLine {
3
- static render(block, gridLineFlag, axes, blockSize, margin, scales) {
4
- if (gridLineFlag.value) {
3
+ static render(block, options, axes, blockSize, margin, scales) {
4
+ if (options.flag.value) {
5
5
  const lineLength = GridLineHelper.getGridLineLength('value', axes.key, axes.value, blockSize, margin);
6
6
  const lineAttributes = GridLineHelper.getLineAttributes(axes.value, lineLength);
7
- this.renderLine(block, axes.value, lineAttributes);
7
+ this.renderLine(block, axes.value, lineAttributes, options)
8
+ .style('display', (d, i, group) => {
9
+ return d === 0 ? 'none' : 'block';
10
+ });
8
11
  }
9
- if (gridLineFlag.key) {
12
+ if (options.flag.key) {
10
13
  const lineAttributes = GridLineHelper.getKeyLineAttributes(axes.key, scales.value);
11
- this.renderLine(block, axes.key, lineAttributes);
14
+ this.renderLine(block, axes.key, lineAttributes, options);
12
15
  }
13
- this.removeGridLinesOnAxes(block, axes.key, axes.value, true);
14
16
  }
15
- static update(block, gridLineFlag, axes, blockSize, margin, scales) {
17
+ static update(block, options, axes, blockSize, margin, scales) {
16
18
  this.clear(block, axes.key.cssClass, axes.value.cssClass);
17
- this.render(block, gridLineFlag, axes, blockSize, margin, scales);
19
+ this.render(block, options, axes, blockSize, margin, scales);
18
20
  }
19
- static renderLine(block, axis, lineAttributes) {
20
- block
21
+ static renderLine(block, axis, lineAttributes, options) {
22
+ const gridLine = block
21
23
  .getSvg()
22
24
  .selectAll(`.${axis.cssClass}`)
23
25
  .selectAll('g.tick')
@@ -27,6 +29,9 @@ export class GridLine {
27
29
  .attr('y1', lineAttributes.y1)
28
30
  .attr('x2', lineAttributes.x2)
29
31
  .attr('y2', lineAttributes.y2);
32
+ if (options.styles.dash.on)
33
+ gridLine.style('stroke-dasharray', 3);
34
+ return gridLine;
30
35
  }
31
36
  static clear(block, keyAxisClass, valueAxisClass) {
32
37
  block.getSvg()
@@ -40,27 +45,5 @@ export class GridLine {
40
45
  .selectAll(`.${this.gridLineClass}`)
41
46
  .remove();
42
47
  }
43
- static removeGridLinesOnAxes(block, keyAxis, valueAxis, excludeKey) {
44
- let tickOnKeyAxisSelector = '';
45
- let tickOnValueAxisSelector = '';
46
- if (valueAxis.orient === 'right' || valueAxis.orient === 'bottom')
47
- tickOnValueAxisSelector = ':last-of-type';
48
- if (keyAxis.orient === 'bottom' || keyAxis.orient === 'right')
49
- tickOnKeyAxisSelector = ':last-of-type';
50
- const tickOnKey = block.getSvg()
51
- .select(`.${valueAxis.cssClass}`)
52
- .select(`g.tick${tickOnKeyAxisSelector}`);
53
- const tickOnValue = block.getSvg()
54
- .select(`.${keyAxis.cssClass}`)
55
- .select(`g.tick${tickOnValueAxisSelector}`);
56
- // this.rmGridLineOnTick(tickOnKey);
57
- // if (!excludeKey)
58
- // this.rmGridLineOnTick(tickOnValue);
59
- }
60
- static rmGridLineOnTick(tick) {
61
- tick
62
- .select(`.${this.gridLineClass}`)
63
- .remove();
64
- }
65
48
  }
66
49
  GridLine.gridLineClass = 'grid-line';
@@ -18,6 +18,9 @@ export declare class Legend {
18
18
  static get(): Legend;
19
19
  static readonly objectClass = "legend-object";
20
20
  static readonly labelClass = "legend-label";
21
+ static readonly label2DClass = "legend-2d-label";
22
+ static readonly labelPolarClass = "legend-polar-label";
23
+ static readonly labelIntervalClass = "legend-interval-label";
21
24
  static readonly itemClass = "legend-item";
22
25
  static readonly markerClass = "legend-marker";
23
26
  static readonly markerCircle = "legend-circle";
@@ -110,6 +110,9 @@ export class Legend {
110
110
  }
111
111
  Legend.objectClass = 'legend-object';
112
112
  Legend.labelClass = 'legend-label';
113
+ Legend.label2DClass = 'legend-2d-label';
114
+ Legend.labelPolarClass = 'legend-polar-label';
115
+ Legend.labelIntervalClass = 'legend-interval-label';
113
116
  Legend.itemClass = 'legend-item';
114
117
  Legend.markerClass = 'legend-marker';
115
118
  Legend.markerCircle = 'legend-circle';
@@ -20,4 +20,5 @@ export declare class LegendHelper {
20
20
  static getSumOfItemsWidths(itemsWidth: number[], marginsLeft: number[]): number;
21
21
  static getLegendCoordinateByPosition(legendPosition: Orient, legendBlockModel: LegendBlockModel, blockSize: Size): LegendCoordinate;
22
22
  static getContentRenderingOptions(chartNotation: ChartNotation, legendPosition: LegendPosition, legendBlockModel: LegendBlockModel): LegendContentRenderingOptions;
23
+ private static getLegendClassByChartNotation;
23
24
  }
@@ -70,21 +70,30 @@ export class LegendHelper {
70
70
  }
71
71
  static getContentRenderingOptions(chartNotation, legendPosition, legendBlockModel) {
72
72
  const itemsDirection = this.service.getLegendItemsDirection(legendPosition);
73
+ const legendLabelClass = this.getLegendClassByChartNotation(chartNotation);
73
74
  return {
74
75
  wrapperClasses: [
75
76
  Legend.legendBlockClass,
77
+ chartNotation === "2d" ? "legend-block-centered" : "",
76
78
  this.service.getWrapperClassByItemsDirection(itemsDirection),
77
- this.service.getWrapperJustifyContentClass(itemsDirection, legendPosition),
78
79
  this.service.getWrapperClassByWrappingItems(legendPosition, chartNotation)
79
80
  ],
80
81
  shouldCropLabels: chartNotation === "2d",
81
82
  blockModel: legendBlockModel,
82
83
  itemsOptions: {
83
84
  markerClass: Legend.markerClass,
84
- labelClass: this.service.getLegendLabelClassByPosition(legendPosition, chartNotation, Legend.labelClass),
85
+ labelClass: this.service.getLegendLabelClassByPosition(legendPosition, chartNotation, legendLabelClass),
85
86
  wrapperClasses: [Legend.itemClass, this.service.getItemClasses(itemsDirection)]
86
87
  }
87
88
  };
88
89
  }
90
+ static getLegendClassByChartNotation(chartNotation) {
91
+ const legendClasses = {
92
+ '2d': Legend.label2DClass,
93
+ 'polar': Legend.labelPolarClass,
94
+ 'interval': Legend.labelIntervalClass
95
+ };
96
+ return `${Legend.labelClass} ${legendClasses[chartNotation]}`;
97
+ }
89
98
  }
90
99
  LegendHelper.service = new LegendHelperService();
@@ -3,7 +3,6 @@ import { LegendItemsDirection } from "../../../model/featuresModel/legendModel/l
3
3
  import { LegendPosition } from "../../../model/model";
4
4
  export declare class LegendHelperService {
5
5
  getWrapperClassByItemsDirection(itemsDirection: LegendItemsDirection): "legend-block-column" | "legend-block-row";
6
- getWrapperJustifyContentClass(itemsDirection: LegendItemsDirection, legendPosition: LegendPosition): "" | "legend-block-centered";
7
6
  getWrapperClassByWrappingItems(legendPosition: LegendPosition, chartNotation: ChartNotation): "legend-wrapper-with-wrap" | "legend-wrapper-without-wrap";
8
7
  getLegendLabelClassByPosition(legendPosition: LegendPosition, chartNotation: ChartNotation, initialLabelClass: string): string;
9
8
  getItemClasses(itemsDirection: LegendItemsDirection): string;
@@ -2,9 +2,6 @@ export class LegendHelperService {
2
2
  getWrapperClassByItemsDirection(itemsDirection) {
3
3
  return itemsDirection === "column" ? "legend-block-column" : "legend-block-row";
4
4
  }
5
- getWrapperJustifyContentClass(itemsDirection, legendPosition) {
6
- return itemsDirection === "column" && legendPosition === "right" ? "legend-block-centered" : "";
7
- }
8
5
  getWrapperClassByWrappingItems(legendPosition, chartNotation) {
9
6
  if (this.doesLegendInTopBy2d(legendPosition, chartNotation)) {
10
7
  return "legend-wrapper-without-wrap";
@@ -1,6 +1,7 @@
1
1
  import { Legend } from "./legend";
2
2
  import { HatchPatternDef } from "../../block/defs/hatchPattern";
3
3
  import { applyLineDash } from "../../twoDimensionalNotation/line/lineHelper";
4
+ import { getClipPathValue } from "../../../engine/twoDimensionalNotation/bar/barHelper";
4
5
  export class LegendMarkerCreator {
5
6
  create(selection, options) {
6
7
  const creator = getMarkerCreator(options);
@@ -51,7 +52,8 @@ class BarMarkerCreator extends SvgMarkerCreator {
51
52
  .attr('y', 0)
52
53
  .attr('height', this.options.width)
53
54
  .attr('width', this.options.width)
54
- .style('fill', color);
55
+ .style('fill', color)
56
+ .style('clip-path', getClipPathValue(this.options.borderRadius));
55
57
  if (this.options.hatch.on) {
56
58
  bars.style('mask', HatchPatternDef.getMaskValue());
57
59
  }
@@ -67,16 +69,17 @@ class LineMarkerCreator extends SvgMarkerCreator {
67
69
  this.options = options;
68
70
  }
69
71
  renderMarker(selection, color) {
70
- const svg = this.renderSvg(selection).style("width", this.options.width);
72
+ const svg = this.renderSvg(selection).style("width", this.options.length);
71
73
  const line = svg
72
74
  .append('line')
73
75
  .style('stroke', 'red')
74
76
  .classed("line", true)
75
77
  .attr('x1', 0)
76
- .attr('x2', this.options.width)
78
+ .attr('x2', this.options.length)
77
79
  .attr('y1', 5)
78
80
  .attr('y2', 5)
79
- .style('stroke', color);
81
+ .style('stroke', color)
82
+ .style('stroke-width', this.options.strokeWidth);
80
83
  if (this.options.dashedStyles.on) {
81
84
  applyLineDash(line, this.options.dashedStyles.dashSize, this.options.dashedStyles.gapSize);
82
85
  }
@@ -39,7 +39,6 @@ export declare class CanvasValueLabels {
39
39
  render(scales: ScalesWithSecondary, charts: TwoDimensionalChartModel[], data: MdtChartsDataSource, dataOptions: OptionsModelData): void;
40
40
  update(scales: ScalesWithSecondary, charts: TwoDimensionalChartModel[], data: MdtChartsDataSource, dataOptions: OptionsModelData): void;
41
41
  private toggleOldValueLabelsVisibility;
42
- private hideValueLabelsCollision;
43
42
  private getAllValueLabels;
44
43
  private getChartScales;
45
44
  }
@@ -84,6 +84,7 @@ export class CanvasValueLabels {
84
84
  this.chartsValueLabels = [];
85
85
  }
86
86
  render(scales, charts, data, dataOptions) {
87
+ const valueLabelsSettings = this.options.canvas.valueLabels;
87
88
  const chartsWithLabels = charts.filter(chart => { var _a; return (_a = chart.valueLabels) === null || _a === void 0 ? void 0 : _a.show; });
88
89
  if (chartsWithLabels.length === 0)
89
90
  return;
@@ -93,25 +94,24 @@ export class CanvasValueLabels {
93
94
  this.chartsValueLabels.push(chartValueLabels);
94
95
  chartValueLabels.render(chartScales, data[dataOptions.dataSource]);
95
96
  });
96
- if (this.options.canvas.valueLabels.collision.mode === 'hide') {
97
- this.hideValueLabelsCollision();
98
- }
97
+ const valueLabels = this.getAllValueLabels();
98
+ ValueLabelsCollision.resolveValueLabelsCollisions(valueLabels, valueLabelsSettings);
99
99
  }
100
100
  update(scales, charts, data, dataOptions) {
101
+ const valueLabelsSettings = this.options.canvas.valueLabels;
101
102
  const chartsWithLabels = charts.filter(chart => { var _a; return (_a = chart.valueLabels) === null || _a === void 0 ? void 0 : _a.show; });
102
103
  if (chartsWithLabels.length === 0)
103
104
  return;
104
- if (this.options.canvas.valueLabels.collision.mode === 'hide')
105
+ if (this.options.canvas.valueLabels.collision.otherValueLables.mode === 'hide')
105
106
  this.toggleOldValueLabelsVisibility();
106
107
  const chartsUpdatePromises = chartsWithLabels.map((chart, index) => {
107
108
  const chartScales = this.getChartScales(scales, chart);
108
109
  return this.chartsValueLabels[index].update(chartScales, data[dataOptions.dataSource]);
109
110
  });
110
- if (this.options.canvas.valueLabels.collision.mode === 'hide') {
111
- Promise.all(chartsUpdatePromises).then(() => {
112
- this.hideValueLabelsCollision();
113
- });
114
- }
111
+ Promise.all(chartsUpdatePromises).then(() => {
112
+ const newValueLabels = this.getAllValueLabels();
113
+ ValueLabelsCollision.resolveValueLabelsCollisions(newValueLabels, valueLabelsSettings);
114
+ });
115
115
  }
116
116
  toggleOldValueLabelsVisibility() {
117
117
  const oldValueLabels = this.getAllValueLabels();
@@ -120,11 +120,6 @@ export class CanvasValueLabels {
120
120
  select(this).style('display', 'block');
121
121
  });
122
122
  }
123
- hideValueLabelsCollision() {
124
- const newValueLabels = this.getAllValueLabels();
125
- const valueLabelElementsRectInfo = ValueLabelsCollision.getValueLabelElementsRectInfo(newValueLabels);
126
- ValueLabelsCollision.toggleValueLabelElementsVisibility(valueLabelElementsRectInfo);
127
- }
128
123
  getAllValueLabels() {
129
124
  const block = this.options.elementAccessors.getBlock().svg.getChartBlock();
130
125
  return block
@@ -1,4 +1,6 @@
1
1
  import { Selection } from "d3-selection";
2
+ import { TwoDimensionalValueLabels } from "../../../model/model";
3
+ import { MdtChartsDataRow } from "../../../config/config";
2
4
  export declare type ValueLabelOnCanvasIndex = number;
3
5
  export interface BoundingRect {
4
6
  x: number;
@@ -18,6 +20,9 @@ export interface LabelVisibility {
18
20
  isVisible: boolean;
19
21
  }
20
22
  export declare class ValueLabelsCollision {
21
- static getValueLabelElementsRectInfo(valueLabels: Selection<SVGTextElement, unknown, SVGGElement, unknown>): ValueLabelElement[];
22
- static toggleValueLabelElementsVisibility(elements: ValueLabelElement[]): void;
23
+ static resolveValueLabelsCollisions(newValueLabels: Selection<SVGTextElement, MdtChartsDataRow, SVGGElement, unknown>, valueLabelsSettings: TwoDimensionalValueLabels): void;
24
+ private static getValueLabelElementsRectInfo;
25
+ private static shiftValueLabelsCollision;
26
+ private static toggleValueLabelElementsVisibility;
27
+ private static changeLabelElementCoordinateX;
23
28
  }
@@ -1,10 +1,18 @@
1
1
  import { select } from "d3-selection";
2
2
  import { ValueLabelsCollisionHelper } from "../../../engine/features/valueLabelsCollision/valueLabelsCollisionHelper";
3
3
  export class ValueLabelsCollision {
4
+ static resolveValueLabelsCollisions(newValueLabels, valueLabelsSettings) {
5
+ const valueLabelElementsRectInfo = this.getValueLabelElementsRectInfo(newValueLabels);
6
+ this.shiftValueLabelsCollision(valueLabelElementsRectInfo, valueLabelsSettings.collision.chartBlock);
7
+ if (valueLabelsSettings.collision.otherValueLables.mode === 'hide')
8
+ this.toggleValueLabelElementsVisibility(valueLabelElementsRectInfo);
9
+ }
4
10
  static getValueLabelElementsRectInfo(valueLabels) {
5
11
  let ValueLabelElementsReactInfo = [];
6
12
  valueLabels.each(function (_, index) {
7
- const { x, y, height, width } = this.getBoundingClientRect();
13
+ const { height, width } = this.getBBox();
14
+ const x = +this.getAttribute("x");
15
+ const y = +this.getAttribute("y");
8
16
  ValueLabelElementsReactInfo.push({
9
17
  index,
10
18
  svgElement: this,
@@ -13,6 +21,18 @@ export class ValueLabelsCollision {
13
21
  });
14
22
  return ValueLabelElementsReactInfo;
15
23
  }
24
+ static shiftValueLabelsCollision(valueLabelElementsRectInfo, chartBlock) {
25
+ valueLabelElementsRectInfo.forEach(element => {
26
+ if (chartBlock.left.mode === 'shift' && chartBlock.left.hasCollision(element.boundingClientRect)) {
27
+ chartBlock.left.shiftCoordinate(element.boundingClientRect);
28
+ this.changeLabelElementCoordinateX(element);
29
+ }
30
+ if (chartBlock.right.mode === 'shift' && chartBlock.right.hasCollision(element.boundingClientRect)) {
31
+ chartBlock.right.shiftCoordinate(element.boundingClientRect);
32
+ this.changeLabelElementCoordinateX(element);
33
+ }
34
+ });
35
+ }
16
36
  static toggleValueLabelElementsVisibility(elements) {
17
37
  const labelsVisibility = ValueLabelsCollisionHelper.calculateValueLabelsVisibility(elements);
18
38
  labelsVisibility.forEach(label => {
@@ -21,4 +41,8 @@ export class ValueLabelsCollision {
21
41
  select(labelInfo.svgElement).style('display', 'none');
22
42
  });
23
43
  }
44
+ static changeLabelElementCoordinateX(element) {
45
+ select(element.svgElement)
46
+ .attr('x', element.boundingClientRect.x);
47
+ }
24
48
  }
@@ -19,6 +19,7 @@ export declare class Bar {
19
19
  private readonly barItemClass;
20
20
  private readonly barSegmentGroupClass;
21
21
  private createBarPipeline;
22
+ private createSegmentGroupBarsPipeline;
22
23
  constructor();
23
24
  render(block: Block, scales: Scales, data: MdtChartsDataRow[], keyField: Field, margin: BlockMargin, keyAxisOrient: Orient, chart: TwoDimensionalChartModel, blockSize: Size, barSettings: BarChartSettings, barsAmounts: number[], isSegmented: boolean, firstBarIndex: number): void;
24
25
  update(block: Block, newData: MdtChartsDataRow[], scales: Scales, margin: BlockMargin, keyAxisOrient: Orient, chart: TwoDimensionalChartModel, blockSize: Size, barsAmounts: number[], keyField: Field, firstBarIndex: number, barSettings: BarChartSettings, isSegmented: boolean): Promise<any>[];
@@ -12,14 +12,15 @@ export class Bar {
12
12
  this.barItemClass = Bar.barItemClass;
13
13
  this.barSegmentGroupClass = 'bar-segment-group';
14
14
  this.createBarPipeline = new Pipeline();
15
- onBarChartInit(this.createBarPipeline);
15
+ this.createSegmentGroupBarsPipeline = new Pipeline();
16
+ onBarChartInit(this.createBarPipeline, this.createSegmentGroupBarsPipeline);
16
17
  }
17
18
  static get() {
18
19
  return new Bar();
19
20
  }
20
21
  render(block, scales, data, keyField, margin, keyAxisOrient, chart, blockSize, barSettings, barsAmounts, isSegmented, firstBarIndex) {
21
22
  if (isSegmented)
22
- this.renderSegmented(block, scales, data, keyField, margin, keyAxisOrient, chart, barsAmounts, blockSize, firstBarIndex, barSettings);
23
+ this.renderSegmented(block, scales, data, keyField, margin, keyAxisOrient, chart, barsAmounts, firstBarIndex, barSettings);
23
24
  else
24
25
  this.renderGrouped(block, scales, data, keyField, margin, keyAxisOrient, chart, barsAmounts, blockSize, firstBarIndex, barSettings);
25
26
  }
@@ -53,7 +54,7 @@ export class Bar {
53
54
  .attr('class', this.barItemClass)
54
55
  .style('clip-path', `url(#${block.svg.getClipPathId()})`);
55
56
  bars = this.createBarPipeline.execute(bars, chart);
56
- const barAttrs = BarHelper.getGroupedBarAttrs(keyAxisOrient, scales, margin, keyField.name, field.name, blockSize, BarHelper.getBarIndex(barsAmounts, chart.index - firstBarIndex) + index, sum(barsAmounts), barSettings);
57
+ const barAttrs = BarHelper.getGroupedBarAttrs(keyAxisOrient, scales, margin, keyField.name, field.name, BarHelper.getBarIndex(barsAmounts, chart.index - firstBarIndex) + index, sum(barsAmounts), barSettings);
57
58
  this.fillBarAttrs(bars, barAttrs);
58
59
  DomHelper.setCssClasses(bars, Helper.getCssClassesWithElementIndex(chart.cssClasses, index));
59
60
  DomHelper.setChartStyle(bars, chart.style, index, 'fill');
@@ -62,7 +63,7 @@ export class Bar {
62
63
  EmbeddedLabels.render(block, bars, barAttrs, EmbeddedLabelsHelper.getLabelField(chart.embeddedLabels, chart.data.valueFields, keyField, index), chart.embeddedLabels, keyAxisOrient, blockSize, margin, index, chart.cssClasses);
63
64
  });
64
65
  }
65
- renderSegmented(block, scales, data, keyField, margin, keyAxisOrient, chart, barsAmounts, blockSize, firstBarIndex, barSettings) {
66
+ renderSegmented(block, scales, data, keyField, margin, keyAxisOrient, chart, barsAmounts, firstBarIndex, barSettings) {
66
67
  const stackedData = getStackedDataWithOwn(data, chart.data.valueFields.map(field => field.name));
67
68
  let groups = block.svg.getChartGroup(chart.index)
68
69
  .selectAll(`g.${this.barSegmentGroupClass}${Helper.getCssClassesLine(chart.cssClasses)}`)
@@ -81,14 +82,16 @@ export class Bar {
81
82
  .attr('class', this.barItemClass)
82
83
  .style('clip-path', `url(#${block.svg.getClipPathId()})`);
83
84
  bars = this.createBarPipeline.execute(bars, chart);
84
- const barAttrs = BarHelper.getStackedBarAttr(keyAxisOrient, scales, margin, keyField.name, blockSize, BarHelper.getBarIndex(barsAmounts, chart.index) - firstBarIndex, sum(barsAmounts), barSettings);
85
+ const barAttrs = BarHelper.getStackedBarAttr(keyAxisOrient, scales, margin, keyField.name, BarHelper.getBarIndex(barsAmounts, chart.index) - firstBarIndex, sum(barsAmounts), barSettings);
85
86
  this.fillBarAttrs(bars, barAttrs);
86
87
  this.setInitialAttrsInfo(bars, keyAxisOrient, barSettings);
87
88
  DomHelper.setCssClasses(groups, chart.cssClasses);
88
89
  DomHelper.setCssClasses(bars, chart.cssClasses); // Для обозначения принадлежности бара к конкретному чарту
89
90
  const thisClass = this;
90
91
  groups.each(function (d, i) {
91
- DomHelper.setCssClasses(select(this).selectAll(`rect${Helper.getCssClassesLine(chart.cssClasses)}`), Helper.getCssClassesWithElementIndex(chart.cssClasses, i)); // Для обозначения принадлежности бара к конкретной части стака
92
+ const barsInGroup = select(this).selectAll(`rect${Helper.getCssClassesLine(chart.cssClasses)}`);
93
+ DomHelper.setCssClasses(barsInGroup, Helper.getCssClassesWithElementIndex(chart.cssClasses, i)); // Для обозначения принадлежности бара к конкретной части стака
94
+ thisClass.createSegmentGroupBarsPipeline.execute(barsInGroup, { segmentIndex: i, chart });
92
95
  thisClass.setSegmentColor(select(this).selectAll(Helper.getCssClassesLine(chart.cssClasses)), chart.style.elementColors, i);
93
96
  });
94
97
  }
@@ -120,7 +123,7 @@ export class Bar {
120
123
  .attr('class', this.barItemClass)
121
124
  .style('clip-path', `url(#${block.svg.getClipPathId()})`);
122
125
  newBars = this.createBarPipeline.execute(newBars, chart);
123
- const barAttrs = BarHelper.getGroupedBarAttrs(keyAxisOrient, scales, margin, keyField.name, valueField.name, blockSize, BarHelper.getBarIndex(barsAmounts, chart.index) + index - firstBarIndex, sum(barsAmounts), barSettings);
126
+ const barAttrs = BarHelper.getGroupedBarAttrs(keyAxisOrient, scales, margin, keyField.name, valueField.name, BarHelper.getBarIndex(barsAmounts, chart.index) + index - firstBarIndex, sum(barsAmounts), barSettings);
124
127
  const prom = this.fillBarAttrs(bars, barAttrs, block.transitionManager.durations.chartUpdate)
125
128
  .then(() => {
126
129
  bars.style('opacity', null);
@@ -163,7 +166,7 @@ export class Bar {
163
166
  .attr('class', this.barItemClass)
164
167
  .style('clip-path', `url(#${block.svg.getClipPathId()})`);
165
168
  newBars = this.createBarPipeline.execute(newBars, chart);
166
- const barAttrs = BarHelper.getStackedBarAttr(keyAxisOrient, scales, margin, keyField.name, blockSize, BarHelper.getBarIndex(barsAmounts, chart.index) - firstBarIndex, sum(barsAmounts), barSettings);
169
+ const barAttrs = BarHelper.getStackedBarAttr(keyAxisOrient, scales, margin, keyField.name, BarHelper.getBarIndex(barsAmounts, chart.index) - firstBarIndex, sum(barsAmounts), barSettings);
167
170
  const prom = this.fillBarAttrs(bars, barAttrs, block.transitionManager.durations.chartUpdate)
168
171
  .then(() => {
169
172
  this.setInitialAttrsInfo(bars, keyAxisOrient, barSettings);
@@ -174,7 +177,9 @@ export class Bar {
174
177
  DomHelper.setCssClasses(newBars, chart.cssClasses);
175
178
  const thisClass = this;
176
179
  groups.each(function (d, i) {
177
- DomHelper.setCssClasses(select(this).selectAll(`rect${Helper.getCssClassesLine(chart.cssClasses)}`), Helper.getCssClassesWithElementIndex(chart.cssClasses, i)); // Для обозначения принадлежности бара к конкретной части стака
180
+ const barsInGroup = select(this).selectAll(`rect${Helper.getCssClassesLine(chart.cssClasses)}`);
181
+ DomHelper.setCssClasses(barsInGroup, Helper.getCssClassesWithElementIndex(chart.cssClasses, i)); // Для обозначения принадлежности бара к конкретной части стака
182
+ thisClass.createSegmentGroupBarsPipeline.execute(barsInGroup, { segmentIndex: i, chart });
178
183
  thisClass.setSegmentColor(select(this).selectAll(Helper.getCssClassesLine(chart.cssClasses)), chart.style.elementColors, i);
179
184
  });
180
185
  return [prom];