mdt-charts 1.12.0 → 1.12.4

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 (60) hide show
  1. package/lib/config/config.d.ts +24 -12
  2. package/lib/designer/designerConfig.d.ts +3 -5
  3. package/lib/engine/features/aggregator/aggregator.d.ts +9 -7
  4. package/lib/engine/features/aggregator/aggregator.js +51 -37
  5. package/lib/engine/features/legend/legend.d.ts +10 -1
  6. package/lib/engine/features/legend/legend.js +10 -22
  7. package/lib/engine/features/legend/legendHelper.d.ts +4 -5
  8. package/lib/engine/features/legend/legendHelper.js +19 -23
  9. package/lib/engine/features/legend/legendHelperService.d.ts +12 -0
  10. package/lib/engine/features/legend/legendHelperService.js +30 -0
  11. package/lib/engine/polarNotation/donut/donut.js +1 -1
  12. package/lib/engine/polarNotation/extenders/polarRecordOverflowAlert.d.ts +0 -1
  13. package/lib/engine/polarNotation/extenders/polarRecordOverflowAlert.js +9 -17
  14. package/lib/engine/polarNotation/polarManager.js +1 -1
  15. package/lib/model/chartStyleModel/TwoDimensionalChartStyleModel.d.ts +4 -4
  16. package/lib/model/dataManagerModel/dataManagerModel.d.ts +8 -0
  17. package/lib/model/dataManagerModel/dataManagerModel.js +26 -13
  18. package/lib/model/featuresModel/axisModel.d.ts +5 -4
  19. package/lib/model/featuresModel/axisModel.js +13 -11
  20. package/lib/model/featuresModel/axisModelService.d.ts +4 -0
  21. package/lib/model/featuresModel/axisModelService.js +11 -0
  22. package/lib/model/featuresModel/legendModel/legendCanvasModel.d.ts +4 -2
  23. package/lib/model/featuresModel/legendModel/legendCanvasModel.js +42 -29
  24. package/lib/model/featuresModel/legendModel/legendModel.d.ts +1 -2
  25. package/lib/model/featuresModel/legendModel/legendModel.js +15 -15
  26. package/lib/model/featuresModel/legendModel/polarMarginCalculator.d.ts +11 -0
  27. package/lib/model/featuresModel/legendModel/polarMarginCalculator.js +42 -0
  28. package/lib/model/featuresModel/scaleModel.d.ts +6 -6
  29. package/lib/model/featuresModel/titleModel.js +4 -4
  30. package/lib/model/marginModel.d.ts +3 -2
  31. package/lib/model/marginModel.js +6 -3
  32. package/lib/model/model.d.ts +19 -8
  33. package/lib/model/modelBuilder.js +8 -9
  34. package/lib/model/modelInstance/dataModel/dataModel.d.ts +14 -0
  35. package/lib/model/modelInstance/dataModel/dataModel.js +26 -0
  36. package/lib/model/modelInstance/dataModel/dataRepository.d.ts +12 -0
  37. package/lib/model/modelInstance/dataModel/dataRepository.js +20 -0
  38. package/lib/model/modelInstance/modelInstance.d.ts +3 -3
  39. package/lib/model/modelInstance/modelInstance.js +6 -4
  40. package/lib/model/notations/intervalModel.d.ts +2 -2
  41. package/lib/model/notations/polar/donut/donutAggregatorService.d.ts +12 -0
  42. package/lib/model/notations/polar/donut/donutAggregatorService.js +25 -0
  43. package/lib/model/notations/polar/donut/donutModel.d.ts +10 -0
  44. package/lib/model/notations/polar/donut/donutModel.js +32 -0
  45. package/lib/model/notations/polar/donut/donutThicknessService.d.ts +9 -0
  46. package/lib/model/notations/polar/donut/donutThicknessService.js +30 -0
  47. package/lib/model/notations/polar/polarModel.d.ts +15 -0
  48. package/lib/model/notations/polar/polarModel.js +53 -0
  49. package/lib/model/notations/polarModel.d.ts +3 -1
  50. package/lib/model/notations/polarModel.js +12 -1
  51. package/lib/model/notations/twoDimensionalModel.d.ts +6 -6
  52. package/lib/model/notations/twoDimensionalModel.js +3 -3
  53. package/lib/style/charts-main.css +29 -9
  54. package/lib/style/charts-main.less +29 -9
  55. package/package.json +2 -2
  56. package/tsconfig.production.json +23 -0
  57. package/lib/engine/features/recordOverflowAlert/recordOverflowAlert.d.ts +0 -14
  58. package/lib/engine/features/recordOverflowAlert/recordOverflowAlert.js +0 -97
  59. package/lib/model/dataManagerModel.d.ts +0 -23
  60. package/lib/model/dataManagerModel.js +0 -139
@@ -1,6 +1,6 @@
1
1
  import { MarginModel } from './marginModel';
2
2
  import { TwoDimensionalModel } from './notations/twoDimensionalModel';
3
- import { PolarModel } from './notations/polarModel';
3
+ import { PolarModel } from './notations/polar/polarModel';
4
4
  import { DataManagerModel } from './dataManagerModel/dataManagerModel';
5
5
  import { IntervalModel } from './notations/intervalModel';
6
6
  import { OtherComponentsModel } from './featuresModel/otherComponents';
@@ -30,16 +30,16 @@ function getChartBlockModel(modelInstance) {
30
30
  margin: modelInstance.canvasModel.getMargin()
31
31
  };
32
32
  }
33
- function getOptions(config, designerConfig, modelInstance, dataScope, data) {
33
+ function getOptions(config, designerConfig, modelInstance, data) {
34
34
  //TODO: migrate to polymorphism
35
35
  if (config.options.type === '2d') {
36
- return TwoDimensionalModel.getOptions(config.options, designerConfig, dataScope, data, modelInstance);
36
+ return TwoDimensionalModel.getOptions(config.options, designerConfig, data, modelInstance);
37
37
  }
38
38
  else if (config.options.type === 'polar') {
39
- return PolarModel.getOptions(config.options, data, designerConfig, modelInstance);
39
+ return PolarModel.getOptions(config.options, designerConfig, modelInstance);
40
40
  }
41
41
  else if (config.options.type === 'interval') {
42
- return IntervalModel.getOptions(config, designerConfig, modelInstance.canvasModel.getMargin(), dataScope, data, modelInstance);
42
+ return IntervalModel.getOptions(config, designerConfig, modelInstance.canvasModel.getMargin(), modelInstance.dataModel.getScope(), data, modelInstance);
43
43
  }
44
44
  }
45
45
  function getDataSettings(dataScope, designerConfig) {
@@ -57,7 +57,7 @@ function getTransitions(designerConfig) {
57
57
  return designerConfig.transitions;
58
58
  }
59
59
  export function assembleModel(config, data, designerConfig) {
60
- const modelInstance = ModelInstance.create(config);
60
+ const modelInstance = ModelInstance.create(config, data);
61
61
  if (!data || Object.keys(data).length === 0)
62
62
  return {
63
63
  blockCanvas: getBlockCanvas(config, modelInstance),
@@ -71,15 +71,14 @@ export function assembleModel(config, data, designerConfig) {
71
71
  MarginModel.initMargin(designerConfig, config, otherComponents, data, modelInstance);
72
72
  DataManagerModel.initDataScope(config, data, designerConfig, otherComponents.legendBlock, modelInstance);
73
73
  const preparedData = DataManagerModel.getPreparedData(data, modelInstance.dataModel.getAllowableKeys(), config);
74
+ modelInstance.dataModel.repository.initScopedFullSource(preparedData);
74
75
  if (config.options.type === '2d' && config.options.axis.key.visibility)
75
76
  MarginModel.recalcMarginByVerticalAxisLabel(modelInstance, config, designerConfig, modelInstance.dataModel.getScope());
76
77
  const blockCanvas = getBlockCanvas(config, modelInstance);
77
78
  const chartBlock = getChartBlockModel(modelInstance);
78
- const options = getOptions(config, designerConfig, modelInstance, modelInstance.dataModel.getScope(), preparedData);
79
+ const options = getOptions(config, designerConfig, modelInstance, preparedData);
79
80
  const dataSettings = getDataSettings(modelInstance.dataModel.getScope(), designerConfig);
80
81
  const transitions = getTransitions(designerConfig);
81
- if (options.type === 'polar')
82
- MarginModel.recalcPolarMarginWithScopedData(modelInstance, designerConfig, config, otherComponents.legendBlock, modelInstance.dataModel.getScope(), options);
83
82
  modelInstance.canvasModel.roundMargin();
84
83
  return {
85
84
  blockCanvas,
@@ -0,0 +1,14 @@
1
+ import { DataScope } from "../../model";
2
+ import { DataRepositoryModel } from "./dataRepository";
3
+ export declare const DEFAULT_MAX_RECORDS_AMOUNT = 50;
4
+ export declare class DataModelInstance {
5
+ repository: DataRepositoryModel;
6
+ constructor();
7
+ private maxRecordsAmount;
8
+ private scope;
9
+ initMaxRecordsAmount(amount: number): void;
10
+ getMaxRecordsAmount(): number;
11
+ initScope(scope: DataScope): void;
12
+ getScope(): DataScope;
13
+ getAllowableKeys(): string[];
14
+ }
@@ -0,0 +1,26 @@
1
+ import { DataRepositoryModel } from "./dataRepository";
2
+ export const DEFAULT_MAX_RECORDS_AMOUNT = 50;
3
+ export class DataModelInstance {
4
+ constructor() {
5
+ //TODO: create dataScopeModel.
6
+ this.maxRecordsAmount = DEFAULT_MAX_RECORDS_AMOUNT;
7
+ this.repository = new DataRepositoryModel();
8
+ }
9
+ initMaxRecordsAmount(amount) {
10
+ if (typeof amount === "number" && amount > 0) {
11
+ this.maxRecordsAmount = amount;
12
+ }
13
+ }
14
+ getMaxRecordsAmount() {
15
+ return this.maxRecordsAmount;
16
+ }
17
+ initScope(scope) {
18
+ this.scope = scope;
19
+ }
20
+ getScope() {
21
+ return this.scope;
22
+ }
23
+ getAllowableKeys() {
24
+ return this.getScope().allowableKeys;
25
+ }
26
+ }
@@ -0,0 +1,12 @@
1
+ import { MdtChartsDataSource } from "../../../config/config";
2
+ export declare class DataRepositoryModel {
3
+ private rawFullSource;
4
+ private scopedFullSource;
5
+ private sourceName;
6
+ initSourceName(sourceName: string): void;
7
+ initRawFullSource(rawSource: MdtChartsDataSource): void;
8
+ getRawRows(): import("../../../config/config").MdtChartsDataRow[];
9
+ initScopedFullSource(scopedSource: MdtChartsDataSource): void;
10
+ getScopedFullSource(): MdtChartsDataSource;
11
+ getScopedRows(): import("../../../config/config").MdtChartsDataRow[];
12
+ }
@@ -0,0 +1,20 @@
1
+ export class DataRepositoryModel {
2
+ initSourceName(sourceName) {
3
+ this.sourceName = sourceName;
4
+ }
5
+ initRawFullSource(rawSource) {
6
+ this.rawFullSource = rawSource;
7
+ }
8
+ getRawRows() {
9
+ return this.rawFullSource[this.sourceName];
10
+ }
11
+ initScopedFullSource(scopedSource) {
12
+ this.scopedFullSource = scopedSource;
13
+ }
14
+ getScopedFullSource() {
15
+ return this.scopedFullSource;
16
+ }
17
+ getScopedRows() {
18
+ return this.scopedFullSource[this.sourceName];
19
+ }
20
+ }
@@ -1,8 +1,8 @@
1
- import { MdtChartsConfig } from "../../main";
1
+ import { MdtChartsConfig, MdtChartsDataSource } from "../../config/config";
2
2
  import { CanvasModel } from "./canvasModel/canvasModel";
3
- import { DataModelInstance } from "./dataModel";
3
+ import { DataModelInstance } from "./dataModel/dataModel";
4
4
  export declare class ModelInstance {
5
- static create(config: MdtChartsConfig): ModelInstance;
5
+ static create(config: MdtChartsConfig, data: MdtChartsDataSource): ModelInstance;
6
6
  private static initInitialParams;
7
7
  canvasModel: CanvasModel;
8
8
  dataModel: DataModelInstance;
@@ -1,17 +1,19 @@
1
1
  import { CanvasModel } from "./canvasModel/canvasModel";
2
- import { DataModelInstance } from "./dataModel";
2
+ import { DataModelInstance } from "./dataModel/dataModel";
3
3
  export class ModelInstance {
4
4
  constructor() {
5
5
  this.canvasModel = new CanvasModel();
6
6
  this.dataModel = new DataModelInstance();
7
7
  }
8
- static create(config) {
8
+ static create(config, data) {
9
9
  const modelInstance = new ModelInstance();
10
- this.initInitialParams(modelInstance, config);
10
+ this.initInitialParams(modelInstance, config, data);
11
11
  return modelInstance;
12
12
  }
13
- static initInitialParams(modelInstance, config) {
13
+ static initInitialParams(modelInstance, config, data) {
14
14
  modelInstance.canvasModel.initBlockSize(config.canvas.size);
15
15
  modelInstance.dataModel.initMaxRecordsAmount(config.options.data.maxRecordsAmount);
16
+ modelInstance.dataModel.repository.initSourceName(config.options.data.dataSource);
17
+ modelInstance.dataModel.repository.initRawFullSource(data);
16
18
  }
17
19
  }
@@ -1,9 +1,9 @@
1
- import { MdtChartsConfig, MdtChartsDataSource, IntervalOptions } from "../../config/config";
1
+ import { MdtChartsConfig, MdtChartsDataSource, MdtChartsIntervalOptions } from "../../config/config";
2
2
  import { DesignerConfig } from "../../designer/designerConfig";
3
3
  import { AdditionalElementsOptions, BlockMargin, DataScope, IntervalOptionsModel } from "../model";
4
4
  import { ModelInstance } from "../modelInstance/modelInstance";
5
5
  export declare class IntervalModel {
6
6
  static getOptions(config: MdtChartsConfig, designerConfig: DesignerConfig, margin: BlockMargin, dataScope: DataScope, data: MdtChartsDataSource, modelInstance: ModelInstance): IntervalOptionsModel;
7
- static getAdditionalElements(options: IntervalOptions): AdditionalElementsOptions;
7
+ static getAdditionalElements(options: MdtChartsIntervalOptions): AdditionalElementsOptions;
8
8
  private static getChartsModel;
9
9
  }
@@ -0,0 +1,12 @@
1
+ import { MdtChartsDataRow, MdtChartsDonutAggregator } from "../../../../config/config";
2
+ import { DonutAggregatorContent } from "../../../model";
3
+ export declare const AGGREGATOR_DEFAULT_TITLE = "\u0421\u0443\u043C\u043C\u0430";
4
+ export interface AggregatorServiceDataOptions {
5
+ rows: MdtChartsDataRow[];
6
+ valueFieldName: string;
7
+ }
8
+ export declare class DonutAggregatorService {
9
+ getContent(aggregatorOptions: MdtChartsDonutAggregator, dataOptions: AggregatorServiceDataOptions): DonutAggregatorContent;
10
+ private doesValueExist;
11
+ private generateDefaultContent;
12
+ }
@@ -0,0 +1,25 @@
1
+ export const AGGREGATOR_DEFAULT_TITLE = "Сумма";
2
+ export class DonutAggregatorService {
3
+ getContent(aggregatorOptions, dataOptions) {
4
+ if (!(aggregatorOptions === null || aggregatorOptions === void 0 ? void 0 : aggregatorOptions.content) || !dataOptions.rows)
5
+ return this.generateDefaultContent(dataOptions);
6
+ const content = aggregatorOptions.content({ data: dataOptions.rows });
7
+ if (this.doesValueExist(content.value) && content.title)
8
+ return content;
9
+ if (!content.title && this.doesValueExist(content.value))
10
+ return {
11
+ value: content.value,
12
+ title: AGGREGATOR_DEFAULT_TITLE
13
+ };
14
+ return this.generateDefaultContent(dataOptions);
15
+ }
16
+ doesValueExist(content) {
17
+ return content != null;
18
+ }
19
+ generateDefaultContent(dataOptions) {
20
+ return {
21
+ title: AGGREGATOR_DEFAULT_TITLE,
22
+ value: dataOptions.rows ? dataOptions.rows.reduce((acc, row) => acc + row[dataOptions.valueFieldName], 0) : 0
23
+ };
24
+ }
25
+ }
@@ -0,0 +1,10 @@
1
+ import { MdtChartsDataRow, PolarChart } from "../../../../config/config";
2
+ import { DonutOptionsCanvas } from "../../../../designer/designerConfig";
3
+ import { DonutChartSettings } from "../../../model";
4
+ export declare class DonutModel {
5
+ private thicknessService;
6
+ private aggregatorService;
7
+ getSettings(settingsFromConfig: DonutOptionsCanvas, chartOptions: PolarChart, rawDataRows: MdtChartsDataRow[]): DonutChartSettings;
8
+ private getThicknessOptions;
9
+ private getAggregatorOptions;
10
+ }
@@ -0,0 +1,32 @@
1
+ import { DonutAggregatorService } from "./donutAggregatorService";
2
+ import { DonutThicknessService } from "./donutThicknessService";
3
+ export class DonutModel {
4
+ constructor() {
5
+ this.thicknessService = new DonutThicknessService();
6
+ this.aggregatorService = new DonutAggregatorService();
7
+ }
8
+ getSettings(settingsFromConfig, chartOptions, rawDataRows) {
9
+ return {
10
+ padAngle: settingsFromConfig.padAngle,
11
+ thickness: this.getThicknessOptions(settingsFromConfig.thickness),
12
+ aggregator: this.getAggregatorOptions(settingsFromConfig, chartOptions, rawDataRows)
13
+ };
14
+ }
15
+ getThicknessOptions(settingsFromConfig) {
16
+ return {
17
+ unit: this.thicknessService.getUnit(settingsFromConfig),
18
+ max: this.thicknessService.valueToNumber(settingsFromConfig.max),
19
+ min: this.thicknessService.valueToNumber(settingsFromConfig.min),
20
+ value: this.thicknessService.valueToNumber(settingsFromConfig.value),
21
+ };
22
+ }
23
+ getAggregatorOptions(settingsFromConfig, chartOptions, rawDataRows) {
24
+ return {
25
+ margin: settingsFromConfig.aggregatorPad,
26
+ content: this.aggregatorService.getContent(chartOptions.aggregator, {
27
+ rows: rawDataRows,
28
+ valueFieldName: chartOptions.data.valueField.name
29
+ })
30
+ };
31
+ }
32
+ }
@@ -0,0 +1,9 @@
1
+ import { MdtChartsDonutThicknessOptions } from "../../../../designer/designerConfig";
2
+ import { DonutThicknessUnit } from "../../../model";
3
+ export declare class DonutThicknessService {
4
+ private defaultUnit;
5
+ getUnit(settingsFromConfig: MdtChartsDonutThicknessOptions): DonutThicknessUnit;
6
+ valueToNumber(value: string | number): number;
7
+ private getUnitByValue;
8
+ private getLastUnitFromString;
9
+ }
@@ -0,0 +1,30 @@
1
+ export class DonutThicknessService {
2
+ constructor() {
3
+ this.defaultUnit = "px";
4
+ }
5
+ getUnit(settingsFromConfig) {
6
+ if (settingsFromConfig.value)
7
+ return this.getUnitByValue(settingsFromConfig.value);
8
+ const minUnit = this.getUnitByValue(settingsFromConfig.min);
9
+ const maxUnit = this.getUnitByValue(settingsFromConfig.max);
10
+ return minUnit === maxUnit ? minUnit : this.defaultUnit;
11
+ }
12
+ valueToNumber(value) {
13
+ if (typeof value === "number")
14
+ return value;
15
+ return parseInt(value);
16
+ }
17
+ getUnitByValue(value) {
18
+ if (typeof value !== "string")
19
+ return this.defaultUnit;
20
+ return this.getLastUnitFromString(value);
21
+ }
22
+ getLastUnitFromString(value) {
23
+ let resultUnit = this.defaultUnit;
24
+ ["%", "px"].forEach(unit => {
25
+ if (value.endsWith(unit))
26
+ resultUnit = unit;
27
+ });
28
+ return resultUnit;
29
+ }
30
+ }
@@ -0,0 +1,15 @@
1
+ import { MdtChartsPolarOptions } from "../../../config/config";
2
+ import { DesignerConfig } from "../../../designer/designerConfig";
3
+ import { PolarOptionsModel, LegendCoordinate } from "../../model";
4
+ import { CanvasModel } from "../../modelInstance/canvasModel/canvasModel";
5
+ import { ModelInstance } from "../../modelInstance/modelInstance";
6
+ export declare const MIN_DONUT_BLOCK_SIZE = 120;
7
+ export declare class PolarModel {
8
+ private static donutModel;
9
+ static getOptions(options: MdtChartsPolarOptions, designerConfig: DesignerConfig, modelInstance: ModelInstance): PolarOptionsModel;
10
+ static getLegendPositionByBlockSize(canvasModel: CanvasModel): "bottom" | "right";
11
+ static doesChartBlockHasEnoughWidthForContainsLegend(chartBlockWidth: number, legendWidth: number, legendCoordinate: LegendCoordinate): boolean;
12
+ static doesChartBlockHasEnoughHeightForContainsLegend(chartBlockHeight: number, legendCoordinate: LegendCoordinate): boolean;
13
+ private static getDonutSettings;
14
+ private static getChartsModel;
15
+ }
@@ -0,0 +1,53 @@
1
+ import { ChartStyleModelService } from "../../chartStyleModel/chartStyleModel";
2
+ import { DonutModel } from "./donut/donutModel";
3
+ export const MIN_DONUT_BLOCK_SIZE = 120;
4
+ export class PolarModel {
5
+ static getOptions(options, designerConfig, modelInstance) {
6
+ return {
7
+ type: options.type,
8
+ selectable: !!options.selectable,
9
+ title: options.title,
10
+ data: Object.assign({}, options.data),
11
+ charts: this.getChartsModel(options.chart, modelInstance.dataModel.repository.getScopedRows().length, designerConfig.chartStyle),
12
+ legend: modelInstance.canvasModel.legendCanvas.getModel(),
13
+ tooltip: options.tooltip,
14
+ chartCanvas: this.getDonutSettings(designerConfig.canvas.chartOptions.donut, options.chart, modelInstance.dataModel.repository.getRawRows())
15
+ };
16
+ }
17
+ //TODO: type for returned value
18
+ static getLegendPositionByBlockSize(canvasModel) {
19
+ const widthCoefficientWhenLegendShouldInBottom = 1.5;
20
+ const avgLegendWidth = 100;
21
+ const blockWidth = canvasModel.getBlockSize().width;
22
+ const blockHeight = canvasModel.getBlockSize().height;
23
+ return canvasModel.getChartBlockWidth() < MIN_DONUT_BLOCK_SIZE + avgLegendWidth
24
+ && blockWidth * widthCoefficientWhenLegendShouldInBottom < blockHeight
25
+ ? 'bottom'
26
+ : 'right';
27
+ }
28
+ static doesChartBlockHasEnoughWidthForContainsLegend(chartBlockWidth, legendWidth, legendCoordinate) {
29
+ const rightLegendMargin = legendCoordinate.right.margin;
30
+ return chartBlockWidth - legendWidth - rightLegendMargin.left - rightLegendMargin.right >= MIN_DONUT_BLOCK_SIZE;
31
+ }
32
+ static doesChartBlockHasEnoughHeightForContainsLegend(chartBlockHeight, legendCoordinate) {
33
+ const minHeightForLegend = 30;
34
+ const bottomLegendMargin = legendCoordinate.bottom.margin;
35
+ const heightForLegend = chartBlockHeight - bottomLegendMargin.bottom - bottomLegendMargin.top - MIN_DONUT_BLOCK_SIZE;
36
+ return heightForLegend >= minHeightForLegend;
37
+ }
38
+ static getDonutSettings(settings, chartOptions, dataRows) {
39
+ return this.donutModel.getSettings(settings, chartOptions, dataRows);
40
+ }
41
+ static getChartsModel(chart, dataLength, chartStyleConfig) {
42
+ const chartsModel = [];
43
+ chartsModel.push({
44
+ type: chart.type,
45
+ data: Object.assign({}, chart.data),
46
+ tooltip: chart.tooltip,
47
+ cssClasses: ChartStyleModelService.getCssClasses(0),
48
+ style: ChartStyleModelService.getChartStyle(dataLength, chartStyleConfig)
49
+ });
50
+ return chartsModel;
51
+ }
52
+ }
53
+ PolarModel.donutModel = new DonutModel();
@@ -1,6 +1,6 @@
1
1
  import { MdtChartsDataSource, MdtChartsPolarOptions } from "../../config/config";
2
2
  import { DesignerConfig } from "../../designer/designerConfig";
3
- import { PolarOptionsModel } from "../model";
3
+ import { PolarOptionsModel, LegendCoordinate } from "../model";
4
4
  import { CanvasModel } from "../modelInstance/canvasModel/canvasModel";
5
5
  import { ModelInstance } from "../modelInstance/modelInstance";
6
6
  /** If donut block has width less than this const, legend change postion from "right" to "bottom" */
@@ -8,6 +8,8 @@ export declare const MIN_DONUT_BLOCK_SIZE = 120;
8
8
  export declare class PolarModel {
9
9
  static getOptions(options: MdtChartsPolarOptions, data: MdtChartsDataSource, designerConfig: DesignerConfig, modelInstance: ModelInstance): PolarOptionsModel;
10
10
  static getLegendPositionByBlockSize(canvasModel: CanvasModel): "bottom" | "right";
11
+ static doesChartBlockHasEnoughWidthForContainsLegend(chartBlockWidth: number, legendWidth: number, legendCoordinate: LegendCoordinate): boolean;
12
+ static doesChartBlockHasEnoughHeightForContainsLegend(chartBlockHeight: number, legendCoordinate: LegendCoordinate): boolean;
11
13
  private static getDonutSettings;
12
14
  private static getChartsModel;
13
15
  }
@@ -17,13 +17,24 @@ export class PolarModel {
17
17
  //TODO: type for returned value
18
18
  static getLegendPositionByBlockSize(canvasModel) {
19
19
  const widthCoefficientWhenLegendShouldInBottom = 1.5;
20
+ const avgLegendWidth = 100;
20
21
  const blockWidth = canvasModel.getBlockSize().width;
21
22
  const blockHeight = canvasModel.getBlockSize().height;
22
- return canvasModel.getChartBlockWidth() < MIN_DONUT_BLOCK_SIZE
23
+ return canvasModel.getChartBlockWidth() < MIN_DONUT_BLOCK_SIZE + avgLegendWidth
23
24
  && blockWidth * widthCoefficientWhenLegendShouldInBottom < blockHeight
24
25
  ? 'bottom'
25
26
  : 'right';
26
27
  }
28
+ static doesChartBlockHasEnoughWidthForContainsLegend(chartBlockWidth, legendWidth, legendCoordinate) {
29
+ const rightLegendMargin = legendCoordinate.right.margin;
30
+ return chartBlockWidth - legendWidth - rightLegendMargin.left - rightLegendMargin.right >= MIN_DONUT_BLOCK_SIZE;
31
+ }
32
+ static doesChartBlockHasEnoughHeightForContainsLegend(chartBlockHeight, legendCoordinate) {
33
+ const minHeightForLegend = 30;
34
+ const bottomLegendMargin = legendCoordinate.bottom.margin;
35
+ const heightForLegend = chartBlockHeight - bottomLegendMargin.bottom - bottomLegendMargin.top - MIN_DONUT_BLOCK_SIZE;
36
+ return heightForLegend >= minHeightForLegend;
37
+ }
27
38
  static getDonutSettings(settings, chartOptions) {
28
39
  return {
29
40
  padAngle: settings.padAngle,
@@ -1,21 +1,21 @@
1
- import { ChartOrientation, MdtChartsDataSource, TwoDimensionalChart, MdtChartsTwoDimensionalOptions } from "../../config/config";
1
+ import { ChartOrientation, MdtChartsDataSource, MdtChartsTwoDimensionalChart, MdtChartsTwoDimensionalOptions } from "../../config/config";
2
2
  import { BarOptionsCanvas, DesignerConfig } from "../../designer/designerConfig";
3
- import { DataScope, TwoDimensionalOptionsModel, TwoDimChartElementsSettings } from "../model";
3
+ import { TwoDimensionalOptionsModel, TwoDimChartElementsSettings } from "../model";
4
4
  import { ModelInstance } from "../modelInstance/modelInstance";
5
5
  export declare class TwoDimensionalModel {
6
- static getOptions(options: MdtChartsTwoDimensionalOptions, designerConfig: DesignerConfig, dataScope: DataScope, data: MdtChartsDataSource, modelInstance: ModelInstance): TwoDimensionalOptionsModel;
7
- static getChartsEmbeddedLabelsFlag(charts: TwoDimensionalChart[], chartOrientation: ChartOrientation): boolean;
6
+ static getOptions(options: MdtChartsTwoDimensionalOptions, designerConfig: DesignerConfig, data: MdtChartsDataSource, modelInstance: ModelInstance): TwoDimensionalOptionsModel;
7
+ static getChartsEmbeddedLabelsFlag(charts: MdtChartsTwoDimensionalChart[], chartOrientation: ChartOrientation): boolean;
8
8
  /**
9
9
  * Сортирует список чартов в порядке: area - bar - line.
10
10
  * Используется для того, чтобы при рендере графики с наибольшей площадью (area) не перекрывали графики с меньшей площадью (bar, line).
11
11
  * @param charts Чарты из конфига
12
12
  */
13
- static sortCharts(charts: TwoDimensionalChart[]): void;
13
+ static sortCharts(charts: MdtChartsTwoDimensionalChart[]): void;
14
14
  static getChartsSettings(barSettings: BarOptionsCanvas): TwoDimChartElementsSettings;
15
15
  private static getChartsModel;
16
16
  private static findChartsWithEmbeddedKeyLabels;
17
17
  private static getEmbeddedLabelType;
18
18
  private static getAdditionalElements;
19
19
  private static getChartsByType;
20
- static getChartsValueFieldsAmount(charts: TwoDimensionalChart[]): number[];
20
+ static getChartsValueFieldsAmount(charts: MdtChartsTwoDimensionalChart[]): number[];
21
21
  }
@@ -3,7 +3,7 @@ import { TwoDimensionalChartStyleModel } from "../chartStyleModel/TwoDimensional
3
3
  import { AxisModel } from "../featuresModel/axisModel";
4
4
  import { ScaleModel } from "../featuresModel/scaleModel";
5
5
  export class TwoDimensionalModel {
6
- static getOptions(options, designerConfig, dataScope, data, modelInstance) {
6
+ static getOptions(options, designerConfig, data, modelInstance) {
7
7
  const canvasModel = modelInstance.canvasModel;
8
8
  return {
9
9
  legend: canvasModel.legendCanvas.getModel(),
@@ -11,11 +11,11 @@ export class TwoDimensionalModel {
11
11
  selectable: !!options.selectable,
12
12
  orient: options.orientation,
13
13
  scale: {
14
- key: ScaleModel.getScaleKey(dataScope.allowableKeys, options.orientation, canvasModel, options.charts, this.getChartsByType(options.charts, 'bar')),
14
+ key: ScaleModel.getScaleKey(modelInstance.dataModel.getAllowableKeys(), options.orientation, canvasModel, options.charts, this.getChartsByType(options.charts, 'bar')),
15
15
  value: ScaleModel.getScaleLinear(options, data, canvasModel)
16
16
  },
17
17
  axis: {
18
- key: AxisModel.getKeyAxis(options.charts, data, options.data, options.orientation, options.axis.key, designerConfig.canvas.axisLabel, canvasModel, designerConfig.elementsOptions.tooltip),
18
+ key: AxisModel.getKeyAxis(options, data, designerConfig.canvas.axisLabel, canvasModel, designerConfig.elementsOptions.tooltip),
19
19
  value: AxisModel.getValueAxis(options.orientation, options.axis.value, designerConfig.canvas.axisLabel, canvasModel)
20
20
  },
21
21
  type: options.type,
@@ -41,28 +41,45 @@
41
41
 
42
42
 
43
43
  /*========================================================================== Legend */
44
+ .legend-block {
45
+ display: flex;
46
+ height: 100%;
47
+ }
48
+ .legend-block-column {
49
+ flex-direction: column;
50
+ }
51
+ .legend-block-row {
52
+ flex-direction: row;
53
+ flex-wrap: wrap;
54
+ }
55
+ .legend-block-centered {
56
+ justify-content: center;
57
+ }
44
58
  .legend-item {
45
59
  cursor: default;
46
60
  transition: opacity 0.1s;
61
+ /* will-change: opacity; */
62
+ }
63
+ .legend-block-column .legend-item:not(:first-of-type) {
64
+ margin-top: 15px;
47
65
  }
48
66
  .legend-item-inline {
49
67
  white-space: nowrap;
68
+ overflow: hidden;
69
+ text-overflow: ellipsis;
50
70
  }
51
- .legend-item-inline:not(:first-of-type) {
71
+ .legend-wrapper-without-wrap .legend-item-inline:not(:first-of-type) {
52
72
  margin-left: 20px;
53
73
  }
74
+ .legend-wrapper-with-wrap .legend-item-inline {
75
+ margin: 5px;
76
+ }
54
77
  .legend-item-row {
55
78
  display: flex;
56
79
  }
57
80
  .legend-item-row > span {
58
81
  display: block;
59
82
  }
60
- .mt-15 {
61
- margin-top: 15px;
62
- }
63
- .mt-10 {
64
- margin-top: 10px;
65
- }
66
83
 
67
84
  .legend-label {
68
85
  font-size: 12px;
@@ -183,12 +200,15 @@
183
200
  line-height: 1;
184
201
  }
185
202
  .aggregator-value {
186
- margin-top: 20px;
203
+ margin-top: 0.5em;
187
204
  pointer-events: auto;
188
205
  }
189
206
  .aggregator-name {
190
- margin-top: 10px;
207
+ margin-top: 0.5em;
191
208
  pointer-events: auto;
209
+ max-width: 90%;
210
+ overflow: hidden;
211
+ text-overflow: ellipsis;
192
212
  }
193
213
 
194
214
  /* Grid */
@@ -41,28 +41,45 @@
41
41
 
42
42
 
43
43
  /*========================================================================== Legend */
44
+ .legend-block {
45
+ display: flex;
46
+ height: 100%;
47
+ }
48
+ .legend-block-column {
49
+ flex-direction: column;
50
+ }
51
+ .legend-block-row {
52
+ flex-direction: row;
53
+ flex-wrap: wrap;
54
+ }
55
+ .legend-block-centered {
56
+ justify-content: center;
57
+ }
44
58
  .legend-item {
45
59
  cursor: default;
46
60
  transition: opacity 0.1s;
61
+ /* will-change: opacity; */
62
+ }
63
+ .legend-block-column .legend-item:not(:first-of-type) {
64
+ margin-top: 15px;
47
65
  }
48
66
  .legend-item-inline {
49
67
  white-space: nowrap;
68
+ overflow: hidden;
69
+ text-overflow: ellipsis;
50
70
  }
51
- .legend-item-inline:not(:first-of-type) {
71
+ .legend-wrapper-without-wrap .legend-item-inline:not(:first-of-type) {
52
72
  margin-left: 20px;
53
73
  }
74
+ .legend-wrapper-with-wrap .legend-item-inline {
75
+ margin: 5px;
76
+ }
54
77
  .legend-item-row {
55
78
  display: flex;
56
79
  }
57
80
  .legend-item-row > span {
58
81
  display: block;
59
82
  }
60
- .mt-15 {
61
- margin-top: 15px;
62
- }
63
- .mt-10 {
64
- margin-top: 10px;
65
- }
66
83
 
67
84
  .legend-label {
68
85
  font-size: 12px;
@@ -183,12 +200,15 @@
183
200
  line-height: 1;
184
201
  }
185
202
  .aggregator-value {
186
- margin-top: 20px;
203
+ margin-top: 0.5em;
187
204
  pointer-events: auto;
188
205
  }
189
206
  .aggregator-name {
190
- margin-top: 10px;
207
+ margin-top: 0.5em;
191
208
  pointer-events: auto;
209
+ max-width: 90%;
210
+ overflow: hidden;
211
+ text-overflow: ellipsis;
192
212
  }
193
213
 
194
214
  /* Grid */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdt-charts",
3
- "version": "1.12.0",
3
+ "version": "1.12.4",
4
4
  "description": "",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@
8
8
  "build": "npx webpack --mode production",
9
9
  "watch": "npx webpack --mode development --watch",
10
10
  "test": "jest",
11
- "build-lib": "npx tsc -p ."
11
+ "build-lib": "npx tsc -p tsconfig.production.json"
12
12
  },
13
13
  "homepage": "https://github.com/VishulaKnow/charts",
14
14
  "author": "",