mdt-charts 1.11.1 → 1.12.3

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 (69) hide show
  1. package/lib/config/config.d.ts +25 -12
  2. package/lib/designer/designerConfig.d.ts +3 -5
  3. package/lib/engine/features/aggregator/aggregator.d.ts +8 -6
  4. package/lib/engine/features/aggregator/aggregator.js +45 -32
  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/features/recordOverflowAlert/recordOverflowAlertCore.d.ts +28 -0
  12. package/lib/engine/features/recordOverflowAlert/recordOverflowAlertCore.js +50 -0
  13. package/lib/engine/intervalNotation/intervalManager.js +0 -3
  14. package/lib/engine/polarNotation/donut/donut.js +1 -1
  15. package/lib/engine/polarNotation/extenders/polarRecordOverflowAlert.d.ts +15 -0
  16. package/lib/engine/polarNotation/extenders/polarRecordOverflowAlert.js +40 -0
  17. package/lib/engine/polarNotation/polarManager.js +11 -6
  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 +9 -3
  21. package/lib/model/chartStyleModel/TwoDimensionalChartStyleModel.d.ts +4 -4
  22. package/lib/model/{dataManagerModel.d.ts → dataManagerModel/dataManagerModel.d.ts} +18 -7
  23. package/lib/model/{dataManagerModel.js → dataManagerModel/dataManagerModel.js} +51 -45
  24. package/lib/model/dataManagerModel/dataManagerModelService.d.ts +5 -0
  25. package/lib/model/dataManagerModel/dataManagerModelService.js +28 -0
  26. package/lib/model/featuresModel/axisModel.d.ts +5 -4
  27. package/lib/model/featuresModel/axisModel.js +14 -12
  28. package/lib/model/featuresModel/axisModelService.d.ts +4 -0
  29. package/lib/model/featuresModel/axisModelService.js +11 -0
  30. package/lib/model/featuresModel/legendModel/legendCanvasModel.d.ts +4 -2
  31. package/lib/model/featuresModel/legendModel/legendCanvasModel.js +42 -29
  32. package/lib/model/featuresModel/legendModel/legendModel.d.ts +1 -4
  33. package/lib/model/featuresModel/legendModel/legendModel.js +15 -16
  34. package/lib/model/featuresModel/legendModel/polarMarginCalculator.d.ts +11 -0
  35. package/lib/model/featuresModel/legendModel/polarMarginCalculator.js +42 -0
  36. package/lib/model/featuresModel/scaleModel.d.ts +6 -6
  37. package/lib/model/featuresModel/titleModel.js +4 -4
  38. package/lib/model/marginModel.d.ts +3 -2
  39. package/lib/model/marginModel.js +11 -7
  40. package/lib/model/model.d.ts +19 -8
  41. package/lib/model/modelBuilder.js +9 -9
  42. package/lib/model/modelInstance/canvasModel/canvasModel.d.ts +2 -0
  43. package/lib/model/modelInstance/canvasModel/canvasModel.js +2 -0
  44. package/lib/model/modelInstance/canvasModel/legendCanvasModel.d.ts +7 -0
  45. package/lib/model/modelInstance/canvasModel/legendCanvasModel.js +13 -0
  46. package/lib/model/modelInstance/dataModel.d.ts +11 -0
  47. package/lib/model/modelInstance/dataModel.js +23 -0
  48. package/lib/model/modelInstance/modelInstance.d.ts +3 -0
  49. package/lib/model/modelInstance/modelInstance.js +7 -1
  50. package/lib/model/notations/intervalModel.d.ts +2 -2
  51. package/lib/model/notations/intervalModel.js +2 -3
  52. package/lib/model/notations/polar/donut/donutAggregatorService.d.ts +12 -0
  53. package/lib/model/notations/polar/donut/donutAggregatorService.js +25 -0
  54. package/lib/model/notations/polar/donut/donutModel.d.ts +10 -0
  55. package/lib/model/notations/polar/donut/donutModel.js +32 -0
  56. package/lib/model/notations/polar/donut/donutThicknessService.d.ts +9 -0
  57. package/lib/model/notations/polar/donut/donutThicknessService.js +30 -0
  58. package/lib/model/notations/polar/polarModel.d.ts +16 -0
  59. package/lib/model/notations/polar/polarModel.js +55 -0
  60. package/lib/model/notations/polarModel.d.ts +7 -1
  61. package/lib/model/notations/polarModel.js +24 -2
  62. package/lib/model/notations/twoDimensionalModel.d.ts +4 -4
  63. package/lib/model/notations/twoDimensionalModel.js +2 -3
  64. package/lib/style/charts-main.css +29 -9
  65. package/lib/style/charts-main.less +29 -9
  66. package/package.json +2 -2
  67. package/tsconfig.production.json +23 -0
  68. package/lib/engine/features/recordOverflowAlert/recordOverflowAlert.d.ts +0 -14
  69. package/lib/engine/features/recordOverflowAlert/recordOverflowAlert.js +0 -97
@@ -0,0 +1,40 @@
1
+ import { RecordOverflowAlertCore } from "../../features/recordOverflowAlert/recordOverflowAlertCore";
2
+ class PolarRecordOverflowAlertClass {
3
+ constructor() {
4
+ this.text = {
5
+ one: 'категория',
6
+ twoToFour: 'категории',
7
+ tenToTwenty: 'категорий',
8
+ other: 'категорий'
9
+ };
10
+ }
11
+ render(block, options) {
12
+ RecordOverflowAlertCore.render(block, this.buildCoreOptions(options));
13
+ }
14
+ update(block, options) {
15
+ RecordOverflowAlertCore.update(block, this.buildCoreOptions(options));
16
+ }
17
+ buildCoreOptions(options) {
18
+ return {
19
+ hidedRecordsAmount: options.hidedRecordsAmount,
20
+ text: this.text,
21
+ positionAttrs: this.getPositionAttrs(options)
22
+ };
23
+ }
24
+ getPositionAttrs(options) {
25
+ const position = options.legendPosition === 'off' ? 'bottom' : options.legendPosition;
26
+ if (position === 'right') {
27
+ return {
28
+ bottom: '0',
29
+ right: '0'
30
+ };
31
+ }
32
+ if (position === 'bottom') {
33
+ return {
34
+ bottom: '0',
35
+ left: '0'
36
+ };
37
+ }
38
+ }
39
+ }
40
+ export const PolarRecordOverflowAlert = new PolarRecordOverflowAlertClass();
@@ -1,10 +1,10 @@
1
1
  import { Legend } from "../features/legend/legend";
2
- import { RecordOverflowAlert } from "../features/recordOverflowAlert/recordOverflowAlert";
3
2
  import { Title } from "../features/title/title";
4
3
  import { ElementHighlighter } from "../elementHighlighter/elementHighlighter";
5
4
  import { Tooltip } from "../features/tolltip/tooltip";
6
5
  import { Aggregator } from "../features/aggregator/aggregator";
7
6
  import { Donut } from "./donut/donut";
7
+ import { PolarRecordOverflowAlert } from "./extenders/polarRecordOverflowAlert";
8
8
  export class PolarManager {
9
9
  static render(engine, model) {
10
10
  const options = model.options;
@@ -14,8 +14,11 @@ export class PolarManager {
14
14
  Legend.render(engine.block, engine.data, options, model);
15
15
  Tooltip.render(engine.block, model, engine.data, model.otherComponents.tooltipBlock);
16
16
  engine.block.filterEventManager.setListenerPolar(model.chartBlock.margin, model.blockCanvas.size, options);
17
- if (model.dataSettings.scope.hidedRecordsAmount !== 0 && model.options.legend.position !== 'off')
18
- RecordOverflowAlert.render(engine.block, model.dataSettings.scope.hidedRecordsAmount, model.options.legend.position);
17
+ if (model.dataSettings.scope.hidedRecordsAmount !== 0)
18
+ PolarRecordOverflowAlert.render(engine.block, {
19
+ hidedRecordsAmount: model.dataSettings.scope.hidedRecordsAmount,
20
+ legendPosition: model.options.legend.position
21
+ });
19
22
  engine.block.getSvg()
20
23
  .on('click', (e) => {
21
24
  if (e.target === engine.block.getSvg().node())
@@ -36,10 +39,12 @@ export class PolarManager {
36
39
  Tooltip.render(block, model, data, model.otherComponents.tooltipBlock);
37
40
  block.filterEventManager.setListenerPolar(model.chartBlock.margin, model.blockCanvas.size, options);
38
41
  });
39
- Aggregator.update(block, data[options.data.dataSource], options.charts[0].data.valueField, options.chartCanvas.aggregator);
42
+ Aggregator.update(block, options.charts[0].data.valueField, options.chartCanvas.aggregator);
40
43
  Legend.update(block, data, model);
41
- if (model.options.legend.position !== 'off')
42
- RecordOverflowAlert.update(block, model.dataSettings.scope.hidedRecordsAmount, model.options.legend.position);
44
+ PolarRecordOverflowAlert.update(block, {
45
+ hidedRecordsAmount: model.dataSettings.scope.hidedRecordsAmount,
46
+ legendPosition: model.options.legend.position
47
+ });
43
48
  }
44
49
  static updateColors(block, model) {
45
50
  Legend.updateColors(block, model.options);
@@ -0,0 +1,15 @@
1
+ import { ChartOrientation } from "../../../config/config";
2
+ import { Block } from "../../block/block";
3
+ interface TwoDimRecordOverflowAlertOptions {
4
+ hidedRecordsAmount: number;
5
+ chartOrientation: ChartOrientation;
6
+ }
7
+ declare class TwoDimRecordOverflowAlertClass {
8
+ render(block: Block, options: TwoDimRecordOverflowAlertOptions): void;
9
+ update(block: Block, options: TwoDimRecordOverflowAlertOptions): void;
10
+ private buildCoreOptions;
11
+ private getText;
12
+ private getPositionAttrs;
13
+ }
14
+ export declare const TwoDimRecordOverflowAlert: TwoDimRecordOverflowAlertClass;
15
+ export {};
@@ -0,0 +1,32 @@
1
+ import { RecordOverflowAlertCore } from "../../features/recordOverflowAlert/recordOverflowAlertCore";
2
+ class TwoDimRecordOverflowAlertClass {
3
+ render(block, options) {
4
+ RecordOverflowAlertCore.render(block, this.buildCoreOptions(options));
5
+ }
6
+ update(block, options) {
7
+ RecordOverflowAlertCore.update(block, this.buildCoreOptions(options));
8
+ }
9
+ buildCoreOptions(options) {
10
+ return {
11
+ hidedRecordsAmount: options.hidedRecordsAmount,
12
+ text: this.getText(options.chartOrientation),
13
+ positionAttrs: this.getPositionAttrs()
14
+ };
15
+ }
16
+ getText(chartOrientation) {
17
+ const isHorizontal = chartOrientation === 'horizontal';
18
+ return {
19
+ one: isHorizontal ? 'строка' : 'столбец',
20
+ twoToFour: isHorizontal ? 'строки' : 'столбца',
21
+ tenToTwenty: isHorizontal ? 'строк' : 'столбцов',
22
+ other: isHorizontal ? 'строк' : 'столбцов'
23
+ };
24
+ }
25
+ getPositionAttrs() {
26
+ return {
27
+ right: '17px',
28
+ top: '1rem'
29
+ };
30
+ }
31
+ }
32
+ export const TwoDimRecordOverflowAlert = new TwoDimRecordOverflowAlertClass();
@@ -3,7 +3,6 @@ import { Axis } from "../features/axis/axis";
3
3
  import { EmbeddedLabels } from "../features/embeddedLabels/embeddedLabels";
4
4
  import { GridLine } from "../features/gridLine/gridLine";
5
5
  import { Legend } from "../features/legend/legend";
6
- import { RecordOverflowAlert } from "../features/recordOverflowAlert/recordOverflowAlert";
7
6
  import { Scale } from "../features/scale/scale";
8
7
  import { TipBox } from "../features/tipBox/tipBox";
9
8
  import { Title } from "../features/title/title";
@@ -12,6 +11,7 @@ import { Helper } from "../helpers/helper";
12
11
  import { Area } from "./area/area";
13
12
  import { Bar } from "./bar/bar";
14
13
  import { BarHelper } from "./bar/barHelper";
14
+ import { TwoDimRecordOverflowAlert } from "./extenders/twoDimRecordOverflowAlert";
15
15
  import { Line } from "./line/line";
16
16
  export class TwoDimensionalManager {
17
17
  static render(engine, model) {
@@ -28,7 +28,10 @@ export class TwoDimensionalManager {
28
28
  Legend.render(engine.block, engine.data, options, model);
29
29
  Tooltip.render(engine.block, model, engine.data, model.otherComponents.tooltipBlock, scales);
30
30
  if (model.dataSettings.scope.hidedRecordsAmount !== 0)
31
- RecordOverflowAlert.render(engine.block, model.dataSettings.scope.hidedRecordsAmount, 'top', options.orient);
31
+ TwoDimRecordOverflowAlert.render(engine.block, {
32
+ hidedRecordsAmount: model.dataSettings.scope.hidedRecordsAmount,
33
+ chartOrientation: options.orient
34
+ });
32
35
  engine.block.getSvg()
33
36
  .on('click', (e) => {
34
37
  if (e.target === engine.block.getSvg().node())
@@ -54,7 +57,10 @@ export class TwoDimensionalManager {
54
57
  block.filterEventManager.registerEventFor2D(scales.key, model.chartBlock.margin, model.blockCanvas.size, options);
55
58
  Tooltip.render(block, model, data, model.otherComponents.tooltipBlock, scales);
56
59
  });
57
- RecordOverflowAlert.update(block, model.dataSettings.scope.hidedRecordsAmount, 'top', options.orient);
60
+ TwoDimRecordOverflowAlert.update(block, {
61
+ hidedRecordsAmount: model.dataSettings.scope.hidedRecordsAmount,
62
+ chartOrientation: options.orient
63
+ });
58
64
  }
59
65
  static updateColors(block, model) {
60
66
  Legend.updateColors(block, model.options);
@@ -1,16 +1,16 @@
1
- import { TwoDimensionalChart, TwoDimensionalChartType } from "../../config/config";
1
+ import { MdtChartsTwoDimensionalChart, TwoDimensionalChartType } from "../../config/config";
2
2
  import { ChartStyleConfig } from "../../designer/designerConfig";
3
3
  import { ChartStyle } from "../model";
4
4
  export declare class TwoDimensionalChartStyleModel {
5
5
  private charts;
6
6
  private chartStyleConfig;
7
7
  private service;
8
- constructor(charts: TwoDimensionalChart[], chartStyleConfig: ChartStyleConfig);
9
- getChartStyle(chart: TwoDimensionalChart, chartIndex: number): ChartStyle;
8
+ constructor(charts: MdtChartsTwoDimensionalChart[], chartStyleConfig: ChartStyleConfig);
9
+ getChartStyle(chart: MdtChartsTwoDimensionalChart, chartIndex: number): ChartStyle;
10
10
  private getChartsValueFieldsAmounts;
11
11
  }
12
12
  export declare class TwoDimensionalChartStyleService {
13
- getChartColors(chart: TwoDimensionalChart, styleConfig: ChartStyleConfig, chartsFieldsAmounts: number[], chartIndex: number): string[];
13
+ getChartColors(chart: MdtChartsTwoDimensionalChart, styleConfig: ChartStyleConfig, chartsFieldsAmounts: number[], chartIndex: number): string[];
14
14
  getChartOpacity(chartsLength: number, chartType: TwoDimensionalChartType, chartsValueFieldAmount: number, isChartSegmented: boolean): number;
15
15
  private generateNewChartColors;
16
16
  private isMoreThanOneValueFieldOnCanvas;
@@ -1,13 +1,24 @@
1
- import { MdtChartsConfig, MdtChartsDataSource } from "../config/config";
2
- import { DesignerConfig } from "../designer/designerConfig";
3
- import { DataScope, LegendBlockModel } from "./model";
4
- import { ModelInstance } from "./modelInstance/modelInstance";
1
+ import { MdtChartsConfig, MdtChartsDataSource } from "../../config/config";
2
+ import { DesignerConfig } from "../../designer/designerConfig";
3
+ import { LegendBlockModel } from "../model";
4
+ import { ModelInstance } from "../modelInstance/modelInstance";
5
+ export interface DataLegendParams {
6
+ amount: number;
7
+ size: {
8
+ width: number;
9
+ height: number;
10
+ };
11
+ }
5
12
  export declare class DataManagerModel {
13
+ private static service;
6
14
  static getPreparedData(data: MdtChartsDataSource, allowableKeys: string[], config: MdtChartsConfig): MdtChartsDataSource;
7
- static getDataScope(config: MdtChartsConfig, data: MdtChartsDataSource, designerConfig: DesignerConfig, legendBlock: LegendBlockModel, modelInstance: ModelInstance): DataScope;
15
+ static initDataScope(config: MdtChartsConfig, data: MdtChartsDataSource, designerConfig: DesignerConfig, legendBlock: LegendBlockModel, modelInstance: ModelInstance): void;
8
16
  static getDataValuesByKeyField(data: MdtChartsDataSource, dataSourceName: string, keyFieldName: string): string[];
9
- private static getDataScopeFor2D;
10
- private static getDataScopeForPolar;
17
+ private static initDataScopeFor2D;
18
+ private static initDataScopeForPolar;
19
+ private static getLegendDataParams;
20
+ private static getMaximumPossibleScope;
21
+ private static limitAllowableKeys;
11
22
  /**
12
23
  * Выводит количество элементов (преимущественно баров) в одной группе. Группа - один ключ
13
24
  * @param configOptions
@@ -1,25 +1,27 @@
1
- import { AxisModel } from "./featuresModel/axisModel";
2
- import { LegendCanvasModel } from "./featuresModel/legendModel/legendCanvasModel";
3
- import { MIN_DONUT_BLOCK_SIZE } from "./featuresModel/legendModel/legendModel";
4
- import { ModelHelper } from "./modelHelper";
1
+ import { AxisModel } from "../featuresModel/axisModel";
2
+ import { LegendCanvasModel } from "../featuresModel/legendModel/legendCanvasModel";
3
+ import { LegendPolarMarginCalculator } from "../featuresModel/legendModel/polarMarginCalculator";
4
+ import { ModelHelper } from "../modelHelper";
5
+ import { MIN_DONUT_BLOCK_SIZE, PolarModel } from "../notations/polar/polarModel";
6
+ import { DataManagerModelService } from "./dataManagerModelService";
5
7
  export class DataManagerModel {
6
8
  static getPreparedData(data, allowableKeys, config) {
7
9
  const scopedData = this.getScopedData(data, allowableKeys, config);
8
10
  this.setDataType(scopedData, config);
9
11
  return scopedData;
10
12
  }
11
- static getDataScope(config, data, designerConfig, legendBlock, modelInstance) {
13
+ static initDataScope(config, data, designerConfig, legendBlock, modelInstance) {
12
14
  if (config.options.type === '2d' || config.options.type === 'interval') {
13
- return this.getDataScopeFor2D(config.options, modelInstance, data, designerConfig);
15
+ this.initDataScopeFor2D(config.options, modelInstance, data, designerConfig);
14
16
  }
15
17
  else if (config.options.type === 'polar') {
16
- return this.getDataScopeForPolar(config.options, modelInstance, data, legendBlock, designerConfig.canvas.legendBlock);
18
+ this.initDataScopeForPolar(config.options, modelInstance, data, legendBlock, designerConfig.canvas.legendBlock);
17
19
  }
18
20
  }
19
21
  static getDataValuesByKeyField(data, dataSourceName, keyFieldName) {
20
22
  return data[dataSourceName].map(dataRow => dataRow[keyFieldName]);
21
23
  }
22
- static getDataScopeFor2D(configOptions, modelInstance, data, designerConfig) {
24
+ static initDataScopeFor2D(configOptions, modelInstance, data, designerConfig) {
23
25
  // Для interval всегда один элемент, так как там может быть только один столбик
24
26
  let itemsLength = 1;
25
27
  if (configOptions.type === '2d') {
@@ -34,45 +36,54 @@ export class DataManagerModel {
34
36
  const dataLength = uniqueKeys.length;
35
37
  const limit = this.getDataLimitByItemSize(this.getElementsInGroupAmount(configOptions, itemsLength), dataLength, axisLength, designerConfig.canvas.chartOptions.bar);
36
38
  const allowableKeys = uniqueKeys.slice(0, limit);
37
- return {
38
- allowableKeys,
39
- hidedRecordsAmount: dataLength - allowableKeys.length
40
- };
39
+ const hidedRecordsAmount = dataLength - allowableKeys.length;
40
+ modelInstance.dataModel.initScope(this.limitAllowableKeys(allowableKeys, hidedRecordsAmount, modelInstance.dataModel));
41
+ }
42
+ else {
43
+ const allKeys = this.getDataValuesByKeyField(data, configOptions.data.dataSource, configOptions.data.keyField.name);
44
+ modelInstance.dataModel.initScope(this.getMaximumPossibleScope(allKeys, modelInstance.dataModel));
41
45
  }
42
- return {
43
- allowableKeys: this.getDataValuesByKeyField(data, configOptions.data.dataSource, configOptions.data.keyField.name),
44
- hidedRecordsAmount: 0
45
- };
46
46
  }
47
- static getDataScopeForPolar(configOptions, modelInstance, data, legendBlock, legendCanvas) {
48
- const canvas = modelInstance.canvasModel;
49
- const dataset = data[configOptions.data.dataSource];
47
+ static initDataScopeForPolar(configOptions, modelInstance, data, legendBlock, legendCanvas) {
48
+ const canvasModel = modelInstance.canvasModel;
50
49
  const keyFieldName = configOptions.data.keyField.name;
51
- const keys = dataset.map(dataRow => dataRow[keyFieldName]);
50
+ const keys = data[configOptions.data.dataSource].map(dataRow => dataRow[keyFieldName]);
52
51
  if (!configOptions.legend.show) {
53
- return {
54
- allowableKeys: keys,
55
- hidedRecordsAmount: 0
56
- };
52
+ modelInstance.dataModel.initScope(this.getMaximumPossibleScope(keys, modelInstance.dataModel));
53
+ return;
54
+ }
55
+ let position = PolarModel.getLegendPositionByBlockSize(modelInstance.canvasModel);
56
+ let { amount: maxItemsNumber, size } = this.getLegendDataParams(position, keys, legendCanvas, canvasModel, legendBlock);
57
+ if (position === "right" && !PolarModel.doesChartBlockHasEnoughWidthForContainsLegend(canvasModel.getChartBlockWidth(), size.width, legendBlock.coordinate)) {
58
+ const doesFreeSpaceExist = PolarModel.doesChartBlockHasEnoughHeightForContainsLegend(canvasModel.getChartBlockHeight(), legendBlock.coordinate);
59
+ if (doesFreeSpaceExist) {
60
+ const newParams = this.getLegendDataParams("bottom", keys, legendCanvas, canvasModel, legendBlock);
61
+ position = "bottom";
62
+ maxItemsNumber = newParams.amount;
63
+ size = newParams.size;
64
+ }
57
65
  }
58
- let position;
59
- if (canvas.getChartBlockWidth() >= MIN_DONUT_BLOCK_SIZE)
60
- position = 'right';
61
- else
62
- position = 'bottom';
63
- let maxItemsNumber;
66
+ //TODO: global refactor of method
67
+ const allowableKeys = keys.slice(0, maxItemsNumber);
68
+ const hidedRecordsAmount = keys.length - maxItemsNumber;
69
+ const marginCalculator = new LegendPolarMarginCalculator();
70
+ marginCalculator.updateMargin(position, canvasModel, legendBlock, position === "bottom" ? size.height : size.width);
71
+ modelInstance.dataModel.initScope(this.limitAllowableKeys(allowableKeys, hidedRecordsAmount, modelInstance.dataModel));
72
+ }
73
+ //TODO: position type
74
+ static getLegendDataParams(position, keys, legendCanvas, canvasModel, legendBlock) {
64
75
  if (position === 'right') {
65
- maxItemsNumber = LegendCanvasModel.findElementsAmountByLegendSize(keys, position, legendCanvas.maxWidth, canvas.getChartBlockHeight());
76
+ return LegendCanvasModel.findElementsAmountByLegendSize(keys, position, legendCanvas.maxWidth, canvasModel.getChartBlockHeight() - legendBlock.coordinate.bottom.margin.bottom);
66
77
  }
67
78
  else {
68
- const margin = canvas.getMargin();
69
- const marginBottomWithoutLegendBlock = margin.bottom - (legendBlock.coordinate.bottom.size === 0 ? legendBlock.coordinate.bottom.size : legendBlock.coordinate.bottom.size - legendBlock.coordinate.bottom.margin.bottom);
70
- maxItemsNumber = LegendCanvasModel.findElementsAmountByLegendSize(keys, position, canvas.getChartBlockWidth(), canvas.getBlockSize().height - margin.top - marginBottomWithoutLegendBlock - legendBlock.coordinate.bottom.margin.bottom - MIN_DONUT_BLOCK_SIZE);
79
+ return LegendCanvasModel.findElementsAmountByLegendSize(keys, position, canvasModel.getChartBlockWidth() - legendBlock.coordinate.bottom.margin.left - legendBlock.coordinate.bottom.margin.right, canvasModel.getChartBlockHeight() - legendBlock.coordinate.bottom.margin.bottom - legendBlock.coordinate.bottom.margin.top - MIN_DONUT_BLOCK_SIZE);
71
80
  }
72
- return {
73
- allowableKeys: keys.slice(0, maxItemsNumber),
74
- hidedRecordsAmount: keys.length - maxItemsNumber
75
- };
81
+ }
82
+ static getMaximumPossibleScope(keys, dataModel) {
83
+ return this.service.getMaximumPossibleAmount(keys, dataModel.getMaxRecordsAmount());
84
+ }
85
+ static limitAllowableKeys(allowableKeys, hidedRecordsAmount, dataModel) {
86
+ return this.service.limitAllowableKeys(allowableKeys, hidedRecordsAmount, dataModel.getMaxRecordsAmount());
76
87
  }
77
88
  /**
78
89
  * Выводит количество элементов (преимущественно баров) в одной группе. Группа - один ключ
@@ -103,13 +114,7 @@ export class DataManagerModel {
103
114
  return data.filter(d => allowableKeys.findIndex(key => key === d[keyFieldName]) !== -1);
104
115
  }
105
116
  static setDataType(data, config) {
106
- if (config.options.type === 'polar' || config.options.type === '2d') {
107
- // Форматиривание для оси ключей пока не совсем верно установлено
108
- // if(config.options.data.keyField.format === 'date') {
109
- // data[config.options.data.dataSource] = this.getTypedData(data[config.options.data.dataSource], config.options.data.keyField);
110
- // }
111
- }
112
- else if (config.options.type === 'interval') {
117
+ if (config.options.type === 'interval') {
113
118
  const chart = config.options.chart;
114
119
  if (chart.data.valueField1.format === 'date') {
115
120
  data[config.options.data.dataSource] = this.getTypedData(data[config.options.data.dataSource], chart.data.valueField1);
@@ -137,3 +142,4 @@ export class DataManagerModel {
137
142
  return dataLength;
138
143
  }
139
144
  }
145
+ DataManagerModel.service = new DataManagerModelService();
@@ -0,0 +1,5 @@
1
+ import { DataScope } from "../model";
2
+ export declare class DataManagerModelService {
3
+ getMaximumPossibleAmount(keys: string[], maxPossibleAmount: number): DataScope;
4
+ limitAllowableKeys(allowableKeys: string[], hidedRecordsAmount: number, globalRecordsMaxAmount: number): DataScope;
5
+ }
@@ -0,0 +1,28 @@
1
+ export class DataManagerModelService {
2
+ getMaximumPossibleAmount(keys, maxPossibleAmount) {
3
+ if (maxPossibleAmount >= keys.length) {
4
+ return {
5
+ allowableKeys: keys,
6
+ hidedRecordsAmount: 0
7
+ };
8
+ }
9
+ else {
10
+ return {
11
+ allowableKeys: keys.slice(0, maxPossibleAmount),
12
+ hidedRecordsAmount: keys.length - maxPossibleAmount
13
+ };
14
+ }
15
+ }
16
+ limitAllowableKeys(allowableKeys, hidedRecordsAmount, globalRecordsMaxAmount) {
17
+ if (allowableKeys.length <= globalRecordsMaxAmount) {
18
+ return {
19
+ allowableKeys,
20
+ hidedRecordsAmount
21
+ };
22
+ }
23
+ return {
24
+ allowableKeys: allowableKeys.slice(0, globalRecordsMaxAmount),
25
+ hidedRecordsAmount: hidedRecordsAmount + allowableKeys.length - globalRecordsMaxAmount
26
+ };
27
+ }
28
+ }
@@ -1,5 +1,5 @@
1
- import { AxisPosition, ChartOrientation, DataOptions, MdtChartsDataSource, DiscreteAxisOptions, NumberAxisOptions, TwoDimensionalChart } from "../../config/config";
2
- import { AxisLabelPosition, AxisModelOptions, Orient } from "../model";
1
+ import { AxisPosition, ChartOrientation, MdtChartsDataSource, NumberAxisOptions, AxisLabelPosition, MdtChartsTwoDimensionalOptions, DiscreteAxisOptions } from "../../config/config";
2
+ import { AxisModelOptions, Orient } from "../model";
3
3
  import { AxisType } from "../modelBuilder";
4
4
  import { AxisLabelCanvas, TooltipSettings } from "../../designer/designerConfig";
5
5
  import { CanvasModel } from "../modelInstance/canvasModel/canvasModel";
@@ -8,12 +8,13 @@ export interface LabelSize {
8
8
  height: number;
9
9
  }
10
10
  export declare class AxisModel {
11
- static getKeyAxis(charts: TwoDimensionalChart[], data: MdtChartsDataSource, dataOptions: DataOptions, orient: ChartOrientation, axisConfig: DiscreteAxisOptions, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel, tooltipSettings: TooltipSettings): AxisModelOptions;
11
+ private static service;
12
+ static getKeyAxis(options: MdtChartsTwoDimensionalOptions, data: MdtChartsDataSource, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel, tooltipSettings: TooltipSettings): AxisModelOptions;
12
13
  static getValueAxis(orient: ChartOrientation, axisConfig: NumberAxisOptions, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel): AxisModelOptions;
13
14
  static getAxisLength(chartOrientation: ChartOrientation, canvasModel: CanvasModel): number;
14
15
  static getAxisOrient(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition): Orient;
15
16
  static getAxisTranslateX(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition, canvasModel: CanvasModel): number;
16
17
  static getAxisTranslateY(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition, canvasModel: CanvasModel): number;
17
- static getKeyAxisLabelPosition(canvasModel: CanvasModel, scopedDataLength: number): AxisLabelPosition;
18
+ static getKeyAxisLabelPosition(canvasModel: CanvasModel, scopedDataLength: number, axisConfig?: DiscreteAxisOptions): AxisLabelPosition;
18
19
  static getLabelSize(labelMaxWidth: number, labelTexts: any[]): LabelSize;
19
20
  }
@@ -1,22 +1,25 @@
1
1
  import { ModelHelper } from "../modelHelper";
2
2
  import { AxisType, CLASSES } from "../modelBuilder";
3
- import { DataManagerModel } from "../dataManagerModel";
3
+ import { DataManagerModel } from "../dataManagerModel/dataManagerModel";
4
4
  import { TwoDimensionalModel } from "../notations/twoDimensionalModel";
5
+ import { AxisModelService } from "./axisModelService";
5
6
  export class AxisModel {
6
- static getKeyAxis(charts, data, dataOptions, orient, axisConfig, labelConfig, canvasModel, tooltipSettings) {
7
+ static getKeyAxis(options, data, labelConfig, canvasModel, tooltipSettings) {
8
+ const { charts, orientation, data: dataOptions } = options;
9
+ const axisConfig = options.axis.key;
7
10
  return {
8
11
  type: 'key',
9
- orient: AxisModel.getAxisOrient(AxisType.Key, orient, axisConfig.position),
12
+ orient: AxisModel.getAxisOrient(AxisType.Key, orientation, axisConfig.position),
10
13
  translate: {
11
- translateX: AxisModel.getAxisTranslateX(AxisType.Key, orient, axisConfig.position, canvasModel),
12
- translateY: AxisModel.getAxisTranslateY(AxisType.Key, orient, axisConfig.position, canvasModel)
14
+ translateX: AxisModel.getAxisTranslateX(AxisType.Key, orientation, axisConfig.position, canvasModel),
15
+ translateY: AxisModel.getAxisTranslateY(AxisType.Key, orientation, axisConfig.position, canvasModel)
13
16
  },
14
17
  cssClass: 'key-axis',
15
18
  ticks: axisConfig.ticks,
16
19
  labels: {
17
20
  maxSize: AxisModel.getLabelSize(labelConfig.maxSize.main, data[dataOptions.dataSource].map(d => d[dataOptions.keyField.name])).width,
18
- position: AxisModel.getKeyAxisLabelPosition(canvasModel, DataManagerModel.getDataValuesByKeyField(data, dataOptions.dataSource, dataOptions.keyField.name).length),
19
- visible: !TwoDimensionalModel.getChartsEmbeddedLabelsFlag(charts, orient),
21
+ position: AxisModel.getKeyAxisLabelPosition(canvasModel, DataManagerModel.getDataValuesByKeyField(data, dataOptions.dataSource, dataOptions.keyField.name).length, axisConfig),
22
+ visible: !TwoDimensionalModel.getChartsEmbeddedLabelsFlag(charts, orientation),
20
23
  defaultTooltip: tooltipSettings.position === 'fixed'
21
24
  },
22
25
  visibility: axisConfig.visibility
@@ -75,11 +78,9 @@ export class AxisModel {
75
78
  return canvasModel.getBlockSize().height - canvasModel.getMarginSide("bottom");
76
79
  return canvasModel.getMarginSide("top");
77
80
  }
78
- static getKeyAxisLabelPosition(canvasModel, scopedDataLength) {
79
- const minBandSize = 50;
80
- if (canvasModel.getChartBlockWidth() / scopedDataLength < minBandSize)
81
- return 'rotated';
82
- return 'straight';
81
+ static getKeyAxisLabelPosition(canvasModel, scopedDataLength, axisConfig) {
82
+ var _a;
83
+ return this.service.getKeyAxisLabelPosition(canvasModel.getChartBlockWidth(), scopedDataLength, (_a = axisConfig === null || axisConfig === void 0 ? void 0 : axisConfig.labels) === null || _a === void 0 ? void 0 : _a.position);
83
84
  }
84
85
  static getLabelSize(labelMaxWidth, labelTexts) {
85
86
  const labelSize = {
@@ -109,3 +110,4 @@ export class AxisModel {
109
110
  return labelSize;
110
111
  }
111
112
  }
113
+ AxisModel.service = new AxisModelService();
@@ -0,0 +1,4 @@
1
+ import { AxisLabelPosition } from "../../config/config";
2
+ export declare class AxisModelService {
3
+ getKeyAxisLabelPosition(chartBlockWidth: number, scopedDataLength: number, positionFromConfig?: AxisLabelPosition): AxisLabelPosition;
4
+ }
@@ -0,0 +1,11 @@
1
+ export class AxisModelService {
2
+ getKeyAxisLabelPosition(chartBlockWidth, scopedDataLength, positionFromConfig) {
3
+ if (positionFromConfig === "rotated" || positionFromConfig === "straight") {
4
+ return positionFromConfig;
5
+ }
6
+ const minBandSize = 50;
7
+ if (chartBlockWidth / scopedDataLength < minBandSize)
8
+ return 'rotated';
9
+ return 'straight';
10
+ }
11
+ }
@@ -1,7 +1,9 @@
1
+ import { DataLegendParams } from "../../dataManagerModel/dataManagerModel";
1
2
  import { LegendPosition } from "../../model";
2
3
  export declare type LegendItemsDirection = 'row' | 'column';
3
4
  export declare class LegendCanvasModel {
4
- static getLegendHeight(texts: string[], blockWidth: number, marginLeft: number, marginRight: number, itemsPosition: LegendItemsDirection, legendPosition: LegendPosition): number;
5
+ static getLegendHeight(texts: string[], chartBlockWidth: number, itemsDirection: LegendItemsDirection, legendPosition: LegendPosition): number;
5
6
  static getLegendItemWidth(text: string): number;
6
- static findElementsAmountByLegendSize(texts: string[], position: LegendPosition, legendBlockWidth: number, legendBlockHeight: number): number;
7
+ static findElementsAmountByLegendSize(texts: string[], position: LegendPosition, legendBlockWidth: number, legendBlockHeight: number): DataLegendParams;
8
+ private static getLegendWrapperEl;
7
9
  }
@@ -1,22 +1,18 @@
1
1
  import { CLASSES } from "../../modelBuilder";
2
- import { LegendModel } from "./legendModel";
3
2
  export class LegendCanvasModel {
4
- static getLegendHeight(texts, blockWidth, marginLeft, marginRight, itemsPosition, legendPosition) {
5
- const legendWrapper = document.createElement('div');
6
- legendWrapper.style.opacity = '0';
7
- legendWrapper.style.display = 'flex';
8
- if (itemsPosition === 'column')
9
- legendWrapper.style.flexDirection = 'column';
10
- legendWrapper.style.position = 'absolute';
11
- legendWrapper.style.width = blockWidth - marginLeft - marginRight + 'px';
3
+ static getLegendHeight(texts, chartBlockWidth, itemsDirection, legendPosition) {
4
+ const legendWrapper = this.getLegendWrapperEl(chartBlockWidth, itemsDirection);
12
5
  texts.forEach(text => {
13
6
  const itemWrapper = document.createElement('div');
14
7
  const colorBlock = document.createElement('span');
15
8
  const textBlock = document.createElement('span');
16
- itemWrapper.classList.add(LegendModel.getLegendItemClass(itemsPosition));
17
- if (itemsPosition === 'column') {
18
- itemWrapper.style.whiteSpace = 'nowrap';
19
- itemWrapper.classList.add(LegendModel.getMarginClass(legendPosition));
9
+ itemWrapper.classList.add("legend-item");
10
+ if (legendPosition === 'bottom') {
11
+ itemWrapper.classList.add('legend-item-inline');
12
+ textBlock.classList.add('legend-label-nowrap');
13
+ }
14
+ else {
15
+ itemWrapper.classList.add('legend-item-row');
20
16
  }
21
17
  colorBlock.classList.add(CLASSES.legendColor);
22
18
  textBlock.classList.add(CLASSES.legendLabel);
@@ -27,7 +23,7 @@ export class LegendCanvasModel {
27
23
  document.body.append(legendWrapper);
28
24
  const height = legendWrapper.offsetHeight;
29
25
  legendWrapper.remove();
30
- return height;
26
+ return height + 1;
31
27
  }
32
28
  static getLegendItemWidth(text) {
33
29
  const itemWrapper = document.createElement('div');
@@ -48,39 +44,56 @@ export class LegendCanvasModel {
48
44
  return sumWidth;
49
45
  }
50
46
  static findElementsAmountByLegendSize(texts, position, legendBlockWidth, legendBlockHeight) {
51
- const legendWrapper = document.createElement('div');
52
- legendWrapper.style.opacity = '0';
53
- legendWrapper.style.display = 'flex';
54
- legendWrapper.style.flexDirection = 'column';
55
- legendWrapper.style.position = 'absolute';
56
- legendWrapper.style.width = legendBlockWidth + 'px';
47
+ const legendWrapper = this.getLegendWrapperEl(legendBlockWidth, position === "right" ? "column" : "row");
57
48
  document.body.append(legendWrapper);
58
49
  let amount = 0;
59
50
  for (let i = 0; i < texts.length; i++) {
60
51
  const itemWrapper = document.createElement('div');
61
52
  const colorBlock = document.createElement('span');
62
53
  const textBlock = document.createElement('span');
63
- itemWrapper.classList.add('legend-item-row');
64
- if (position === 'bottom')
65
- textBlock.classList.add('legend-label-nowrap', 'mt-10');
66
- else
67
- itemWrapper.classList.add('mt-15');
54
+ itemWrapper.classList.add("legend-item");
55
+ if (position === 'bottom') {
56
+ itemWrapper.classList.add('legend-item-inline');
57
+ textBlock.classList.add('legend-label-nowrap');
58
+ }
59
+ else {
60
+ itemWrapper.classList.add('legend-item-row');
61
+ }
68
62
  colorBlock.classList.add(CLASSES.legendColor);
69
63
  textBlock.classList.add(CLASSES.legendLabel);
70
64
  textBlock.textContent = texts[i];
71
65
  itemWrapper.append(colorBlock, textBlock);
72
66
  legendWrapper.append(itemWrapper);
67
+ amount++;
73
68
  if (legendWrapper.offsetHeight > legendBlockHeight) {
74
69
  itemWrapper.remove();
75
70
  if (legendBlockHeight - legendWrapper.offsetHeight >= 15 && position !== 'bottom')
76
- amount = i;
71
+ amount = amount; //TODO: remove
77
72
  else
78
- amount = i - 1;
73
+ amount -= 1;
79
74
  break;
80
75
  }
81
- amount++;
82
76
  }
77
+ const size = {
78
+ width: legendWrapper.offsetWidth,
79
+ height: legendWrapper.offsetHeight
80
+ };
83
81
  legendWrapper.remove();
84
- return amount < 0 ? 0 : amount;
82
+ return {
83
+ amount: amount < 0 ? 0 : amount,
84
+ size
85
+ };
86
+ }
87
+ static getLegendWrapperEl(legendBlockWidth, itemsDirection) {
88
+ const legendWrapper = document.createElement('div');
89
+ legendWrapper.style.opacity = '0';
90
+ legendWrapper.style.position = 'absolute';
91
+ legendWrapper.style.display = "flex";
92
+ if (itemsDirection === "column")
93
+ legendWrapper.classList.add("legend-block-column");
94
+ else
95
+ legendWrapper.classList.add("legend-block-row", "legend-wrapper-with-wrap");
96
+ legendWrapper.style.maxWidth = legendBlockWidth + 'px';
97
+ return legendWrapper;
85
98
  }
86
99
  }