mdt-charts 1.13.2 → 1.14.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 (82) hide show
  1. package/README.md +1 -189
  2. package/lib/config/config.d.ts +28 -6
  3. package/lib/designer/designerConfig.d.ts +20 -2
  4. package/lib/engine/block/blockSvg.d.ts +3 -1
  5. package/lib/engine/block/blockSvg.js +8 -3
  6. package/lib/engine/block/defs.d.ts +7 -0
  7. package/lib/engine/block/defs.js +18 -0
  8. package/lib/engine/cardsNotation/card/cardService.js +2 -2
  9. package/lib/engine/elementHighlighter/elementHighlighter.js +2 -1
  10. package/lib/engine/features/axis/axis.js +6 -3
  11. package/lib/engine/features/axis/axisHelper.d.ts +2 -2
  12. package/lib/engine/features/axis/axisHelper.js +6 -11
  13. package/lib/engine/features/axis/axisLabelDomHelper.js +9 -11
  14. package/lib/engine/features/legend/legend.d.ts +17 -12
  15. package/lib/engine/features/legend/legend.js +38 -22
  16. package/lib/engine/features/legend/legendDomHelper.d.ts +8 -4
  17. package/lib/engine/features/legend/legendDomHelper.js +20 -8
  18. package/lib/engine/features/legend/legendEventsManager.d.ts +2 -2
  19. package/lib/engine/features/legend/legendEventsManager.js +5 -5
  20. package/lib/engine/features/legend/legendHelper.d.ts +6 -3
  21. package/lib/engine/features/legend/legendHelper.js +5 -7
  22. package/lib/engine/features/legend/legendMarkerCreator.d.ts +21 -0
  23. package/lib/engine/features/legend/legendMarkerCreator.js +88 -0
  24. package/lib/engine/features/legend/legendWidthCalculator.d.ts +16 -0
  25. package/lib/engine/features/legend/legendWidthCalculator.js +119 -0
  26. package/lib/engine/features/tolltip/tooltip.js +2 -5
  27. package/lib/engine/features/tolltip/tooltipDomHelper.d.ts +4 -4
  28. package/lib/engine/features/tolltip/tooltipDomHelper.js +13 -26
  29. package/lib/engine/helpers/domHelper.js +1 -1
  30. package/lib/engine/helpers/pipeline/Pipeline.d.ts +9 -0
  31. package/lib/engine/helpers/pipeline/Pipeline.js +37 -0
  32. package/lib/engine/intervalNotation/intervalManager.js +0 -2
  33. package/lib/engine/polarNotation/polarManager.js +3 -3
  34. package/lib/engine/twoDimensionalNotation/bar/bar.d.ts +16 -13
  35. package/lib/engine/twoDimensionalNotation/bar/bar.js +30 -18
  36. package/lib/engine/twoDimensionalNotation/bar/barHelper.d.ts +3 -0
  37. package/lib/engine/twoDimensionalNotation/bar/barHelper.js +9 -0
  38. package/lib/engine/twoDimensionalNotation/line/line.d.ts +22 -11
  39. package/lib/engine/twoDimensionalNotation/line/line.js +33 -17
  40. package/lib/engine/twoDimensionalNotation/line/lineGenerator.d.ts +15 -0
  41. package/lib/engine/twoDimensionalNotation/line/lineGenerator.js +27 -0
  42. package/lib/engine/twoDimensionalNotation/line/lineHelper.d.ts +18 -4
  43. package/lib/engine/twoDimensionalNotation/line/lineHelper.js +26 -16
  44. package/lib/engine/twoDimensionalNotation/twoDimensionalManager.js +13 -12
  45. package/lib/model/featuresModel/axisModel.d.ts +2 -1
  46. package/lib/model/featuresModel/axisModel.js +11 -1
  47. package/lib/model/featuresModel/legendModel/legendModel.d.ts +2 -1
  48. package/lib/model/featuresModel/legendModel/legendModel.js +5 -1
  49. package/lib/model/featuresModel/otherComponents.d.ts +2 -1
  50. package/lib/model/featuresModel/otherComponents.js +1 -1
  51. package/lib/model/featuresModel/scaleModel/scaleModel.d.ts +2 -1
  52. package/lib/model/featuresModel/scaleModel/scaleModel.js +4 -2
  53. package/lib/model/margin/marginModel.d.ts +6 -3
  54. package/lib/model/margin/marginModel.js +12 -8
  55. package/lib/model/margin/twoDim/twoDimMarginModel.d.ts +6 -3
  56. package/lib/model/margin/twoDim/twoDimMarginModel.js +30 -29
  57. package/lib/model/model.d.ts +56 -4
  58. package/lib/model/model.js +7 -1
  59. package/lib/model/modelBuilder.js +11 -6
  60. package/lib/model/modelInstance/configReader.d.ts +19 -0
  61. package/lib/model/modelInstance/configReader.js +35 -0
  62. package/lib/model/modelInstance/dataModel/dataModel.d.ts +2 -2
  63. package/lib/model/modelInstance/dataModel/dataModel.js +0 -1
  64. package/lib/model/modelInstance/dataModel/dataRepository.d.ts +6 -2
  65. package/lib/model/modelInstance/dataModel/dataRepository.js +15 -2
  66. package/lib/model/modelInstance/modelInstance.d.ts +2 -1
  67. package/lib/model/modelInstance/modelInstance.js +6 -4
  68. package/lib/model/notations/cards/cardsChangeService.js +2 -2
  69. package/lib/model/notations/cards/cardsModelService.js +1 -1
  70. package/lib/model/notations/intervalModel.js +4 -3
  71. package/lib/model/notations/polar/polarModel.js +6 -1
  72. package/lib/model/notations/twoDimensional/styles.d.ts +6 -0
  73. package/lib/model/notations/twoDimensional/styles.js +41 -0
  74. package/lib/model/notations/twoDimensionalModel.d.ts +5 -5
  75. package/lib/model/notations/twoDimensionalModel.js +13 -8
  76. package/lib/style/charts-main.css +3 -0
  77. package/lib/style/charts-main.less +3 -0
  78. package/package.json +5 -5
  79. package/lib/engine/contentManager.d.ts +0 -9
  80. package/lib/engine/contentManager.js +0 -29
  81. package/lib/model/modelInstance/canvasModel/marginModelService.d.ts +0 -11
  82. package/lib/model/modelInstance/canvasModel/marginModelService.js +0 -26
@@ -1,8 +1,22 @@
1
1
  import { Line as ILine } from 'd3-shape';
2
2
  import { MdtChartsDataRow } from '../../../config/config';
3
- import { Orient, BlockMargin } from "../../../model/model";
3
+ import { Orient, BlockMargin, LineCurveType, TwoDimensionalChartModel } from "../../../model/model";
4
4
  import { Scales } from "../../features/scale/scale";
5
- export declare class LineHelper {
6
- static getLineGenerator(keyAxisOrient: Orient, scales: Scales, keyFieldName: string, valueFieldName: string, margin: BlockMargin): ILine<MdtChartsDataRow>;
7
- static getSegmentedLineGenerator(keyAxisOrient: Orient, scales: Scales, keyFieldName: string, margin: BlockMargin): ILine<MdtChartsDataRow>;
5
+ import { Pipeline } from '../../helpers/pipeline/Pipeline';
6
+ import { BaseType, Selection } from 'd3-selection';
7
+ interface LineGeneratorFactoryOptions {
8
+ keyAxisOrient: Orient;
9
+ scales: Scales;
10
+ keyFieldName: string;
11
+ margin: BlockMargin;
12
+ curve: LineCurveType;
8
13
  }
14
+ export declare class LineGeneratorFactory {
15
+ private options;
16
+ constructor(options: LineGeneratorFactoryOptions);
17
+ getLineGenerator(valueFieldName: string): ILine<MdtChartsDataRow>;
18
+ getSegmentedLineGenerator(): ILine<MdtChartsDataRow>;
19
+ }
20
+ export declare function onLineChartInit(creatingPipeline: Pipeline<Selection<SVGElement, any, BaseType, any>, TwoDimensionalChartModel>): void;
21
+ export declare function applyLineDash(lineSelection: Selection<SVGElement, any, BaseType, any>, dashSize: number, gapSize: number): Selection<SVGElement, any, BaseType, any>;
22
+ export {};
@@ -1,28 +1,38 @@
1
- import { line } from 'd3-shape';
2
1
  import { Scale } from "../../features/scale/scale";
3
- export class LineHelper {
4
- static getLineGenerator(keyAxisOrient, scales, keyFieldName, valueFieldName, margin) {
2
+ import { LineGenerator } from './lineGenerator';
3
+ export class LineGeneratorFactory {
4
+ constructor(options) {
5
+ this.options = options;
6
+ }
7
+ getLineGenerator(valueFieldName) {
8
+ const { keyAxisOrient, scales, keyFieldName, margin } = this.options;
9
+ const generator = new LineGenerator({ curve: this.options.curve });
5
10
  if (keyAxisOrient === 'bottom' || keyAxisOrient === 'top') {
6
- return line()
7
- .x(d => Scale.getScaledValue(scales.key, d[keyFieldName]) + margin.left)
8
- .y(d => scales.value(d[valueFieldName]) + margin.top);
11
+ return generator.get(d => Scale.getScaledValue(scales.key, d[keyFieldName]) + margin.left, d => scales.value(d[valueFieldName]) + margin.top);
9
12
  }
10
13
  if (keyAxisOrient === 'left' || keyAxisOrient === 'right') {
11
- return line()
12
- .x(d => scales.value(d[valueFieldName]) + margin.left)
13
- .y(d => Scale.getScaledValue(scales.key, d[keyFieldName]) + margin.top);
14
+ return generator.get(d => scales.value(d[valueFieldName]) + margin.left, d => Scale.getScaledValue(scales.key, d[keyFieldName]) + margin.top);
14
15
  }
15
16
  }
16
- static getSegmentedLineGenerator(keyAxisOrient, scales, keyFieldName, margin) {
17
+ getSegmentedLineGenerator() {
18
+ const { keyAxisOrient, scales, keyFieldName, margin } = this.options;
19
+ const generator = new LineGenerator({ curve: this.options.curve });
17
20
  if (keyAxisOrient === 'bottom' || keyAxisOrient === 'top') {
18
- return line()
19
- .x(d => Scale.getScaledValue(scales.key, d.data[keyFieldName]) + margin.left)
20
- .y(d => scales.value(d[1]) + margin.top);
21
+ return generator.get(d => Scale.getScaledValue(scales.key, d.data[keyFieldName]) + margin.left, d => scales.value(d[1]) + margin.top);
21
22
  }
22
23
  if (keyAxisOrient === 'left' || keyAxisOrient === 'right') {
23
- return line()
24
- .x(d => scales.value(d[1]) + margin.left)
25
- .y(d => Scale.getScaledValue(scales.key, d.data[keyFieldName]) + margin.top);
24
+ return generator.get(d => scales.value(d[1]) + margin.left, d => Scale.getScaledValue(scales.key, d.data[keyFieldName]) + margin.top);
26
25
  }
27
26
  }
28
27
  }
28
+ export function onLineChartInit(creatingPipeline) {
29
+ creatingPipeline.push((path, chart) => {
30
+ if (chart.lineViewOptions.dashedStyles.on) {
31
+ return applyLineDash(path, chart.lineViewOptions.dashedStyles.dashSize, chart.lineViewOptions.dashedStyles.gapSize);
32
+ }
33
+ return path;
34
+ });
35
+ }
36
+ export function applyLineDash(lineSelection, dashSize, gapSize) {
37
+ return lineSelection.style('stroke-dasharray', `${dashSize} ${gapSize}`);
38
+ }
@@ -21,12 +21,12 @@ export class TwoDimensionalManager {
21
21
  engine.block.svg.render(model.blockCanvas.size);
22
22
  Axis.render(engine.block, scales, options.scale, options.axis, model.blockCanvas.size);
23
23
  GridLine.render(engine.block, options.additionalElements.gridLine.flag, options.axis, model.blockCanvas.size, model.chartBlock.margin, scales);
24
- this.renderCharts(engine.block, options.charts, scales, engine.data, options.data, model.chartBlock.margin, options.axis.key.orient, options.chartSettings.bar, model.blockCanvas.size);
24
+ this.renderCharts(engine.block, options.charts, scales, engine.data, options.data, model.chartBlock.margin, options.axis.key.orient, options.chartSettings, model.blockCanvas.size);
25
25
  Axis.raiseKeyAxis(engine.block, options.axis.key);
26
26
  engine.block.filterEventManager.registerEventFor2D(scales.key, model.chartBlock.margin, model.blockCanvas.size, options);
27
27
  engine.block.filterEventManager.event2DUpdate(options);
28
28
  Title.render(engine.block, options.title, model.otherComponents.titleBlock, model.blockCanvas.size);
29
- Legend.render(engine.block, engine.data, options, model);
29
+ Legend.get().render(engine.block, engine.data, options, model);
30
30
  Tooltip.render(engine.block, model, engine.data, model.otherComponents.tooltipBlock, scales);
31
31
  if (model.dataSettings.scope.hidedRecordsAmount !== 0)
32
32
  TwoDimRecordOverflowAlert.render(engine.block, {
@@ -51,7 +51,7 @@ export class TwoDimensionalManager {
51
51
  block.scales = scales;
52
52
  Axis.update(block, scales, options.scale, options.axis, model.blockCanvas.size, keyDomainEquality);
53
53
  GridLine.update(block, options.additionalElements.gridLine.flag, options.axis, model.blockCanvas.size, model.chartBlock.margin, scales);
54
- const promises = this.updateCharts(block, options.charts, scales, data, model.options.data, model.chartBlock.margin, options.axis.key.orient, model.blockCanvas.size, options.chartSettings.bar);
54
+ const promises = this.updateCharts(block, options.charts, scales, data, model.options.data, model.chartBlock.margin, options.axis.key.orient, model.blockCanvas.size, options.chartSettings);
55
55
  Promise.all(promises)
56
56
  .then(() => {
57
57
  block.filterEventManager.event2DUpdate(options);
@@ -64,39 +64,40 @@ export class TwoDimensionalManager {
64
64
  });
65
65
  }
66
66
  updateColors(block, model) {
67
- Legend.updateColors(block, model.options);
67
+ Legend.get().updateColors(block, model.options);
68
68
  model.options.charts.forEach(chart => {
69
69
  if (chart.type === 'bar')
70
- Bar.updateColors(block, chart);
70
+ Bar.get().updateColors(block, chart);
71
71
  else if (chart.type === 'line')
72
- Line.updateColors(block, chart);
72
+ Line.get({ staticSettings: model.options.chartSettings.lineLike }).updateColors(block, chart);
73
73
  else if (chart.type === 'area')
74
74
  Area.updateColors(block, chart);
75
75
  });
76
76
  }
77
- renderCharts(block, charts, scales, data, dataOptions, margin, keyAxisOrient, barSettings, blockSize) {
77
+ renderCharts(block, charts, scales, data, dataOptions, margin, keyAxisOrient, chartSettings, blockSize) {
78
78
  block.svg.renderChartClipPath(margin, blockSize);
79
+ block.svg.renderBarHatchPattern();
79
80
  block.svg.renderChartsBlock();
80
81
  charts.forEach((chart) => {
81
82
  if (chart.type === 'bar')
82
- Bar.render(block, scales, data[dataOptions.dataSource], dataOptions.keyField, margin, keyAxisOrient, chart, blockSize, barSettings, BarHelper.getBarsInGroupAmount(charts), chart.isSegmented, charts.findIndex(ch => ch.type === 'bar'));
83
+ Bar.get().render(block, scales, data[dataOptions.dataSource], dataOptions.keyField, margin, keyAxisOrient, chart, blockSize, chartSettings.bar, BarHelper.getBarsInGroupAmount(charts), chart.isSegmented, charts.findIndex(ch => ch.type === 'bar'));
83
84
  else if (chart.type === 'line')
84
- Line.render(block, scales, data[dataOptions.dataSource], dataOptions.keyField, margin, keyAxisOrient, chart);
85
+ Line.get({ staticSettings: chartSettings.lineLike }).render(block, scales, data[dataOptions.dataSource], dataOptions.keyField, margin, keyAxisOrient, chart);
85
86
  else if (chart.type === 'area')
86
87
  Area.render(block, scales, data[dataOptions.dataSource], dataOptions.keyField, margin, keyAxisOrient, chart, blockSize);
87
88
  });
88
89
  EmbeddedLabels.raiseGroups(block);
89
90
  }
90
- updateCharts(block, charts, scales, data, dataOptions, margin, keyAxisOrient, blockSize, barSettings) {
91
+ updateCharts(block, charts, scales, data, dataOptions, margin, keyAxisOrient, blockSize, chartSettings) {
91
92
  block.svg.updateChartClipPath(margin, blockSize);
92
93
  let promises = [];
93
94
  charts.forEach((chart) => {
94
95
  let proms;
95
96
  if (chart.type === 'bar') {
96
- proms = Bar.update(block, data[dataOptions.dataSource], scales, margin, keyAxisOrient, chart, blockSize, BarHelper.getBarsInGroupAmount(charts), dataOptions.keyField, charts.findIndex(ch => ch.type === 'bar'), barSettings, chart.isSegmented);
97
+ proms = Bar.get().update(block, data[dataOptions.dataSource], scales, margin, keyAxisOrient, chart, blockSize, BarHelper.getBarsInGroupAmount(charts), dataOptions.keyField, charts.findIndex(ch => ch.type === 'bar'), chartSettings.bar, chart.isSegmented);
97
98
  }
98
99
  else if (chart.type === 'line') {
99
- proms = Line.update(block, scales, data[dataOptions.dataSource], dataOptions.keyField, margin, keyAxisOrient, chart);
100
+ proms = Line.get({ staticSettings: chartSettings.lineLike }).update(block, scales, data[dataOptions.dataSource], dataOptions.keyField, margin, keyAxisOrient, chart);
100
101
  }
101
102
  else if (chart.type === 'area') {
102
103
  proms = Area.update(block, scales, data[dataOptions.dataSource], dataOptions.keyField, margin, chart, keyAxisOrient, blockSize);
@@ -16,6 +16,7 @@ export declare class AxisModel {
16
16
  static getAxisTranslateX(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition, canvasModel: CanvasModel): number;
17
17
  static getAxisTranslateY(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition, canvasModel: CanvasModel): number;
18
18
  static getKeyAxisLabelPosition(canvasModel: CanvasModel, scopedDataLength: number, axisConfig?: DiscreteAxisOptions): AxisLabelPosition;
19
- static getLabelSize(labelMaxWidth: number, labelTexts: any[]): LabelSize;
19
+ static getLabelSize(labelMaxWidth: number, labelTexts: string[]): LabelSize;
20
+ static getLabelSizeLegacy(labelMaxWidth: number, labelTexts: string[]): LabelSize;
20
21
  private static getKeyAxisTranslateModel;
21
22
  }
@@ -15,7 +15,7 @@ export class AxisModel {
15
15
  cssClass: 'key-axis',
16
16
  ticks: axisConfig.ticks,
17
17
  labels: {
18
- maxSize: AxisModel.getLabelSize(labelConfig.maxSize.main, data[dataOptions.dataSource].map(d => d[dataOptions.keyField.name])).width,
18
+ maxSize: AxisModel.getLabelSizeLegacy(labelConfig.maxSize.main, data[dataOptions.dataSource].map(d => d[dataOptions.keyField.name])).width,
19
19
  position: AxisModel.getKeyAxisLabelPosition(canvasModel, DataManagerModel.getDataValuesByKeyField(data, dataOptions.dataSource, dataOptions.keyField.name).length, axisConfig),
20
20
  visible: !TwoDimensionalModel.getChartsEmbeddedLabelsFlag(charts, orientation),
21
21
  defaultTooltip: tooltipSettings.position === 'fixed'
@@ -81,6 +81,16 @@ export class AxisModel {
81
81
  return this.service.getKeyAxisLabelPosition(canvasModel.getChartBlockWidth(), scopedDataLength, (_a = axisConfig === null || axisConfig === void 0 ? void 0 : axisConfig.labels) === null || _a === void 0 ? void 0 : _a.position);
82
82
  }
83
83
  static getLabelSize(labelMaxWidth, labelTexts) {
84
+ const LABEL_ELEMENT_HEIGHT_PX = 17;
85
+ const ONE_UPPER_SYMBOL_WIDTH_PX = 8.6;
86
+ const longestLabelLength = Math.max(...labelTexts.map(t => ModelHelper.getStringScore(t)));
87
+ const longestLabelWidth = ONE_UPPER_SYMBOL_WIDTH_PX * longestLabelLength;
88
+ return {
89
+ height: LABEL_ELEMENT_HEIGHT_PX,
90
+ width: longestLabelWidth > labelMaxWidth ? labelMaxWidth : longestLabelWidth
91
+ };
92
+ }
93
+ static getLabelSizeLegacy(labelMaxWidth, labelTexts) {
84
94
  const labelSize = {
85
95
  width: 0,
86
96
  height: 0
@@ -1,8 +1,9 @@
1
+ import { LegendBlockCanvas } from "../../../main";
1
2
  import { LegendBlockModel, Orient } from "../../model";
2
3
  import { CanvasModel } from "../../modelInstance/canvasModel/canvasModel";
3
4
  import { LegendItemsDirection } from "./legendCanvasModel";
4
5
  export declare class LegendModel {
5
- static getBaseLegendBlockModel(canvasModel: CanvasModel): LegendBlockModel;
6
+ static getBaseLegendBlockModel(canvasModel: CanvasModel, legendConfig: LegendBlockCanvas): LegendBlockModel;
6
7
  static getLegendItemClass(itemsPosition: LegendItemsDirection): string;
7
8
  static appendToGlobalMarginValuesLegendMargin(canvasModel: CanvasModel, position: Orient, legendBlockModel: LegendBlockModel): void;
8
9
  }
@@ -1,5 +1,6 @@
1
1
  export class LegendModel {
2
- static getBaseLegendBlockModel(canvasModel) {
2
+ static getBaseLegendBlockModel(canvasModel, legendConfig) {
3
+ var _a, _b;
3
4
  const mt = 20, mb = 20, ml = 20, mr = 20;
4
5
  return {
5
6
  coordinate: {
@@ -23,6 +24,9 @@ export class LegendModel {
23
24
  margin: { top: 5, bottom: 10, left: 0, right: 0 },
24
25
  pad: canvasModel.titleCanvas.getAllNeededSpace()
25
26
  }
27
+ },
28
+ static: {
29
+ maxLinesAmount: (_b = (_a = legendConfig.static) === null || _a === void 0 ? void 0 : _a.maxLinesAmount) !== null && _b !== void 0 ? _b : 3
26
30
  }
27
31
  };
28
32
  }
@@ -1,8 +1,9 @@
1
1
  import { OtherCommonComponents } from "../model";
2
- import { ElementsOptions } from "../../designer/designerConfig";
2
+ import { ElementsOptions, LegendBlockCanvas } from "../../designer/designerConfig";
3
3
  import { ModelInstance } from "../modelInstance/modelInstance";
4
4
  interface OtherComponentsModelDependencies {
5
5
  elementsOptions: ElementsOptions;
6
+ legendConfig: LegendBlockCanvas;
6
7
  title: string;
7
8
  }
8
9
  export declare class OtherComponentsModel {
@@ -6,7 +6,7 @@ export class OtherComponentsModel {
6
6
  const canvasModel = modelInstance.canvasModel;
7
7
  canvasModel.titleCanvas.init(TitleModel.getTitleModel(dependencies.title));
8
8
  return {
9
- legendBlock: LegendModel.getBaseLegendBlockModel(canvasModel),
9
+ legendBlock: LegendModel.getBaseLegendBlockModel(canvasModel, dependencies.legendConfig),
10
10
  titleBlock: canvasModel.titleCanvas.getModel(),
11
11
  tooltipBlock: TooltipModel.getTooltipModel(dependencies.elementsOptions.tooltip)
12
12
  };
@@ -1,12 +1,13 @@
1
1
  import { ScaleKeyModel, ScaleValueModel } from "../../model";
2
2
  import { MdtChartsTwoDimensionalChart, MdtChartsTwoDimensionalOptions, ChartOrientation, MdtChartsDataRow } from "../../../config/config";
3
3
  import { CanvasModel } from "../../modelInstance/canvasModel/canvasModel";
4
+ import { TwoDimConfigReader } from "../../modelInstance/configReader";
4
5
  export declare enum ScaleType {
5
6
  Key = 0,
6
7
  Value = 1
7
8
  }
8
9
  export declare class ScaleModel {
9
10
  getScaleKey(allowableKeys: string[], orient: ChartOrientation, canvasModel: CanvasModel, charts: MdtChartsTwoDimensionalChart[], barCharts: MdtChartsTwoDimensionalChart[]): ScaleKeyModel;
10
- getScaleLinear(options: MdtChartsTwoDimensionalOptions, dataRows: MdtChartsDataRow[], canvasModel: CanvasModel): ScaleValueModel;
11
+ getScaleLinear(options: MdtChartsTwoDimensionalOptions, dataRows: MdtChartsDataRow[], canvasModel: CanvasModel, configReader?: TwoDimConfigReader): ScaleValueModel;
11
12
  private getScaleKeyType;
12
13
  }
@@ -17,14 +17,16 @@ export class ScaleModel {
17
17
  elementsAmount: getElementsAmountForScale(barCharts)
18
18
  };
19
19
  }
20
- getScaleLinear(options, dataRows, canvasModel) {
20
+ getScaleLinear(options, dataRows, canvasModel, configReader) {
21
+ var _a;
21
22
  return {
22
23
  domain: getScaleLinearDomain(options.axis.value.domain, dataRows, options),
23
24
  range: {
24
25
  start: 0,
25
26
  end: getScaleValueRangePeek(options.orientation, canvasModel)
26
27
  },
27
- type: "linear"
28
+ type: "linear",
29
+ formatter: (_a = configReader === null || configReader === void 0 ? void 0 : configReader.getAxisLabelFormatter()) !== null && _a !== void 0 ? _a : null
28
30
  };
29
31
  }
30
32
  getScaleKeyType(charts) {
@@ -1,10 +1,13 @@
1
- import { MdtChartsConfig, MdtChartsDataSource, MdtChartsTwoDimensionalOptions } from "../../config/config";
1
+ import { MdtChartsConfig } from "../../config/config";
2
2
  import { DesignerConfig } from "../../designer/designerConfig";
3
3
  import { OtherCommonComponents } from "../model";
4
4
  import { ModelInstance } from "../modelInstance/modelInstance";
5
5
  export declare class MarginModel {
6
+ private designerConfig;
7
+ private config;
6
8
  private twoDimModel;
7
- initMargin(designerConfig: DesignerConfig, config: MdtChartsConfig, otherComponents: OtherCommonComponents, data: MdtChartsDataSource, modelInstance: ModelInstance): void;
8
- recalcMarginByVerticalAxisLabel(modelInstance: ModelInstance, options: MdtChartsTwoDimensionalOptions, designerConfig: DesignerConfig): void;
9
+ constructor(designerConfig: DesignerConfig, config: MdtChartsConfig);
10
+ initMargin(otherComponents: OtherCommonComponents, modelInstance: ModelInstance): void;
11
+ recalcMarginByVerticalAxisLabel(modelInstance: ModelInstance): void;
9
12
  private recalcMarginByTitle;
10
13
  }
@@ -1,18 +1,22 @@
1
1
  import { TwoDimMarginModel } from "./twoDim/twoDimMarginModel";
2
+ import { TwoDimConfigReader } from "../modelInstance/configReader";
2
3
  export class MarginModel {
3
- constructor() {
4
- this.twoDimModel = new TwoDimMarginModel();
4
+ constructor(designerConfig, config) {
5
+ this.designerConfig = designerConfig;
6
+ this.config = config;
7
+ //TODO: ensure
8
+ this.twoDimModel = new TwoDimMarginModel(this.designerConfig, new TwoDimConfigReader(this.config, this.designerConfig));
5
9
  }
6
- initMargin(designerConfig, config, otherComponents, data, modelInstance) {
10
+ initMargin(otherComponents, modelInstance) {
7
11
  const canvasModel = modelInstance.canvasModel;
8
- canvasModel.initMargin(Object.assign({}, designerConfig.canvas.chartBlockMargin));
12
+ canvasModel.initMargin(Object.assign({}, this.designerConfig.canvas.chartBlockMargin));
9
13
  this.recalcMarginByTitle(canvasModel);
10
- if (config.options.type === '2d') {
11
- this.twoDimModel.recalcMargin(designerConfig, config.options, otherComponents, data, modelInstance);
14
+ if (this.config.options.type === '2d') {
15
+ this.twoDimModel.recalcMargin(otherComponents, modelInstance);
12
16
  }
13
17
  }
14
- recalcMarginByVerticalAxisLabel(modelInstance, options, designerConfig) {
15
- this.twoDimModel.recalcMarginByVerticalAxisLabel(modelInstance, options, designerConfig);
18
+ recalcMarginByVerticalAxisLabel(modelInstance) {
19
+ this.twoDimModel.recalcMarginByVerticalAxisLabel(modelInstance);
16
20
  }
17
21
  recalcMarginByTitle(canvasModel) {
18
22
  canvasModel.increaseMarginSide("top", canvasModel.titleCanvas.getAllNeededSpace());
@@ -1,13 +1,16 @@
1
- import { MdtChartsDataSource, MdtChartsTwoDimensionalOptions } from "../../../config/config";
2
1
  import { DesignerConfig } from "../../../designer/designerConfig";
3
2
  import { OtherCommonComponents } from "../../model";
3
+ import { TwoDimConfigReader } from "../../modelInstance/configReader";
4
4
  import { ModelInstance } from "../../modelInstance/modelInstance";
5
5
  export declare const AXIS_HORIZONTAL_LABEL_PADDING = 15;
6
6
  export declare const AXIS_VERTICAL_LABEL_PADDING = 10;
7
7
  export declare class TwoDimMarginModel {
8
+ private designerConfig;
9
+ private configReader;
8
10
  private twoDimLegendModel;
9
- recalcMargin(designerConfig: DesignerConfig, options: MdtChartsTwoDimensionalOptions, otherComponents: OtherCommonComponents, data: MdtChartsDataSource, modelInstance: ModelInstance): void;
10
- recalcMarginByVerticalAxisLabel(modelInstance: ModelInstance, options: MdtChartsTwoDimensionalOptions, designerConfig: DesignerConfig): void;
11
+ constructor(designerConfig: DesignerConfig, configReader: TwoDimConfigReader);
12
+ recalcMargin(otherComponents: OtherCommonComponents, modelInstance: ModelInstance): void;
13
+ recalcMarginByVerticalAxisLabel(modelInstance: ModelInstance): void;
11
14
  private getHorizontalMarginByAxisLabels;
12
15
  private recalcVerticalMarginByAxisLabelHeight;
13
16
  private recalcHorizontalMarginByAxisLabelWidth;
@@ -1,4 +1,3 @@
1
- import { DataManagerModel } from "../../dataManagerModel/dataManagerModel";
2
1
  import { AxisModel } from "../../featuresModel/axisModel";
3
2
  import { TwoDimLegendModel } from "../../featuresModel/legendModel/twoDimLegendModel";
4
3
  import { keyAxisLabelHorizontalLog, keyAxisLabelVerticalLog } from "../../featuresModel/scaleModel/scaleAxisRecalcer";
@@ -7,62 +6,64 @@ import { TwoDimensionalModel } from "../../notations/twoDimensionalModel";
7
6
  export const AXIS_HORIZONTAL_LABEL_PADDING = 15;
8
7
  export const AXIS_VERTICAL_LABEL_PADDING = 10;
9
8
  export class TwoDimMarginModel {
10
- constructor() {
9
+ constructor(designerConfig, configReader) {
10
+ this.designerConfig = designerConfig;
11
+ this.configReader = configReader;
11
12
  this.twoDimLegendModel = new TwoDimLegendModel();
12
13
  }
13
- recalcMargin(designerConfig, options, otherComponents, data, modelInstance) {
14
+ recalcMargin(otherComponents, modelInstance) {
14
15
  const canvasModel = modelInstance.canvasModel;
15
- this.twoDimLegendModel.recalcMarginWith2DLegend(modelInstance, otherComponents.legendBlock, options.legend);
16
- const labelSize = this.getHorizontalMarginByAxisLabels(designerConfig.canvas.axisLabel.maxSize.main, options.axis, data, options);
17
- this.recalcVerticalMarginByAxisLabelHeight(labelSize, canvasModel, options.orientation, options.axis);
16
+ this.twoDimLegendModel.recalcMarginWith2DLegend(modelInstance, otherComponents.legendBlock, this.configReader.options.legend);
17
+ const labelSize = this.getHorizontalMarginByAxisLabels(modelInstance);
18
+ this.recalcVerticalMarginByAxisLabelHeight(labelSize, canvasModel);
18
19
  // Если встроенный лейбл показывает ключи, то лейблы оси ключей не показываются
19
20
  // При этом все графики должны иметь: embeddedLabels = 'key'
20
21
  // И все графики должны быть типа bar.
21
- const showingFlag = options.type === '2d'
22
- ? !TwoDimensionalModel.getChartsEmbeddedLabelsFlag(options.charts, options.orientation)
22
+ const showingFlag = this.configReader.options.type === '2d'
23
+ ? !TwoDimensionalModel.getChartsEmbeddedLabelsFlag(this.configReader.options.charts, this.configReader.options.orientation)
23
24
  : true;
24
- this.recalcHorizontalMarginByAxisLabelWidth(labelSize, canvasModel, options.orientation, options.axis, showingFlag);
25
+ this.recalcHorizontalMarginByAxisLabelWidth(labelSize, canvasModel, showingFlag);
25
26
  }
26
- recalcMarginByVerticalAxisLabel(modelInstance, options, designerConfig) {
27
- if (options.orientation === 'vertical') {
27
+ recalcMarginByVerticalAxisLabel(modelInstance) {
28
+ if (this.configReader.options.orientation === 'vertical') {
28
29
  const dataModel = modelInstance.dataModel;
29
- const axisLabelSize = AxisModel.getLabelSize(designerConfig.canvas.axisLabel.maxSize.main, dataModel.getAllowableKeys());
30
- const axisConfig = AxisModel.getKeyAxisLabelPosition(modelInstance.canvasModel, dataModel.getAllowableKeys().length, options.axis.key);
31
- const marginOrient = options.axis.key.position === 'end' ? 'bottom' : 'top';
30
+ const axisLabelSize = AxisModel.getLabelSize(this.designerConfig.canvas.axisLabel.maxSize.main, dataModel.getAllowableKeys());
31
+ const axisConfig = AxisModel.getKeyAxisLabelPosition(modelInstance.canvasModel, dataModel.getAllowableKeys().length, this.configReader.options.axis.key);
32
+ const marginOrient = this.configReader.options.axis.key.position === 'end' ? 'bottom' : 'top';
32
33
  if (axisConfig === 'rotated') {
33
34
  modelInstance.canvasModel.decreaseMarginSide(marginOrient, axisLabelSize.height);
34
35
  modelInstance.canvasModel.increaseMarginSide(marginOrient, axisLabelSize.width, keyAxisLabelVerticalLog);
35
36
  }
36
37
  }
37
38
  }
38
- getHorizontalMarginByAxisLabels(labelsMaxWidth, axis, data, options) {
39
- const keyAxisOrient = AxisModel.getAxisOrient(AxisType.Key, options.orientation, axis.key.position);
39
+ getHorizontalMarginByAxisLabels(modelInstance) {
40
+ const keyAxisOrient = AxisModel.getAxisOrient(AxisType.Key, this.configReader.options.orientation, this.configReader.options.axis.key.position);
40
41
  let labelsTexts;
41
42
  if (keyAxisOrient === 'left' || keyAxisOrient === 'right') {
42
- labelsTexts = DataManagerModel.getDataValuesByKeyField(data, options.data.dataSource, options.data.keyField.name);
43
+ labelsTexts = modelInstance.dataModel.repository.getValuesByKeyField();
43
44
  }
44
45
  else {
45
- labelsTexts = ['0000'];
46
+ labelsTexts = modelInstance.dataModel.repository.getBiggestValueAndDecremented().map(v => this.configReader.getAxisLabelFormatter()(v));
46
47
  }
47
- return AxisModel.getLabelSize(labelsMaxWidth, labelsTexts);
48
+ return AxisModel.getLabelSize(this.designerConfig.canvas.axisLabel.maxSize.main, labelsTexts);
48
49
  }
49
- recalcVerticalMarginByAxisLabelHeight(labelSize, canvasModel, orientation, axis) {
50
- const keyAxisOrient = AxisModel.getAxisOrient(AxisType.Key, orientation, axis.key.position);
51
- const valueAxisOrient = AxisModel.getAxisOrient(AxisType.Value, orientation, axis.value.position);
50
+ recalcVerticalMarginByAxisLabelHeight(labelSize, canvasModel) {
51
+ const keyAxisOrient = AxisModel.getAxisOrient(AxisType.Key, this.configReader.options.orientation, this.configReader.options.axis.key.position);
52
+ const valueAxisOrient = AxisModel.getAxisOrient(AxisType.Value, this.configReader.options.orientation, this.configReader.options.axis.value.position);
52
53
  if ((keyAxisOrient === 'bottom' || keyAxisOrient === 'top')) {
53
- if (axis.key.visibility)
54
+ if (this.configReader.options.axis.key.visibility)
54
55
  canvasModel.increaseMarginSide(keyAxisOrient, labelSize.height + AXIS_HORIZONTAL_LABEL_PADDING, keyAxisLabelVerticalLog);
55
56
  }
56
- else if (axis.value.visibility)
57
+ else if (this.configReader.options.axis.value.visibility)
57
58
  canvasModel.increaseMarginSide(valueAxisOrient, labelSize.height + AXIS_HORIZONTAL_LABEL_PADDING);
58
59
  }
59
- recalcHorizontalMarginByAxisLabelWidth(labelSize, canvasModel, orientation, axis, isShow) {
60
- const keyAxisOrient = AxisModel.getAxisOrient(AxisType.Key, orientation, axis.key.position);
61
- const valueAxisOrient = AxisModel.getAxisOrient(AxisType.Value, orientation, axis.value.position);
62
- if ((keyAxisOrient === 'left' || keyAxisOrient === 'right') && isShow && axis.key.visibility) {
60
+ recalcHorizontalMarginByAxisLabelWidth(labelSize, canvasModel, isShow) {
61
+ const keyAxisOrient = AxisModel.getAxisOrient(AxisType.Key, this.configReader.options.orientation, this.configReader.options.axis.key.position);
62
+ const valueAxisOrient = AxisModel.getAxisOrient(AxisType.Value, this.configReader.options.orientation, this.configReader.options.axis.value.position);
63
+ if ((keyAxisOrient === 'left' || keyAxisOrient === 'right') && isShow && this.configReader.options.axis.key.visibility) {
63
64
  canvasModel.increaseMarginSide(keyAxisOrient, labelSize.width + AXIS_VERTICAL_LABEL_PADDING, keyAxisLabelHorizontalLog);
64
65
  }
65
- else if ((valueAxisOrient === 'left' || valueAxisOrient === 'right') && axis.value.visibility) {
66
+ else if ((valueAxisOrient === 'left' || valueAxisOrient === 'right') && this.configReader.options.axis.value.visibility) {
66
67
  canvasModel.increaseMarginSide(valueAxisOrient, labelSize.width + AXIS_VERTICAL_LABEL_PADDING);
67
68
  }
68
69
  }
@@ -1,5 +1,5 @@
1
1
  import { ChartOrientation, MdtChartsColorField, IntervalChartType, PolarChartType, Size, TooltipOptions, TwoDimensionalChartType, AxisLabelPosition, MdtChartsIconElement, MdtChartsCardValue, MdtChartsColorName } from "../config/config";
2
- import { DataType, DonutOptionsCanvas, Formatter, TooltipSettings, Transitions } from "../designer/designerConfig";
2
+ import { DataType, DonutOptionsCanvas, Formatter, StaticLegendBlockCanvas, TooltipSettings, Transitions } from "../designer/designerConfig";
3
3
  declare type AxisType = "key" | "value";
4
4
  export declare type Orient = "top" | "bottom" | "left" | "right";
5
5
  export declare type ScaleKeyType = "band" | "point";
@@ -101,6 +101,7 @@ export interface ScaleValueModel {
101
101
  domain: any[];
102
102
  range: RangeModel;
103
103
  type: ScaleValueType;
104
+ formatter: ((v: number) => string) | null;
104
105
  }
105
106
  export interface RangeModel {
106
107
  start: number;
@@ -144,6 +145,7 @@ export interface GridLineFlag {
144
145
  }
145
146
  export interface TwoDimChartElementsSettings {
146
147
  bar: BarChartSettings;
148
+ lineLike: LineLikeChartSettings;
147
149
  }
148
150
  export interface BarChartSettings {
149
151
  groupMaxDistance: number;
@@ -152,6 +154,29 @@ export interface BarChartSettings {
152
154
  maxBarWidth: number;
153
155
  minBarWidth: number;
154
156
  }
157
+ export interface LineLikeChartSettings {
158
+ shape: LineLikeChartShapeOptions;
159
+ }
160
+ export interface LineLikeChartShapeOptions {
161
+ curve: LineLikeChartCurveOptions;
162
+ }
163
+ export interface LineLikeChartDashOptions {
164
+ on: boolean;
165
+ dashSize: number;
166
+ gapSize: number;
167
+ }
168
+ export declare enum LineCurveType {
169
+ monotoneX = 0,
170
+ monotoneY = 1,
171
+ basis = 2,
172
+ none = 3
173
+ }
174
+ interface LineLikeChartCurveOptions {
175
+ type: LineCurveType;
176
+ }
177
+ interface BarLikeChartHatchOptions {
178
+ on: boolean;
179
+ }
155
180
  export interface DonutChartSettings extends Omit<DonutOptionsCanvas, "aggregatorPad" | "thickness"> {
156
181
  aggregator: DonutAggregatorModel;
157
182
  thickness: DonutThicknessOptions;
@@ -190,21 +215,47 @@ export interface ChartStyle {
190
215
  elementColors: string[];
191
216
  opacity: number;
192
217
  }
193
- export interface TwoDimensionalChartModel extends ChartModel {
218
+ export interface ChartLegendModel {
219
+ markerShape: LegendMarkerShape;
220
+ barViewOptions: TwoDimensionalChartLegendBarModel;
221
+ lineViewOptions: TwoDimensionalChartLegendLineModel;
222
+ }
223
+ export declare type LegendMarkerShape = "default" | "bar" | "line";
224
+ export interface TwoDimensionalChartLegendBarModel extends TwoDimensionalBarLikeChartViewModel {
225
+ width: number;
226
+ }
227
+ export interface TwoDimensionalChartLegendLineModel extends TwoDimensionalLineLikeChartViewModel {
228
+ width: number;
229
+ }
230
+ interface TwoDimensionalLineLikeChartModel {
231
+ lineViewOptions: TwoDimensionalLineLikeChartViewModel;
232
+ markersOptions: MarkersOptions;
233
+ }
234
+ interface TwoDimensionalLineLikeChartViewModel {
235
+ dashedStyles: LineLikeChartDashOptions;
236
+ }
237
+ interface TwoDimensionalBarLikeChartModel {
238
+ barViewOptions: TwoDimensionalBarLikeChartViewModel;
239
+ }
240
+ interface TwoDimensionalBarLikeChartViewModel {
241
+ hatch: BarLikeChartHatchOptions;
242
+ }
243
+ export interface TwoDimensionalChartModel extends ChartModel, TwoDimensionalLineLikeChartModel, TwoDimensionalBarLikeChartModel {
194
244
  type: TwoDimensionalChartType;
195
245
  data: TwoDimensionalChartDataModel;
196
246
  index: number;
197
247
  embeddedLabels: EmbeddedLabelTypeModel;
198
248
  isSegmented: boolean;
199
- markersOptions: MarkersOptions;
249
+ legend: ChartLegendModel;
200
250
  }
201
- export interface IntervalChartModel extends ChartModel {
251
+ export interface IntervalChartModel extends Omit<ChartModel, "legend"> {
202
252
  type: IntervalChartType;
203
253
  data: IntervalChartDataModel;
204
254
  }
205
255
  export interface PolarChartModel extends ChartModel {
206
256
  type: PolarChartType;
207
257
  data: PolarChartDataModel;
258
+ legend: ChartLegendModel;
208
259
  }
209
260
  export interface TwoDimensionalChartDataModel {
210
261
  valueFields: ValueField[];
@@ -246,6 +297,7 @@ interface ComponentBlockModel {
246
297
  }
247
298
  export interface LegendBlockModel {
248
299
  coordinate: LegendCoordinate;
300
+ static: StaticLegendBlockCanvas;
249
301
  }
250
302
  export interface LegendCoordinate {
251
303
  top: LegendCanvasCoordinate;
@@ -1 +1,7 @@
1
- export {};
1
+ export var LineCurveType;
2
+ (function (LineCurveType) {
3
+ LineCurveType[LineCurveType["monotoneX"] = 0] = "monotoneX";
4
+ LineCurveType[LineCurveType["monotoneY"] = 1] = "monotoneY";
5
+ LineCurveType[LineCurveType["basis"] = 2] = "basis";
6
+ LineCurveType[LineCurveType["none"] = 3] = "none";
7
+ })(LineCurveType || (LineCurveType = {}));
@@ -7,6 +7,7 @@ import { OtherComponentsModel } from './featuresModel/otherComponents';
7
7
  import { ConfigValidator } from './configsValidator/configValidator';
8
8
  import { ModelInstance } from './modelInstance/modelInstance';
9
9
  import { CardsModelInstance } from './notations/cards/cardsModel';
10
+ import { TwoDimConfigReader } from './modelInstance/configReader';
10
11
  export var AxisType;
11
12
  (function (AxisType) {
12
13
  AxisType[AxisType["Key"] = 0] = "Key";
@@ -34,7 +35,7 @@ function getChartBlockModel(modelInstance) {
34
35
  function getOptions(config, designerConfig, modelInstance) {
35
36
  //TODO: migrate to polymorphism
36
37
  if (config.options.type === '2d') {
37
- return TwoDimensionalModel.getOptions(config.options, designerConfig, modelInstance);
38
+ return TwoDimensionalModel.getOptions(new TwoDimConfigReader(config, designerConfig), designerConfig, modelInstance);
38
39
  }
39
40
  else if (config.options.type === 'polar') {
40
41
  return PolarModel.getOptions(config.options, designerConfig, modelInstance);
@@ -61,7 +62,7 @@ function getTransitions(designerConfig) {
61
62
  return designerConfig.transitions;
62
63
  }
63
64
  export function assembleModel(config, data, designerConfig) {
64
- const modelInstance = ModelInstance.create(config, data);
65
+ const modelInstance = ModelInstance.create(config, data, designerConfig);
65
66
  if (!data || Object.keys(data).length === 0)
66
67
  return {
67
68
  blockCanvas: getBlockCanvas(config, modelInstance),
@@ -71,12 +72,16 @@ export function assembleModel(config, data, designerConfig) {
71
72
  dataSettings: null
72
73
  };
73
74
  resetFalsyValues(data);
74
- const otherComponents = OtherComponentsModel.getOtherComponentsModel({ elementsOptions: designerConfig.elementsOptions, title: config.options.title }, modelInstance);
75
- const marginModel = new MarginModel();
76
- marginModel.initMargin(designerConfig, config, otherComponents, data, modelInstance);
75
+ const otherComponents = OtherComponentsModel.getOtherComponentsModel({
76
+ elementsOptions: designerConfig.elementsOptions,
77
+ legendConfig: designerConfig.canvas.legendBlock,
78
+ title: config.options.title
79
+ }, modelInstance);
80
+ const marginModel = new MarginModel(designerConfig, config);
81
+ marginModel.initMargin(otherComponents, modelInstance);
77
82
  DataManagerModel.initDataScope(config, data, designerConfig, otherComponents.legendBlock, modelInstance);
78
83
  if (config.options.type === '2d' && config.options.axis.key.visibility)
79
- marginModel.recalcMarginByVerticalAxisLabel(modelInstance, config.options, designerConfig);
84
+ marginModel.recalcMarginByVerticalAxisLabel(modelInstance);
80
85
  const blockCanvas = getBlockCanvas(config, modelInstance);
81
86
  const chartBlock = getChartBlockModel(modelInstance);
82
87
  const options = getOptions(config, designerConfig, modelInstance);