mdt-charts 1.26.0 → 1.26.2

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.
@@ -24,12 +24,14 @@ export interface ValueLabelAttrs {
24
24
  export declare class ChartValueLabels {
25
25
  private readonly globalOptions;
26
26
  private readonly chart;
27
- private static readonly valueLabelClass;
27
+ static readonly valueLabelClass: string;
28
28
  private readonly renderPipeline;
29
+ private readonly attrsProvider;
29
30
  constructor(globalOptions: ValueLabelsOptions, chart: TwoDimensionalChartModel);
30
31
  render(scales: Scales, data: MdtChartsDataRow[]): void;
31
32
  update(scales: Scales, newData: MdtChartsDataRow[]): Promise<void[]>;
32
- static getChartValueLabelsClassName(): string;
33
+ private renderByGroupIndex;
34
+ private updateByGroupIndex;
33
35
  private getAllValueLabelsOfChart;
34
36
  private setAttrs;
35
37
  private setClasses;
@@ -1,16 +1,18 @@
1
1
  import { NamesHelper } from "../../../engine/helpers/namesHelper";
2
- import { ValueLabelsHelper } from "../../../engine/features/valueLabels/valueLabelsHelper";
2
+ import { ValueLabelsAttrsProvider } from "../../../engine/features/valueLabels/valueLabelsHelper";
3
3
  import { Helper } from "../../../engine/helpers/helper";
4
4
  import { select } from "d3-selection";
5
5
  import { DomHelper } from "../../../engine/helpers/domHelper";
6
6
  import { CLASSES } from "../../../model/modelBuilder";
7
7
  import { ValueLabelsCollision } from "../../../engine/features/valueLabelsCollision/valueLabelsCollision";
8
8
  import { Pipeline } from "../../helpers/pipeline/Pipeline";
9
+ import { getStackedData } from "../../twoDimensionalNotation/line/lineHelper";
9
10
  export class ChartValueLabels {
10
11
  constructor(globalOptions, chart) {
11
12
  this.globalOptions = globalOptions;
12
13
  this.chart = chart;
13
14
  this.renderPipeline = new Pipeline();
15
+ this.attrsProvider = new ValueLabelsAttrsProvider();
14
16
  this.renderPipeline.push((valueLabels, { style }) => {
15
17
  valueLabels
16
18
  .attr('fill', 'currentColor')
@@ -22,50 +24,70 @@ export class ChartValueLabels {
22
24
  });
23
25
  }
24
26
  render(scales, data) {
25
- this.chart.data.valueFields.forEach((valueField, vfIndex) => {
26
- let valueLabels = this.getAllValueLabelsOfChart(vfIndex)
27
- .data(data)
28
- .enter()
29
- .append('text');
30
- valueLabels = this.renderPipeline.execute(valueLabels, { style: this.globalOptions.canvas.style });
31
- const attrs = ValueLabelsHelper.getValueLabelsAttrs(this.globalOptions, this.chart.valueLabels, scales, valueField);
32
- this.setAttrs(valueLabels, attrs, valueField.name, this.chart.valueLabels.format);
33
- this.setClasses(valueLabels, this.chart.cssClasses, vfIndex);
34
- });
27
+ if (this.chart.isSegmented) {
28
+ const preparedData = getStackedData(data, this.chart);
29
+ preparedData.forEach((segment, segmentIndex) => {
30
+ this.renderByGroupIndex(scales, segmentIndex, segment, segment[0].fieldName, '1', d => d.data);
31
+ });
32
+ }
33
+ else {
34
+ this.chart.data.valueFields.forEach((valueField, vfIndex) => {
35
+ this.renderByGroupIndex(scales, vfIndex, data, valueField.name, valueField.name, d => d);
36
+ });
37
+ }
35
38
  }
36
39
  update(scales, newData) {
37
40
  const updatePromises = [];
38
- this.chart.data.valueFields.forEach((valueField, vfIndex) => {
39
- const updateProms = new Promise((resolve) => {
40
- const valueLabels = this.getAllValueLabelsOfChart(vfIndex)
41
- .data(newData);
42
- valueLabels.exit().remove();
43
- const attrs = ValueLabelsHelper.getValueLabelsAttrs(this.globalOptions, this.chart.valueLabels, scales, valueField);
44
- let newValueLabels = valueLabels
45
- .enter()
46
- .append('text');
47
- newValueLabels = this.renderPipeline.execute(newValueLabels, { style: this.globalOptions.canvas.style });
48
- const mergedValueLabels = newValueLabels.merge(valueLabels);
49
- this.setAttrs(newValueLabels, attrs, valueField.name, this.chart.valueLabels.format);
50
- this.setClasses(mergedValueLabels, this.chart.cssClasses, vfIndex);
51
- this.setAttrs(valueLabels, attrs, valueField.name, this.chart.valueLabels.format, true, resolve);
41
+ if (this.chart.isSegmented) {
42
+ const preparedData = getStackedData(newData, this.chart);
43
+ preparedData.forEach((segment, segmentIndex) => {
44
+ const promise = this.updateByGroupIndex(scales, segmentIndex, segment, segment[0].fieldName, '1', d => d.data);
45
+ updatePromises.push(promise);
52
46
  });
53
- updatePromises.push(updateProms);
54
- });
47
+ }
48
+ else {
49
+ this.chart.data.valueFields.forEach((valueField, vfIndex) => {
50
+ const promise = this.updateByGroupIndex(scales, vfIndex, newData, valueField.name, valueField.name, d => d);
51
+ updatePromises.push(promise);
52
+ });
53
+ }
55
54
  return Promise.all(updatePromises);
56
55
  }
57
- static getChartValueLabelsClassName() {
58
- return ChartValueLabels.valueLabelClass;
56
+ renderByGroupIndex(scales, groupIndex, data, valueFieldName, datumField, dataRowAccessor) {
57
+ let valueLabels = this.getAllValueLabelsOfChart(groupIndex)
58
+ .data(data)
59
+ .enter()
60
+ .append('text');
61
+ valueLabels = this.renderPipeline.execute(valueLabels, { style: this.globalOptions.canvas.style });
62
+ const attrs = this.attrsProvider.getAttrs(this.globalOptions, this.chart.valueLabels, scales, datumField, dataRowAccessor);
63
+ this.setAttrs(valueLabels, attrs, valueFieldName, this.chart.valueLabels.format, dataRowAccessor);
64
+ this.setClasses(valueLabels, this.chart.cssClasses, groupIndex);
65
+ }
66
+ updateByGroupIndex(scales, groupIndex, data, valueFieldName, datumField, dataRowAccessor) {
67
+ return new Promise((resolve) => {
68
+ const valueLabels = this.getAllValueLabelsOfChart(groupIndex)
69
+ .data(data);
70
+ valueLabels.exit().remove();
71
+ const attrs = this.attrsProvider.getAttrs(this.globalOptions, this.chart.valueLabels, scales, datumField, dataRowAccessor);
72
+ let newValueLabels = valueLabels
73
+ .enter()
74
+ .append('text');
75
+ newValueLabels = this.renderPipeline.execute(newValueLabels, { style: this.globalOptions.canvas.style });
76
+ const mergedValueLabels = newValueLabels.merge(valueLabels);
77
+ this.setAttrs(newValueLabels, attrs, valueFieldName, this.chart.valueLabels.format, dataRowAccessor);
78
+ this.setClasses(mergedValueLabels, this.chart.cssClasses, groupIndex);
79
+ this.setAttrs(valueLabels, attrs, valueFieldName, this.chart.valueLabels.format, dataRowAccessor, true, resolve);
80
+ });
59
81
  }
60
82
  getAllValueLabelsOfChart(vfIndex) {
61
83
  const block = this.globalOptions.elementAccessors.getBlock().svg.getChartBlock();
62
84
  return block
63
85
  .selectAll(`.${ChartValueLabels.valueLabelClass}.${CLASSES.dataLabel}${Helper.getCssClassesLine(this.chart.cssClasses)}.chart-element-${vfIndex}`);
64
86
  }
65
- setAttrs(valueLabels, attrs, valueFieldName, formatter, animate = false, onEndAnimation) {
87
+ setAttrs(valueLabels, attrs, valueFieldName, formatter, dataRowAccessor, animate = false, onEndAnimation) {
66
88
  const animationName = 'labels-updating';
67
89
  valueLabels
68
- .text(d => formatter(d[valueFieldName]))
90
+ .text(d => formatter(dataRowAccessor(d)[valueFieldName]))
69
91
  .attr('dominant-baseline', attrs.dominantBaseline)
70
92
  .attr('text-anchor', attrs.textAnchor);
71
93
  if (animate) {
@@ -136,7 +158,7 @@ export class CanvasValueLabels {
136
158
  getAllValueLabels() {
137
159
  const block = this.options.elementAccessors.getBlock().svg.getChartBlock();
138
160
  return block
139
- .selectAll(`.${ChartValueLabels.getChartValueLabelsClassName()}`);
161
+ .selectAll(`.${ChartValueLabels.valueLabelClass}`);
140
162
  }
141
163
  getChartScales(scales, chart) {
142
164
  return {
@@ -1,6 +1,8 @@
1
1
  import { ValueLabelAttrs, ValueLabelsOptions } from "../../../engine/features/valueLabels/valueLabels";
2
- import { TwoDimChartValueLabelsOptions, ValueField } from "../../../model/model";
2
+ import { TwoDimChartValueLabelsOptions } from "../../../model/model";
3
3
  import { Scales } from "../../../engine/features/scale/scale";
4
- export declare class ValueLabelsHelper {
5
- static getValueLabelsAttrs(globalOptions: ValueLabelsOptions, valueLabels: TwoDimChartValueLabelsOptions, scales: Scales, valueField: ValueField): ValueLabelAttrs;
4
+ import { Segment } from "../../twoDimensionalNotation/lineLike/generatorMiddleware/lineLikeGeneratorDefineMiddleware";
5
+ import { MdtChartsDataRow } from "../../../config/config";
6
+ export declare class ValueLabelsAttrsProvider {
7
+ getAttrs(globalOptions: ValueLabelsOptions, valueLabels: TwoDimChartValueLabelsOptions, scales: Scales, datumField: string, dataRowAccessor: (d: MdtChartsDataRow | Segment) => MdtChartsDataRow): ValueLabelAttrs;
6
8
  }
@@ -1,6 +1,6 @@
1
1
  import { Scale } from "../../../engine/features/scale/scale";
2
- export class ValueLabelsHelper {
3
- static getValueLabelsAttrs(globalOptions, valueLabels, scales, valueField) {
2
+ export class ValueLabelsAttrsProvider {
3
+ getAttrs(globalOptions, valueLabels, scales, datumField, dataRowAccessor) {
4
4
  let attrs = {
5
5
  x: null,
6
6
  y: null,
@@ -9,12 +9,12 @@ export class ValueLabelsHelper {
9
9
  };
10
10
  const orient = globalOptions.canvas.keyAxisOrient;
11
11
  if (orient === 'left' || orient === 'right') {
12
- attrs.x = d => valueLabels.handleX(scales.value(d[valueField.name]));
13
- attrs.y = d => valueLabels.handleY(Scale.getScaledValue(scales.key, d[globalOptions.data.keyFieldName]));
12
+ attrs.x = d => valueLabels.handleX(scales.value(d[datumField]));
13
+ attrs.y = d => valueLabels.handleY(Scale.getScaledValue(scales.key, dataRowAccessor(d)[globalOptions.data.keyFieldName]));
14
14
  }
15
15
  else if (orient === 'bottom' || orient === 'top') {
16
- attrs.x = d => valueLabels.handleX(Scale.getScaledValue(scales.key, d[globalOptions.data.keyFieldName]));
17
- attrs.y = d => valueLabels.handleY(scales.value(d[valueField.name]));
16
+ attrs.x = d => valueLabels.handleX(Scale.getScaledValue(scales.key, dataRowAccessor(d)[globalOptions.data.keyFieldName]));
17
+ attrs.y = d => valueLabels.handleY(scales.value(d[datumField]));
18
18
  }
19
19
  return attrs;
20
20
  }
@@ -21,8 +21,8 @@ export declare class Bar {
21
21
  private createBarPipeline;
22
22
  private createSegmentGroupBarsPipeline;
23
23
  constructor();
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;
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>[];
24
+ render(block: Block, scales: Scales, data: MdtChartsDataRow[], keyField: Field, margin: BlockMargin, keyAxisOrient: Orient, chart: TwoDimensionalChartModel, blockSize: Size, barSettings: BarChartSettings, barsAmounts: number[]): void;
25
+ update(block: Block, newData: MdtChartsDataRow[], scales: Scales, margin: BlockMargin, keyAxisOrient: Orient, chart: TwoDimensionalChartModel, blockSize: Size, barsAmounts: number[], keyField: Field, barSettings: BarChartSettings): Promise<any>[];
26
26
  updateColors(block: Block, chart: TwoDimensionalChartModel): void;
27
27
  getAllBarsForChart(block: Block, chartCssClasses: string[]): Selection<BaseType, MdtChartsDataRow, BaseType, unknown>;
28
28
  private renderGrouped;
@@ -18,19 +18,19 @@ export class Bar {
18
18
  static get() {
19
19
  return new Bar();
20
20
  }
21
- render(block, scales, data, keyField, margin, keyAxisOrient, chart, blockSize, barSettings, barsAmounts, isSegmented, firstBarIndex) {
22
- if (isSegmented)
23
- this.renderSegmented(block, scales, data, keyField, margin, keyAxisOrient, chart, barsAmounts, firstBarIndex, barSettings);
21
+ render(block, scales, data, keyField, margin, keyAxisOrient, chart, blockSize, barSettings, barsAmounts) {
22
+ if (chart.isSegmented)
23
+ this.renderSegmented(block, scales, data, keyField, margin, keyAxisOrient, chart, barsAmounts, barSettings);
24
24
  else
25
- this.renderGrouped(block, scales, data, keyField, margin, keyAxisOrient, chart, barsAmounts, blockSize, firstBarIndex, barSettings);
25
+ this.renderGrouped(block, scales, data, keyField, margin, keyAxisOrient, chart, barsAmounts, blockSize, barSettings);
26
26
  }
27
- update(block, newData, scales, margin, keyAxisOrient, chart, blockSize, barsAmounts, keyField, firstBarIndex, barSettings, isSegmented) {
27
+ update(block, newData, scales, margin, keyAxisOrient, chart, blockSize, barsAmounts, keyField, barSettings) {
28
28
  let promises;
29
- if (isSegmented) {
30
- promises = this.updateSegmented(block, newData, scales, margin, keyAxisOrient, chart, blockSize, barsAmounts, keyField, firstBarIndex, barSettings);
29
+ if (chart.isSegmented) {
30
+ promises = this.updateSegmented(block, newData, scales, margin, keyAxisOrient, chart, barsAmounts, keyField, barSettings);
31
31
  }
32
32
  else {
33
- promises = this.updateGrouped(block, newData, scales, margin, keyAxisOrient, chart, blockSize, barsAmounts, keyField, firstBarIndex, barSettings);
33
+ promises = this.updateGrouped(block, newData, scales, margin, keyAxisOrient, chart, blockSize, barsAmounts, keyField, barSettings);
34
34
  }
35
35
  return promises;
36
36
  }
@@ -44,7 +44,7 @@ export class Bar {
44
44
  getAllBarsForChart(block, chartCssClasses) {
45
45
  return block.getSvg().selectAll(`rect.${this.barItemClass}${Helper.getCssClassesLine(chartCssClasses)}`);
46
46
  }
47
- renderGrouped(block, scales, data, keyField, margin, keyAxisOrient, chart, barsAmounts, blockSize, firstBarIndex, barSettings) {
47
+ renderGrouped(block, scales, data, keyField, margin, keyAxisOrient, chart, barsAmounts, blockSize, barSettings) {
48
48
  chart.data.valueFields.forEach((field, index) => {
49
49
  let bars = block.svg.getChartGroup(chart.index)
50
50
  .selectAll(`.${this.barItemClass}${Helper.getCssClassesLine(chart.cssClasses)}${Helper.getCssClassesLine(Helper.getCssClassesWithElementIndex(chart.cssClasses, index))}`)
@@ -54,7 +54,7 @@ export class Bar {
54
54
  .attr('class', this.barItemClass)
55
55
  .style('clip-path', `url(#${block.svg.getClipPathId()})`);
56
56
  bars = this.createBarPipeline.execute(bars, chart);
57
- const barAttrs = BarHelper.getGroupedBarAttrs(keyAxisOrient, scales, margin, keyField.name, field.name, BarHelper.getBarIndex(barsAmounts, chart.index - firstBarIndex) + index, sum(barsAmounts), barSettings);
57
+ const barAttrs = BarHelper.getGroupedBarAttrs(keyAxisOrient, scales, margin, keyField.name, field.name, chart.barViewOptions.barIndexes[index], sum(barsAmounts), barSettings);
58
58
  this.fillBarAttrs(bars, barAttrs);
59
59
  DomHelper.setCssClasses(bars, Helper.getCssClassesWithElementIndex(chart.cssClasses, index));
60
60
  DomHelper.setChartStyle(bars, chart.style, index, 'fill');
@@ -63,7 +63,7 @@ export class Bar {
63
63
  EmbeddedLabels.render(block, bars, barAttrs, EmbeddedLabelsHelper.getLabelField(chart.embeddedLabels, chart.data.valueFields, keyField, index), chart.embeddedLabels, keyAxisOrient, blockSize, margin, index, chart.cssClasses);
64
64
  });
65
65
  }
66
- renderSegmented(block, scales, data, keyField, margin, keyAxisOrient, chart, barsAmounts, firstBarIndex, barSettings) {
66
+ renderSegmented(block, scales, data, keyField, margin, keyAxisOrient, chart, barsAmounts, barSettings) {
67
67
  const stackedData = getStackedDataWithOwn(data, chart.data.valueFields.map(field => field.name));
68
68
  let groups = block.svg.getChartGroup(chart.index)
69
69
  .selectAll(`g.${this.barSegmentGroupClass}${Helper.getCssClassesLine(chart.cssClasses)}`)
@@ -82,7 +82,7 @@ export class Bar {
82
82
  .attr('class', this.barItemClass)
83
83
  .style('clip-path', `url(#${block.svg.getClipPathId()})`);
84
84
  bars = this.createBarPipeline.execute(bars, chart);
85
- const barAttrs = BarHelper.getStackedBarAttr(keyAxisOrient, scales, margin, keyField.name, BarHelper.getBarIndex(barsAmounts, chart.index) - firstBarIndex, sum(barsAmounts), barSettings);
85
+ const barAttrs = BarHelper.getStackedBarAttr(keyAxisOrient, scales, margin, keyField.name, chart.barViewOptions.barIndexes[0], sum(barsAmounts), barSettings);
86
86
  this.fillBarAttrs(bars, barAttrs);
87
87
  this.setInitialAttrsInfo(bars, keyAxisOrient, barSettings);
88
88
  DomHelper.setCssClasses(groups, chart.cssClasses);
@@ -95,7 +95,7 @@ export class Bar {
95
95
  thisClass.setSegmentColor(select(this).selectAll(Helper.getCssClassesLine(chart.cssClasses)), chart.style.elementColors, i);
96
96
  });
97
97
  }
98
- updateGrouped(block, newData, scales, margin, keyAxisOrient, chart, blockSize, barsAmounts, keyField, firstBarIndex, barSettings) {
98
+ updateGrouped(block, newData, scales, margin, keyAxisOrient, chart, blockSize, barsAmounts, keyField, barSettings) {
99
99
  const promises = [];
100
100
  chart.data.valueFields.forEach((valueField, index) => {
101
101
  const indexesOfRemoved = [];
@@ -123,7 +123,7 @@ export class Bar {
123
123
  .attr('class', this.barItemClass)
124
124
  .style('clip-path', `url(#${block.svg.getClipPathId()})`);
125
125
  newBars = this.createBarPipeline.execute(newBars, chart);
126
- const barAttrs = BarHelper.getGroupedBarAttrs(keyAxisOrient, scales, margin, keyField.name, valueField.name, BarHelper.getBarIndex(barsAmounts, chart.index) + index - firstBarIndex, sum(barsAmounts), barSettings);
126
+ const barAttrs = BarHelper.getGroupedBarAttrs(keyAxisOrient, scales, margin, keyField.name, valueField.name, chart.barViewOptions.barIndexes[index], sum(barsAmounts), barSettings);
127
127
  const prom = this.fillBarAttrs(bars, barAttrs, block.transitionManager.durations.chartUpdate)
128
128
  .then(() => {
129
129
  bars.style('opacity', null);
@@ -144,7 +144,7 @@ export class Bar {
144
144
  });
145
145
  return promises;
146
146
  }
147
- updateSegmented(block, newData, scales, margin, keyAxisOrient, chart, blockSize, barsAmounts, keyField, firstBarIndex, barSettings) {
147
+ updateSegmented(block, newData, scales, margin, keyAxisOrient, chart, barsAmounts, keyField, barSettings) {
148
148
  const stackedData = getStackedDataWithOwn(newData, chart.data.valueFields.map(field => field.name));
149
149
  block.svg.getChartGroup(chart.index)
150
150
  .selectAll(`.${this.barItemClass}${Helper.getCssClassesLine(chart.cssClasses)}`)
@@ -166,7 +166,7 @@ export class Bar {
166
166
  .attr('class', this.barItemClass)
167
167
  .style('clip-path', `url(#${block.svg.getClipPathId()})`);
168
168
  newBars = this.createBarPipeline.execute(newBars, chart);
169
- const barAttrs = BarHelper.getStackedBarAttr(keyAxisOrient, scales, margin, keyField.name, BarHelper.getBarIndex(barsAmounts, chart.index) - firstBarIndex, sum(barsAmounts), barSettings);
169
+ const barAttrs = BarHelper.getStackedBarAttr(keyAxisOrient, scales, margin, keyField.name, chart.barViewOptions.barIndexes[0], sum(barsAmounts), barSettings);
170
170
  const prom = this.fillBarAttrs(bars, barAttrs, block.transitionManager.durations.chartUpdate)
171
171
  .then(() => {
172
172
  this.setInitialAttrsInfo(bars, keyAxisOrient, barSettings);
@@ -41,13 +41,6 @@ export declare class BarHelper {
41
41
  static getGroupedBarAttrs(keyAxisOrient: Orient, scales: Scales, margin: BlockMargin, keyField: string, valueFieldName: string, barIndex: number, barsAmount: number, barSettings: BarChartSettings): BarAttrsHelper;
42
42
  static getStackedBarAttr(keyAxisOrient: Orient, scales: Scales, margin: BlockMargin, keyField: string, barIndex: number, barsAmount: number, barSettings: BarChartSettings): BarAttrsHelper;
43
43
  static getBarsInGroupAmount(charts: TwoDimensionalChartModel[]): number[];
44
- /**
45
- * Получение индекса бара среди всх графиков и value-филдов. Используется для того, чтобы узнать, какой по счету в группе
46
- * этот бар идет (сегментированный всегда один, группированный - количество value-филдов).
47
- * @param barsAmounts
48
- * @param chartIndex
49
- */
50
- static getBarIndex(barsAmounts: number[], chartIndex: number): number;
51
44
  static setBarAttrsByKey(attrs: BarAttrsHelper, keyAxisOrient: Orient, scaleKey: AxisScale<any>, margin: BlockMargin, keyField: string, barIndex: number, settingsStore: BandLikeChartSettingsStore, isSegmented: boolean): void;
52
45
  private static setGroupedBarAttrsByValue;
53
46
  static getBandItemValueStretch(scaleValue: AxisScale<any>, valueFieldName: string): (dataRow: MdtChartsDataRow) => number;
@@ -63,23 +63,6 @@ export class BarHelper {
63
63
  });
64
64
  return amounts;
65
65
  }
66
- /**
67
- * Получение индекса бара среди всх графиков и value-филдов. Используется для того, чтобы узнать, какой по счету в группе
68
- * этот бар идет (сегментированный всегда один, группированный - количество value-филдов).
69
- * @param barsAmounts
70
- * @param chartIndex
71
- */
72
- static getBarIndex(barsAmounts, chartIndex) {
73
- if (barsAmounts.length < 2)
74
- return 0;
75
- let index = 0;
76
- barsAmounts.forEach((chartBars, i) => {
77
- if (i < chartIndex) {
78
- index += chartBars;
79
- }
80
- });
81
- return index;
82
- }
83
66
  static setBarAttrsByKey(attrs, keyAxisOrient, scaleKey, margin, keyField, barIndex, settingsStore, isSegmented) {
84
67
  if (keyAxisOrient === 'top' || keyAxisOrient === 'bottom') {
85
68
  attrs.x = d => scaleKey(Helper.getKeyFieldValue(d, keyField, isSegmented)) + margin.left + settingsStore.getBandItemPad(barIndex);
@@ -124,7 +124,7 @@ export class TwoDimensionalManager {
124
124
  charts.forEach((chart) => {
125
125
  const chartScales = { key: scales.key, value: chart.data.valueGroup === "secondary" ? scales.valueSecondary : scales.value };
126
126
  if (chart.type === 'bar')
127
- Bar.get().render(block, chartScales, data[dataOptions.dataSource], dataOptions.keyField, margin, keyAxisOrient, chart, blockSize, chartSettings.bar, BarHelper.getBarsInGroupAmount(charts), chart.isSegmented, charts.findIndex(ch => ch.type === 'bar'));
127
+ Bar.get().render(block, chartScales, data[dataOptions.dataSource], dataOptions.keyField, margin, keyAxisOrient, chart, blockSize, chartSettings.bar, BarHelper.getBarsInGroupAmount(charts));
128
128
  else if (chart.type === 'line')
129
129
  Line.get({ staticSettings: chartSettings.lineLike }).render(block, chartScales, data[dataOptions.dataSource], dataOptions.keyField, margin, keyAxisOrient, chart);
130
130
  else if (chart.type === 'area')
@@ -141,7 +141,7 @@ export class TwoDimensionalManager {
141
141
  const chartScales = { key: scales.key, value: chart.data.valueGroup === "secondary" ? scales.valueSecondary : scales.value };
142
142
  let proms;
143
143
  if (chart.type === 'bar') {
144
- proms = Bar.get().update(block, data[dataOptions.dataSource], chartScales, margin, keyAxisOrient, chart, blockSize, BarHelper.getBarsInGroupAmount(charts), dataOptions.keyField, charts.findIndex(ch => ch.type === 'bar'), chartSettings.bar, chart.isSegmented);
144
+ proms = Bar.get().update(block, data[dataOptions.dataSource], chartScales, margin, keyAxisOrient, chart, blockSize, BarHelper.getBarsInGroupAmount(charts), dataOptions.keyField, chartSettings.bar);
145
145
  }
146
146
  else if (chart.type === 'line') {
147
147
  proms = Line.get({ staticSettings: chartSettings.lineLike }).update(block, chartScales, data[dataOptions.dataSource], dataOptions.keyField, margin, keyAxisOrient, chart);
@@ -317,6 +317,7 @@ interface TwoDimensionalBarLikeChartModel {
317
317
  export interface TwoDimensionalBarLikeChartViewModel {
318
318
  hatch: BarLikeChartHatchOptions;
319
319
  borderRadius: BarLikeChartBorderRadius;
320
+ barIndexes: number[];
320
321
  }
321
322
  interface TwoDimensionalAreaChartModel {
322
323
  areaViewOptions: AreaChartViewOptions;
@@ -4,7 +4,8 @@ import { MdtChartsLineLikeChartShape } from "../../../designer/designerConfig";
4
4
  export declare const LINE_CHART_DEFAULT_WIDTH = 2;
5
5
  export declare function parseShape(chartOrientation: ChartOrientation, configOptions?: MdtChartsLineLikeChartShape): LineLikeChartShapeOptions;
6
6
  export declare function parseDashStyles(configOptions?: MdtChartsLineLikeChartDashedStyles): LineLikeChartDashOptions;
7
- export declare function getBarViewOptions(chart: MdtChartsTwoDimensionalChart, keyAxisOrient: Orient): TwoDimensionalBarLikeChartViewModel;
7
+ export declare function getBarViewOptions(chart: MdtChartsTwoDimensionalChart, keyAxisOrient: Orient, barIndexes: number[]): TwoDimensionalBarLikeChartViewModel;
8
+ export declare function calculateBarIndexes(allCharts: Pick<MdtChartsTwoDimensionalChart, "isSegmented" | "data" | "type">[], currentChart: Pick<MdtChartsTwoDimensionalChart, "isSegmented" | "data" | "type">, currentChartIndex: number): number[];
8
9
  export declare function getSegmentedRadiusValues(segmentsLength: number, segmentIndex: number, keyAxisOrient: Orient, defaultRadius: number): BarBorderRadius;
9
10
  export declare function getLegendMarkerOptions(chart: MdtChartsTwoDimensionalChart): ChartLegendModel;
10
11
  export declare function getLineViewOptions(chart: MdtChartsTwoDimensionalChart): TwoDimensionalChartLegendLineModel;
@@ -29,7 +29,7 @@ export function parseDashStyles(configOptions) {
29
29
  gapSize: (_c = configOptions === null || configOptions === void 0 ? void 0 : configOptions.gapSize) !== null && _c !== void 0 ? _c : DEFAULT_GAP_SIZE_PX
30
30
  };
31
31
  }
32
- export function getBarViewOptions(chart, keyAxisOrient) {
32
+ export function getBarViewOptions(chart, keyAxisOrient, barIndexes) {
33
33
  var _a, _b, _c, _d, _e, _f;
34
34
  const hatch = { on: (_c = (_b = (_a = chart.barStyles) === null || _a === void 0 ? void 0 : _a.hatch) === null || _b === void 0 ? void 0 : _b.on) !== null && _c !== void 0 ? _c : false };
35
35
  const defaultRadius = (_f = (_e = (_d = chart.barStyles) === null || _d === void 0 ? void 0 : _d.borderRadius) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : BAR_CHART_BORDER_RADIUS_DEFAULT;
@@ -39,7 +39,14 @@ export function getBarViewOptions(chart, keyAxisOrient) {
39
39
  handle: (valueIndex) => getSegmentedRadiusValues(chart.data.valueFields.length, valueIndex, keyAxisOrient, defaultRadius),
40
40
  }
41
41
  };
42
- return { hatch, borderRadius };
42
+ return { hatch, borderRadius, barIndexes };
43
+ }
44
+ export function calculateBarIndexes(allCharts, currentChart, currentChartIndex) {
45
+ const prevBarCharts = allCharts.slice(0, currentChartIndex).filter(ch => ch.type === "bar");
46
+ const startBarIndex = prevBarCharts.reduce((acc, ch) => acc + (ch.isSegmented ? 1 : ch.data.valueFields.length), 0);
47
+ if (currentChart.isSegmented)
48
+ return [startBarIndex];
49
+ return currentChart.data.valueFields.map((_, index) => startBarIndex + index);
43
50
  }
44
51
  function getRadiusValues(defaultRadius) {
45
52
  return {
@@ -3,7 +3,7 @@ import { TwoDimensionalChartStyleModel } from "../chartStyleModel/twoDimensional
3
3
  import { AxisModel } from "../featuresModel/axisModel";
4
4
  import { ScaleAxisRecalcer } from "../featuresModel/scaleModel/scaleAxisRecalcer";
5
5
  import { ScaleModel } from "../featuresModel/scaleModel/scaleModel";
6
- import { getAreaViewOptions, getBarViewOptions, getLegendMarkerOptions, LINE_CHART_DEFAULT_WIDTH, parseDashStyles, parseShape } from "./twoDimensional/styles";
6
+ import { calculateBarIndexes, getAreaViewOptions, getBarViewOptions, getLegendMarkerOptions, LINE_CHART_DEFAULT_WIDTH, parseDashStyles, parseShape } from "./twoDimensional/styles";
7
7
  import { calculateValueLabelAlignment, getValueLabelX, getValueLabelY } from "../../model/featuresModel/valueLabelsModel/valueLabelsModel";
8
8
  import { TwoDimensionalModelHelper } from "../helpers/twoDimensionalModelHelper";
9
9
  import { TitleConfigReader } from "../modelInstance/titleConfigReader";
@@ -102,7 +102,7 @@ export class TwoDimensionalModel {
102
102
  strokeWidth: (_m = (_l = chart.lineStyles) === null || _l === void 0 ? void 0 : _l.width) !== null && _m !== void 0 ? _m : LINE_CHART_DEFAULT_WIDTH,
103
103
  renderForKey: (dataRow, valueFieldName) => dataRow[valueFieldName] !== null && dataRow[valueFieldName] !== undefined
104
104
  },
105
- barViewOptions: getBarViewOptions(chart, keyAxisOrient),
105
+ barViewOptions: getBarViewOptions(chart, keyAxisOrient, calculateBarIndexes(charts, chart, index)),
106
106
  legend: getLegendMarkerOptions(chart),
107
107
  index,
108
108
  valueLabels: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdt-charts",
3
- "version": "1.26.0",
3
+ "version": "1.26.2",
4
4
  "description": "",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {