mdt-charts 1.19.0 → 1.20.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.
@@ -131,7 +131,9 @@ interface GridLineFlag {
131
131
  export interface TwoDimensionalAxis {
132
132
  key: DiscreteAxisOptions;
133
133
  value: NumberAxisOptions;
134
+ valueSecondary?: NumberSecondaryAxisOptions;
134
135
  }
136
+ export declare type NumberSecondaryAxisOptions = Omit<NumberAxisOptions, 'position'>;
135
137
  export interface AxisOptions {
136
138
  visibility: boolean;
137
139
  position: AxisPosition;
@@ -1,11 +1,11 @@
1
1
  import { AxisModelOptions, IAxisModel, IScaleModel } from "../../../model/model";
2
2
  import { Block } from "../../block/block";
3
- import { Scales } from "../scale/scale";
3
+ import { ScalesWithSecondary } from "../scale/scale";
4
4
  import { Size } from '../../../config/config';
5
5
  export declare class Axis {
6
6
  static axesClass: string;
7
- static render(block: Block, scales: Scales, scaleModel: IScaleModel, axisModel: IAxisModel, blockSize: Size): void;
8
- static update(block: Block, scales: Scales, scalesOptions: IScaleModel, axisModel: IAxisModel, blockSize: Size, keyDomainsEquality: boolean): void;
7
+ static render(block: Block, scales: ScalesWithSecondary, scaleModel: IScaleModel, axisModel: IAxisModel, blockSize: Size): void;
8
+ static update(block: Block, scales: ScalesWithSecondary, scalesOptions: IScaleModel, axisModel: IAxisModel, blockSize: Size, keyDomainsEquality: boolean): void;
9
9
  static raiseKeyAxis(block: Block, axisOptions: AxisModelOptions): void;
10
10
  private static findAxis;
11
11
  private static renderAxis;
@@ -9,14 +9,20 @@ import { AXIS_VERTICAL_LABEL_PADDING } from '../../../model/margin/twoDim/twoDim
9
9
  const MINIMAL_STEP_SIZE_FOR_WRAPPING = 38;
10
10
  export class Axis {
11
11
  static render(block, scales, scaleModel, axisModel, blockSize) {
12
+ var _a;
12
13
  if (axisModel.value.visibility)
13
14
  this.renderAxis(block, scales.value, scaleModel.value, axisModel.value, blockSize);
15
+ if ((_a = axisModel.valueSecondary) === null || _a === void 0 ? void 0 : _a.visibility)
16
+ this.renderAxis(block, scales.valueSecondary, scaleModel.valueSecondary, axisModel.valueSecondary, blockSize);
14
17
  if (axisModel.key.visibility)
15
18
  this.renderAxis(block, scales.key, scaleModel.key, axisModel.key, blockSize);
16
19
  }
17
20
  static update(block, scales, scalesOptions, axisModel, blockSize, keyDomainsEquality) {
21
+ var _a;
18
22
  if (axisModel.value.visibility)
19
23
  this.updateValueAxis(block, scales.value, scalesOptions.value, axisModel.value, blockSize);
24
+ if ((_a = axisModel.valueSecondary) === null || _a === void 0 ? void 0 : _a.visibility)
25
+ this.updateValueAxis(block, scales.valueSecondary, scalesOptions.valueSecondary, axisModel.valueSecondary, blockSize);
20
26
  if (axisModel.key.visibility)
21
27
  this.updateKeyAxis(block, scales.key, scalesOptions.key, axisModel.key, blockSize, keyDomainsEquality);
22
28
  }
@@ -14,7 +14,7 @@ export class Scale {
14
14
  }
15
15
  static getScalesWithSecondary(scaleKey, scaleValue, scaleValueSecondary, bandSettings) {
16
16
  const scales = this.getScales(scaleKey, scaleValue, bandSettings);
17
- return Object.assign(Object.assign({}, scales), { valueSecondary: this.getScaleValue(scaleValueSecondary) });
17
+ return Object.assign(Object.assign({}, scales), (scaleValueSecondary && { valueSecondary: this.getScaleValue(scaleValueSecondary) }));
18
18
  }
19
19
  static getScaleValue(scaleValue) {
20
20
  if (scaleValue.type === 'linear')
@@ -1,4 +1,4 @@
1
- import { AxisPosition, ChartOrientation, MdtChartsDataSource, NumberAxisOptions, AxisLabelPosition, MdtChartsTwoDimensionalOptions, DiscreteAxisOptions } from "../../config/config";
1
+ import { AxisPosition, ChartOrientation, MdtChartsDataSource, NumberAxisOptions, AxisLabelPosition, MdtChartsTwoDimensionalOptions, DiscreteAxisOptions, NumberSecondaryAxisOptions } from "../../config/config";
2
2
  import { AxisModelOptions, Orient } from "../model";
3
3
  import { AxisType } from "../modelBuilder";
4
4
  import { AxisLabelCanvas, TooltipSettings } from "../../designer/designerConfig";
@@ -12,7 +12,9 @@ export declare const MINIMAL_HORIZONTAL_STEP_SIZE = 100;
12
12
  export declare class AxisModel {
13
13
  private static service;
14
14
  static getKeyAxis(options: MdtChartsTwoDimensionalOptions, data: MdtChartsDataSource, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel, tooltipSettings: TooltipSettings, getZeroCoordinate?: () => number): AxisModelOptions;
15
- static getValueAxis(orient: ChartOrientation, axisConfig: NumberAxisOptions, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel): AxisModelOptions;
15
+ static getMainValueAxis(orient: ChartOrientation, position: AxisPosition, axisConfig: NumberAxisOptions, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel): AxisModelOptions;
16
+ static getSecondaryValueAxis(orient: ChartOrientation, mainAxisPosition: AxisPosition, axisConfig: NumberSecondaryAxisOptions, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel): AxisModelOptions;
17
+ private static getValueAxis;
16
18
  static getAxisLength(chartOrientation: ChartOrientation, canvasModel: CanvasModel): number;
17
19
  static getAxisOrient(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition): Orient;
18
20
  static getAxisTranslateX(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition, canvasModel: CanvasModel): number;
@@ -29,16 +29,22 @@ export class AxisModel {
29
29
  visibility: axisConfig.visibility
30
30
  };
31
31
  }
32
- static getValueAxis(orient, axisConfig, labelConfig, canvasModel) {
32
+ static getMainValueAxis(orient, position, axisConfig, labelConfig, canvasModel) {
33
+ return this.getValueAxis(orient, position, 'value-axis', axisConfig, labelConfig, canvasModel);
34
+ }
35
+ static getSecondaryValueAxis(orient, mainAxisPosition, axisConfig, labelConfig, canvasModel) {
36
+ return this.getValueAxis(orient, mainAxisPosition === "start" ? "end" : "start", 'value-secondary-axis', axisConfig, labelConfig, canvasModel);
37
+ }
38
+ static getValueAxis(orient, position, cssClass, axisConfig, labelConfig, canvasModel) {
33
39
  var _a, _b;
34
40
  return {
35
41
  type: 'value',
36
- orient: AxisModel.getAxisOrient(AxisType.Value, orient, axisConfig.position),
42
+ orient: AxisModel.getAxisOrient(AxisType.Value, orient, position),
37
43
  translate: {
38
- translateX: AxisModel.getAxisTranslateX(AxisType.Value, orient, axisConfig.position, canvasModel),
39
- translateY: AxisModel.getAxisTranslateY(AxisType.Value, orient, axisConfig.position, canvasModel)
44
+ translateX: AxisModel.getAxisTranslateX(AxisType.Value, orient, position, canvasModel),
45
+ translateY: AxisModel.getAxisTranslateY(AxisType.Value, orient, position, canvasModel)
40
46
  },
41
- cssClass: 'value-axis',
47
+ cssClass,
42
48
  ticks: axisConfig.ticks,
43
49
  labels: {
44
50
  maxSize: labelConfig.maxSize.main,
@@ -38,7 +38,7 @@ export class ScaleModel {
38
38
  end: getScaleValueRangePeek(options.orientation, canvasModel)
39
39
  },
40
40
  type: "linear",
41
- formatter: (_a = configReader === null || configReader === void 0 ? void 0 : configReader.getAxisLabelFormatter()) !== null && _a !== void 0 ? _a : null
41
+ formatter: (_a = configReader === null || configReader === void 0 ? void 0 : configReader.getSecondaryAxisLabelFormatter()) !== null && _a !== void 0 ? _a : null
42
42
  };
43
43
  }
44
44
  getScaleKeyType(charts) {
@@ -12,6 +12,8 @@ export declare class TwoDimMarginModel {
12
12
  recalcMargin(otherComponents: OtherCommonComponents, modelInstance: ModelInstance): void;
13
13
  recalcMarginByVerticalAxisLabel(modelInstance: ModelInstance): void;
14
14
  private getMaxLabelSize;
15
+ private getMaxLabelSizeSecondary;
15
16
  private recalcVerticalMarginByAxisLabelHeight;
16
17
  private recalcHorizontalMarginByAxisLabelWidth;
18
+ private recalcMarginBySecondaryAxisLabelSize;
17
19
  }
@@ -23,6 +23,10 @@ export class TwoDimMarginModel {
23
23
  ? !TwoDimensionalModel.getChartsEmbeddedLabelsFlag(this.configReader.options.charts, this.configReader.options.orientation)
24
24
  : true;
25
25
  this.recalcHorizontalMarginByAxisLabelWidth(labelSize, canvasModel, showingFlag);
26
+ if (this.configReader.containsSecondaryAxis()) {
27
+ const secondaryLabelSize = this.getMaxLabelSizeSecondary(modelInstance);
28
+ this.recalcMarginBySecondaryAxisLabelSize(secondaryLabelSize, canvasModel);
29
+ }
26
30
  }
27
31
  recalcMarginByVerticalAxisLabel(modelInstance) {
28
32
  if (this.configReader.options.orientation === 'vertical') {
@@ -43,11 +47,23 @@ export class TwoDimMarginModel {
43
47
  labelsTexts = modelInstance.dataModel.repository.getValuesByKeyField();
44
48
  }
45
49
  else {
46
- labelsTexts = this.configReader.calculateBiggestValueAndDecremented(modelInstance.dataModel.repository)
50
+ labelsTexts = this.configReader.getBiggestValueAndDecremented(modelInstance.dataModel.repository)
47
51
  .map(v => this.configReader.getAxisLabelFormatter()(v).toString());
48
52
  }
49
53
  return AxisModel.getLabelSize(this.designerConfig.canvas.axisLabel.maxSize.main, labelsTexts);
50
54
  }
55
+ getMaxLabelSizeSecondary(modelInstance) {
56
+ const keyAxisOrient = AxisModel.getAxisOrient(AxisType.Key, this.configReader.options.orientation, this.configReader.options.axis.key.position);
57
+ let labelsTexts;
58
+ if (keyAxisOrient === 'left' || keyAxisOrient === 'right') {
59
+ labelsTexts = modelInstance.dataModel.repository.getValuesByKeyField();
60
+ }
61
+ else {
62
+ labelsTexts = this.configReader.getBiggestValueAndDecrementedSecondary(modelInstance.dataModel.repository)
63
+ .map(v => this.configReader.getSecondaryAxisLabelFormatter()(v).toString());
64
+ }
65
+ return AxisModel.getLabelSize(this.designerConfig.canvas.axisLabel.maxSize.main, labelsTexts);
66
+ }
51
67
  recalcVerticalMarginByAxisLabelHeight(labelSize, canvasModel) {
52
68
  const keyAxisOrient = AxisModel.getAxisOrient(AxisType.Key, this.configReader.options.orientation, this.configReader.options.axis.key.position);
53
69
  const valueAxisOrient = AxisModel.getAxisOrient(AxisType.Value, this.configReader.options.orientation, this.configReader.options.axis.value.position);
@@ -68,4 +84,21 @@ export class TwoDimMarginModel {
68
84
  canvasModel.increaseMarginSide(valueAxisOrient, labelSize.width + AXIS_VERTICAL_LABEL_PADDING);
69
85
  }
70
86
  }
87
+ recalcMarginBySecondaryAxisLabelSize(labelSize, canvasModel) {
88
+ const valueAxisOrient = AxisModel.getAxisOrient(AxisType.Value, this.configReader.options.orientation, this.configReader.options.axis.value.position);
89
+ const secondaryOrientByMain = {
90
+ bottom: "top",
91
+ left: "right",
92
+ right: "left",
93
+ top: "bottom"
94
+ };
95
+ const secondaryOrient = secondaryOrientByMain[valueAxisOrient];
96
+ const sizeMap = {
97
+ vertical: labelSize.width + AXIS_VERTICAL_LABEL_PADDING,
98
+ horizontal: labelSize.height + AXIS_HORIZONTAL_LABEL_PADDING
99
+ };
100
+ if (this.configReader.options.axis.valueSecondary.visibility) {
101
+ canvasModel.increaseMarginSide(secondaryOrient, sizeMap[this.configReader.options.orientation]);
102
+ }
103
+ }
71
104
  }
@@ -101,6 +101,7 @@ export interface RangeModel {
101
101
  export interface IAxisModel {
102
102
  key: AxisModelOptions;
103
103
  value: AxisModelOptions;
104
+ valueSecondary?: AxisModelOptions;
104
105
  }
105
106
  export interface AxisModelOptions {
106
107
  visibility: boolean;
@@ -1,4 +1,4 @@
1
- import { AxisLabelFormatter, MdtChartsConfig, MdtChartsField, MdtChartsFieldName, MdtChartsTwoDimensionalOptions, TwoDimensionalChartType } from "../../config/config";
1
+ import { AxisLabelFormatter, MdtChartsConfig, MdtChartsField, MdtChartsFieldName, MdtChartsTwoDimensionalOptions, TwoDimensionalChartType, TwoDimensionalValueGroup } from "../../config/config";
2
2
  import { DesignerConfig } from "../../designer/designerConfig";
3
3
  import { DataRepositoryModel } from "../../model/modelInstance/dataModel/dataRepository";
4
4
  interface BaseConfigReader {
@@ -10,13 +10,18 @@ export declare class TwoDimConfigReader implements BaseConfigReader {
10
10
  readonly options: MdtChartsTwoDimensionalOptions;
11
11
  constructor(config: MdtChartsConfig, designerConfig: DesignerConfig);
12
12
  getValueFields(): MdtChartsField[];
13
- calculateBiggestValueAndDecremented(repository: DataRepositoryModel): number[];
14
- getFieldsBySegments(): MdtChartsFieldName[][];
13
+ getBiggestValueAndDecremented(repository: DataRepositoryModel): number[];
14
+ getBiggestValueAndDecrementedSecondary(repository: DataRepositoryModel): number[];
15
+ getFieldsBySegments(valueGroup: TwoDimensionalValueGroup): MdtChartsFieldName[][];
15
16
  getAxisLabelFormatter(): AxisLabelFormatter;
17
+ getSecondaryAxisLabelFormatter(): AxisLabelFormatter;
16
18
  getLegendItemInfo(): {
17
19
  text: string;
18
20
  chartType: TwoDimensionalChartType;
19
21
  }[];
22
+ containsSecondaryAxis(): boolean;
23
+ private calculateBiggestValueAndDecremented;
24
+ private calculateAxisLabelFormatter;
20
25
  }
21
26
  export declare class PolarConfigReader implements BaseConfigReader {
22
27
  private options;
@@ -18,18 +18,16 @@ export class TwoDimConfigReader {
18
18
  });
19
19
  return fields;
20
20
  }
21
- calculateBiggestValueAndDecremented(repository) {
22
- const domain = this.options.axis.value.domain;
23
- const resolvedDomain = getResolvedDomain(domain, repository.getRawRows());
24
- if (resolvedDomain && resolvedDomain.end !== -1) {
25
- return [resolvedDomain.end, resolvedDomain.end - 1];
26
- }
27
- return repository.getBiggestValueAndDecremented(this.getFieldsBySegments());
21
+ getBiggestValueAndDecremented(repository) {
22
+ return this.calculateBiggestValueAndDecremented(repository, this.options.axis.value.domain, this.getFieldsBySegments("main"));
23
+ }
24
+ getBiggestValueAndDecrementedSecondary(repository) {
25
+ return this.calculateBiggestValueAndDecremented(repository, this.options.axis.valueSecondary.domain, this.getFieldsBySegments("secondary"));
28
26
  }
29
- getFieldsBySegments() {
27
+ getFieldsBySegments(valueGroup) {
30
28
  const segments = [];
31
- const mainCharts = this.options.charts.filter(chart => chart.data.valueGroup !== 'secondary');
32
- mainCharts.forEach(chart => {
29
+ const valueGroupCharts = this.options.charts.filter(chart => { var _a; return ((_a = chart.data.valueGroup) !== null && _a !== void 0 ? _a : "main") === valueGroup; });
30
+ valueGroupCharts.forEach(chart => {
33
31
  if (!chart.isSegmented)
34
32
  segments.push(...chart.data.valueFields.map(vf => [vf.name]));
35
33
  else
@@ -38,11 +36,10 @@ export class TwoDimConfigReader {
38
36
  return segments;
39
37
  }
40
38
  getAxisLabelFormatter() {
41
- var _a, _b;
42
- if ((_a = this.options.axis.value.labels) === null || _a === void 0 ? void 0 : _a.format)
43
- return (_b = this.options.axis.value.labels) === null || _b === void 0 ? void 0 : _b.format;
44
- const valueFieldFormat = this.options.charts[0].data.valueFields[0].format;
45
- return (v) => this.designerConfig.dataFormat.formatters(v, { type: valueFieldFormat });
39
+ return this.calculateAxisLabelFormatter(this.options.axis.value);
40
+ }
41
+ getSecondaryAxisLabelFormatter() {
42
+ return this.calculateAxisLabelFormatter(this.options.axis.valueSecondary);
46
43
  }
47
44
  getLegendItemInfo() {
48
45
  const info = [];
@@ -54,6 +51,23 @@ export class TwoDimConfigReader {
54
51
  });
55
52
  return info;
56
53
  }
54
+ containsSecondaryAxis() {
55
+ return !!this.options.axis.valueSecondary && this.options.charts.some(chart => chart.data.valueGroup === 'secondary');
56
+ }
57
+ calculateBiggestValueAndDecremented(repository, domain, fields) {
58
+ const resolvedDomain = getResolvedDomain(domain, repository.getRawRows());
59
+ if (resolvedDomain && resolvedDomain.end !== -1) {
60
+ return [resolvedDomain.end, resolvedDomain.end - 1];
61
+ }
62
+ return repository.getBiggestValueAndDecremented(fields);
63
+ }
64
+ calculateAxisLabelFormatter(axisValue) {
65
+ var _a, _b;
66
+ if ((_a = axisValue.labels) === null || _a === void 0 ? void 0 : _a.format)
67
+ return (_b = axisValue.labels) === null || _b === void 0 ? void 0 : _b.format;
68
+ const valueFieldFormat = this.options.charts[0].data.valueFields[0].format;
69
+ return (v) => this.designerConfig.dataFormat.formatters(v, { type: valueFieldFormat });
70
+ }
57
71
  }
58
72
  export class PolarConfigReader {
59
73
  constructor(config) {
@@ -7,6 +7,7 @@ import { getLegendMarkerOptions, parseDashStyles, parseShape } from "./twoDimens
7
7
  import { getResolvedTitle } from "../../model/featuresModel/titleModel";
8
8
  export class TwoDimensionalModel {
9
9
  static getOptions(configReader, designerConfig, modelInstance) {
10
+ let secondaryScaleValueInfo;
10
11
  const options = configReader.options;
11
12
  const canvasModel = modelInstance.canvasModel;
12
13
  const resolvedTitle = getResolvedTitle(options.title, modelInstance.dataModel.repository.getRawRows());
@@ -14,23 +15,18 @@ export class TwoDimensionalModel {
14
15
  const scaleMarginRecalcer = new ScaleAxisRecalcer(() => scaleModel.getScaleLinear(options, modelInstance.dataModel.repository.getScopedRows(), canvasModel, configReader));
15
16
  scaleMarginRecalcer.recalculateMargin(canvasModel, options.orientation, options.axis.key);
16
17
  const scaleValueInfo = scaleMarginRecalcer.getScaleValue();
17
- const secondaryScaleMarginRecalcer = new ScaleAxisRecalcer(() => scaleModel.getScaleSecondaryLinear(options, modelInstance.dataModel.repository.getScopedRows(), canvasModel, configReader));
18
- secondaryScaleMarginRecalcer.recalculateMargin(canvasModel, options.orientation, options.axis.key);
19
- const secondaryScaleValueInfo = secondaryScaleMarginRecalcer.getScaleValue();
18
+ if (configReader.containsSecondaryAxis()) {
19
+ const secondaryScaleMarginRecalcer = new ScaleAxisRecalcer(() => scaleModel.getScaleSecondaryLinear(options, modelInstance.dataModel.repository.getScopedRows(), canvasModel, configReader));
20
+ secondaryScaleMarginRecalcer.recalculateMargin(canvasModel, options.orientation, options.axis.key);
21
+ secondaryScaleValueInfo = secondaryScaleMarginRecalcer.getScaleValue();
22
+ }
20
23
  return {
21
24
  legend: canvasModel.legendCanvas.getModel(),
22
25
  title: resolvedTitle,
23
26
  selectable: !!options.selectable,
24
27
  orient: options.orientation,
25
- scale: {
26
- key: scaleModel.getScaleKey(modelInstance.dataModel.getAllowableKeys(), options.orientation, canvasModel, options.charts, this.getChartsByType(options.charts, 'bar')),
27
- value: scaleValueInfo.scale,
28
- valueSecondary: secondaryScaleValueInfo.scale,
29
- },
30
- axis: {
31
- key: AxisModel.getKeyAxis(options, modelInstance.dataModel.repository.getScopedFullSource(), designerConfig.canvas.axisLabel, canvasModel, designerConfig.elementsOptions.tooltip, () => scaleValueInfo.scaleFn(0)),
32
- value: AxisModel.getValueAxis(options.orientation, options.axis.value, designerConfig.canvas.axisLabel, canvasModel)
33
- },
28
+ scale: Object.assign({ key: scaleModel.getScaleKey(modelInstance.dataModel.getAllowableKeys(), options.orientation, canvasModel, options.charts, this.getChartsByType(options.charts, 'bar')), value: scaleValueInfo.scale }, (configReader.containsSecondaryAxis() && { valueSecondary: secondaryScaleValueInfo.scale })),
29
+ axis: Object.assign({ key: AxisModel.getKeyAxis(options, modelInstance.dataModel.repository.getScopedFullSource(), designerConfig.canvas.axisLabel, canvasModel, designerConfig.elementsOptions.tooltip, () => scaleValueInfo.scaleFn(0)), value: AxisModel.getMainValueAxis(options.orientation, options.axis.value.position, options.axis.value, designerConfig.canvas.axisLabel, canvasModel) }, (configReader.containsSecondaryAxis() && { valueSecondary: AxisModel.getSecondaryValueAxis(options.orientation, options.axis.value.position, options.axis.valueSecondary, designerConfig.canvas.axisLabel, canvasModel) })),
34
30
  type: options.type,
35
31
  data: Object.assign({}, options.data),
36
32
  charts: this.getChartsModel(options.charts, options.orientation, designerConfig, modelInstance.dataModel.repository),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdt-charts",
3
- "version": "1.19.0",
3
+ "version": "1.20.0",
4
4
  "description": "",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {