mdt-charts 1.13.3 → 1.14.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.
Files changed (87) 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/features/axis/axis.js +6 -3
  10. package/lib/engine/features/axis/axisHelper.d.ts +2 -2
  11. package/lib/engine/features/axis/axisHelper.js +6 -11
  12. package/lib/engine/features/axis/axisLabelDomHelper.js +9 -11
  13. package/lib/engine/features/legend/legend.d.ts +17 -12
  14. package/lib/engine/features/legend/legend.js +39 -23
  15. package/lib/engine/features/legend/legendDomHelper.d.ts +8 -4
  16. package/lib/engine/features/legend/legendDomHelper.js +20 -8
  17. package/lib/engine/features/legend/legendEventsManager.d.ts +2 -2
  18. package/lib/engine/features/legend/legendEventsManager.js +5 -5
  19. package/lib/engine/features/legend/legendHelper.d.ts +6 -3
  20. package/lib/engine/features/legend/legendHelper.js +5 -7
  21. package/lib/engine/features/legend/legendMarkerCreator.d.ts +21 -0
  22. package/lib/engine/features/legend/legendMarkerCreator.js +88 -0
  23. package/lib/engine/features/legend/legendWidthCalculator.d.ts +16 -0
  24. package/lib/engine/features/legend/legendWidthCalculator.js +136 -0
  25. package/lib/engine/features/tolltip/tooltip.js +2 -5
  26. package/lib/engine/features/tolltip/tooltipDomHelper.d.ts +4 -4
  27. package/lib/engine/features/tolltip/tooltipDomHelper.js +13 -26
  28. package/lib/engine/helpers/domHelper.js +1 -1
  29. package/lib/engine/helpers/pipeline/Pipeline.d.ts +9 -0
  30. package/lib/engine/helpers/pipeline/Pipeline.js +37 -0
  31. package/lib/engine/intervalNotation/intervalManager.js +0 -2
  32. package/lib/engine/polarNotation/polarManager.js +3 -3
  33. package/lib/engine/twoDimensionalNotation/bar/bar.d.ts +16 -13
  34. package/lib/engine/twoDimensionalNotation/bar/bar.js +30 -18
  35. package/lib/engine/twoDimensionalNotation/bar/barHelper.d.ts +3 -0
  36. package/lib/engine/twoDimensionalNotation/bar/barHelper.js +9 -0
  37. package/lib/engine/twoDimensionalNotation/line/line.d.ts +22 -11
  38. package/lib/engine/twoDimensionalNotation/line/line.js +33 -17
  39. package/lib/engine/twoDimensionalNotation/line/lineGenerator.d.ts +15 -0
  40. package/lib/engine/twoDimensionalNotation/line/lineGenerator.js +27 -0
  41. package/lib/engine/twoDimensionalNotation/line/lineHelper.d.ts +18 -4
  42. package/lib/engine/twoDimensionalNotation/line/lineHelper.js +26 -16
  43. package/lib/engine/twoDimensionalNotation/twoDimensionalManager.js +13 -12
  44. package/lib/model/dataManagerModel/dataManagerModel.js +8 -2
  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/legendCanvasModel.d.ts +12 -1
  48. package/lib/model/featuresModel/legendModel/legendCanvasModel.js +12 -6
  49. package/lib/model/featuresModel/legendModel/legendModel.d.ts +2 -1
  50. package/lib/model/featuresModel/legendModel/legendModel.js +5 -1
  51. package/lib/model/featuresModel/legendModel/twoDimLegendModel.d.ts +4 -1
  52. package/lib/model/featuresModel/legendModel/twoDimLegendModel.js +13 -2
  53. package/lib/model/featuresModel/otherComponents.d.ts +2 -1
  54. package/lib/model/featuresModel/otherComponents.js +1 -1
  55. package/lib/model/featuresModel/scaleModel/scaleModel.d.ts +2 -1
  56. package/lib/model/featuresModel/scaleModel/scaleModel.js +4 -2
  57. package/lib/model/margin/marginModel.d.ts +6 -3
  58. package/lib/model/margin/marginModel.js +12 -8
  59. package/lib/model/margin/twoDim/twoDimMarginModel.d.ts +6 -3
  60. package/lib/model/margin/twoDim/twoDimMarginModel.js +31 -30
  61. package/lib/model/model.d.ts +56 -4
  62. package/lib/model/model.js +7 -1
  63. package/lib/model/modelBuilder.d.ts +12 -0
  64. package/lib/model/modelBuilder.js +23 -6
  65. package/lib/model/modelInstance/configReader.d.ts +23 -0
  66. package/lib/model/modelInstance/configReader.js +45 -0
  67. package/lib/model/modelInstance/dataModel/dataModel.d.ts +2 -2
  68. package/lib/model/modelInstance/dataModel/dataModel.js +0 -1
  69. package/lib/model/modelInstance/dataModel/dataRepository.d.ts +6 -2
  70. package/lib/model/modelInstance/dataModel/dataRepository.js +15 -2
  71. package/lib/model/modelInstance/modelInstance.d.ts +2 -1
  72. package/lib/model/modelInstance/modelInstance.js +6 -4
  73. package/lib/model/notations/cards/cardsChangeService.js +2 -2
  74. package/lib/model/notations/cards/cardsModelService.js +1 -1
  75. package/lib/model/notations/intervalModel.js +4 -3
  76. package/lib/model/notations/polar/polarModel.js +6 -1
  77. package/lib/model/notations/twoDimensional/styles.d.ts +7 -0
  78. package/lib/model/notations/twoDimensional/styles.js +50 -0
  79. package/lib/model/notations/twoDimensionalModel.d.ts +5 -5
  80. package/lib/model/notations/twoDimensionalModel.js +13 -8
  81. package/lib/style/charts-main.css +6 -3
  82. package/lib/style/charts-main.less +6 -3
  83. package/package.json +5 -5
  84. package/lib/engine/contentManager.d.ts +0 -9
  85. package/lib/engine/contentManager.js +0 -29
  86. package/lib/model/modelInstance/canvasModel/marginModelService.d.ts +0 -11
  87. 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);
@@ -5,6 +5,7 @@ import { MIN_DONUT_BLOCK_SIZE, PolarModel } from "../notations/polar/polarModel"
5
5
  import { DataManagerModelService } from "./dataManagerModelService";
6
6
  import { LegendPolarMarginCalculator } from "../featuresModel/legendModel/polarMarginCalculator";
7
7
  import { CardsDataManagerModel } from "./notations/cardsDataManagerModel";
8
+ import { styledElementValues } from "../modelBuilder";
8
9
  export class DataManagerModel {
9
10
  static getPreparedData(data, allowableKeys, config) {
10
11
  const scopedData = config.options.type !== "card" ? this.getScopedData(data, allowableKeys, config.options.data) : data;
@@ -83,11 +84,16 @@ export class DataManagerModel {
83
84
  }
84
85
  //TODO: position type
85
86
  static getLegendDataParams(position, keys, legendCanvas, canvasModel, legendBlock) {
87
+ const legendItemContentOptions = keys.map(k => ({
88
+ text: k,
89
+ markerSize: styledElementValues.defaultLegendMarkerSizes,
90
+ wrapperSize: { marginRightPx: styledElementValues.legend.inlineDynamicItemWrapperMarginRightPx }
91
+ }));
86
92
  if (position === 'right') {
87
- return LegendCanvasModel.findElementsAmountByLegendSize(keys, position, this.polarMarginCalculator.getMaxLegendWidth(legendCanvas, canvasModel.getBlockSize().width), canvasModel.getChartBlockHeight() - legendBlock.coordinate.bottom.margin.bottom);
93
+ return LegendCanvasModel.findElementsAmountByLegendSize(legendItemContentOptions, position, this.polarMarginCalculator.getMaxLegendWidth(legendCanvas, canvasModel.getBlockSize().width), canvasModel.getChartBlockHeight() - legendBlock.coordinate.bottom.margin.bottom);
88
94
  }
89
95
  else {
90
- return LegendCanvasModel.findElementsAmountByLegendSize(keys, position, canvasModel.getChartBlockWidth() - legendBlock.coordinate.bottom.margin.left - legendBlock.coordinate.bottom.margin.right, canvasModel.getChartBlockHeight() - legendBlock.coordinate.bottom.margin.bottom - legendBlock.coordinate.bottom.margin.top - MIN_DONUT_BLOCK_SIZE);
96
+ return LegendCanvasModel.findElementsAmountByLegendSize(legendItemContentOptions, position, canvasModel.getChartBlockWidth() - legendBlock.coordinate.bottom.margin.left - legendBlock.coordinate.bottom.margin.right, canvasModel.getChartBlockHeight() - legendBlock.coordinate.bottom.margin.bottom - legendBlock.coordinate.bottom.margin.top - MIN_DONUT_BLOCK_SIZE);
91
97
  }
92
98
  }
93
99
  static getMaximumPossibleScope(keys, dataModel) {
@@ -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,19 @@
1
1
  import { DataLegendParams } from "../../dataManagerModel/dataManagerModel";
2
2
  import { LegendPosition } from "../../model";
3
3
  export declare type LegendItemsDirection = 'row' | 'column';
4
+ export interface LegendItemContentOptions {
5
+ text: string;
6
+ markerSize: {
7
+ widthPx: number;
8
+ heightPx: number;
9
+ marginRightPx: number;
10
+ };
11
+ wrapperSize: {
12
+ marginRightPx: number;
13
+ };
14
+ }
4
15
  export declare class LegendCanvasModel {
5
16
  static getLegendItemWidth(text: string): number;
6
- static findElementsAmountByLegendSize(texts: string[], position: LegendPosition, legendBlockWidth: number, legendBlockHeight: number): DataLegendParams;
17
+ static findElementsAmountByLegendSize(items: LegendItemContentOptions[], position: LegendPosition, legendBlockWidth: number, legendBlockHeight: number): DataLegendParams;
7
18
  private static getLegendWrapperEl;
8
19
  }
@@ -18,31 +18,37 @@ export class LegendCanvasModel {
18
18
  itemWrapper.remove();
19
19
  return sumWidth;
20
20
  }
21
- static findElementsAmountByLegendSize(texts, position, legendBlockWidth, legendBlockHeight) {
21
+ //TODO: find better solution
22
+ static findElementsAmountByLegendSize(items, position, legendBlockWidth, legendBlockHeight) {
22
23
  const legendWrapper = this.getLegendWrapperEl(legendBlockWidth, position === "right" ? "column" : "row");
23
24
  document.body.append(legendWrapper);
24
25
  let amount = 0;
25
- for (let i = 0; i < texts.length; i++) {
26
+ for (let i = 0; i < items.length; i++) {
26
27
  const itemWrapper = document.createElement('div');
27
28
  const colorBlock = document.createElement('span');
28
29
  const textBlock = document.createElement('span');
29
30
  itemWrapper.classList.add("legend-item");
30
- if (position === 'bottom') {
31
+ if (position === 'bottom' || position === 'top') {
31
32
  itemWrapper.classList.add('legend-item-inline');
32
33
  textBlock.classList.add('legend-label-nowrap');
33
34
  }
34
35
  else {
35
36
  itemWrapper.classList.add('legend-item-row');
36
37
  }
37
- colorBlock.classList.add(CLASSES.legendColor);
38
+ // colorBlock.classList.add(CLASSES.legendColor);
39
+ colorBlock.style.display = "inline-block";
40
+ colorBlock.style.width = `${items[i].markerSize.widthPx}px`;
41
+ colorBlock.style.height = `${items[i].markerSize.heightPx}px`;
42
+ colorBlock.style.marginRight = `${items[i].markerSize.marginRightPx}px`;
38
43
  textBlock.classList.add(CLASSES.legendLabel);
39
- textBlock.textContent = texts[i];
44
+ textBlock.textContent = items[i].text;
45
+ itemWrapper.style.marginRight = `${items[i].wrapperSize.marginRightPx}px`;
40
46
  itemWrapper.append(colorBlock, textBlock);
41
47
  legendWrapper.append(itemWrapper);
42
48
  amount++;
43
49
  if (legendWrapper.offsetHeight > legendBlockHeight) {
44
50
  itemWrapper.remove();
45
- if (legendBlockHeight - legendWrapper.offsetHeight >= 15 && position !== 'bottom')
51
+ if (legendBlockHeight - legendWrapper.offsetHeight >= 15 && position !== 'bottom' && position !== 'top')
46
52
  amount = amount; //TODO: remove
47
53
  else
48
54
  amount -= 1;
@@ -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,11 @@
1
1
  import { Legend } from "../../../config/config";
2
2
  import { LegendBlockModel } from "../../model";
3
+ import { TwoDimConfigReader } from "../../modelInstance/configReader";
3
4
  import { ModelInstance } from "../../modelInstance/modelInstance";
4
5
  export declare class TwoDimLegendModel {
6
+ private configReader;
7
+ constructor(configReader: TwoDimConfigReader);
5
8
  recalcMarginWith2DLegend(modelInstance: ModelInstance, legendBlockModel: LegendBlockModel, legendOptions: Legend): void;
6
- private getLegendSize;
9
+ private getLegendSizeLegacy;
7
10
  private getLegendModel;
8
11
  }
@@ -1,18 +1,29 @@
1
+ import { styledElementValues } from "../../modelBuilder";
2
+ import { getWidthOfLegendMarkerByType } from "../../notations/twoDimensional/styles";
3
+ import { LegendCanvasModel } from "./legendCanvasModel";
1
4
  import { LegendModel } from "./legendModel";
2
5
  export class TwoDimLegendModel {
6
+ constructor(configReader) {
7
+ this.configReader = configReader;
8
+ }
3
9
  recalcMarginWith2DLegend(modelInstance, legendBlockModel, legendOptions) {
4
10
  const canvasModel = modelInstance.canvasModel;
5
11
  const legendPosition = this.getLegendModel(legendOptions).position;
6
12
  modelInstance.canvasModel.legendCanvas.setPosition(legendPosition);
7
13
  if (legendPosition !== 'off') {
8
- const legendSize = this.getLegendSize();
14
+ const legendItemInfo = this.configReader.getLegendItemInfo();
15
+ const legendSize = LegendCanvasModel.findElementsAmountByLegendSize(legendItemInfo.map(i => ({
16
+ text: i.text,
17
+ markerSize: Object.assign(Object.assign({}, styledElementValues.defaultLegendMarkerSizes), { widthPx: getWidthOfLegendMarkerByType(i.chartType) }),
18
+ wrapperSize: { marginRightPx: styledElementValues.legend.inlineItemWrapperMarginRightPx }
19
+ })), 'top', modelInstance.canvasModel.getBlockSize().width, legendBlockModel.static.maxLinesAmount * styledElementValues.legend.inlineLegendOneLineHeightPx).size.height;
9
20
  canvasModel.increaseMarginSide(legendPosition, legendSize);
10
21
  if (legendSize !== 0)
11
22
  LegendModel.appendToGlobalMarginValuesLegendMargin(canvasModel, legendPosition, legendBlockModel);
12
23
  legendBlockModel.coordinate[legendPosition].size = legendSize;
13
24
  }
14
25
  }
15
- getLegendSize() {
26
+ getLegendSizeLegacy() {
16
27
  const heightOfLegendItemWithoutWordWrapping = 20;
17
28
  return heightOfLegendItemWithoutWordWrapping;
18
29
  }
@@ -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() {
11
- this.twoDimLegendModel = new TwoDimLegendModel();
9
+ constructor(designerConfig, configReader) {
10
+ this.designerConfig = designerConfig;
11
+ this.configReader = configReader;
12
+ this.twoDimLegendModel = new TwoDimLegendModel(this.configReader);
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
  }