mdt-charts 1.12.0 → 1.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/lib/config/config.d.ts +5 -0
  2. package/lib/engine/features/legend/legend.d.ts +10 -1
  3. package/lib/engine/features/legend/legend.js +10 -22
  4. package/lib/engine/features/legend/legendHelper.d.ts +4 -5
  5. package/lib/engine/features/legend/legendHelper.js +19 -23
  6. package/lib/engine/features/legend/legendHelperService.d.ts +12 -0
  7. package/lib/engine/features/legend/legendHelperService.js +30 -0
  8. package/lib/engine/polarNotation/extenders/polarRecordOverflowAlert.d.ts +0 -1
  9. package/lib/engine/polarNotation/extenders/polarRecordOverflowAlert.js +9 -17
  10. package/lib/model/dataManagerModel/dataManagerModel.d.ts +8 -0
  11. package/lib/model/dataManagerModel/dataManagerModel.js +25 -12
  12. package/lib/model/featuresModel/axisModel.d.ts +5 -4
  13. package/lib/model/featuresModel/axisModel.js +13 -11
  14. package/lib/model/featuresModel/axisModelService.d.ts +4 -0
  15. package/lib/model/featuresModel/axisModelService.js +11 -0
  16. package/lib/model/featuresModel/legendModel/legendCanvasModel.d.ts +4 -2
  17. package/lib/model/featuresModel/legendModel/legendCanvasModel.js +42 -29
  18. package/lib/model/featuresModel/legendModel/legendModel.d.ts +1 -2
  19. package/lib/model/featuresModel/legendModel/legendModel.js +14 -14
  20. package/lib/model/featuresModel/legendModel/polarMarginCalculator.d.ts +11 -0
  21. package/lib/model/featuresModel/legendModel/polarMarginCalculator.js +42 -0
  22. package/lib/model/featuresModel/titleModel.js +1 -1
  23. package/lib/model/marginModel.d.ts +3 -2
  24. package/lib/model/marginModel.js +5 -2
  25. package/lib/model/model.d.ts +1 -2
  26. package/lib/model/modelBuilder.js +2 -2
  27. package/lib/model/notations/polarModel.d.ts +3 -1
  28. package/lib/model/notations/polarModel.js +12 -1
  29. package/lib/model/notations/twoDimensionalModel.js +1 -1
  30. package/lib/style/charts-main.css +26 -7
  31. package/lib/style/charts-main.less +26 -7
  32. package/package.json +2 -2
  33. package/tsconfig.production.json +23 -0
  34. package/lib/engine/features/recordOverflowAlert/recordOverflowAlert.d.ts +0 -14
  35. package/lib/engine/features/recordOverflowAlert/recordOverflowAlert.js +0 -97
  36. package/lib/model/dataManagerModel.d.ts +0 -23
  37. package/lib/model/dataManagerModel.js +0 -139
@@ -14,6 +14,7 @@ export declare type MdtChartsDataRow = {
14
14
  export interface MdtChartsDataSource {
15
15
  [source: string]: MdtChartsDataRow[];
16
16
  }
17
+ export declare type AxisLabelPosition = "straight" | "rotated";
17
18
  export interface MdtChartsConfig {
18
19
  canvas: ChartBlockCanvas;
19
20
  options: MdtChartsPolarOptions | MdtChartsTwoDimensionalOptions | IntervalOptions;
@@ -106,6 +107,10 @@ export interface NumberDomain {
106
107
  end: number;
107
108
  }
108
109
  export interface DiscreteAxisOptions extends AxisOptions {
110
+ labels?: MdtChartsDiscreteAxisLabel;
111
+ }
112
+ export interface MdtChartsDiscreteAxisLabel {
113
+ position?: AxisLabelPosition;
109
114
  }
110
115
  export interface IntervalAxis {
111
116
  key: DiscreteAxisOptions;
@@ -3,12 +3,21 @@ import { MdtChartsDataSource } from "../../../config/config";
3
3
  import { IntervalOptionsModel, Model, PolarOptionsModel, TwoDimensionalOptionsModel } from "../../../model/model";
4
4
  import { Block } from "../../block/block";
5
5
  import { SelectionCondition } from "../../helpers/domHelper";
6
+ export interface LegendContentRenderingOptions {
7
+ wrapperClasses: string[];
8
+ shouldCropLabels: boolean;
9
+ itemsOptions: {
10
+ wrapperClasses: string[];
11
+ markerClass: string;
12
+ labelClass: string;
13
+ };
14
+ }
6
15
  export declare class Legend {
7
16
  static readonly objectClass = "legend-object";
8
17
  static readonly labelClass = "legend-label";
9
18
  static readonly itemClass = "legend-item";
10
19
  static readonly markerClass = "legend-circle";
11
- private static readonly legendBlockClass;
20
+ static readonly legendBlockClass = "legend-block";
12
21
  static render(block: Block, data: MdtChartsDataSource, options: TwoDimensionalOptionsModel | PolarOptionsModel | IntervalOptionsModel, model: Model): void;
13
22
  static update(block: Block, data: MdtChartsDataSource, model: Model): void;
14
23
  static updateColors(block: Block, options: TwoDimensionalOptionsModel | PolarOptionsModel | IntervalOptionsModel): void;
@@ -1,4 +1,3 @@
1
- import { select } from "d3-selection";
2
1
  import { ColorReader } from "../../colorReader/colorReader";
3
2
  import { SelectionCondition } from "../../helpers/domHelper";
4
3
  import { LegendDomHelper } from "./legendDomHelper";
@@ -41,8 +40,8 @@ export class Legend {
41
40
  static setContent(block, data, options, legendObject) {
42
41
  const items = LegendHelper.getLegendItemsContent(options, data);
43
42
  const colors = LegendHelper.getMarksColor(options, data[options.data.dataSource]);
44
- const itemsDirection = LegendHelper.getLegendItemsDirection(options.type, options.legend.position);
45
- const itemBlocks = this.renderContent(legendObject, items, colors, itemsDirection, options.legend.position);
43
+ const renderingOptions = LegendHelper.getContentRenderingOptions(options.type, options.legend.position);
44
+ const itemBlocks = this.renderContent(legendObject, items, colors, renderingOptions);
46
45
  if (options.type === 'polar') {
47
46
  LegendEventsManager.setListeners(block, options.data.keyField.name, itemBlocks, options.selectable);
48
47
  }
@@ -58,36 +57,25 @@ export class Legend {
58
57
  this.fillCoordinate(legendObject, legendCoordinate);
59
58
  return legendObject;
60
59
  }
61
- static renderContent(legendObject, items, colorPalette, itemsDirection, position) {
62
- const wrapper = legendObject.append('xhtml:div')
63
- .attr('class', Legend.legendBlockClass);
64
- wrapper
65
- .style('height', '100%')
66
- .style('display', 'flex');
67
- if (itemsDirection === 'column') {
68
- wrapper.style('flex-direction', 'column');
69
- if (position === 'right')
70
- wrapper.style('justify-content', 'center');
71
- }
60
+ static renderContent(foreignObject, items, colorPalette, options) {
61
+ const wrapper = foreignObject.append('xhtml:div');
62
+ wrapper.classed(options.wrapperClasses.join(" "), true);
72
63
  const itemWrappers = wrapper
73
64
  .selectAll(`.${this.itemClass}`)
74
65
  .data(items)
75
66
  .enter()
76
67
  .append('div');
77
- const thisClass = this;
78
- itemWrappers.each(function (d, i) {
79
- select(this).attr('class', `${thisClass.itemClass} ${LegendHelper.getItemClasses(itemsDirection, position, i)}`);
80
- });
68
+ itemWrappers.classed(options.itemsOptions.wrapperClasses.join(" "), true);
81
69
  itemWrappers
82
70
  .append('span')
83
- .attr('class', this.markerClass);
71
+ .classed(options.itemsOptions.markerClass, true);
84
72
  LegendDomHelper.setItemsColors(itemWrappers, colorPalette);
85
73
  itemWrappers
86
74
  .append('span')
87
- .attr('class', LegendHelper.getLegendLabelClassByPosition(position))
75
+ .attr('class', options.itemsOptions.labelClass)
88
76
  .text(d => d);
89
- if (itemsDirection === 'row')
90
- LegendDomHelper.cropRowLabels(legendObject, itemWrappers);
77
+ if (options.shouldCropLabels)
78
+ LegendDomHelper.cropRowLabels(foreignObject, itemWrappers);
91
79
  return itemWrappers;
92
80
  }
93
81
  static getObject(block) {
@@ -1,6 +1,8 @@
1
1
  import { ChartNotation, MdtChartsDataRow, MdtChartsDataSource, Size } from "../../../config/config";
2
2
  import { LegendItemsDirection } from "../../../model/featuresModel/legendModel/legendCanvasModel";
3
3
  import { IntervalOptionsModel, LegendBlockModel, LegendPosition, Orient, PolarOptionsModel, TwoDimensionalOptionsModel } from "../../../model/model";
4
+ import { LegendContentRenderingOptions } from "./legend";
5
+ import { LegendHelperService } from "./legendHelperService";
4
6
  export interface LegendCoordinate {
5
7
  x: number;
6
8
  y: number;
@@ -8,14 +10,11 @@ export interface LegendCoordinate {
8
10
  width: number;
9
11
  }
10
12
  export declare class LegendHelper {
13
+ static service: LegendHelperService;
11
14
  static getLegendItemsContent(options: TwoDimensionalOptionsModel | PolarOptionsModel | IntervalOptionsModel, data: MdtChartsDataSource): string[];
12
15
  static getMarksColor(options: TwoDimensionalOptionsModel | PolarOptionsModel | IntervalOptionsModel, dataRows?: MdtChartsDataRow[]): string[];
13
16
  static getMaxItemWidth(legendBlockWidth: string, marginsLeft: number[], itemsDirection: LegendItemsDirection): number;
14
- static getItemClasses(itemsDirection: LegendItemsDirection, position: LegendPosition, index: number): string;
15
- static getLegendItemClassByDirection(itemsDirection: LegendItemsDirection): string;
16
- static getLegendItemsMarginClass(legendPosition: LegendPosition): string;
17
- static getLegendLabelClassByPosition(position: LegendPosition): string;
18
- static getLegendItemsDirection(chartNotation: ChartNotation, legendPosition: LegendPosition): LegendItemsDirection;
19
17
  static getSumOfItemsWidths(itemsWidth: number[], marginsLeft: number[]): number;
20
18
  static getLegendCoordinateByPosition(legendPosition: Orient, legendBlockModel: LegendBlockModel, blockSize: Size): LegendCoordinate;
19
+ static getContentRenderingOptions(chartNotation: ChartNotation, legendPosition: LegendPosition): LegendContentRenderingOptions;
21
20
  }
@@ -1,5 +1,6 @@
1
1
  import { Helper } from '../../helpers/helper';
2
2
  import { Legend } from "./legend";
3
+ import { LegendHelperService } from "./legendHelperService";
3
4
  export class LegendHelper {
4
5
  static getLegendItemsContent(options, data) {
5
6
  if (options.type === '2d') {
@@ -40,29 +41,6 @@ export class LegendHelper {
40
41
  }
41
42
  return parseFloat(legendBlockWidth);
42
43
  }
43
- static getItemClasses(itemsDirection, position, index) {
44
- let cssClasses = this.getLegendItemClassByDirection(itemsDirection);
45
- if (itemsDirection === 'column' && index !== 0)
46
- cssClasses += ` ${this.getLegendItemsMarginClass(position)}`;
47
- return cssClasses;
48
- }
49
- static getLegendItemClassByDirection(itemsDirection) {
50
- return itemsDirection === 'column' ? 'legend-item-row' : 'legend-item-inline';
51
- }
52
- static getLegendItemsMarginClass(legendPosition) {
53
- return legendPosition === 'right' ? 'mt-15' : 'mt-10';
54
- }
55
- static getLegendLabelClassByPosition(position) {
56
- if (position === 'top' || position === 'bottom')
57
- return `${Legend.labelClass} ${Legend.labelClass + '-nowrap'}`;
58
- return Legend.labelClass;
59
- }
60
- static getLegendItemsDirection(chartNotation, legendPosition) {
61
- if (legendPosition === 'right' || legendPosition === 'left')
62
- return 'column';
63
- else
64
- return chartNotation === 'polar' ? 'column' : 'row';
65
- }
66
44
  static getSumOfItemsWidths(itemsWidth, marginsLeft) {
67
45
  let sumOfItemsWidth = Helper.getSumOfNumeric(itemsWidth);
68
46
  sumOfItemsWidth += Helper.getSumOfNumeric(marginsLeft);
@@ -96,4 +74,22 @@ export class LegendHelper {
96
74
  coordinate.y = blockSize.height - legendModel.size - legendModel.margin.bottom;
97
75
  return coordinate;
98
76
  }
77
+ static getContentRenderingOptions(chartNotation, legendPosition) {
78
+ const itemsDirection = this.service.getLegendItemsDirection(legendPosition);
79
+ return {
80
+ wrapperClasses: [
81
+ Legend.legendBlockClass,
82
+ this.service.getWrapperClassByItemsDirection(itemsDirection),
83
+ this.service.getWrapperJustifyContentClass(itemsDirection, legendPosition),
84
+ this.service.getWrapperClassByWrappingItems(legendPosition, chartNotation)
85
+ ],
86
+ shouldCropLabels: chartNotation === "2d",
87
+ itemsOptions: {
88
+ markerClass: Legend.markerClass,
89
+ labelClass: this.service.getLegendLabelClassByPosition(legendPosition, chartNotation, Legend.labelClass),
90
+ wrapperClasses: [Legend.itemClass, this.service.getItemClasses(itemsDirection)]
91
+ }
92
+ };
93
+ }
99
94
  }
95
+ LegendHelper.service = new LegendHelperService();
@@ -0,0 +1,12 @@
1
+ import { ChartNotation } from "../../../config/config";
2
+ import { LegendItemsDirection } from "../../../model/featuresModel/legendModel/legendCanvasModel";
3
+ import { LegendPosition } from "../../../model/model";
4
+ export declare class LegendHelperService {
5
+ getWrapperClassByItemsDirection(itemsDirection: LegendItemsDirection): "legend-block-column" | "legend-block-row";
6
+ getWrapperJustifyContentClass(itemsDirection: LegendItemsDirection, legendPosition: LegendPosition): "" | "legend-block-centered";
7
+ getWrapperClassByWrappingItems(legendPosition: LegendPosition, chartNotation: ChartNotation): "legend-wrapper-with-wrap" | "legend-wrapper-without-wrap";
8
+ getLegendLabelClassByPosition(legendPosition: LegendPosition, chartNotation: ChartNotation, initialLabelClass: string): string;
9
+ getItemClasses(itemsDirection: LegendItemsDirection): string;
10
+ getLegendItemsDirection(legendPosition: LegendPosition): LegendItemsDirection;
11
+ private doesLegendInTopBy2d;
12
+ }
@@ -0,0 +1,30 @@
1
+ export class LegendHelperService {
2
+ getWrapperClassByItemsDirection(itemsDirection) {
3
+ return itemsDirection === "column" ? "legend-block-column" : "legend-block-row";
4
+ }
5
+ getWrapperJustifyContentClass(itemsDirection, legendPosition) {
6
+ return itemsDirection === "column" && legendPosition === "right" ? "legend-block-centered" : "";
7
+ }
8
+ getWrapperClassByWrappingItems(legendPosition, chartNotation) {
9
+ if (this.doesLegendInTopBy2d(legendPosition, chartNotation)) {
10
+ return "legend-wrapper-without-wrap";
11
+ }
12
+ return "legend-wrapper-with-wrap";
13
+ }
14
+ getLegendLabelClassByPosition(legendPosition, chartNotation, initialLabelClass) {
15
+ if (this.doesLegendInTopBy2d(legendPosition, chartNotation))
16
+ return `${initialLabelClass} ${initialLabelClass + '-nowrap'}`;
17
+ return initialLabelClass;
18
+ }
19
+ getItemClasses(itemsDirection) {
20
+ return itemsDirection === 'column' ? 'legend-item-row' : 'legend-item-inline';
21
+ }
22
+ getLegendItemsDirection(legendPosition) {
23
+ if (legendPosition === 'right' || legendPosition === 'left')
24
+ return 'column';
25
+ return "row";
26
+ }
27
+ doesLegendInTopBy2d(legendPosition, chartNotation) {
28
+ return legendPosition === 'top' && chartNotation === "2d";
29
+ }
30
+ }
@@ -10,7 +10,6 @@ declare class PolarRecordOverflowAlertClass {
10
10
  update(block: Block, options: PolarRecordOverflowAlertOptions): void;
11
11
  private buildCoreOptions;
12
12
  private getPositionAttrs;
13
- private getLeftAttrForRightBlock;
14
13
  }
15
14
  export declare const PolarRecordOverflowAlert: PolarRecordOverflowAlertClass;
16
15
  export {};
@@ -1,6 +1,4 @@
1
- import { Legend } from "../../features/legend/legend";
2
1
  import { RecordOverflowAlertCore } from "../../features/recordOverflowAlert/recordOverflowAlertCore";
3
- import { DomHelper } from "../../helpers/domHelper";
4
2
  class PolarRecordOverflowAlertClass {
5
3
  constructor() {
6
4
  this.text = {
@@ -11,38 +9,32 @@ class PolarRecordOverflowAlertClass {
11
9
  };
12
10
  }
13
11
  render(block, options) {
14
- RecordOverflowAlertCore.render(block, this.buildCoreOptions(block, options));
12
+ RecordOverflowAlertCore.render(block, this.buildCoreOptions(options));
15
13
  }
16
14
  update(block, options) {
17
- RecordOverflowAlertCore.update(block, this.buildCoreOptions(block, options));
15
+ RecordOverflowAlertCore.update(block, this.buildCoreOptions(options));
18
16
  }
19
- buildCoreOptions(block, options) {
17
+ buildCoreOptions(options) {
20
18
  return {
21
19
  hidedRecordsAmount: options.hidedRecordsAmount,
22
20
  text: this.text,
23
- positionAttrs: this.getPositionAttrs(block, options)
21
+ positionAttrs: this.getPositionAttrs(options)
24
22
  };
25
23
  }
26
- getPositionAttrs(block, options) {
24
+ getPositionAttrs(options) {
27
25
  const position = options.legendPosition === 'off' ? 'bottom' : options.legendPosition;
28
26
  if (position === 'right') {
29
27
  return {
30
- bottom: '20px',
31
- left: this.getLeftAttrForRightBlock(block) + 'px'
28
+ bottom: '0',
29
+ right: '0'
32
30
  };
33
31
  }
34
32
  if (position === 'bottom') {
35
33
  return {
36
- bottom: '20px',
37
- left: '20px'
34
+ bottom: '0',
35
+ left: '0'
38
36
  };
39
37
  }
40
38
  }
41
- getLeftAttrForRightBlock(block) {
42
- const legendBlock = block.getSvg().select(`.${Legend.objectClass}`);
43
- if (legendBlock.empty())
44
- return 17;
45
- return DomHelper.getSelectionNumericAttr(legendBlock, 'x');
46
- }
47
39
  }
48
40
  export const PolarRecordOverflowAlert = new PolarRecordOverflowAlertClass();
@@ -2,6 +2,13 @@ import { MdtChartsConfig, MdtChartsDataSource } from "../../config/config";
2
2
  import { DesignerConfig } from "../../designer/designerConfig";
3
3
  import { LegendBlockModel } from "../model";
4
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 {
6
13
  private static service;
7
14
  static getPreparedData(data: MdtChartsDataSource, allowableKeys: string[], config: MdtChartsConfig): MdtChartsDataSource;
@@ -9,6 +16,7 @@ export declare class DataManagerModel {
9
16
  static getDataValuesByKeyField(data: MdtChartsDataSource, dataSourceName: string, keyFieldName: string): string[];
10
17
  private static initDataScopeFor2D;
11
18
  private static initDataScopeForPolar;
19
+ private static getLegendDataParams;
12
20
  private static getMaximumPossibleScope;
13
21
  private static limitAllowableKeys;
14
22
  /**
@@ -1,5 +1,6 @@
1
1
  import { AxisModel } from "../featuresModel/axisModel";
2
2
  import { LegendCanvasModel } from "../featuresModel/legendModel/legendCanvasModel";
3
+ import { LegendPolarMarginCalculator } from "../featuresModel/legendModel/polarMarginCalculator";
3
4
  import { ModelHelper } from "../modelHelper";
4
5
  import { MIN_DONUT_BLOCK_SIZE, PolarModel } from "../notations/polarModel";
5
6
  import { DataManagerModelService } from "./dataManagerModelService";
@@ -44,28 +45,40 @@ export class DataManagerModel {
44
45
  }
45
46
  }
46
47
  static initDataScopeForPolar(configOptions, modelInstance, data, legendBlock, legendCanvas) {
47
- const canvas = modelInstance.canvasModel;
48
- const dataset = data[configOptions.data.dataSource];
48
+ const canvasModel = modelInstance.canvasModel;
49
49
  const keyFieldName = configOptions.data.keyField.name;
50
- const keys = dataset.map(dataRow => dataRow[keyFieldName]);
50
+ const keys = data[configOptions.data.dataSource].map(dataRow => dataRow[keyFieldName]);
51
51
  if (!configOptions.legend.show) {
52
52
  modelInstance.dataModel.initScope(this.getMaximumPossibleScope(keys, modelInstance.dataModel));
53
53
  return;
54
54
  }
55
- const position = PolarModel.getLegendPositionByBlockSize(modelInstance.canvasModel);
56
- let maxItemsNumber;
57
- if (position === 'right') {
58
- maxItemsNumber = LegendCanvasModel.findElementsAmountByLegendSize(keys, position, legendCanvas.maxWidth, canvas.getChartBlockHeight());
59
- }
60
- else {
61
- const margin = canvas.getMargin();
62
- const marginBottomWithoutLegendBlock = margin.bottom - (legendBlock.coordinate.bottom.size === 0 ? legendBlock.coordinate.bottom.size : legendBlock.coordinate.bottom.size - legendBlock.coordinate.bottom.margin.bottom);
63
- maxItemsNumber = LegendCanvasModel.findElementsAmountByLegendSize(keys, position, canvas.getChartBlockWidth(), canvas.getBlockSize().height - margin.top - marginBottomWithoutLegendBlock - legendBlock.coordinate.bottom.margin.bottom - MIN_DONUT_BLOCK_SIZE);
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
+ }
64
65
  }
66
+ //TODO: global refactor of method
65
67
  const allowableKeys = keys.slice(0, maxItemsNumber);
66
68
  const hidedRecordsAmount = keys.length - maxItemsNumber;
69
+ const marginCalculator = new LegendPolarMarginCalculator();
70
+ marginCalculator.updateMargin(position, canvasModel, legendBlock, position === "bottom" ? size.height : size.width);
67
71
  modelInstance.dataModel.initScope(this.limitAllowableKeys(allowableKeys, hidedRecordsAmount, modelInstance.dataModel));
68
72
  }
73
+ //TODO: position type
74
+ static getLegendDataParams(position, keys, legendCanvas, canvasModel, legendBlock) {
75
+ if (position === 'right') {
76
+ return LegendCanvasModel.findElementsAmountByLegendSize(keys, position, legendCanvas.maxWidth, canvasModel.getChartBlockHeight() - legendBlock.coordinate.bottom.margin.bottom);
77
+ }
78
+ else {
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);
80
+ }
81
+ }
69
82
  static getMaximumPossibleScope(keys, dataModel) {
70
83
  return this.service.getMaximumPossibleAmount(keys, dataModel.getMaxRecordsAmount());
71
84
  }
@@ -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
  }
@@ -2,21 +2,24 @@ import { ModelHelper } from "../modelHelper";
2
2
  import { AxisType, CLASSES } from "../modelBuilder";
3
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
  }
@@ -1,5 +1,5 @@
1
1
  import { ChartNotation, Size } from "../../../config/config";
2
- import { ILegendModel, LegendBlockModel, LegendPosition, Orient } from "../../model";
2
+ import { ILegendModel, LegendBlockModel, Orient } from "../../model";
3
3
  import { CanvasModel } from "../../modelInstance/canvasModel/canvasModel";
4
4
  import { LegendItemsDirection } from "./legendCanvasModel";
5
5
  export declare class LegendModel {
@@ -7,6 +7,5 @@ export declare class LegendModel {
7
7
  static getBaseLegendBlockModel(notation: ChartNotation, canvasModel: CanvasModel): LegendBlockModel;
8
8
  static getLegendModel(chartNotation: ChartNotation, legendShow: boolean, canvasModel: CanvasModel): ILegendModel;
9
9
  static getLegendItemClass(itemsPosition: LegendItemsDirection): string;
10
- static getMarginClass(legendPosition: LegendPosition): string;
11
10
  private static getLegendWidth;
12
11
  }