mdt-charts 1.26.0 → 1.26.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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[], 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): 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,15 +18,15 @@ 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)
21
+ render(block, scales, data, keyField, margin, keyAxisOrient, chart, blockSize, barSettings, barsAmounts, firstBarIndex) {
22
+ if (chart.isSegmented)
23
23
  this.renderSegmented(block, scales, data, keyField, margin, keyAxisOrient, chart, barsAmounts, firstBarIndex, barSettings);
24
24
  else
25
25
  this.renderGrouped(block, scales, data, keyField, margin, keyAxisOrient, chart, barsAmounts, blockSize, firstBarIndex, 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, firstBarIndex, barSettings) {
28
28
  let promises;
29
- if (isSegmented) {
29
+ if (chart.isSegmented) {
30
30
  promises = this.updateSegmented(block, newData, scales, margin, keyAxisOrient, chart, blockSize, barsAmounts, keyField, firstBarIndex, barSettings);
31
31
  }
32
32
  else {
@@ -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');
@@ -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);
@@ -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);
@@ -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), charts.findIndex(ch => ch.type === 'bar'));
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, charts.findIndex(ch => ch.type === 'bar'), 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.1",
4
4
  "description": "",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {