mdt-charts 1.10.3 → 1.11.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 (51) hide show
  1. package/lib/config/config.d.ts +9 -2
  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/title/title.js +2 -0
  6. package/lib/engine/features/tolltip/tooltip.js +1 -1
  7. package/lib/engine/filterManager/filterEventManager.d.ts +3 -3
  8. package/lib/engine/filterManager/filterEventManager.js +4 -4
  9. package/lib/engine/intervalNotation/intervalManager.js +2 -2
  10. package/lib/engine/polarNotation/donut/DonutHelper.d.ts +2 -0
  11. package/lib/engine/polarNotation/donut/DonutHelper.js +20 -3
  12. package/lib/engine/polarNotation/donut/donut.js +1 -1
  13. package/lib/engine/polarNotation/polarManager.js +6 -7
  14. package/lib/engine/twoDimensionalNotation/twoDimensionalManager.js +4 -4
  15. package/lib/model/chartStyleModel/TwoDimensionalChartStyleModel.d.ts +19 -0
  16. package/lib/model/chartStyleModel/TwoDimensionalChartStyleModel.js +61 -0
  17. package/lib/model/chartStyleModel/chartStyleModel.d.ts +9 -0
  18. package/lib/model/chartStyleModel/chartStyleModel.js +27 -0
  19. package/lib/model/dataManagerModel.d.ts +3 -2
  20. package/lib/model/dataManagerModel.js +12 -10
  21. package/lib/model/featuresModel/axisModel.d.ts +9 -8
  22. package/lib/model/featuresModel/axisModel.js +20 -20
  23. package/lib/model/featuresModel/legendModel/legendModel.d.ts +4 -3
  24. package/lib/model/featuresModel/legendModel/legendModel.js +5 -7
  25. package/lib/model/featuresModel/otherComponents.d.ts +9 -2
  26. package/lib/model/featuresModel/otherComponents.js +6 -4
  27. package/lib/model/featuresModel/scaleModel.d.ts +6 -5
  28. package/lib/model/featuresModel/scaleModel.js +9 -9
  29. package/lib/model/featuresModel/titleModel.d.ts +1 -1
  30. package/lib/model/featuresModel/titleModel.js +7 -5
  31. package/lib/model/marginModel.d.ts +5 -5
  32. package/lib/model/marginModel.js +37 -35
  33. package/lib/model/model.d.ts +24 -18
  34. package/lib/model/modelBuilder.js +23 -34
  35. package/lib/model/modelInstance/canvasModel/canvasModel.d.ts +22 -0
  36. package/lib/model/modelInstance/canvasModel/canvasModel.js +42 -0
  37. package/lib/model/modelInstance/canvasModel/titleCanvas.d.ts +9 -0
  38. package/lib/model/modelInstance/canvasModel/titleCanvas.js +11 -0
  39. package/lib/model/modelInstance/modelInstance.d.ts +7 -0
  40. package/lib/model/modelInstance/modelInstance.js +11 -0
  41. package/lib/model/notations/intervalModel.d.ts +2 -1
  42. package/lib/model/notations/intervalModel.js +16 -13
  43. package/lib/model/notations/polarModel.d.ts +5 -3
  44. package/lib/model/notations/polarModel.js +17 -7
  45. package/lib/model/notations/twoDimensionalModel.d.ts +7 -5
  46. package/lib/model/notations/twoDimensionalModel.js +19 -11
  47. package/lib/style/charts-main.css +1 -0
  48. package/lib/style/charts-main.less +1 -0
  49. package/package.json +3 -2
  50. package/lib/model/chartStyleModel.d.ts +0 -16
  51. package/lib/model/chartStyleModel.js +0 -67
@@ -5,6 +5,7 @@ import { DataManagerModel } from './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);
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
+ const dataScope = DataManagerModel.getDataScope(config, data, designerConfig, otherComponents.legendBlock, modelInstance);
82
73
  const preparedData = DataManagerModel.getPreparedData(data, dataScope.allowableKeys, 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);
75
+ MarginModel.recalcMarginByVerticalAxisLabel(modelInstance, config, designerConfig, dataScope);
76
+ const blockCanvas = getBlockCanvas(config, modelInstance);
77
+ const chartBlock = getChartBlockModel(modelInstance);
78
+ const options = getOptions(config, designerConfig, modelInstance, dataScope, preparedData);
88
79
  const dataSettings = getDataSettings(dataScope, designerConfig);
89
- const chartSettings = getChartSettings(designerConfig.canvas.chartOptions.bar, designerConfig.canvas.chartOptions.donut);
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, dataScope, 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,22 @@
1
+ import { Size } from "../../../config/config";
2
+ import { BlockMargin } from "../../model";
3
+ import { TitleCanvasModel } from "./titleCanvas";
4
+ declare type MarginSide = keyof BlockMargin;
5
+ export declare class CanvasModel {
6
+ titleCanvas: TitleCanvasModel;
7
+ private blockSize;
8
+ private margin;
9
+ constructor();
10
+ initMargin(margin: BlockMargin): void;
11
+ getMargin(): BlockMargin;
12
+ getMarginSide(side: MarginSide): number;
13
+ setMarginSide(side: MarginSide, size: number): void;
14
+ increaseMarginSide(side: MarginSide, byValue: number): void;
15
+ descreaseMarginSide(side: MarginSide, byValue: number): void;
16
+ roundMargin(): void;
17
+ initBlockSize(blockSize: Size): void;
18
+ getBlockSize(): Size;
19
+ getChartBlockWidth(): number;
20
+ getChartBlockHeight(): number;
21
+ }
22
+ export {};
@@ -0,0 +1,42 @@
1
+ import { TitleCanvasModel } from "./titleCanvas";
2
+ export class CanvasModel {
3
+ constructor() {
4
+ this.titleCanvas = new TitleCanvasModel();
5
+ }
6
+ initMargin(margin) {
7
+ this.margin = margin;
8
+ }
9
+ getMargin() {
10
+ return this.margin;
11
+ }
12
+ getMarginSide(side) {
13
+ return this.margin[side];
14
+ }
15
+ setMarginSide(side, size) {
16
+ this.margin[side] = size;
17
+ }
18
+ increaseMarginSide(side, byValue) {
19
+ this.margin[side] += byValue;
20
+ }
21
+ descreaseMarginSide(side, byValue) {
22
+ this.margin[side] -= byValue;
23
+ }
24
+ roundMargin() {
25
+ this.margin.top = Math.ceil(this.margin.top);
26
+ this.margin.bottom = Math.ceil(this.margin.bottom);
27
+ this.margin.left = Math.ceil(this.margin.left);
28
+ this.margin.right = Math.ceil(this.margin.right);
29
+ }
30
+ initBlockSize(blockSize) {
31
+ this.blockSize = blockSize;
32
+ }
33
+ getBlockSize() {
34
+ return this.blockSize;
35
+ }
36
+ getChartBlockWidth() {
37
+ return this.blockSize.width - this.margin.left - this.margin.right;
38
+ }
39
+ getChartBlockHeight() {
40
+ return this.blockSize.height - this.margin.top - this.margin.bottom;
41
+ }
42
+ }
@@ -0,0 +1,9 @@
1
+ import { TitleBlockModel } from "../../model";
2
+ declare type TitleBlockCanvas = TitleBlockModel;
3
+ export declare class TitleCanvasModel {
4
+ private model;
5
+ init(model: TitleBlockCanvas): void;
6
+ getModel(): TitleBlockModel;
7
+ getAllNeededSpace(): number;
8
+ }
9
+ export {};
@@ -0,0 +1,11 @@
1
+ export class TitleCanvasModel {
2
+ init(model) {
3
+ this.model = model;
4
+ }
5
+ getModel() {
6
+ return this.model;
7
+ }
8
+ getAllNeededSpace() {
9
+ return this.model.pad + this.model.size + this.model.margin.top;
10
+ }
11
+ }
@@ -0,0 +1,7 @@
1
+ import { MdtChartsConfig } from "../../main";
2
+ import { CanvasModel } from "./canvasModel/canvasModel";
3
+ export declare class ModelInstance {
4
+ static create(config: MdtChartsConfig): ModelInstance;
5
+ canvasModel: CanvasModel;
6
+ constructor();
7
+ }
@@ -0,0 +1,11 @@
1
+ import { CanvasModel } from "./canvasModel/canvasModel";
2
+ export class ModelInstance {
3
+ constructor() {
4
+ this.canvasModel = new CanvasModel();
5
+ }
6
+ static create(config) {
7
+ const modelInstance = new ModelInstance();
8
+ modelInstance.canvasModel.initBlockSize(config.canvas.size);
9
+ return modelInstance;
10
+ }
11
+ }
@@ -1,8 +1,9 @@
1
1
  import { MdtChartsConfig, MdtChartsDataSource, IntervalOptions } from "../../config/config";
2
2
  import { DesignerConfig } from "../../designer/designerConfig";
3
3
  import { AdditionalElementsOptions, BlockMargin, DataScope, IntervalOptionsModel } from "../model";
4
+ import { ModelInstance } from "../modelInstance/modelInstance";
4
5
  export declare class IntervalModel {
5
- static getOptions(config: MdtChartsConfig, designerConfig: DesignerConfig, margin: BlockMargin, dataScope: DataScope, data: MdtChartsDataSource): IntervalOptionsModel;
6
+ static getOptions(config: MdtChartsConfig, designerConfig: DesignerConfig, margin: BlockMargin, dataScope: DataScope, data: MdtChartsDataSource, modelInstance: ModelInstance): IntervalOptionsModel;
6
7
  static getAdditionalElements(options: IntervalOptions): AdditionalElementsOptions;
7
8
  private static getChartsModel;
8
9
  }
@@ -1,14 +1,16 @@
1
1
  import { AxisModel } from "../featuresModel/axisModel";
2
- import { ChartStyleModel } from "../chartStyleModel";
2
+ import { ChartStyleModelService } from "../chartStyleModel/chartStyleModel";
3
3
  import { DataManagerModel } from "../dataManagerModel";
4
4
  import { LegendModel } from "../featuresModel/legendModel/legendModel";
5
5
  import { AxisType } from "../modelBuilder";
6
6
  import { ScaleModel, ScaleType } from "../featuresModel/scaleModel";
7
+ import { TwoDimensionalModel } from "./twoDimensionalModel";
7
8
  export class IntervalModel {
8
- static getOptions(config, designerConfig, margin, dataScope, data) {
9
+ static getOptions(config, designerConfig, margin, dataScope, data, modelInstance) {
9
10
  const options = config.options;
11
+ const canvasModel = modelInstance.canvasModel;
10
12
  return {
11
- legend: LegendModel.getLegendModel(config.options.type, config.options.legend.show, config.canvas.size, margin),
13
+ legend: LegendModel.getLegendModel(config.options.type, config.options.legend.show, canvasModel),
12
14
  title: options.title,
13
15
  selectable: !!options.selectable,
14
16
  orient: options.orientation,
@@ -17,7 +19,7 @@ export class IntervalModel {
17
19
  domain: dataScope.allowableKeys,
18
20
  range: {
19
21
  start: 0,
20
- end: ScaleModel.getRangePeek(ScaleType.Key, options.orientation, margin, config.canvas.size)
22
+ end: ScaleModel.getRangePeek(ScaleType.Key, options.orientation, canvasModel)
21
23
  },
22
24
  type: 'band',
23
25
  elementsAmount: 1
@@ -26,7 +28,7 @@ export class IntervalModel {
26
28
  domain: ScaleModel.getDateValueDomain(data, options.chart, options.axis.key.position, options.data.dataSource),
27
29
  range: {
28
30
  start: 0,
29
- end: ScaleModel.getRangePeek(ScaleType.Value, options.orientation, margin, config.canvas.size)
31
+ end: ScaleModel.getRangePeek(ScaleType.Value, options.orientation, canvasModel)
30
32
  },
31
33
  type: 'datetime'
32
34
  }
@@ -36,14 +38,14 @@ export class IntervalModel {
36
38
  type: 'key',
37
39
  orient: AxisModel.getAxisOrient(AxisType.Key, options.orientation, options.axis.key.position),
38
40
  translate: {
39
- translateX: AxisModel.getAxisTranslateX(AxisType.Key, options.orientation, options.axis.key.position, margin, config.canvas.size.width),
40
- translateY: AxisModel.getAxisTranslateY(AxisType.Key, options.orientation, options.axis.key.position, margin, config.canvas.size.height)
41
+ translateX: AxisModel.getAxisTranslateX(AxisType.Key, options.orientation, options.axis.key.position, canvasModel),
42
+ translateY: AxisModel.getAxisTranslateY(AxisType.Key, options.orientation, options.axis.key.position, canvasModel)
41
43
  },
42
44
  cssClass: 'key-axis',
43
45
  ticks: options.axis.key.ticks,
44
46
  labels: {
45
47
  maxSize: AxisModel.getLabelSize(designerConfig.canvas.axisLabel.maxSize.main, data[options.data.dataSource].map(d => d[options.data.keyField.name])).width,
46
- position: AxisModel.getKeyAxisLabelPosition(margin, config.canvas.size, DataManagerModel.getDataValuesByKeyField(data, options.data.dataSource, options.data.keyField.name).length),
48
+ position: AxisModel.getKeyAxisLabelPosition(canvasModel, DataManagerModel.getDataValuesByKeyField(data, options.data.dataSource, options.data.keyField.name).length),
47
49
  visible: true,
48
50
  defaultTooltip: designerConfig.elementsOptions.tooltip.position === 'fixed'
49
51
  },
@@ -53,8 +55,8 @@ export class IntervalModel {
53
55
  type: 'value',
54
56
  orient: AxisModel.getAxisOrient(AxisType.Value, options.orientation, options.axis.value.position),
55
57
  translate: {
56
- translateX: AxisModel.getAxisTranslateX(AxisType.Value, options.orientation, options.axis.value.position, margin, config.canvas.size.width),
57
- translateY: AxisModel.getAxisTranslateY(AxisType.Value, options.orientation, options.axis.value.position, margin, config.canvas.size.height)
58
+ translateX: AxisModel.getAxisTranslateX(AxisType.Value, options.orientation, options.axis.value.position, canvasModel),
59
+ translateY: AxisModel.getAxisTranslateY(AxisType.Value, options.orientation, options.axis.value.position, canvasModel)
58
60
  },
59
61
  cssClass: 'value-axis',
60
62
  ticks: options.axis.value.ticks,
@@ -71,7 +73,8 @@ export class IntervalModel {
71
73
  type: options.type,
72
74
  charts: this.getChartsModel(options.chart, designerConfig.chartStyle),
73
75
  additionalElements: this.getAdditionalElements(options),
74
- tooltip: options.tooltip
76
+ tooltip: options.tooltip,
77
+ chartSettings: TwoDimensionalModel.getChartsSettings(designerConfig.canvas.chartOptions.bar)
75
78
  };
76
79
  }
77
80
  static getAdditionalElements(options) {
@@ -85,8 +88,8 @@ export class IntervalModel {
85
88
  type: chart.type,
86
89
  data: Object.assign({}, chart.data),
87
90
  tooltip: chart.tooltip,
88
- cssClasses: ChartStyleModel.getCssClasses(0),
89
- style: ChartStyleModel.getChartStyle(1, chartStyleConfig)
91
+ cssClasses: ChartStyleModelService.getCssClasses(0),
92
+ style: ChartStyleModelService.getChartStyle(1, chartStyleConfig)
90
93
  });
91
94
  return chartsModel;
92
95
  }
@@ -1,7 +1,9 @@
1
- import { MdtChartsConfig, MdtChartsDataSource } from "../../config/config";
1
+ import { MdtChartsDataSource, PolarOptions } from "../../config/config";
2
2
  import { DesignerConfig } from "../../designer/designerConfig";
3
- import { BlockMargin, PolarOptionsModel } from "../model";
3
+ import { PolarOptionsModel } from "../model";
4
+ import { ModelInstance } from "../modelInstance/modelInstance";
4
5
  export declare class PolarModel {
5
- static getOptions(config: MdtChartsConfig, data: MdtChartsDataSource, margin: BlockMargin, designerConfig: DesignerConfig): PolarOptionsModel;
6
+ static getOptions(options: PolarOptions, data: MdtChartsDataSource, designerConfig: DesignerConfig, modelInstance: ModelInstance): PolarOptionsModel;
7
+ private static getDonutSettings;
6
8
  private static getChartsModel;
7
9
  }
@@ -1,16 +1,26 @@
1
- import { ChartStyleModel } from "../chartStyleModel";
1
+ import { ChartStyleModelService } from "../chartStyleModel/chartStyleModel";
2
2
  import { LegendModel } from "../featuresModel/legendModel/legendModel";
3
3
  export class PolarModel {
4
- static getOptions(config, data, margin, designerConfig) {
5
- const options = config.options;
4
+ static getOptions(options, data, designerConfig, modelInstance) {
6
5
  return {
7
6
  type: options.type,
8
7
  selectable: !!options.selectable,
9
8
  title: options.title,
10
9
  data: Object.assign({}, options.data),
11
10
  charts: this.getChartsModel(options.chart, data[options.data.dataSource].length, designerConfig.chartStyle),
12
- legend: LegendModel.getLegendModel(config.options.type, config.options.legend.show, config.canvas.size, margin),
13
- tooltip: options.tooltip
11
+ legend: LegendModel.getLegendModel(options.type, options.legend.show, modelInstance.canvasModel),
12
+ tooltip: options.tooltip,
13
+ chartCanvas: this.getDonutSettings(designerConfig.canvas.chartOptions.donut, options.chart)
14
+ };
15
+ }
16
+ static getDonutSettings(settings, chartOptions) {
17
+ return {
18
+ padAngle: settings.padAngle,
19
+ thickness: Object.assign({}, settings.thickness),
20
+ aggregator: {
21
+ margin: settings.aggregatorPad,
22
+ text: chartOptions.aggregator.text
23
+ }
14
24
  };
15
25
  }
16
26
  static getChartsModel(chart, dataLength, chartStyleConfig) {
@@ -19,8 +29,8 @@ export class PolarModel {
19
29
  type: chart.type,
20
30
  data: Object.assign({}, chart.data),
21
31
  tooltip: chart.tooltip,
22
- cssClasses: ChartStyleModel.getCssClasses(0),
23
- style: ChartStyleModel.getChartStyle(dataLength, chartStyleConfig)
32
+ cssClasses: ChartStyleModelService.getCssClasses(0),
33
+ style: ChartStyleModelService.getChartStyle(dataLength, chartStyleConfig)
24
34
  });
25
35
  return chartsModel;
26
36
  }
@@ -1,8 +1,9 @@
1
- import { ChartOrientation, MdtChartsConfig, MdtChartsDataSource, TwoDimensionalChart } from "../../config/config";
2
- import { DesignerConfig } from "../../designer/designerConfig";
3
- import { BlockMargin, DataScope, TwoDimensionalOptionsModel } from "../model";
1
+ import { ChartOrientation, MdtChartsDataSource, TwoDimensionalChart, TwoDimensionalOptions } from "../../config/config";
2
+ import { BarOptionsCanvas, DesignerConfig } from "../../designer/designerConfig";
3
+ import { DataScope, TwoDimensionalOptionsModel, TwoDimChartElementsSettings } from "../model";
4
+ import { ModelInstance } from "../modelInstance/modelInstance";
4
5
  export declare class TwoDimensionalModel {
5
- static getOptions(config: MdtChartsConfig, designerConfig: DesignerConfig, margin: BlockMargin, dataScope: DataScope, data: MdtChartsDataSource): TwoDimensionalOptionsModel;
6
+ static getOptions(options: TwoDimensionalOptions, designerConfig: DesignerConfig, dataScope: DataScope, data: MdtChartsDataSource, modelInstance: ModelInstance): TwoDimensionalOptionsModel;
6
7
  static getChartsEmbeddedLabelsFlag(charts: TwoDimensionalChart[], chartOrientation: ChartOrientation): boolean;
7
8
  /**
8
9
  * Сортирует список чартов в порядке: area - bar - line.
@@ -10,10 +11,11 @@ export declare class TwoDimensionalModel {
10
11
  * @param charts Чарты из конфига
11
12
  */
12
13
  static sortCharts(charts: TwoDimensionalChart[]): void;
14
+ static getChartsSettings(barSettings: BarOptionsCanvas): TwoDimChartElementsSettings;
13
15
  private static getChartsModel;
14
16
  private static findChartsWithEmbeddedKeyLabels;
15
17
  private static getEmbeddedLabelType;
16
18
  private static getAdditionalElements;
17
19
  private static getChartsByType;
18
- private static getChartsValueFieldsAmount;
20
+ static getChartsValueFieldsAmount(charts: TwoDimensionalChart[]): number[];
19
21
  }
@@ -1,28 +1,30 @@
1
- import { ChartStyleModel } from "../chartStyleModel";
1
+ import { ChartStyleModelService } from "../chartStyleModel/chartStyleModel";
2
+ import { TwoDimensionalChartStyleModel } from "../chartStyleModel/TwoDimensionalChartStyleModel";
2
3
  import { AxisModel } from "../featuresModel/axisModel";
3
4
  import { LegendModel } from "../featuresModel/legendModel/legendModel";
4
5
  import { ScaleModel } from "../featuresModel/scaleModel";
5
6
  export class TwoDimensionalModel {
6
- static getOptions(config, designerConfig, margin, dataScope, data) {
7
- const options = config.options;
7
+ static getOptions(options, designerConfig, dataScope, data, modelInstance) {
8
+ const canvasModel = modelInstance.canvasModel;
8
9
  return {
9
- legend: LegendModel.getLegendModel(config.options.type, config.options.legend.show, config.canvas.size, margin),
10
+ legend: LegendModel.getLegendModel(options.type, options.legend.show, canvasModel),
10
11
  title: options.title,
11
12
  selectable: !!options.selectable,
12
13
  orient: options.orientation,
13
14
  scale: {
14
- key: ScaleModel.getScaleKey(dataScope.allowableKeys, options.orientation, margin, config.canvas.size, options.charts, this.getChartsByType(options.charts, 'bar')),
15
- value: ScaleModel.getScaleLinear(options, data, margin, config.canvas.size)
15
+ key: ScaleModel.getScaleKey(dataScope.allowableKeys, options.orientation, canvasModel, options.charts, this.getChartsByType(options.charts, 'bar')),
16
+ value: ScaleModel.getScaleLinear(options, data, canvasModel)
16
17
  },
17
18
  axis: {
18
- key: AxisModel.getKeyAxis(options.charts, data, options.data, options.orientation, options.axis.key, designerConfig.canvas.axisLabel, margin, config.canvas.size, designerConfig.elementsOptions.tooltip),
19
- value: AxisModel.getValueAxis(options.orientation, options.axis.value, designerConfig.canvas.axisLabel, margin, config.canvas.size)
19
+ key: AxisModel.getKeyAxis(options.charts, data, options.data, options.orientation, options.axis.key, designerConfig.canvas.axisLabel, canvasModel, designerConfig.elementsOptions.tooltip),
20
+ value: AxisModel.getValueAxis(options.orientation, options.axis.value, designerConfig.canvas.axisLabel, canvasModel)
20
21
  },
21
22
  type: options.type,
22
23
  data: Object.assign({}, options.data),
23
24
  charts: this.getChartsModel(options.charts, options.orientation, designerConfig.chartStyle),
24
25
  additionalElements: this.getAdditionalElements(options),
25
- tooltip: options.tooltip
26
+ tooltip: options.tooltip,
27
+ chartSettings: this.getChartsSettings(designerConfig.canvas.chartOptions.bar)
26
28
  };
27
29
  }
28
30
  static getChartsEmbeddedLabelsFlag(charts, chartOrientation) {
@@ -40,7 +42,13 @@ export class TwoDimensionalModel {
40
42
  const chartOrder = ['area', 'bar', 'line'];
41
43
  charts.sort((chart1, chart2) => chartOrder.indexOf(chart1.type) - chartOrder.indexOf(chart2.type));
42
44
  }
45
+ static getChartsSettings(barSettings) {
46
+ return {
47
+ bar: Object.assign({}, barSettings)
48
+ };
49
+ }
43
50
  static getChartsModel(charts, chartOrientation, chartStyleConfig) {
51
+ const styleModel = new TwoDimensionalChartStyleModel(charts, chartStyleConfig);
44
52
  this.sortCharts(charts);
45
53
  const chartsModel = [];
46
54
  charts.forEach((chart, index) => {
@@ -49,8 +57,8 @@ export class TwoDimensionalModel {
49
57
  isSegmented: chart.isSegmented,
50
58
  data: Object.assign({}, chart.data),
51
59
  tooltip: chart.tooltip,
52
- cssClasses: ChartStyleModel.getCssClasses(index),
53
- style: ChartStyleModel.get2DChartStyle(charts.length, chart.type, this.getChartsValueFieldsAmount(charts), index, chart.isSegmented, chartStyleConfig),
60
+ cssClasses: ChartStyleModelService.getCssClasses(index),
61
+ style: styleModel.getChartStyle(chart, index),
54
62
  embeddedLabels: this.getEmbeddedLabelType(chart, chartOrientation),
55
63
  markersOptions: chart.markers,
56
64
  index
@@ -188,6 +188,7 @@
188
188
  }
189
189
  .aggregator-name {
190
190
  margin-top: 10px;
191
+ pointer-events: auto;
191
192
  }
192
193
 
193
194
  /* Grid */
@@ -188,6 +188,7 @@
188
188
  }
189
189
  .aggregator-name {
190
190
  margin-top: 10px;
191
+ pointer-events: auto;
191
192
  }
192
193
 
193
194
  /* Grid */
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "mdt-charts",
3
- "version": "1.10.3",
3
+ "version": "1.11.0",
4
4
  "description": "",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {
7
7
  "dev": "npx webpack --mode development",
8
8
  "build": "npx webpack --mode production",
9
9
  "watch": "npx webpack --mode development --watch",
10
- "test": "jest"
10
+ "test": "jest",
11
+ "build-lib": "npx tsc -p ."
11
12
  },
12
13
  "homepage": "https://github.com/VishulaKnow/charts",
13
14
  "author": "",
@@ -1,16 +0,0 @@
1
- import { TwoDimensionalChartType } from "../config/config";
2
- import { ChartStyleConfig } from "../designer/designerConfig";
3
- import { ChartStyle } from "./model";
4
- export declare class ChartStyleModel {
5
- private static safeColorsAmount;
6
- private static standartColors;
7
- static getCssClasses(chartIndex: number): string[];
8
- static get2DChartStyle(chartsAmount: number, chartType: TwoDimensionalChartType, chartsFieldsAmounts: number[], chartIndex: number, isSegmented: boolean, styleConfig: ChartStyleConfig): ChartStyle;
9
- static getChartStyle(elementsAmount: number, styleConfig: ChartStyleConfig): ChartStyle;
10
- private static getChartColors;
11
- private static getChartOpacity;
12
- private static getColorSet;
13
- private static checkAndGet;
14
- private static getStartIndex;
15
- private static resetColor;
16
- }
@@ -1,67 +0,0 @@
1
- import * as chroma from "chroma-js";
2
- import { ModelHelper } from "./modelHelper";
3
- export class ChartStyleModel {
4
- static getCssClasses(chartIndex) {
5
- const cssClasses = [`chart-${chartIndex}`];
6
- return cssClasses;
7
- }
8
- static get2DChartStyle(chartsAmount, chartType, chartsFieldsAmounts, chartIndex, isSegmented, styleConfig) {
9
- const startIndex = this.getStartIndex(chartIndex, chartsFieldsAmounts);
10
- const baseColors = this.checkAndGet(styleConfig.baseColors);
11
- const palette = this.getColorSet(baseColors, ModelHelper.getSum(chartsFieldsAmounts));
12
- return {
13
- elementColors: this.getChartColors(palette, chartsFieldsAmounts[chartIndex], startIndex, chartType),
14
- opacity: this.getChartOpacity(chartsAmount, chartType, chartsFieldsAmounts[chartIndex], isSegmented)
15
- };
16
- }
17
- static getChartStyle(elementsAmount, styleConfig) {
18
- const baseColors = this.checkAndGet(styleConfig.baseColors);
19
- return {
20
- elementColors: this.getColorSet(baseColors, elementsAmount),
21
- opacity: 1
22
- };
23
- }
24
- static getChartColors(palette, elementsAmount, startIndex, chartType) {
25
- const selectedColors = palette.slice(startIndex, startIndex + elementsAmount);
26
- if (chartType !== 'line')
27
- return selectedColors;
28
- for (let i = 0; i < selectedColors.length; i++) {
29
- selectedColors[i] = chroma.mix(selectedColors[i], 'white', 0.2).saturate(3).hex();
30
- }
31
- return selectedColors;
32
- }
33
- static getChartOpacity(chartsLength, chartType, chartsValueFieldAmount, isSegmented) {
34
- if (chartType === 'area' && (chartsLength > 1 || chartsValueFieldAmount > 1) && !isSegmented)
35
- return 0.5; // combined area with other charts has 0.5 opacity
36
- return 1;
37
- }
38
- static getColorSet(baseColors, elementsAmount) {
39
- return chroma.scale(baseColors)
40
- .mode('rgb')
41
- .domain([0, 0.55, 0.75, 1])
42
- .colors(elementsAmount <= 1 ? 2 : elementsAmount);
43
- }
44
- static checkAndGet(baseColors) {
45
- if (baseColors.length === 0 || baseColors.filter(color => color === 'rgba(0, 0, 0, 0)' || !color).length > 0) {
46
- return this.standartColors;
47
- }
48
- return baseColors;
49
- }
50
- static getStartIndex(chartIndex, chartsFieldsAmounts) {
51
- let startIndex = 0;
52
- for (let i = 0; i < chartIndex; i++) {
53
- startIndex += chartsFieldsAmounts[i];
54
- }
55
- return startIndex;
56
- }
57
- static resetColor(index, baseColor) {
58
- let color = chroma(baseColor)
59
- .luminance(0.5)
60
- .saturate(1.5 + Math.floor(index / this.safeColorsAmount) * 0.5);
61
- color = chroma(color)
62
- .set('hsv.h', chroma(color).get('hsv.h') + Math.floor(index / this.safeColorsAmount) * 4);
63
- return color.hex();
64
- }
65
- }
66
- ChartStyleModel.safeColorsAmount = 8;
67
- ChartStyleModel.standartColors = ["#209DE3", "#FF3131", "#FFBA00", "#20B078"];