mdt-charts 1.10.2 → 1.12.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 (65) hide show
  1. package/lib/config/config.d.ts +13 -5
  2. package/lib/designer/designerConfig.d.ts +8 -2
  3. package/lib/engine/features/aggregator/aggregator.d.ts +4 -3
  4. package/lib/engine/features/aggregator/aggregator.js +14 -11
  5. package/lib/engine/features/recordOverflowAlert/recordOverflowAlertCore.d.ts +28 -0
  6. package/lib/engine/features/recordOverflowAlert/recordOverflowAlertCore.js +50 -0
  7. package/lib/engine/features/title/title.js +2 -0
  8. package/lib/engine/features/tolltip/tooltip.js +1 -1
  9. package/lib/engine/filterManager/filterEventManager.d.ts +3 -3
  10. package/lib/engine/filterManager/filterEventManager.js +4 -4
  11. package/lib/engine/intervalNotation/intervalManager.js +2 -5
  12. package/lib/engine/polarNotation/donut/DonutHelper.d.ts +2 -0
  13. package/lib/engine/polarNotation/donut/DonutHelper.js +20 -3
  14. package/lib/engine/polarNotation/donut/donut.js +1 -1
  15. package/lib/engine/polarNotation/extenders/polarRecordOverflowAlert.d.ts +16 -0
  16. package/lib/engine/polarNotation/extenders/polarRecordOverflowAlert.js +48 -0
  17. package/lib/engine/polarNotation/polarManager.js +16 -12
  18. package/lib/engine/twoDimensionalNotation/extenders/twoDimRecordOverflowAlert.d.ts +15 -0
  19. package/lib/engine/twoDimensionalNotation/extenders/twoDimRecordOverflowAlert.js +32 -0
  20. package/lib/engine/twoDimensionalNotation/twoDimensionalManager.js +13 -7
  21. package/lib/model/chartStyleModel/TwoDimensionalChartStyleModel.d.ts +19 -0
  22. package/lib/model/chartStyleModel/TwoDimensionalChartStyleModel.js +61 -0
  23. package/lib/model/chartStyleModel/chartStyleModel.d.ts +9 -0
  24. package/lib/model/chartStyleModel/chartStyleModel.js +27 -0
  25. package/lib/model/dataManagerModel/dataManagerModel.d.ts +26 -0
  26. package/lib/model/dataManagerModel/dataManagerModel.js +132 -0
  27. package/lib/model/dataManagerModel/dataManagerModelService.d.ts +5 -0
  28. package/lib/model/dataManagerModel/dataManagerModelService.js +28 -0
  29. package/lib/model/dataManagerModel.d.ts +3 -2
  30. package/lib/model/dataManagerModel.js +12 -10
  31. package/lib/model/featuresModel/axisModel.d.ts +9 -8
  32. package/lib/model/featuresModel/axisModel.js +21 -21
  33. package/lib/model/featuresModel/legendModel/legendModel.d.ts +4 -5
  34. package/lib/model/featuresModel/legendModel/legendModel.js +6 -9
  35. package/lib/model/featuresModel/otherComponents.d.ts +9 -2
  36. package/lib/model/featuresModel/otherComponents.js +6 -4
  37. package/lib/model/featuresModel/scaleModel.d.ts +7 -6
  38. package/lib/model/featuresModel/scaleModel.js +9 -9
  39. package/lib/model/featuresModel/titleModel.d.ts +1 -1
  40. package/lib/model/featuresModel/titleModel.js +7 -5
  41. package/lib/model/marginModel.d.ts +5 -5
  42. package/lib/model/marginModel.js +41 -38
  43. package/lib/model/model.d.ts +24 -18
  44. package/lib/model/modelBuilder.js +26 -37
  45. package/lib/model/modelInstance/canvasModel/canvasModel.d.ts +24 -0
  46. package/lib/model/modelInstance/canvasModel/canvasModel.js +44 -0
  47. package/lib/model/modelInstance/canvasModel/legendCanvasModel.d.ts +7 -0
  48. package/lib/model/modelInstance/canvasModel/legendCanvasModel.js +13 -0
  49. package/lib/model/modelInstance/canvasModel/titleCanvas.d.ts +9 -0
  50. package/lib/model/modelInstance/canvasModel/titleCanvas.js +11 -0
  51. package/lib/model/modelInstance/dataModel.d.ts +11 -0
  52. package/lib/model/modelInstance/dataModel.js +23 -0
  53. package/lib/model/modelInstance/modelInstance.d.ts +10 -0
  54. package/lib/model/modelInstance/modelInstance.js +17 -0
  55. package/lib/model/notations/intervalModel.d.ts +2 -1
  56. package/lib/model/notations/intervalModel.js +17 -15
  57. package/lib/model/notations/polarModel.d.ts +9 -3
  58. package/lib/model/notations/polarModel.js +29 -8
  59. package/lib/model/notations/twoDimensionalModel.d.ts +7 -5
  60. package/lib/model/notations/twoDimensionalModel.js +19 -12
  61. package/lib/style/charts-main.css +2 -0
  62. package/lib/style/charts-main.less +2 -0
  63. package/package.json +3 -2
  64. package/lib/model/chartStyleModel.d.ts +0 -16
  65. package/lib/model/chartStyleModel.js +0 -67
@@ -1,8 +1,6 @@
1
1
  import { ModelHelper } from "../../modelHelper";
2
- import { TitleModel } from "../titleModel";
2
+ import { PolarModel } from "../../notations/polarModel";
3
3
  import { LegendCanvasModel } from "./legendCanvasModel";
4
- /** If donut block has width less than this const, legend change postion from "right" to "bottom" */
5
- export const MIN_DONUT_BLOCK_SIZE = 260;
6
4
  export class LegendModel {
7
5
  static getLegendSize(chartNotation, position, texts, legendMaxWidth, blockSize, legendBlockModel) {
8
6
  if (position === 'left' || position === 'right')
@@ -15,9 +13,8 @@ export class LegendModel {
15
13
  return size;
16
14
  }
17
15
  }
18
- static getBaseLegendBlockModel(notation) {
16
+ static getBaseLegendBlockModel(notation, canvasModel) {
19
17
  const mt = 20, mb = 20, ml = 20, mr = 20;
20
- const titleModelTemplate = TitleModel.getTitleModel();
21
18
  return {
22
19
  coordinate: {
23
20
  left: {
@@ -32,25 +29,25 @@ export class LegendModel {
32
29
  },
33
30
  right: {
34
31
  size: 0,
35
- margin: { top: titleModelTemplate.pad + titleModelTemplate.margin.top + titleModelTemplate.size, bottom: mb, left: 0, right: mr },
32
+ margin: { top: canvasModel.titleCanvas.getAllNeededSpace(), bottom: mb, left: 0, right: mr },
36
33
  pad: 0
37
34
  },
38
35
  top: {
39
36
  size: 0,
40
37
  margin: { top: 20, bottom: 0, left: 20, right: 20 },
41
- pad: titleModelTemplate.pad + titleModelTemplate.margin.top + titleModelTemplate.size
38
+ pad: canvasModel.titleCanvas.getAllNeededSpace()
42
39
  }
43
40
  },
44
41
  standartTooltip: notation === 'polar' ? false : true
45
42
  };
46
43
  }
47
- static getLegendModel(chartNotation, legendShow, blockSize, margin) {
44
+ static getLegendModel(chartNotation, legendShow, canvasModel) {
48
45
  let legendPosition = 'off';
49
46
  if (legendShow) {
50
47
  if (chartNotation === '2d' || chartNotation === 'interval')
51
48
  legendPosition = 'top';
52
49
  else if (chartNotation === 'polar') {
53
- legendPosition = blockSize.width - margin.left - margin.right < MIN_DONUT_BLOCK_SIZE ? 'bottom' : 'right';
50
+ legendPosition = PolarModel.getLegendPositionByBlockSize(canvasModel);
54
51
  }
55
52
  }
56
53
  return {
@@ -1,6 +1,13 @@
1
- import { OtherComponents } from "../model";
1
+ import { OtherCommonComponents } from "../model";
2
2
  import { ElementsOptions } from "../../designer/designerConfig";
3
3
  import { ChartNotation } from "../../config/config";
4
+ import { ModelInstance } from "../modelInstance/modelInstance";
5
+ interface OtherComponentsModelDependencies {
6
+ elementsOptions: ElementsOptions;
7
+ title: string;
8
+ notation: ChartNotation;
9
+ }
4
10
  export declare class OtherComponentsModel {
5
- static getOtherComponentsModel(elementsOptions: ElementsOptions, notation: ChartNotation): OtherComponents;
11
+ static getOtherComponentsModel(dependencies: OtherComponentsModelDependencies, modelInstance: ModelInstance): OtherCommonComponents;
6
12
  }
13
+ export {};
@@ -2,11 +2,13 @@ import { LegendModel } from "./legendModel/legendModel";
2
2
  import { TitleModel } from "./titleModel";
3
3
  import { TooltipModel } from "./tooltipModel";
4
4
  export class OtherComponentsModel {
5
- static getOtherComponentsModel(elementsOptions, notation) {
5
+ static getOtherComponentsModel(dependencies, modelInstance) {
6
+ const canvasModel = modelInstance.canvasModel;
7
+ canvasModel.titleCanvas.init(TitleModel.getTitleModel(dependencies.title));
6
8
  return {
7
- legendBlock: LegendModel.getBaseLegendBlockModel(notation),
8
- titleBlock: TitleModel.getTitleModel(),
9
- tooltipBlock: TooltipModel.getTooltipModel(elementsOptions.tooltip)
9
+ legendBlock: LegendModel.getBaseLegendBlockModel(dependencies.notation, canvasModel),
10
+ titleBlock: canvasModel.titleCanvas.getModel(),
11
+ tooltipBlock: TooltipModel.getTooltipModel(dependencies.elementsOptions.tooltip)
10
12
  };
11
13
  }
12
14
  }
@@ -1,15 +1,16 @@
1
- import { BlockMargin, ScaleKeyModel, ScaleKeyType, ScaleValueModel, ScaleValueType } from "../model";
2
- import { AxisPosition, NumberDomain, IntervalChart, TwoDimensionalChart, TwoDimensionalOptions, Size, ChartOrientation, MdtChartsDataSource } from "../../config/config";
1
+ import { ScaleKeyModel, ScaleKeyType, ScaleValueModel, ScaleValueType } from "../model";
2
+ import { AxisPosition, NumberDomain, IntervalChart, TwoDimensionalChart, MdtChartsTwoDimensionalOptions, ChartOrientation, MdtChartsDataSource } from "../../config/config";
3
+ import { CanvasModel } from "../modelInstance/canvasModel/canvasModel";
3
4
  export declare enum ScaleType {
4
5
  Key = 0,
5
6
  Value = 1
6
7
  }
7
8
  export declare class ScaleModel {
8
- static getScaleKey(allowableKeys: string[], orient: ChartOrientation, margin: BlockMargin, blockSize: Size, charts: TwoDimensionalChart[], barCharts: TwoDimensionalChart[]): ScaleKeyModel;
9
- static getScaleLinear(options: TwoDimensionalOptions, data: MdtChartsDataSource, margin: BlockMargin, blockSize: Size): ScaleValueModel;
10
- static getRangePeek(scaleType: ScaleType, chartOrientation: string, margin: BlockMargin, blockSize: Size): number;
9
+ static getScaleKey(allowableKeys: string[], orient: ChartOrientation, canvasModel: CanvasModel, charts: TwoDimensionalChart[], barCharts: TwoDimensionalChart[]): ScaleKeyModel;
10
+ static getScaleLinear(options: MdtChartsTwoDimensionalOptions, data: MdtChartsDataSource, canvasModel: CanvasModel): ScaleValueModel;
11
+ static getRangePeek(scaleType: ScaleType, chartOrientation: string, canvasModel: CanvasModel): number;
11
12
  static getDateValueDomain(data: MdtChartsDataSource, chart: IntervalChart, keyAxisPosition: AxisPosition, dataSource: string): [Date, Date];
12
- static getLinearDomain(configDomain: NumberDomain, data: MdtChartsDataSource, configOptions: TwoDimensionalOptions): [number, number];
13
+ static getLinearDomain(configDomain: NumberDomain, data: MdtChartsDataSource, configOptions: MdtChartsTwoDimensionalOptions): [number, number];
13
14
  static getScaleKeyType(charts: TwoDimensionalChart[]): ScaleKeyType;
14
15
  static getScaleValueType(charts: TwoDimensionalChart[] | IntervalChart[]): ScaleValueType;
15
16
  static getElementsAmount(barCharts: TwoDimensionalChart[]): number;
@@ -5,35 +5,35 @@ export var ScaleType;
5
5
  ScaleType[ScaleType["Value"] = 1] = "Value";
6
6
  })(ScaleType || (ScaleType = {}));
7
7
  export class ScaleModel {
8
- static getScaleKey(allowableKeys, orient, margin, blockSize, charts, barCharts) {
8
+ static getScaleKey(allowableKeys, orient, canvasModel, charts, barCharts) {
9
9
  return {
10
10
  domain: allowableKeys,
11
11
  range: {
12
12
  start: 0,
13
- end: ScaleModel.getRangePeek(ScaleType.Key, orient, margin, blockSize)
13
+ end: ScaleModel.getRangePeek(ScaleType.Key, orient, canvasModel)
14
14
  },
15
15
  type: ScaleModel.getScaleKeyType(charts),
16
16
  elementsAmount: this.getElementsAmount(barCharts)
17
17
  };
18
18
  }
19
- static getScaleLinear(options, data, margin, blockSize) {
19
+ static getScaleLinear(options, data, canvasModel) {
20
20
  return {
21
21
  domain: ScaleModel.getLinearDomain(options.axis.value.domain, data, options),
22
22
  range: {
23
23
  start: 0,
24
- end: ScaleModel.getRangePeek(ScaleType.Value, options.orientation, margin, blockSize)
24
+ end: ScaleModel.getRangePeek(ScaleType.Value, options.orientation, canvasModel)
25
25
  },
26
26
  type: ScaleModel.getScaleValueType(options.charts)
27
27
  };
28
28
  }
29
- static getRangePeek(scaleType, chartOrientation, margin, blockSize) {
29
+ static getRangePeek(scaleType, chartOrientation, canvasModel) {
30
30
  if (chartOrientation === 'vertical')
31
31
  return scaleType === ScaleType.Key
32
- ? blockSize.width - margin.left - margin.right
33
- : blockSize.height - margin.top - margin.bottom;
32
+ ? canvasModel.getChartBlockWidth()
33
+ : canvasModel.getChartBlockHeight();
34
34
  return scaleType === ScaleType.Key
35
- ? blockSize.height - margin.top - margin.bottom
36
- : blockSize.width - margin.left - margin.right;
35
+ ? canvasModel.getChartBlockHeight()
36
+ : canvasModel.getChartBlockWidth();
37
37
  }
38
38
  static getDateValueDomain(data, chart, keyAxisPosition, dataSource) {
39
39
  const minMax = ModelHelper.getMinAndMaxOfIntervalData(data, dataSource, chart);
@@ -1,4 +1,4 @@
1
1
  import { TitleBlockModel } from "../model";
2
2
  export declare class TitleModel {
3
- static getTitleModel(): TitleBlockModel;
3
+ static getTitleModel(titleText: string): TitleBlockModel;
4
4
  }
@@ -1,13 +1,15 @@
1
1
  export class TitleModel {
2
- static getTitleModel() {
2
+ static getTitleModel(titleText) {
3
+ const defaultPads = 20;
4
+ const pad = titleText ? defaultPads : 0;
3
5
  return {
4
6
  margin: {
5
7
  bottom: 0,
6
- left: 20,
7
- right: 20,
8
- top: 20
8
+ left: pad,
9
+ right: pad,
10
+ top: pad
9
11
  },
10
- size: 20,
12
+ size: pad,
11
13
  pad: 0
12
14
  };
13
15
  }
@@ -1,13 +1,13 @@
1
1
  import { MdtChartsConfig, MdtChartsDataSource } from "../config/config";
2
2
  import { DesignerConfig } from "../designer/designerConfig";
3
- import { BlockMargin, DataScope, LegendBlockModel, OtherComponents, PolarOptionsModel } from "./model";
4
- import { Size } from "../config/config";
3
+ import { DataScope, LegendBlockModel, OtherCommonComponents, PolarOptionsModel } from "./model";
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 MarginModel {
8
- static getMargin(designerConfig: DesignerConfig, config: MdtChartsConfig, otherComponents: OtherComponents, data: MdtChartsDataSource): BlockMargin;
9
- static recalcPolarMarginWithScopedData(margin: BlockMargin, blockSize: Size, designerConfig: DesignerConfig, config: MdtChartsConfig, legendBlockModel: LegendBlockModel, dataScope: DataScope, options: PolarOptionsModel): void;
10
- static recalcMarginByVerticalAxisLabel(margin: BlockMargin, config: MdtChartsConfig, designerConfig: DesignerConfig, dataScope: DataScope): void;
8
+ static initMargin(designerConfig: DesignerConfig, config: MdtChartsConfig, otherComponents: OtherCommonComponents, data: MdtChartsDataSource, modelInstance: ModelInstance): void;
9
+ static recalcPolarMarginWithScopedData(modelInstance: ModelInstance, designerConfig: DesignerConfig, config: MdtChartsConfig, legendBlockModel: LegendBlockModel, dataScope: DataScope, options: PolarOptionsModel): void;
10
+ static recalcMarginByVerticalAxisLabel(modelInstance: ModelInstance, config: MdtChartsConfig, designerConfig: DesignerConfig, dataScope: DataScope): void;
11
11
  private static getHorizontalMarginByAxisLabels;
12
12
  private static recalcVerticalMarginByAxisLabelHeight;
13
13
  private static recalcHorizontalMarginByAxisLabelWidth;
@@ -1,50 +1,51 @@
1
1
  import { AxisModel } from "./featuresModel/axisModel";
2
- import { DataManagerModel } from "./dataManagerModel";
3
- import { LegendModel, MIN_DONUT_BLOCK_SIZE } from "./featuresModel/legendModel/legendModel";
2
+ import { DataManagerModel } from "./dataManagerModel/dataManagerModel";
3
+ import { LegendModel } from "./featuresModel/legendModel/legendModel";
4
4
  import { AxisType } from "./modelBuilder";
5
5
  import { TwoDimensionalModel } from "./notations/twoDimensionalModel";
6
+ import { PolarModel } from "./notations/polarModel";
6
7
  export const AXIS_HORIZONTAL_LABEL_PADDING = 15;
7
8
  export const AXIS_VERTICAL_LABEL_PADDING = 10;
8
9
  export class MarginModel {
9
- static getMargin(designerConfig, config, otherComponents, data) {
10
- const margin = Object.assign({}, designerConfig.canvas.chartBlockMargin);
11
- this.recalcMarginWithLegend(margin, config, designerConfig.canvas.legendBlock.maxWidth, otherComponents.legendBlock, data);
12
- this.recalcMarginByTitle(margin, otherComponents.titleBlock);
10
+ static initMargin(designerConfig, config, otherComponents, data, modelInstance) {
11
+ const canvasModel = modelInstance.canvasModel;
12
+ canvasModel.initMargin(Object.assign({}, designerConfig.canvas.chartBlockMargin));
13
+ this.recalcMarginWithLegend(modelInstance, config, designerConfig.canvas.legendBlock.maxWidth, otherComponents.legendBlock, data);
14
+ this.recalcMarginByTitle(canvasModel, otherComponents.titleBlock);
13
15
  if (config.options.type === '2d' || config.options.type === 'interval') {
14
16
  const labelSize = this.getHorizontalMarginByAxisLabels(designerConfig.canvas.axisLabel.maxSize.main, config.options.axis, data, config.options);
15
- this.recalcVerticalMarginByAxisLabelHeight(labelSize, margin, config.options.orientation, config.options.axis);
17
+ this.recalcVerticalMarginByAxisLabelHeight(labelSize, canvasModel, config.options.orientation, config.options.axis);
16
18
  // Если встроенный лейбл показывает ключи, то лейблы оси ключей не показываются
17
19
  // При этом все графики должны иметь: embeddedLabels = 'key'
18
20
  // И все графики должны быть типа bar.
19
21
  const showingFlag = config.options.type === '2d'
20
22
  ? !TwoDimensionalModel.getChartsEmbeddedLabelsFlag(config.options.charts, config.options.orientation)
21
23
  : true;
22
- this.recalcHorizontalMarginByAxisLabelWidth(labelSize, margin, config.options.orientation, config.options.axis, showingFlag);
24
+ this.recalcHorizontalMarginByAxisLabelWidth(labelSize, canvasModel, config.options.orientation, config.options.axis, showingFlag);
23
25
  }
24
- return margin;
25
26
  }
26
- static recalcPolarMarginWithScopedData(margin, blockSize, designerConfig, config, legendBlockModel, dataScope, options) {
27
- let position = LegendModel.getLegendModel(config.options.type, config.options.legend.show, config.canvas.size, margin).position;
27
+ static recalcPolarMarginWithScopedData(modelInstance, designerConfig, config, legendBlockModel, dataScope, options) {
28
+ const canvasModel = modelInstance.canvasModel;
29
+ let position = canvasModel.legendCanvas.getPosition();
28
30
  if (position !== 'off') {
29
- if (position === 'right' && blockSize.width - margin.left - margin.right < MIN_DONUT_BLOCK_SIZE)
30
- position = 'bottom';
31
- this.clearMarginByLegendBlockPosition(margin, legendBlockModel);
31
+ position = PolarModel.getLegendPositionByBlockSize(canvasModel); // reset position
32
+ this.clearMarginByLegendBlockPosition(canvasModel, legendBlockModel);
32
33
  let allowableKeys = [...dataScope.allowableKeys];
33
34
  if (dataScope.hidedRecordsAmount !== 0 && position === 'bottom')
34
35
  allowableKeys.push('1'); // Если есть спрятанные записи, то в массив добавляется объект, чтобы выделить место в легенде для индикатора переполнения
35
36
  const legendSize = LegendModel.getLegendSize(config.options.type, position, allowableKeys, designerConfig.canvas.legendBlock.maxWidth, config.canvas.size, legendBlockModel);
36
- margin[position] += legendSize + legendBlockModel.coordinate[position].margin[position];
37
+ canvasModel.increaseMarginSide(position, legendSize + legendBlockModel.coordinate[position].margin[position]);
37
38
  legendBlockModel.coordinate[position].size = legendSize;
38
39
  options.legend.position = position;
39
40
  }
40
41
  }
41
- static recalcMarginByVerticalAxisLabel(margin, config, designerConfig, dataScope) {
42
+ static recalcMarginByVerticalAxisLabel(modelInstance, config, designerConfig, dataScope) {
42
43
  if ((config.options.type === '2d' || config.options.type === 'interval') && config.options.orientation === 'vertical') {
43
44
  const axisLabelSize = AxisModel.getLabelSize(designerConfig.canvas.axisLabel.maxSize.main, dataScope.allowableKeys);
44
- const axisConfig = AxisModel.getKeyAxisLabelPosition(margin, config.canvas.size, dataScope.allowableKeys.length);
45
+ const axisConfig = AxisModel.getKeyAxisLabelPosition(modelInstance.canvasModel, dataScope.allowableKeys.length);
45
46
  const marginOrient = config.options.axis.key.position === 'end' ? 'bottom' : 'top';
46
47
  if (axisConfig === 'rotated')
47
- margin[marginOrient] += (axisLabelSize.width - axisLabelSize.height);
48
+ modelInstance.canvasModel.setMarginSide(marginOrient, modelInstance.canvasModel.getMarginSide(marginOrient) + (axisLabelSize.width - axisLabelSize.height));
48
49
  }
49
50
  }
50
51
  static getHorizontalMarginByAxisLabels(labelsMaxWidth, axis, data, options) {
@@ -58,35 +59,36 @@ export class MarginModel {
58
59
  }
59
60
  return AxisModel.getLabelSize(labelsMaxWidth, labelsTexts);
60
61
  }
61
- static recalcVerticalMarginByAxisLabelHeight(labelSize, margin, orientation, axis) {
62
+ static recalcVerticalMarginByAxisLabelHeight(labelSize, canvasModel, orientation, axis) {
62
63
  const keyAxisOrient = AxisModel.getAxisOrient(AxisType.Key, orientation, axis.key.position);
63
64
  const valueAxisOrient = AxisModel.getAxisOrient(AxisType.Value, orientation, axis.value.position);
64
65
  if ((keyAxisOrient === 'bottom' || keyAxisOrient === 'top')) {
65
66
  if (axis.key.visibility)
66
- margin[keyAxisOrient] += labelSize.height + AXIS_HORIZONTAL_LABEL_PADDING;
67
- }
68
- else if (axis.value.visibility) {
69
- margin[valueAxisOrient] += labelSize.height + AXIS_HORIZONTAL_LABEL_PADDING;
67
+ canvasModel.increaseMarginSide(keyAxisOrient, labelSize.height + AXIS_HORIZONTAL_LABEL_PADDING);
70
68
  }
69
+ else if (axis.value.visibility)
70
+ canvasModel.increaseMarginSide(valueAxisOrient, labelSize.height + AXIS_HORIZONTAL_LABEL_PADDING);
71
71
  }
72
- static recalcHorizontalMarginByAxisLabelWidth(labelSize, margin, orientation, axis, isShow) {
72
+ static recalcHorizontalMarginByAxisLabelWidth(labelSize, canvasModel, orientation, axis, isShow) {
73
73
  const keyAxisOrient = AxisModel.getAxisOrient(AxisType.Key, orientation, axis.key.position);
74
74
  const valueAxisOrient = AxisModel.getAxisOrient(AxisType.Value, orientation, axis.value.position);
75
75
  if ((keyAxisOrient === 'left' || keyAxisOrient === 'right') && isShow && axis.key.visibility) {
76
- margin[keyAxisOrient] += labelSize.width + AXIS_VERTICAL_LABEL_PADDING;
76
+ canvasModel.increaseMarginSide(keyAxisOrient, labelSize.width + AXIS_VERTICAL_LABEL_PADDING);
77
77
  }
78
78
  else if ((valueAxisOrient === 'left' || valueAxisOrient === 'right') && axis.value.visibility) {
79
- margin[valueAxisOrient] += labelSize.width + AXIS_VERTICAL_LABEL_PADDING;
79
+ canvasModel.increaseMarginSide(valueAxisOrient, labelSize.width + AXIS_VERTICAL_LABEL_PADDING);
80
80
  }
81
81
  }
82
- static recalcMarginWithLegend(margin, config, legendMaxWidth, legendBlockModel, data) {
83
- const legendPosition = LegendModel.getLegendModel(config.options.type, config.options.legend.show, config.canvas.size, margin).position;
82
+ static recalcMarginWithLegend(modelInstance, config, legendMaxWidth, legendBlockModel, data) {
83
+ const canvasModel = modelInstance.canvasModel;
84
+ const legendPosition = LegendModel.getLegendModel(config.options.type, config.options.legend.show, modelInstance.canvasModel).position;
85
+ modelInstance.canvasModel.legendCanvas.setPosition(legendPosition);
84
86
  if (legendPosition !== 'off') {
85
87
  const legendItemsContent = this.getLegendItemsContent(config.options, data);
86
- const legendSize = LegendModel.getLegendSize(config.options.type, legendPosition, legendItemsContent, legendMaxWidth, config.canvas.size, legendBlockModel);
87
- margin[legendPosition] += legendSize;
88
+ const legendSize = LegendModel.getLegendSize(config.options.type, legendPosition, legendItemsContent, legendMaxWidth, canvasModel.getBlockSize(), legendBlockModel);
89
+ canvasModel.increaseMarginSide(legendPosition, legendSize);
88
90
  if (legendSize !== 0)
89
- this.appendToGlobalMarginValuesLegendMargin(margin, legendPosition, legendBlockModel);
91
+ this.appendToGlobalMarginValuesLegendMargin(canvasModel, legendPosition, legendBlockModel);
90
92
  legendBlockModel.coordinate[legendPosition].size = legendSize;
91
93
  }
92
94
  }
@@ -105,22 +107,23 @@ export class MarginModel {
105
107
  return [options.chart.data.valueField1.name];
106
108
  }
107
109
  }
108
- static appendToGlobalMarginValuesLegendMargin(margin, position, legendBlockModel) {
110
+ static appendToGlobalMarginValuesLegendMargin(canvasModel, position, legendBlockModel) {
109
111
  const legendCoordinate = legendBlockModel.coordinate;
110
112
  if (position === 'left' || position === 'right')
111
- margin[position] += legendCoordinate[position].margin.left + legendCoordinate[position].margin.right;
113
+ canvasModel.increaseMarginSide(position, legendCoordinate[position].margin.left + legendCoordinate[position].margin.right);
112
114
  else
113
- margin[position] += legendCoordinate[position].margin.top + legendCoordinate[position].margin.bottom;
115
+ canvasModel.increaseMarginSide(position, legendCoordinate[position].margin.top + legendCoordinate[position].margin.bottom);
114
116
  }
115
- static clearMarginByLegendBlockPosition(margin, legendBlockModel) {
117
+ static clearMarginByLegendBlockPosition(canvasModel, legendBlockModel) {
116
118
  const legendCoordinate = legendBlockModel.coordinate;
117
119
  ['left', 'right', 'top', 'bottom'].forEach((position) => {
118
- margin[position] -= legendCoordinate[position].size === 0
120
+ const decreaseByValue = legendCoordinate[position].size === 0
119
121
  ? 0
120
122
  : legendCoordinate[position].size + legendCoordinate[position].margin[position];
123
+ canvasModel.descreaseMarginSide(position, decreaseByValue);
121
124
  });
122
125
  }
123
- static recalcMarginByTitle(margin, titleBlockModel) {
124
- margin.top += titleBlockModel.margin.top + titleBlockModel.size;
126
+ static recalcMarginByTitle(canvasModel, titleBlockModel) {
127
+ canvasModel.increaseMarginSide("top", titleBlockModel.margin.top + titleBlockModel.size);
125
128
  }
126
129
  }
@@ -12,18 +12,17 @@ export declare type DataOptions = {
12
12
  };
13
13
  export interface Model {
14
14
  blockCanvas: BlockCanvas;
15
- chartBlock: ChartBlock;
15
+ chartBlock: ChartBlockModel;
16
16
  options: TwoDimensionalOptionsModel | PolarOptionsModel | IntervalOptionsModel;
17
- otherComponents: OtherComponents;
17
+ otherComponents: OtherCommonComponents;
18
18
  dataSettings: DataSettings;
19
- chartSettings: ChartElementsSettings;
20
19
  transitions?: Transitions;
21
20
  }
22
21
  export interface BlockCanvas {
23
22
  size: Size;
24
23
  cssClass: string;
25
24
  }
26
- export interface ChartBlock {
25
+ export interface ChartBlockModel {
27
26
  margin: BlockMargin;
28
27
  }
29
28
  export interface BlockMargin {
@@ -46,10 +45,12 @@ export interface TwoDimensionalOptionsModel extends OptionsModel {
46
45
  charts: TwoDimensionalChartModel[];
47
46
  additionalElements: AdditionalElementsOptions;
48
47
  orient: ChartOrientation;
48
+ chartSettings: TwoDimChartElementsSettings;
49
49
  }
50
50
  export interface PolarOptionsModel extends OptionsModel {
51
51
  type: "polar";
52
52
  charts: PolarChartModel[];
53
+ chartCanvas: DonutChartSettings;
53
54
  }
54
55
  export interface IntervalOptionsModel extends OptionsModel {
55
56
  type: "interval";
@@ -58,6 +59,7 @@ export interface IntervalOptionsModel extends OptionsModel {
58
59
  charts: IntervalChartModel[];
59
60
  additionalElements: AdditionalElementsOptions;
60
61
  orient: ChartOrientation;
62
+ chartSettings: TwoDimChartElementsSettings;
61
63
  }
62
64
  export interface ILegendModel {
63
65
  position: LegendPosition;
@@ -125,6 +127,23 @@ export interface GridLineFlag {
125
127
  key: boolean;
126
128
  value: boolean;
127
129
  }
130
+ export interface TwoDimChartElementsSettings {
131
+ bar: BarChartSettings;
132
+ }
133
+ export interface BarChartSettings {
134
+ groupMaxDistance: number;
135
+ groupMinDistance: number;
136
+ barDistance: number;
137
+ maxBarWidth: number;
138
+ minBarWidth: number;
139
+ }
140
+ export interface DonutChartSettings extends Omit<DonutOptionsCanvas, "aggregatorPad"> {
141
+ aggregator: DonutChartAggreagorModel;
142
+ }
143
+ export interface DonutChartAggreagorModel {
144
+ margin: number;
145
+ text: string;
146
+ }
128
147
  interface ChartModel {
129
148
  tooltip: TooltipModel;
130
149
  cssClasses: string[];
@@ -181,20 +200,7 @@ export interface DataScope {
181
200
  export interface DataFormat {
182
201
  formatters: Formatter;
183
202
  }
184
- export interface ChartElementsSettings {
185
- bar: BarChartSettings;
186
- donut: DonutChartSettings;
187
- }
188
- export interface BarChartSettings {
189
- groupMaxDistance: number;
190
- groupMinDistance: number;
191
- barDistance: number;
192
- maxBarWidth: number;
193
- minBarWidth: number;
194
- }
195
- export interface DonutChartSettings extends DonutOptionsCanvas {
196
- }
197
- export interface OtherComponents {
203
+ export interface OtherCommonComponents {
198
204
  legendBlock: LegendBlockModel;
199
205
  titleBlock: TitleBlockModel;
200
206
  tooltipBlock: TooltipSettings;
@@ -1,10 +1,11 @@
1
1
  import { MarginModel } from './marginModel';
2
2
  import { TwoDimensionalModel } from './notations/twoDimensionalModel';
3
3
  import { PolarModel } from './notations/polarModel';
4
- import { DataManagerModel } from './dataManagerModel';
4
+ import { DataManagerModel } from './dataManagerModel/dataManagerModel';
5
5
  import { IntervalModel } from './notations/intervalModel';
6
6
  import { OtherComponentsModel } from './featuresModel/otherComponents';
7
7
  import { ConfigValidator } from './configsValidator/configValidator';
8
+ import { ModelInstance } from './modelInstance/modelInstance';
8
9
  export var AxisType;
9
10
  (function (AxisType) {
10
11
  AxisType[AxisType["Key"] = 0] = "Key";
@@ -16,27 +17,29 @@ export const CLASSES = {
16
17
  legendColor: 'legend-circle',
17
18
  legendItem: 'legend-item',
18
19
  };
19
- function getBlockCanvas(config) {
20
- const size = ConfigValidator.validateCanvasSize(config.canvas.size) ? Object.assign({}, config.canvas.size) : { width: 0, height: 0 };
20
+ function getBlockCanvas(config, modelInstance) {
21
+ const emptyBlockParams = { width: 0, height: 0 };
22
+ const size = ConfigValidator.validateCanvasSize(modelInstance.canvasModel.getBlockSize()) ? Object.assign({}, modelInstance.canvasModel.getBlockSize()) : emptyBlockParams;
21
23
  return {
22
24
  size,
23
25
  cssClass: config.canvas.class
24
26
  };
25
27
  }
26
- function getChartBlock(margin) {
28
+ function getChartBlockModel(modelInstance) {
27
29
  return {
28
- margin
30
+ margin: modelInstance.canvasModel.getMargin()
29
31
  };
30
32
  }
31
- function getOptions(config, designerConfig, margin, dataScope, data) {
33
+ function getOptions(config, designerConfig, modelInstance, dataScope, data) {
34
+ //TODO: migrate to polymorphism
32
35
  if (config.options.type === '2d') {
33
- return TwoDimensionalModel.getOptions(config, designerConfig, margin, dataScope, data);
36
+ return TwoDimensionalModel.getOptions(config.options, designerConfig, dataScope, data, modelInstance);
34
37
  }
35
38
  else if (config.options.type === 'polar') {
36
- return PolarModel.getOptions(config, data, margin, designerConfig);
39
+ return PolarModel.getOptions(config.options, data, designerConfig, modelInstance);
37
40
  }
38
41
  else if (config.options.type === 'interval') {
39
- return IntervalModel.getOptions(config, designerConfig, margin, dataScope, data);
42
+ return IntervalModel.getOptions(config, designerConfig, modelInstance.canvasModel.getMargin(), dataScope, data, modelInstance);
40
43
  }
41
44
  }
42
45
  function getDataSettings(dataScope, designerConfig) {
@@ -45,12 +48,6 @@ function getDataSettings(dataScope, designerConfig) {
45
48
  format: getDataFormat(designerConfig)
46
49
  };
47
50
  }
48
- function getChartSettings(barSettings, donutSettings) {
49
- return {
50
- bar: Object.assign({}, barSettings),
51
- donut: Object.assign({}, donutSettings)
52
- };
53
- }
54
51
  function getDataFormat(designerConfig) {
55
52
  return {
56
53
  formatters: designerConfig.dataFormat.formatters
@@ -59,45 +56,37 @@ function getDataFormat(designerConfig) {
59
56
  function getTransitions(designerConfig) {
60
57
  return designerConfig.transitions;
61
58
  }
62
- function roundMargin(margin) {
63
- margin.top = Math.ceil(margin.top);
64
- margin.bottom = Math.ceil(margin.bottom);
65
- margin.left = Math.ceil(margin.left);
66
- margin.right = Math.ceil(margin.right);
67
- }
68
59
  export function assembleModel(config, data, designerConfig) {
60
+ const modelInstance = ModelInstance.create(config);
69
61
  if (!data || Object.keys(data).length === 0)
70
62
  return {
71
- blockCanvas: getBlockCanvas(config),
63
+ blockCanvas: getBlockCanvas(config, modelInstance),
72
64
  chartBlock: null,
73
65
  otherComponents: null,
74
66
  options: null,
75
- dataSettings: null,
76
- chartSettings: null
67
+ dataSettings: null
77
68
  };
78
69
  resetFalsyValues(data, config.options.data.keyField.name);
79
- const otherComponents = OtherComponentsModel.getOtherComponentsModel(designerConfig.elementsOptions, config.options.type);
80
- const margin = MarginModel.getMargin(designerConfig, config, otherComponents, data);
81
- const dataScope = DataManagerModel.getDataScope(config, margin, data, designerConfig, otherComponents.legendBlock);
82
- const preparedData = DataManagerModel.getPreparedData(data, dataScope.allowableKeys, config);
70
+ const otherComponents = OtherComponentsModel.getOtherComponentsModel({ elementsOptions: designerConfig.elementsOptions, notation: config.options.type, title: config.options.title }, modelInstance);
71
+ MarginModel.initMargin(designerConfig, config, otherComponents, data, modelInstance);
72
+ DataManagerModel.initDataScope(config, data, designerConfig, otherComponents.legendBlock, modelInstance);
73
+ const preparedData = DataManagerModel.getPreparedData(data, modelInstance.dataModel.getAllowableKeys(), config);
83
74
  if (config.options.type === '2d' && config.options.axis.key.visibility)
84
- MarginModel.recalcMarginByVerticalAxisLabel(margin, config, designerConfig, dataScope);
85
- const blockCanvas = getBlockCanvas(config);
86
- const chartBlock = getChartBlock(margin);
87
- const options = getOptions(config, designerConfig, margin, dataScope, preparedData);
88
- const dataSettings = getDataSettings(dataScope, designerConfig);
89
- const chartSettings = getChartSettings(designerConfig.canvas.chartOptions.bar, designerConfig.canvas.chartOptions.donut);
75
+ MarginModel.recalcMarginByVerticalAxisLabel(modelInstance, config, designerConfig, modelInstance.dataModel.getScope());
76
+ const blockCanvas = getBlockCanvas(config, modelInstance);
77
+ const chartBlock = getChartBlockModel(modelInstance);
78
+ const options = getOptions(config, designerConfig, modelInstance, modelInstance.dataModel.getScope(), preparedData);
79
+ const dataSettings = getDataSettings(modelInstance.dataModel.getScope(), designerConfig);
90
80
  const transitions = getTransitions(designerConfig);
91
81
  if (options.type === 'polar')
92
- MarginModel.recalcPolarMarginWithScopedData(margin, config.canvas.size, designerConfig, config, otherComponents.legendBlock, dataScope, options);
93
- roundMargin(margin);
82
+ MarginModel.recalcPolarMarginWithScopedData(modelInstance, designerConfig, config, otherComponents.legendBlock, modelInstance.dataModel.getScope(), options);
83
+ modelInstance.canvasModel.roundMargin();
94
84
  return {
95
85
  blockCanvas,
96
86
  chartBlock,
97
87
  otherComponents,
98
88
  options,
99
89
  dataSettings,
100
- chartSettings,
101
90
  transitions
102
91
  };
103
92
  }
@@ -0,0 +1,24 @@
1
+ import { Size } from "../../../config/config";
2
+ import { BlockMargin } from "../../model";
3
+ import { LegendCanvasModelInstance } from "./legendCanvasModel";
4
+ import { TitleCanvasModel } from "./titleCanvas";
5
+ declare type MarginSide = keyof BlockMargin;
6
+ export declare class CanvasModel {
7
+ titleCanvas: TitleCanvasModel;
8
+ legendCanvas: LegendCanvasModelInstance;
9
+ private blockSize;
10
+ private margin;
11
+ constructor();
12
+ initMargin(margin: BlockMargin): void;
13
+ getMargin(): BlockMargin;
14
+ getMarginSide(side: MarginSide): number;
15
+ setMarginSide(side: MarginSide, size: number): void;
16
+ increaseMarginSide(side: MarginSide, byValue: number): void;
17
+ descreaseMarginSide(side: MarginSide, byValue: number): void;
18
+ roundMargin(): void;
19
+ initBlockSize(blockSize: Size): void;
20
+ getBlockSize(): Size;
21
+ getChartBlockWidth(): number;
22
+ getChartBlockHeight(): number;
23
+ }
24
+ export {};
@@ -0,0 +1,44 @@
1
+ import { LegendCanvasModelInstance } from "./legendCanvasModel";
2
+ import { TitleCanvasModel } from "./titleCanvas";
3
+ export class CanvasModel {
4
+ constructor() {
5
+ this.titleCanvas = new TitleCanvasModel();
6
+ this.legendCanvas = new LegendCanvasModelInstance();
7
+ }
8
+ initMargin(margin) {
9
+ this.margin = margin;
10
+ }
11
+ getMargin() {
12
+ return this.margin;
13
+ }
14
+ getMarginSide(side) {
15
+ return this.margin[side];
16
+ }
17
+ setMarginSide(side, size) {
18
+ this.margin[side] = size;
19
+ }
20
+ increaseMarginSide(side, byValue) {
21
+ this.margin[side] += byValue;
22
+ }
23
+ descreaseMarginSide(side, byValue) {
24
+ this.margin[side] -= byValue;
25
+ }
26
+ roundMargin() {
27
+ this.margin.top = Math.ceil(this.margin.top);
28
+ this.margin.bottom = Math.ceil(this.margin.bottom);
29
+ this.margin.left = Math.ceil(this.margin.left);
30
+ this.margin.right = Math.ceil(this.margin.right);
31
+ }
32
+ initBlockSize(blockSize) {
33
+ this.blockSize = blockSize;
34
+ }
35
+ getBlockSize() {
36
+ return this.blockSize;
37
+ }
38
+ getChartBlockWidth() {
39
+ return this.blockSize.width - this.margin.left - this.margin.right;
40
+ }
41
+ getChartBlockHeight() {
42
+ return this.blockSize.height - this.margin.top - this.margin.bottom;
43
+ }
44
+ }