mdt-charts 1.23.2 → 1.24.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 (44) hide show
  1. package/lib/config/config.d.ts +1 -1
  2. package/lib/engine/contentManager/contentManager.d.ts +1 -0
  3. package/lib/engine/contentManager/contentManager.js +3 -0
  4. package/lib/engine/contentManager/contentManagerFactory.d.ts +2 -0
  5. package/lib/engine/engine.d.ts +1 -0
  6. package/lib/engine/engine.js +3 -0
  7. package/lib/engine/features/axis/axis.js +3 -3
  8. package/lib/engine/features/axis/axisLabelDomHelper.d.ts +1 -1
  9. package/lib/engine/features/axis/axisLabelDomHelper.js +5 -4
  10. package/lib/engine/features/valueLabelsCollision/valueLabelsCollision.d.ts +2 -1
  11. package/lib/engine/features/valueLabelsCollision/valueLabelsCollision.js +13 -9
  12. package/lib/engine/polarNotation/polarManager.d.ts +2 -0
  13. package/lib/engine/polarNotation/polarManager.js +4 -1
  14. package/lib/engine/twoDimensionalNotation/area/area.d.ts +9 -4
  15. package/lib/engine/twoDimensionalNotation/area/area.js +81 -42
  16. package/lib/engine/twoDimensionalNotation/line/line.d.ts +1 -2
  17. package/lib/engine/twoDimensionalNotation/line/line.js +17 -39
  18. package/lib/engine/twoDimensionalNotation/line/lineBuilder.d.ts +22 -0
  19. package/lib/engine/twoDimensionalNotation/line/lineBuilder.js +49 -0
  20. package/lib/engine/twoDimensionalNotation/twoDimensionalManager.d.ts +2 -0
  21. package/lib/engine/twoDimensionalNotation/twoDimensionalManager.js +6 -3
  22. package/lib/main.d.ts +5 -0
  23. package/lib/main.js +3 -0
  24. package/lib/model/featuresModel/axisModel.d.ts +3 -3
  25. package/lib/model/featuresModel/axisModel.js +11 -5
  26. package/lib/model/featuresModel/titleModel.js +2 -1
  27. package/lib/model/featuresModel/valueLabelsModel/valueLabelsModel.d.ts +6 -0
  28. package/lib/model/featuresModel/valueLabelsModel/valueLabelsModel.js +15 -3
  29. package/lib/model/helpers/modelHelper.d.ts +1 -0
  30. package/lib/model/helpers/modelHelper.js +8 -4
  31. package/lib/model/helpers/twoDimensionalModelHelper.d.ts +5 -2
  32. package/lib/model/helpers/twoDimensionalModelHelper.js +63 -0
  33. package/lib/model/margin/twoDim/twoDimMarginModel.d.ts +1 -0
  34. package/lib/model/margin/twoDim/twoDimMarginModel.js +14 -0
  35. package/lib/model/model.d.ts +16 -11
  36. package/lib/model/modelInstance/configReader.d.ts +2 -0
  37. package/lib/model/modelInstance/configReader.js +8 -2
  38. package/lib/model/notations/twoDimensional/styles.d.ts +2 -1
  39. package/lib/model/notations/twoDimensional/styles.js +28 -9
  40. package/lib/model/notations/twoDimensionalModel.d.ts +0 -1
  41. package/lib/model/notations/twoDimensionalModel.js +5 -26
  42. package/lib/style/charts-main.css +4 -2
  43. package/lib/style/charts-main.less +4 -2
  44. package/package.json +1 -1
@@ -177,7 +177,7 @@ export interface NumberAxisLabel {
177
177
  format: (v: number) => string;
178
178
  stepSize?: number;
179
179
  }
180
- export declare type AxisLabelFormatter = (v: number) => string;
180
+ export declare type AxisLabelFormatter = (v: number | string) => string;
181
181
  export interface DiscreteAxisOptions extends AxisOptions {
182
182
  labels?: MdtChartsDiscreteAxisLabel;
183
183
  }
@@ -8,4 +8,5 @@ export declare class ContentManager {
8
8
  render(model: Model, engine: Engine): void;
9
9
  updateData(block: Block, model: Model, newData: MdtChartsDataSource): void;
10
10
  updateColors(engine: Engine, model: Model): void;
11
+ clearSelection(engine: Engine, model: Model): void;
11
12
  }
@@ -12,4 +12,7 @@ export class ContentManager {
12
12
  updateColors(engine, model) {
13
13
  this.manager.updateColors(engine.block, model);
14
14
  }
15
+ clearSelection(engine, model) {
16
+ this.manager.clearSelection(engine.block.filterEventManager, model);
17
+ }
15
18
  }
@@ -2,10 +2,12 @@ import { ChartNotation, MdtChartsDataSource } from "../../config/config";
2
2
  import { Model } from "../../model/model";
3
3
  import { Block } from "../block/block";
4
4
  import { Engine } from "../engine";
5
+ import { FilterEventManager } from "../filterManager/filterEventManager";
5
6
  export interface ChartContentManager {
6
7
  render(engine: Engine, model: Model): void;
7
8
  updateData(block: Block, model: Model, newData: MdtChartsDataSource): void;
8
9
  updateColors(block: Block, model: Model): void;
10
+ clearSelection(filterEventManager: FilterEventManager, model: Model): void;
9
11
  }
10
12
  export declare class ContentManagerFactory {
11
13
  private managers;
@@ -15,6 +15,7 @@ export declare class Engine {
15
15
  updateFullBlock(model: Model, data: MdtChartsDataSource): void;
16
16
  destroy(): void;
17
17
  updateData(model: Model, newData: MdtChartsDataSource): void;
18
+ clearSelection(model: Model): void;
18
19
  updateColors(model: Model): void;
19
20
  private renderCharts;
20
21
  private setFilterEventManager;
@@ -47,6 +47,9 @@ export class Engine {
47
47
  }
48
48
  }
49
49
  }
50
+ clearSelection(model) {
51
+ this.contentManager.clearSelection(this, model);
52
+ }
50
53
  updateColors(model) {
51
54
  this.contentManager.updateColors(this, model);
52
55
  }
@@ -67,7 +67,7 @@ export class Axis {
67
67
  AxisLabelHelper.cropLabels(block, scale, scaleOptions, axisOptions, blockSize);
68
68
  }
69
69
  if (axisOptions.labels.defaultTooltip)
70
- AxisLabelHelper.setTitles(axisElement);
70
+ AxisLabelHelper.setTitles(axisElement, axisOptions);
71
71
  }
72
72
  static updateValueAxis(block, scaleValue, scaleOptions, axisOptions, blockSize) {
73
73
  const axisGenerator = AxisHelper.getBaseAxisGenerator(axisOptions, scaleValue);
@@ -76,7 +76,7 @@ export class Axis {
76
76
  AxisDomHelper.updateAxisElement(axisGenerator, axisElement, axisOptions.translate, block.transitionManager.durations.chartUpdate)
77
77
  .then(() => {
78
78
  if (axisOptions.labels.defaultTooltip)
79
- AxisLabelHelper.setTitles(axisElement);
79
+ AxisLabelHelper.setTitles(axisElement, axisOptions);
80
80
  if (axisOptions.orient === 'bottom' || axisOptions.orient === 'top') {
81
81
  AxisLabelHelper.cropLabels(block, scaleValue, scaleOptions, axisOptions, blockSize);
82
82
  }
@@ -107,7 +107,7 @@ export class Axis {
107
107
  }
108
108
  AxisLabelsEventManager.setHoverEvents(block, axisElement);
109
109
  if (axisOptions.labels.defaultTooltip)
110
- AxisLabelHelper.setTitles(axisElement);
110
+ AxisLabelHelper.setTitles(axisElement, axisOptions);
111
111
  this.handleLabelsHighlight(axisElement, block.filterEventManager.getSelectedKeys());
112
112
  });
113
113
  // Ведется отсчет нескольких кадров, чтобы получить уже 100%-отрендеренные лейблы оси.
@@ -4,7 +4,7 @@ import { AxisModelOptions, Orient, ScaleKeyModel, ScaleValueModel } from "../../
4
4
  import { Block } from "../../block/block";
5
5
  import { Size } from '../../../config/config';
6
6
  export declare class AxisLabelHelper {
7
- static setTitles(axisElement: Selection<SVGGElement, unknown, BaseType, any>): void;
7
+ static setTitles(axisElement: Selection<SVGGElement, unknown, BaseType, any>, axisOptions: AxisModelOptions): void;
8
8
  static setAxisLabelPaddingByOrient(axis: IAxis<any>, axisOptions: AxisModelOptions): void;
9
9
  static rotateLabels(axisElement: Selection<SVGGElement, unknown, HTMLElement, any>, keyAxisOrient: Orient): void;
10
10
  static cropLabels(block: Block, scale: AxisScale<any>, scaleOptions: ScaleKeyModel | ScaleValueModel, axisOptions: AxisModelOptions, blockSize: Size): void;
@@ -3,16 +3,17 @@ import { DomHelper } from '../../helpers/domHelper';
3
3
  import { Helper } from '../../helpers/helper';
4
4
  import { AXIS_HORIZONTAL_LABEL_PADDING, AXIS_VERTICAL_LABEL_PADDING } from '../../../model/margin/twoDim/twoDimMarginModel';
5
5
  export class AxisLabelHelper {
6
- static setTitles(axisElement) {
6
+ static setTitles(axisElement, axisOptions) {
7
7
  axisElement.selectAll('.tick text')
8
8
  .each(function (d, i) {
9
9
  const tickTitle = select(this).select('title');
10
10
  if (tickTitle.empty())
11
11
  select(this)
12
12
  .append('title')
13
- .text(d);
14
- else
15
- tickTitle.text(d);
13
+ .text(axisOptions.browserTooltip.format(d));
14
+ else {
15
+ tickTitle.text((axisOptions.browserTooltip.format(d)));
16
+ }
16
17
  });
17
18
  }
18
19
  static setAxisLabelPaddingByOrient(axis, axisOptions) {
@@ -23,6 +23,7 @@ export declare class ValueLabelsCollision {
23
23
  static resolveValueLabelsCollisions(newValueLabels: Selection<SVGTextElement, MdtChartsDataRow, SVGGElement, unknown>, valueLabelsSettings: TwoDimensionalValueLabels): void;
24
24
  private static getValueLabelElementsRectInfo;
25
25
  private static shiftValueLabelsCollision;
26
+ private static handleCollisionShift;
26
27
  private static toggleValueLabelElementsVisibility;
27
- private static changeLabelElementCoordinateX;
28
+ private static changeLabelElementCoordinateByAxis;
28
29
  }
@@ -23,13 +23,17 @@ export class ValueLabelsCollision {
23
23
  }
24
24
  static shiftValueLabelsCollision(valueLabelElementsRectInfo, chartBlock) {
25
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);
26
+ this.handleCollisionShift(chartBlock, element);
27
+ });
28
+ }
29
+ static handleCollisionShift(chartBlock, element) {
30
+ const sides = Object.keys(chartBlock);
31
+ sides.forEach(side => {
32
+ const blockSide = chartBlock[side];
33
+ const axisCoordinate = side === 'left' || side === 'right' ? 'x' : 'y';
34
+ if (blockSide.mode === 'shift' && blockSide.hasCollision(element.boundingClientRect)) {
35
+ blockSide.shiftCoordinate(element.boundingClientRect);
36
+ this.changeLabelElementCoordinateByAxis(element, axisCoordinate);
33
37
  }
34
38
  });
35
39
  }
@@ -41,8 +45,8 @@ export class ValueLabelsCollision {
41
45
  select(labelInfo.svgElement).style('display', 'none');
42
46
  });
43
47
  }
44
- static changeLabelElementCoordinateX(element) {
48
+ static changeLabelElementCoordinateByAxis(element, axis) {
45
49
  select(element.svgElement)
46
- .attr('x', element.boundingClientRect.x);
50
+ .attr(axis, element.boundingClientRect[axis]);
47
51
  }
48
52
  }
@@ -3,9 +3,11 @@ import { Block } from "../block/block";
3
3
  import { Engine } from "../engine";
4
4
  import { MdtChartsDataSource } from "../../config/config";
5
5
  import { ChartContentManager } from "../contentManager/contentManagerFactory";
6
+ import { FilterEventManager } from "../filterManager/filterEventManager";
6
7
  export declare class PolarManager implements ChartContentManager {
7
8
  render(engine: Engine, model: Model<PolarOptionsModel>): void;
8
9
  updateData(block: Block, model: Model<PolarOptionsModel>, data: MdtChartsDataSource): void;
9
10
  updateColors(block: Block, model: Model<PolarOptionsModel>): void;
11
+ clearSelection(filterEventManager: FilterEventManager, model: Model<PolarOptionsModel>): void;
10
12
  private renderCharts;
11
13
  }
@@ -22,7 +22,7 @@ export class PolarManager {
22
22
  engine.block.getSvg()
23
23
  .on('click', (e) => {
24
24
  if (e.target === engine.block.getSvg().node())
25
- engine.block.filterEventManager.clearKeysForPolar(model.chartBlock.margin, model.blockCanvas.size, options);
25
+ this.clearSelection(engine.block.filterEventManager, model);
26
26
  });
27
27
  }
28
28
  updateData(block, model, data) {
@@ -51,6 +51,9 @@ export class PolarManager {
51
51
  Legend.get().updateColors(block, model.options);
52
52
  Donut.updateColors(block, model.options.charts[0]);
53
53
  }
54
+ clearSelection(filterEventManager, model) {
55
+ filterEventManager.clearKeysForPolar(model.chartBlock.margin, model.blockCanvas.size, model.options);
56
+ }
54
57
  renderCharts(block, charts, data, dataSource, margin, blockSize, donutSettings) {
55
58
  charts.forEach((chart) => {
56
59
  if (chart.type === 'donut')
@@ -1,7 +1,7 @@
1
1
  import { BlockMargin, Field, LineLikeChartSettings, Orient, TwoDimensionalChartModel } from "../../../model/model";
2
2
  import { Scales } from "../../features/scale/scale";
3
3
  import { Block } from "../../block/block";
4
- import { MdtChartsDataRow, Size } from '../../../config/config';
4
+ import { MdtChartsDataRow } from '../../../config/config';
5
5
  interface AreaOptions {
6
6
  staticSettings: LineLikeChartSettings;
7
7
  }
@@ -11,8 +11,8 @@ export declare class Area {
11
11
  static readonly areaBorderLineClass = "area-border-line";
12
12
  static get(options: AreaOptions): Area;
13
13
  constructor(options: AreaOptions);
14
- render(block: Block, scales: Scales, data: MdtChartsDataRow[], keyField: Field, margin: BlockMargin, keyAxisOrient: Orient, chart: TwoDimensionalChartModel, blockSize: Size): void;
15
- update(block: Block, scales: Scales, newData: MdtChartsDataRow[], keyField: Field, margin: BlockMargin, chart: TwoDimensionalChartModel, keyAxisOrient: Orient, blockSize: Size): Promise<any>[];
14
+ render(block: Block, scales: Scales, data: MdtChartsDataRow[], keyField: Field, margin: BlockMargin, keyAxisOrient: Orient, chart: TwoDimensionalChartModel): void;
15
+ update(block: Block, scales: Scales, newData: MdtChartsDataRow[], keyField: Field, margin: BlockMargin, chart: TwoDimensionalChartModel, keyAxisOrient: Orient): Promise<any>[];
16
16
  updateColors(block: Block, chart: TwoDimensionalChartModel): void;
17
17
  private renderGrouped;
18
18
  private renderSegmented;
@@ -20,13 +20,18 @@ export declare class Area {
20
20
  private updateSegmented;
21
21
  private updateGroupedPath;
22
22
  private updateSegmentedPath;
23
- private setSegmentColor;
24
23
  private setChartFillStyle;
25
24
  private createAreaGeneratorFactory;
26
25
  private createLineGeneratorFactory;
27
26
  private renderArea;
28
27
  private renderBorderLine;
28
+ private renderAreaSegmented;
29
+ private renderBorderLineSegmented;
30
+ private updateAreaSegmented;
31
+ private updateBorderLineSegmented;
29
32
  private updateArea;
30
33
  private updateBorderLine;
34
+ private getAllAreasWithNewData;
35
+ private getLineGeneratorFactory;
31
36
  }
32
37
  export {};
@@ -4,8 +4,9 @@ import { AreaGeneratorFactory } from './areaHelper';
4
4
  import { DomHelper } from '../../helpers/domHelper';
5
5
  import { Helper } from '../../helpers/helper';
6
6
  import { getStackedDataWithOwn } from '../bar/stackedData/dataStacker';
7
- import { LineGeneratorFactory } from "../../../engine/twoDimensionalNotation/line/lineHelper";
7
+ import { getStackedData, LineGeneratorFactory } from "../../../engine/twoDimensionalNotation/line/lineHelper";
8
8
  import { Line } from "../../../engine/twoDimensionalNotation/line/line";
9
+ import { LineBuilder } from "../../../engine/twoDimensionalNotation/line/lineBuilder";
9
10
  export class Area {
10
11
  constructor(options) {
11
12
  this.options = options;
@@ -13,19 +14,19 @@ export class Area {
13
14
  static get(options) {
14
15
  return new Area(options);
15
16
  }
16
- render(block, scales, data, keyField, margin, keyAxisOrient, chart, blockSize) {
17
+ render(block, scales, data, keyField, margin, keyAxisOrient, chart) {
17
18
  if (chart.isSegmented)
18
19
  this.renderSegmented(block, scales, data, keyField, margin, keyAxisOrient, chart);
19
20
  else
20
21
  this.renderGrouped(block, scales, data, keyField, margin, keyAxisOrient, chart);
21
22
  }
22
- update(block, scales, newData, keyField, margin, chart, keyAxisOrient, blockSize) {
23
+ update(block, scales, newData, keyField, margin, chart, keyAxisOrient) {
23
24
  let promises;
24
25
  if (chart.isSegmented) {
25
26
  promises = this.updateSegmented(block, scales, newData, keyField, margin, chart, keyAxisOrient);
26
27
  }
27
28
  else {
28
- promises = this.updateGrouped(block, scales, newData, keyField, margin, chart, keyAxisOrient, blockSize);
29
+ promises = this.updateGrouped(block, scales, newData, keyField, margin, chart, keyAxisOrient);
29
30
  }
30
31
  return promises;
31
32
  }
@@ -45,8 +46,7 @@ export class Area {
45
46
  }
46
47
  renderGrouped(block, scales, data, keyField, margin, keyAxisOrient, chart) {
47
48
  const areaGeneratorFactory = this.createAreaGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
48
- const lineGeneratorFactory = chart.areaViewOptions.borderLine.on
49
- && this.createLineGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
49
+ const lineGeneratorFactory = this.getLineGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
50
50
  chart.data.valueFields.forEach((field, valueIndex) => {
51
51
  this.renderArea(areaGeneratorFactory, block, chart, data, field, valueIndex);
52
52
  if (lineGeneratorFactory)
@@ -55,31 +55,16 @@ export class Area {
55
55
  });
56
56
  }
57
57
  renderSegmented(block, scales, data, keyField, margin, keyAxisOrient, chart) {
58
- const stackedData = getStackedDataWithOwn(data, chart.data.valueFields.map(field => field.name));
59
58
  const areaGeneratorFactory = this.createAreaGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
60
- const areaGenerator = areaGeneratorFactory.getSegmentedAreaGenerator();
61
- const areas = block.svg.getChartGroup(chart.index)
62
- .selectAll(`.${Area.areaChartClass}${Helper.getCssClassesLine(chart.cssClasses)}`)
63
- .data(stackedData)
64
- .enter()
65
- .append('path')
66
- .attr('d', d => areaGenerator(d))
67
- .attr('class', Area.areaChartClass)
68
- .style('clip-path', `url(#${block.svg.getClipPathId()})`)
69
- .style('pointer-events', 'none');
70
- areas.each(function (d, i) {
71
- DomHelper.setCssClasses(select(this), Helper.getCssClassesWithElementIndex(chart.cssClasses, i));
72
- });
73
- this.setSegmentColor(areas, chart.style.elementColors);
74
- stackedData.forEach((dataset, index) => {
75
- MarkDot.render(block, dataset, keyAxisOrient, scales, margin, keyField.name, index, '1', chart);
76
- });
59
+ const lineGeneratorFactory = this.getLineGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
60
+ this.renderAreaSegmented(areaGeneratorFactory, block, scales, data, keyField, margin, keyAxisOrient, chart);
61
+ if (lineGeneratorFactory)
62
+ this.renderBorderLineSegmented(lineGeneratorFactory, block, data, chart);
77
63
  }
78
- updateGrouped(block, scales, newData, keyField, margin, chart, keyAxisOrient, blockSize) {
64
+ updateGrouped(block, scales, newData, keyField, margin, chart, keyAxisOrient) {
79
65
  const promises = [];
80
66
  const areaGeneratorFactory = this.createAreaGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
81
- const lineGeneratorFactory = chart.areaViewOptions.borderLine.on
82
- && this.createLineGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
67
+ const lineGeneratorFactory = this.getLineGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
83
68
  chart.data.valueFields.forEach((field, valueIndex) => {
84
69
  const chartGroup = block.svg.getChartGroup(chart.index);
85
70
  const areaProm = this.updateArea(areaGeneratorFactory, chartGroup, block, field, chart, newData, valueIndex);
@@ -93,18 +78,10 @@ export class Area {
93
78
  return promises;
94
79
  }
95
80
  updateSegmented(block, scales, newData, keyField, margin, chart, keyAxisOrient) {
96
- const stackedData = getStackedDataWithOwn(newData, chart.data.valueFields.map(field => field.name));
97
- const generatorFactory = this.createAreaGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
98
- const areaGenerator = generatorFactory.getSegmentedAreaGenerator();
99
- const areas = block.svg.getChartGroup(chart.index)
100
- .selectAll(`path.${Area.areaChartClass}${Helper.getCssClassesLine(chart.cssClasses)}`)
101
- .data(stackedData);
102
- const prom = this.updateSegmentedPath(block, areas, areaGenerator);
103
- areas.each((dataset, index) => {
104
- // '1' - атрибут, показывающий координаты согласно полю значения
105
- MarkDot.update(block, dataset, keyAxisOrient, scales, margin, keyField.name, index, '1', chart);
106
- });
107
- return [prom];
81
+ return [
82
+ this.updateAreaSegmented(block, scales, newData, keyField, margin, chart, keyAxisOrient),
83
+ this.updateBorderLineSegmented(block, scales, newData, keyField, margin, keyAxisOrient, chart)
84
+ ];
108
85
  }
109
86
  updateGroupedPath(block, areaObject, areaGenerator, newData) {
110
87
  return new Promise(resolve => {
@@ -142,9 +119,6 @@ export class Area {
142
119
  resolve('');
143
120
  });
144
121
  }
145
- setSegmentColor(segments, colorPalette) {
146
- segments.style('fill', (d, i) => colorPalette[i % colorPalette.length]);
147
- }
148
122
  setChartFillStyle(chart, path, valueIndex) {
149
123
  if (chart.areaViewOptions.fill.type === 'gradient')
150
124
  DomHelper.setChartGradientStyle(path, chart.index, valueIndex);
@@ -180,6 +154,62 @@ export class Area {
180
154
  DomHelper.setCssClasses(linePath, Helper.getCssClassesWithElementIndex(chart.cssClasses, valueIndex));
181
155
  DomHelper.setChartStyle(linePath, chart.areaViewOptions.borderLine.colorStyle, valueIndex, 'stroke');
182
156
  }
157
+ renderAreaSegmented(areaGeneratorFactory, block, scales, data, keyField, margin, keyAxisOrient, chart) {
158
+ const stackedData = getStackedDataWithOwn(data, chart.data.valueFields.map(field => field.name));
159
+ const areaGenerator = areaGeneratorFactory.getSegmentedAreaGenerator();
160
+ const areas = block.svg.getChartGroup(chart.index)
161
+ .selectAll(`.${Area.areaChartClass}${Helper.getCssClassesLine(chart.cssClasses)}`)
162
+ .data(stackedData)
163
+ .enter()
164
+ .append('path')
165
+ .attr('d', d => areaGenerator(d))
166
+ .attr('class', Area.areaChartClass)
167
+ .style('clip-path', `url(#${block.svg.getClipPathId()})`)
168
+ .style('pointer-events', 'none');
169
+ const thisClass = this;
170
+ areas.each(function (_, i) {
171
+ thisClass.setChartFillStyle(chart, select(this), i);
172
+ DomHelper.setCssClasses(select(this), Helper.getCssClassesWithElementIndex(chart.cssClasses, i));
173
+ });
174
+ stackedData.forEach((dataset, index) => {
175
+ MarkDot.render(block, dataset, keyAxisOrient, scales, margin, keyField.name, index, '1', chart);
176
+ });
177
+ }
178
+ renderBorderLineSegmented(generatorFactory, block, data, chart) {
179
+ let stackedData = getStackedData(data, chart);
180
+ const lineGenerator = generatorFactory.getSegmentedLineGenerator();
181
+ const lineBuilder = new LineBuilder({
182
+ elementAccessors: { getBlock: () => block }
183
+ }, chart, lineGenerator);
184
+ let lines = lineBuilder.renderSegmented(stackedData, Area.areaBorderLineClass);
185
+ lineBuilder.setSegmentColor(lines, chart.style.elementColors);
186
+ lines.each(function (_, i) {
187
+ DomHelper.setCssClasses(select(this), Helper.getCssClassesWithElementIndex(chart.cssClasses, i));
188
+ });
189
+ }
190
+ updateAreaSegmented(block, scales, newData, keyField, margin, chart, keyAxisOrient) {
191
+ const stackedData = getStackedDataWithOwn(newData, chart.data.valueFields.map(field => field.name));
192
+ const generatorFactory = this.createAreaGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
193
+ const areaGenerator = generatorFactory.getSegmentedAreaGenerator();
194
+ const areas = this.getAllAreasWithNewData(stackedData, block, chart, Area.areaChartClass);
195
+ const prom = this.updateSegmentedPath(block, areas, areaGenerator);
196
+ areas.each(function (dataset, index) {
197
+ // '1' - атрибут, показывающий координаты согласно полю значения
198
+ MarkDot.update(block, dataset, keyAxisOrient, scales, margin, keyField.name, index, '1', chart);
199
+ });
200
+ return prom;
201
+ }
202
+ updateBorderLineSegmented(block, scales, newData, keyField, margin, keyAxisOrient, chart) {
203
+ let stackedData = getStackedData(newData, chart);
204
+ const generatorFactory = this.createLineGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
205
+ const lineGenerator = generatorFactory.getSegmentedLineGenerator();
206
+ const lineBuilder = new LineBuilder({
207
+ elementAccessors: { getBlock: () => block }
208
+ }, chart, lineGenerator);
209
+ let lines = lineBuilder.getAllLinesWithNewData(stackedData, Area.areaBorderLineClass);
210
+ let prom = lineBuilder.updateSegmentedPath(lines);
211
+ return prom;
212
+ }
183
213
  updateArea(areaGeneratorFactory, chartGroup, block, field, chart, newData, valueIndex) {
184
214
  const areaGenerator = areaGeneratorFactory.getAreaGenerator(field.name);
185
215
  const areaObject = chartGroup
@@ -192,6 +222,15 @@ export class Area {
192
222
  .select(`.${Area.areaBorderLineClass}${Helper.getCssClassesLine(chart.cssClasses)}.chart-element-${valueIndex}`);
193
223
  return Line.updateGroupedPath(block, borderLineObject, borderLineGenerator, newData);
194
224
  }
225
+ getAllAreasWithNewData(stackedData, block, chart, lineClass) {
226
+ return block.svg.getChartGroup(chart.index)
227
+ .selectAll(`path.${lineClass}${Helper.getCssClassesLine(chart.cssClasses)}`)
228
+ .data(stackedData);
229
+ }
230
+ getLineGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField) {
231
+ return chart.areaViewOptions.borderLine.on
232
+ && this.createLineGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
233
+ }
195
234
  }
196
235
  Area.areaChartClass = 'area';
197
236
  Area.areaBorderLineClass = 'area-border-line';
@@ -23,7 +23,6 @@ export declare class Line {
23
23
  private updateGrouped;
24
24
  private updateSegmented;
25
25
  static updateGroupedPath(block: Block, lineObject: Selection<BaseType, any, BaseType, any>, lineGenerator: ILine<MdtChartsDataRow>, newData: MdtChartsDataRow[]): Promise<any>;
26
- private updateSegmentedPath;
27
- private setSegmentColor;
26
+ private createLineGeneratorFactory;
28
27
  }
29
28
  export {};
@@ -4,6 +4,7 @@ import { getStackedData, LineGeneratorFactory, onLineChartInit } from './lineHel
4
4
  import { DomHelper } from '../../helpers/domHelper';
5
5
  import { Helper } from '../../helpers/helper';
6
6
  import { Pipeline } from '../../helpers/pipeline/Pipeline';
7
+ import { LineBuilder } from "../../../engine/twoDimensionalNotation/line/lineBuilder";
7
8
  export class Line {
8
9
  constructor(options) {
9
10
  this.options = options;
@@ -57,30 +58,24 @@ export class Line {
57
58
  }
58
59
  renderSegmented(block, scales, data, keyField, margin, keyAxisOrient, chart) {
59
60
  let stackedData = getStackedData(data, chart);
60
- const generatorFactory = new LineGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, curve: this.options.staticSettings.shape.curve.type, shouldRender: chart.lineLikeViewOptions.renderForKey });
61
+ const generatorFactory = this.createLineGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
61
62
  const lineGenerator = generatorFactory.getSegmentedLineGenerator();
62
- let lines = block.svg.getChartGroup(chart.index)
63
- .selectAll(`.${this.lineChartClass}${Helper.getCssClassesLine(chart.cssClasses)}`)
64
- .data(stackedData)
65
- .enter()
66
- .append('path')
67
- .attr('d', d => lineGenerator(d))
68
- .attr('class', this.lineChartClass)
69
- .style('fill', 'none')
70
- .style('clip-path', `url(#${block.svg.getClipPathId()})`)
71
- .style('pointer-events', 'none');
63
+ const lineBuilder = new LineBuilder({
64
+ elementAccessors: { getBlock: () => block }
65
+ }, chart, lineGenerator);
66
+ let lines = lineBuilder.renderSegmented(stackedData, Line.lineChartClass);
72
67
  lines = this.creatingPipeline.execute(lines, chart);
73
- lines.each(function (d, i) {
68
+ lineBuilder.setSegmentColor(lines, chart.style.elementColors);
69
+ lines.each(function (_, i) {
74
70
  DomHelper.setCssClasses(select(this), Helper.getCssClassesWithElementIndex(chart.cssClasses, i));
75
71
  });
76
- this.setSegmentColor(lines, chart.style.elementColors);
77
72
  stackedData.forEach((dataset, stackIndex) => {
78
73
  MarkDot.render(block, dataset, keyAxisOrient, scales, margin, keyField.name, stackIndex, '1', chart);
79
74
  });
80
75
  }
81
76
  updateGrouped(block, scales, newData, keyField, margin, keyAxisOrient, chart) {
82
77
  const promises = [];
83
- const generatorFactory = new LineGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, curve: this.options.staticSettings.shape.curve.type, shouldRender: chart.lineLikeViewOptions.renderForKey });
78
+ const generatorFactory = this.createLineGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
84
79
  chart.data.valueFields.forEach((valueField, valueFieldIndex) => {
85
80
  const lineGenerator = generatorFactory.getLineGenerator(valueField.name);
86
81
  const lineObject = block.svg.getChartGroup(chart.index)
@@ -93,12 +88,13 @@ export class Line {
93
88
  }
94
89
  updateSegmented(block, scales, newData, keyField, margin, keyAxisOrient, chart) {
95
90
  let stackedData = getStackedData(newData, chart);
96
- const generatorFactory = new LineGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, curve: this.options.staticSettings.shape.curve.type, shouldRender: chart.lineLikeViewOptions.renderForKey });
91
+ const generatorFactory = this.createLineGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
97
92
  const lineGenerator = generatorFactory.getSegmentedLineGenerator();
98
- const lines = block.svg.getChartGroup(chart.index)
99
- .selectAll(`path.${this.lineChartClass}${Helper.getCssClassesLine(chart.cssClasses)}`)
100
- .data(stackedData);
101
- const prom = this.updateSegmentedPath(block, lines, lineGenerator);
93
+ const lineBuilder = new LineBuilder({
94
+ elementAccessors: { getBlock: () => block }
95
+ }, chart, lineGenerator);
96
+ let lines = lineBuilder.getAllLinesWithNewData(stackedData, Line.lineChartClass);
97
+ const prom = lineBuilder.updateSegmentedPath(lines);
102
98
  lines.each((dataset, index) => {
103
99
  MarkDot.update(block, dataset, keyAxisOrient, scales, margin, keyField.name, index, '1', chart);
104
100
  });
@@ -122,26 +118,8 @@ export class Line {
122
118
  resolve('');
123
119
  });
124
120
  }
125
- updateSegmentedPath(block, linesObjects, lineGenerator) {
126
- return new Promise(resolve => {
127
- if (linesObjects.size() === 0) {
128
- resolve('');
129
- return;
130
- }
131
- let linesHandler = linesObjects;
132
- if (block.transitionManager.durations.chartUpdate > 0)
133
- linesHandler = linesHandler.interrupt()
134
- .transition()
135
- .duration(block.transitionManager.durations.chartUpdate)
136
- .on('end', () => resolve(''));
137
- linesHandler
138
- .attr('d', d => lineGenerator(d));
139
- if (block.transitionManager.durations.chartUpdate <= 0)
140
- resolve('');
141
- });
142
- }
143
- setSegmentColor(segments, colorPalette) {
144
- segments.style('stroke', (d, i) => colorPalette[i % colorPalette.length]);
121
+ createLineGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField) {
122
+ return new LineGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, shouldRender: chart.lineLikeViewOptions.renderForKey, curve: this.options.staticSettings.shape.curve.type });
145
123
  }
146
124
  }
147
125
  Line.lineChartClass = 'line';
@@ -0,0 +1,22 @@
1
+ import { Block } from "../../../engine/block/block";
2
+ import { MdtChartsDataRow } from "../../../config/config";
3
+ import { TwoDimensionalChartModel } from "../../../model/model";
4
+ import { BaseType, Selection } from "d3-selection";
5
+ import { Segment } from "../../../engine/twoDimensionalNotation/lineLike/generatorMiddleware/lineLikeGeneratorDefineMiddleware";
6
+ import { Line as ILine } from "d3-shape";
7
+ interface LineBuilderOptions {
8
+ elementAccessors: {
9
+ getBlock: () => Block;
10
+ };
11
+ }
12
+ export declare class LineBuilder {
13
+ private readonly options;
14
+ private readonly chart;
15
+ private readonly lineGenerator;
16
+ constructor(options: LineBuilderOptions, chart: TwoDimensionalChartModel, lineGenerator: ILine<MdtChartsDataRow>);
17
+ renderSegmented(stakedData: Segment[][], lineClass: string): Selection<SVGPathElement, Segment[], SVGGElement, any>;
18
+ setSegmentColor(segments: Selection<SVGGElement, unknown, SVGGElement, unknown>, colorPalette: string[]): void;
19
+ updateSegmentedPath(linesObjects: Selection<BaseType, any, BaseType, any>): Promise<any>;
20
+ getAllLinesWithNewData(stakedData: Segment[][], lineClass: string): Selection<SVGPathElement, Segment[], SVGGElement, any>;
21
+ }
22
+ export {};
@@ -0,0 +1,49 @@
1
+ import { Helper } from "../../../engine/helpers/helper";
2
+ export class LineBuilder {
3
+ constructor(options, chart, lineGenerator) {
4
+ this.options = options;
5
+ this.chart = chart;
6
+ this.lineGenerator = lineGenerator;
7
+ }
8
+ renderSegmented(stakedData, lineClass) {
9
+ const block = this.options.elementAccessors.getBlock();
10
+ return block.svg.getChartGroup(this.chart.index)
11
+ .selectAll(`.${lineClass}${Helper.getCssClassesLine(this.chart.cssClasses)}`)
12
+ .data(stakedData)
13
+ .enter()
14
+ .append('path')
15
+ .attr('d', d => this.lineGenerator(d))
16
+ .attr('class', lineClass)
17
+ .style('fill', 'none')
18
+ .style('clip-path', `url(#${block.svg.getClipPathId()})`)
19
+ .style('pointer-events', 'none');
20
+ }
21
+ setSegmentColor(segments, colorPalette) {
22
+ segments.style('stroke', (d, i) => colorPalette[i % colorPalette.length]);
23
+ }
24
+ updateSegmentedPath(linesObjects) {
25
+ const block = this.options.elementAccessors.getBlock();
26
+ return new Promise(resolve => {
27
+ if (linesObjects.size() === 0) {
28
+ resolve('');
29
+ return;
30
+ }
31
+ let linesHandler = linesObjects;
32
+ if (block.transitionManager.durations.chartUpdate > 0)
33
+ linesHandler = linesHandler.interrupt()
34
+ .transition()
35
+ .duration(block.transitionManager.durations.chartUpdate)
36
+ .on('end', () => resolve(''));
37
+ linesHandler
38
+ .attr('d', d => this.lineGenerator(d));
39
+ if (block.transitionManager.durations.chartUpdate <= 0)
40
+ resolve('');
41
+ });
42
+ }
43
+ getAllLinesWithNewData(stakedData, lineClass) {
44
+ const block = this.options.elementAccessors.getBlock();
45
+ return block.svg.getChartGroup(this.chart.index)
46
+ .selectAll(`path.${lineClass}${Helper.getCssClassesLine(this.chart.cssClasses)}`)
47
+ .data(stakedData);
48
+ }
49
+ }
@@ -3,6 +3,7 @@ import { Model, TwoDimensionalOptionsModel } from "../../model/model";
3
3
  import { Block } from "../block/block";
4
4
  import { ChartContentManager } from "../contentManager/contentManagerFactory";
5
5
  import { Engine } from "../engine";
6
+ import { FilterEventManager } from "../filterManager/filterEventManager";
6
7
  export declare class TwoDimensionalManager implements ChartContentManager {
7
8
  private canvasValueLabels?;
8
9
  private linearGradientDef?;
@@ -10,6 +11,7 @@ export declare class TwoDimensionalManager implements ChartContentManager {
10
11
  render(engine: Engine, model: Model<TwoDimensionalOptionsModel>): void;
11
12
  updateData(block: Block, model: Model<TwoDimensionalOptionsModel>, data: MdtChartsDataSource): void;
12
13
  updateColors(block: Block, model: Model<TwoDimensionalOptionsModel>): void;
14
+ clearSelection(filterEventManager: FilterEventManager, model: Model<TwoDimensionalOptionsModel>): void;
13
15
  private renderCharts;
14
16
  private updateCharts;
15
17
  }