mdt-charts 1.23.2 → 1.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/lib/config/config.d.ts +1 -1
  2. package/lib/engine/contentManager/contentManager.d.ts +1 -0
  3. package/lib/engine/contentManager/contentManager.js +3 -0
  4. package/lib/engine/contentManager/contentManagerFactory.d.ts +2 -0
  5. package/lib/engine/engine.d.ts +1 -0
  6. package/lib/engine/engine.js +3 -0
  7. package/lib/engine/features/axis/axis.js +3 -3
  8. package/lib/engine/features/axis/axisLabelDomHelper.d.ts +1 -1
  9. package/lib/engine/features/axis/axisLabelDomHelper.js +5 -4
  10. package/lib/engine/features/valueLabelsCollision/valueLabelsCollision.d.ts +2 -1
  11. package/lib/engine/features/valueLabelsCollision/valueLabelsCollision.js +13 -9
  12. package/lib/engine/polarNotation/polarManager.d.ts +2 -0
  13. package/lib/engine/polarNotation/polarManager.js +4 -1
  14. package/lib/engine/twoDimensionalNotation/area/area.d.ts +9 -4
  15. package/lib/engine/twoDimensionalNotation/area/area.js +81 -42
  16. package/lib/engine/twoDimensionalNotation/line/line.d.ts +1 -2
  17. package/lib/engine/twoDimensionalNotation/line/line.js +17 -39
  18. package/lib/engine/twoDimensionalNotation/line/lineBuilder.d.ts +22 -0
  19. package/lib/engine/twoDimensionalNotation/line/lineBuilder.js +49 -0
  20. package/lib/engine/twoDimensionalNotation/twoDimensionalManager.d.ts +2 -0
  21. package/lib/engine/twoDimensionalNotation/twoDimensionalManager.js +6 -3
  22. package/lib/main.d.ts +5 -0
  23. package/lib/main.js +3 -0
  24. package/lib/model/featuresModel/axisModel.d.ts +3 -3
  25. package/lib/model/featuresModel/axisModel.js +11 -5
  26. package/lib/model/featuresModel/titleModel.js +2 -1
  27. package/lib/model/featuresModel/valueLabelsModel/valueLabelsModel.d.ts +6 -0
  28. package/lib/model/featuresModel/valueLabelsModel/valueLabelsModel.js +15 -3
  29. package/lib/model/helpers/modelHelper.d.ts +1 -0
  30. package/lib/model/helpers/modelHelper.js +8 -4
  31. package/lib/model/helpers/twoDimensionalModelHelper.d.ts +5 -2
  32. package/lib/model/helpers/twoDimensionalModelHelper.js +63 -0
  33. package/lib/model/margin/twoDim/twoDimMarginModel.d.ts +1 -0
  34. package/lib/model/margin/twoDim/twoDimMarginModel.js +14 -0
  35. package/lib/model/model.d.ts +16 -11
  36. package/lib/model/modelInstance/configReader.d.ts +2 -0
  37. package/lib/model/modelInstance/configReader.js +8 -2
  38. package/lib/model/notations/twoDimensional/styles.d.ts +2 -1
  39. package/lib/model/notations/twoDimensional/styles.js +28 -9
  40. package/lib/model/notations/twoDimensionalModel.d.ts +0 -1
  41. package/lib/model/notations/twoDimensionalModel.js +5 -26
  42. package/lib/style/charts-main.css +4 -2
  43. package/lib/style/charts-main.less +4 -2
  44. package/package.json +1 -1
@@ -53,7 +53,7 @@ export class TwoDimensionalManager {
53
53
  engine.block.getSvg()
54
54
  .on('click', (e) => {
55
55
  if (e.target === engine.block.getSvg().node())
56
- engine.block.filterEventManager.clearKeysFor2D(options);
56
+ this.clearSelection(engine.block.filterEventManager, model);
57
57
  });
58
58
  this.canvasValueLabels = new CanvasValueLabels({
59
59
  elementAccessors: {
@@ -113,6 +113,9 @@ export class TwoDimensionalManager {
113
113
  Area.get({ staticSettings: model.options.chartSettings.lineLike }).updateColors(block, chart);
114
114
  });
115
115
  }
116
+ clearSelection(filterEventManager, model) {
117
+ filterEventManager.clearKeysFor2D(model.options);
118
+ }
116
119
  renderCharts(block, charts, scales, data, dataOptions, margin, keyAxisOrient, chartSettings, blockSize) {
117
120
  block.svg.renderChartClipPath(margin, blockSize);
118
121
  block.svg.renderBarHatchPattern();
@@ -124,7 +127,7 @@ export class TwoDimensionalManager {
124
127
  else if (chart.type === 'line')
125
128
  Line.get({ staticSettings: chartSettings.lineLike }).render(block, chartScales, data[dataOptions.dataSource], dataOptions.keyField, margin, keyAxisOrient, chart);
126
129
  else if (chart.type === 'area')
127
- Area.get({ staticSettings: chartSettings.lineLike }).render(block, chartScales, data[dataOptions.dataSource], dataOptions.keyField, margin, keyAxisOrient, chart, blockSize);
130
+ Area.get({ staticSettings: chartSettings.lineLike }).render(block, chartScales, data[dataOptions.dataSource], dataOptions.keyField, margin, keyAxisOrient, chart);
128
131
  else if (chart.type === 'dot')
129
132
  this.dotChart.render(chartScales, chart, data[dataOptions.dataSource], margin);
130
133
  });
@@ -143,7 +146,7 @@ export class TwoDimensionalManager {
143
146
  proms = Line.get({ staticSettings: chartSettings.lineLike }).update(block, chartScales, data[dataOptions.dataSource], dataOptions.keyField, margin, keyAxisOrient, chart);
144
147
  }
145
148
  else if (chart.type === 'area') {
146
- proms = Area.get({ staticSettings: chartSettings.lineLike }).update(block, chartScales, data[dataOptions.dataSource], dataOptions.keyField, margin, chart, keyAxisOrient, blockSize);
149
+ proms = Area.get({ staticSettings: chartSettings.lineLike }).update(block, chartScales, data[dataOptions.dataSource], dataOptions.keyField, margin, chart, keyAxisOrient);
147
150
  }
148
151
  else if (chart.type === 'dot') {
149
152
  proms = this.dotChart.update(chartScales, data[dataOptions.dataSource], margin);
package/lib/main.d.ts CHANGED
@@ -26,6 +26,10 @@ export interface IChart {
26
26
  * @param newColors Новые базовые цвета
27
27
  */
28
28
  updateColors(newColors: string[]): void;
29
+ /**
30
+ * Сброс выделения ключей
31
+ */
32
+ clearSelection(): void;
29
33
  }
30
34
  export declare class Chart implements IChart {
31
35
  static chartCounter: number;
@@ -70,6 +74,7 @@ export declare class Chart implements IChart {
70
74
  * @param newColors Новые базовые цвета
71
75
  */
72
76
  updateColors(newColors: string[]): void;
77
+ clearSelection(): void;
73
78
  private registerResizeEvent;
74
79
  private removeResizeEvent;
75
80
  private resizeListener;
package/lib/main.js CHANGED
@@ -70,6 +70,9 @@ export class Chart {
70
70
  this.model = assembleModel(this.config, this.data, this.designerConfig);
71
71
  this.engine.updateColors(this.model);
72
72
  }
73
+ clearSelection() {
74
+ this.engine.clearSelection(this.model);
75
+ }
73
76
  registerResizeEvent() {
74
77
  window.addEventListener('resize', this.resizeHandler);
75
78
  }
@@ -1,4 +1,4 @@
1
- import { AxisPosition, ChartOrientation, MdtChartsDataSource, NumberAxisOptions, AxisLabelPosition, MdtChartsTwoDimensionalOptions, DiscreteAxisOptions, NumberSecondaryAxisOptions } from "../../config/config";
1
+ import { AxisPosition, ChartOrientation, MdtChartsDataSource, NumberAxisOptions, AxisLabelPosition, MdtChartsTwoDimensionalOptions, DiscreteAxisOptions, NumberSecondaryAxisOptions, AxisLabelFormatter } from "../../config/config";
2
2
  import { AxisModelOptions, Orient } from "../model";
3
3
  import { AxisType } from "../modelBuilder";
4
4
  import { AxisLabelCanvas, TooltipSettings } from "../../designer/designerConfig";
@@ -12,8 +12,8 @@ export declare const MINIMAL_HORIZONTAL_STEP_SIZE = 100;
12
12
  export declare class AxisModel {
13
13
  private static service;
14
14
  static getKeyAxis(options: MdtChartsTwoDimensionalOptions, data: MdtChartsDataSource, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel, tooltipSettings: TooltipSettings, getZeroCoordinate?: () => number): AxisModelOptions;
15
- static getMainValueAxis(orient: ChartOrientation, position: AxisPosition, axisConfig: NumberAxisOptions, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel): AxisModelOptions;
16
- static getSecondaryValueAxis(orient: ChartOrientation, mainAxisPosition: AxisPosition, axisConfig: NumberSecondaryAxisOptions, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel): AxisModelOptions;
15
+ static getMainValueAxis(defaultFormatter: AxisLabelFormatter, orient: ChartOrientation, position: AxisPosition, axisConfig: NumberAxisOptions, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel): AxisModelOptions;
16
+ static getSecondaryValueAxis(defaultFormatter: AxisLabelFormatter, orient: ChartOrientation, mainAxisPosition: AxisPosition, axisConfig: NumberSecondaryAxisOptions, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel): AxisModelOptions;
17
17
  private static getValueAxis;
18
18
  static getAxisLength(chartOrientation: ChartOrientation, canvasModel: CanvasModel): number;
19
19
  static getAxisOrient(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition): Orient;
@@ -30,16 +30,19 @@ export class AxisModel {
30
30
  visibility: axisConfig.visibility,
31
31
  line: {
32
32
  visible: (_c = (_b = axisConfig.line) === null || _b === void 0 ? void 0 : _b.visible) !== null && _c !== void 0 ? _c : DEFAULT_AXIS_LINE_VISIBLE
33
+ },
34
+ browserTooltip: {
35
+ format: value => value
33
36
  }
34
37
  };
35
38
  }
36
- static getMainValueAxis(orient, position, axisConfig, labelConfig, canvasModel) {
37
- return this.getValueAxis(orient, position, 'value-axis', axisConfig, labelConfig, canvasModel);
39
+ static getMainValueAxis(defaultFormatter, orient, position, axisConfig, labelConfig, canvasModel) {
40
+ return this.getValueAxis(defaultFormatter, orient, position, 'value-axis', axisConfig, labelConfig, canvasModel);
38
41
  }
39
- static getSecondaryValueAxis(orient, mainAxisPosition, axisConfig, labelConfig, canvasModel) {
40
- return this.getValueAxis(orient, mainAxisPosition === "start" ? "end" : "start", 'value-secondary-axis', axisConfig, labelConfig, canvasModel);
42
+ static getSecondaryValueAxis(defaultFormatter, orient, mainAxisPosition, axisConfig, labelConfig, canvasModel) {
43
+ return this.getValueAxis(defaultFormatter, orient, mainAxisPosition === "start" ? "end" : "start", 'value-secondary-axis', axisConfig, labelConfig, canvasModel);
41
44
  }
42
- static getValueAxis(orient, position, cssClass, axisConfig, labelConfig, canvasModel) {
45
+ static getValueAxis(defaultFormatter, orient, position, cssClass, axisConfig, labelConfig, canvasModel) {
43
46
  var _a, _b, _c, _d;
44
47
  return {
45
48
  type: 'value',
@@ -61,6 +64,9 @@ export class AxisModel {
61
64
  visibility: axisConfig.visibility,
62
65
  line: {
63
66
  visible: (_d = (_c = axisConfig.line) === null || _c === void 0 ? void 0 : _c.visible) !== null && _d !== void 0 ? _d : DEFAULT_AXIS_LINE_VISIBLE
67
+ },
68
+ browserTooltip: {
69
+ format: value => defaultFormatter(value)
64
70
  }
65
71
  };
66
72
  }
@@ -1,3 +1,4 @@
1
+ import { ModelHelper } from "../helpers/modelHelper";
1
2
  export const getResolvedTitle = (title, dataRows) => {
2
3
  return typeof title === 'function'
3
4
  ? title({ data: dataRows })
@@ -5,7 +6,7 @@ export const getResolvedTitle = (title, dataRows) => {
5
6
  };
6
7
  export class TitleModel {
7
8
  static getTitleModel(titleText) {
8
- const defaultPads = 20;
9
+ const defaultPads = ModelHelper.getFontSizeCssValue('--chart-title-font-size', 16);
9
10
  const pad = titleText ? defaultPads : 0;
10
11
  return {
11
12
  margin: {
@@ -5,11 +5,17 @@ interface ValueLabelAlignment {
5
5
  dominantBaseline: ValueLabelDominantBaseline;
6
6
  textAnchor: ValueLabelAnchor;
7
7
  }
8
+ export declare const OFFSET_SIZE_PX = 10;
9
+ export declare const BORDER_OFFSET_SIZE_PX = 2;
8
10
  export declare function getValueLabelY(scaledValue: number, keyAxisOrient: Orient, margin: BlockMargin): number;
9
11
  export declare function getValueLabelX(scaledValue: number, keyAxisOrient: Orient, margin: BlockMargin): number;
10
12
  export declare function calculateValueLabelAlignment(keyAxisOrient: Orient): ValueLabelAlignment;
11
13
  export declare function hasCollisionLeftSide(labelClientRect: BoundingRect, margin: BlockMargin): boolean;
12
14
  export declare function hasCollisionRightSide(labelClientRect: BoundingRect, blockSize: Size, margin: BlockMargin): boolean;
15
+ export declare function hasCollisionTopSide(labelClientRect: BoundingRect, margin: BlockMargin): boolean;
16
+ export declare function hasCollisionBottomSide(labelClientRect: BoundingRect, blockSize: Size, margin: BlockMargin): boolean;
13
17
  export declare function shiftCoordinateXLeft(labelClientRect: BoundingRect): void;
14
18
  export declare function shiftCoordinateXRight(labelClientRect: BoundingRect): void;
19
+ export declare function shiftCoordinateYTop(labelClientRect: BoundingRect): void;
20
+ export declare function shiftCoordinateYBottom(labelClientRect: BoundingRect): void;
15
21
  export {};
@@ -1,5 +1,5 @@
1
- const OFFSET_SIZE_PX = 10;
2
- const BORDER_OFFSET_SIZE_PX = 2;
1
+ export const OFFSET_SIZE_PX = 10;
2
+ export const BORDER_OFFSET_SIZE_PX = 2;
3
3
  export function getValueLabelY(scaledValue, keyAxisOrient, margin) {
4
4
  switch (keyAxisOrient) {
5
5
  case 'bottom':
@@ -38,9 +38,21 @@ export function hasCollisionLeftSide(labelClientRect, margin) {
38
38
  export function hasCollisionRightSide(labelClientRect, blockSize, margin) {
39
39
  return labelClientRect.x + labelClientRect.width / 2 >= blockSize.width - margin.right;
40
40
  }
41
+ export function hasCollisionTopSide(labelClientRect, margin) {
42
+ return labelClientRect.y - labelClientRect.height / 2 <= margin.top;
43
+ }
44
+ export function hasCollisionBottomSide(labelClientRect, blockSize, margin) {
45
+ return labelClientRect.y + labelClientRect.height / 2 >= blockSize.height - margin.bottom;
46
+ }
41
47
  export function shiftCoordinateXLeft(labelClientRect) {
42
48
  labelClientRect.x -= labelClientRect.width / 2 + BORDER_OFFSET_SIZE_PX;
43
49
  }
44
50
  export function shiftCoordinateXRight(labelClientRect) {
45
- labelClientRect.x += +labelClientRect.width / 2 + BORDER_OFFSET_SIZE_PX;
51
+ labelClientRect.x += labelClientRect.width / 2 + BORDER_OFFSET_SIZE_PX;
52
+ }
53
+ export function shiftCoordinateYTop(labelClientRect) {
54
+ labelClientRect.y -= labelClientRect.height / 2 + BORDER_OFFSET_SIZE_PX;
55
+ }
56
+ export function shiftCoordinateYBottom(labelClientRect) {
57
+ labelClientRect.y += labelClientRect.height / 2 + BORDER_OFFSET_SIZE_PX;
46
58
  }
@@ -2,6 +2,7 @@ export declare class ModelHelper {
2
2
  private static readonly defaultBaseFontSize;
3
3
  private static baseFontSize;
4
4
  private static getBaseFontSize;
5
+ static getFontSizeCssValue(propertyName: string, defaultValue: number): number;
5
6
  static getSum(items: number[]): number;
6
7
  static getUniqueValues(values: string[]): string[];
7
8
  static getStringScore(word: string): number;
@@ -1,9 +1,13 @@
1
1
  import { DomHelper } from "../../engine/helpers/domHelper";
2
2
  export class ModelHelper {
3
- static getBaseFontSize() {
3
+ static getBaseFontSize(propertyName) {
4
4
  if (!this.baseFontSize)
5
- this.baseFontSize = parseInt(DomHelper.getCssPropertyValue(document.documentElement, '--chart-base-font-size'));
6
- return (!this.baseFontSize || isNaN(this.baseFontSize)) ? this.defaultBaseFontSize : this.baseFontSize;
5
+ this.baseFontSize = this.getFontSizeCssValue(propertyName, this.defaultBaseFontSize);
6
+ return this.baseFontSize;
7
+ }
8
+ static getFontSizeCssValue(propertyName, defaultValue) {
9
+ const value = parseInt(DomHelper.getCssPropertyValue(document.documentElement, propertyName));
10
+ return isNaN(value) ? defaultValue : value;
7
11
  }
8
12
  static getSum(items) {
9
13
  return items.reduce((acc, item) => acc + item, 0);
@@ -15,7 +19,7 @@ export class ModelHelper {
15
19
  static getStringScore(word) {
16
20
  // lower case letter width ~ 0.8 from upper case width.
17
21
  // Number width == lower case letter width
18
- const fontSize = this.getBaseFontSize();
22
+ const fontSize = this.getBaseFontSize('--chart-base-font-size');
19
23
  let score = 0;
20
24
  const upperLetterScore = fontSize / 10;
21
25
  const lowerLetterScore = fontSize / 14;
@@ -1,9 +1,12 @@
1
- import { ChartOrientation, MdtChartsDataRow, MdtChartsTwoDimensionalChart } from "../../config/config";
2
- import { GradientDef, MarkDotDatumItem, Orient, TwoDimensionalChartModel } from "../model";
1
+ import { ChartOrientation, MdtChartsDataRow, MdtChartsTwoDimensionalChart, MdtChartsTwoDimensionalValueLabels } from "../../config/config";
2
+ import { GradientDef, MarkDotDatumItem, Orient, TwoDimensionalChartModel, TwoDimensionalValueLabels } from "../model";
3
+ import { CanvasModel } from "../modelInstance/canvasModel/canvasModel";
3
4
  export declare class TwoDimensionalModelHelper {
4
5
  static shouldMarkerShow(chart: MdtChartsTwoDimensionalChart, dataRows: MdtChartsDataRow[], valueFieldName: string, currentRow: MarkDotDatumItem, keyFieldName: string): boolean;
5
6
  static getGradientDefs(charts: TwoDimensionalChartModel[], keyAxisOrient: Orient, chartOrient: ChartOrientation): GradientDef[];
6
7
  private static getGradientItems;
7
8
  private static calculateOpacityItem;
8
9
  private static getGradientItemColor;
10
+ static getValueLabels(valueLabels: MdtChartsTwoDimensionalValueLabels, canvasModel: CanvasModel, chartOrientation: ChartOrientation): TwoDimensionalValueLabels;
11
+ private static getChartBlockSidesOptions;
9
12
  }
@@ -1,4 +1,5 @@
1
1
  import { getGradientId } from "../../model/notations/twoDimensional/styles";
2
+ import { hasCollisionBottomSide, hasCollisionLeftSide, hasCollisionRightSide, hasCollisionTopSide, shiftCoordinateXLeft, shiftCoordinateXRight, shiftCoordinateYBottom, shiftCoordinateYTop } from "../featuresModel/valueLabelsModel/valueLabelsModel";
2
3
  export class TwoDimensionalModelHelper {
3
4
  static shouldMarkerShow(chart, dataRows, valueFieldName, currentRow, keyFieldName) {
4
5
  if (chart.markers.show || dataRows.length === 1)
@@ -61,4 +62,66 @@ export class TwoDimensionalModelHelper {
61
62
  else
62
63
  return itemIndex === 0 ? minColor : maxColor;
63
64
  }
65
+ static getValueLabels(valueLabels, canvasModel, chartOrientation) {
66
+ var _a;
67
+ const blockSidesOptions = this.getChartBlockSidesOptions(canvasModel);
68
+ const chartBlockConfig = {
69
+ vertical: {
70
+ left: {
71
+ mode: 'shift',
72
+ hasCollision: blockSidesOptions.hasCollisionLeft,
73
+ shiftCoordinate: blockSidesOptions.shiftRight
74
+ },
75
+ right: {
76
+ mode: 'shift',
77
+ hasCollision: blockSidesOptions.hasCollisionRight,
78
+ shiftCoordinate: blockSidesOptions.shiftLeft
79
+ },
80
+ top: {
81
+ mode: 'none'
82
+ },
83
+ bottom: {
84
+ mode: 'none'
85
+ }
86
+ },
87
+ horizontal: {
88
+ left: {
89
+ mode: 'none'
90
+ },
91
+ right: {
92
+ mode: 'none'
93
+ },
94
+ top: {
95
+ mode: 'shift',
96
+ hasCollision: blockSidesOptions.hasCollisionTop,
97
+ shiftCoordinate: blockSidesOptions.shiftBottom
98
+ },
99
+ bottom: {
100
+ mode: 'shift',
101
+ hasCollision: blockSidesOptions.hasCollisionBottom,
102
+ shiftCoordinate: blockSidesOptions.shiftTop
103
+ }
104
+ }
105
+ };
106
+ return {
107
+ collision: {
108
+ otherValueLables: (_a = valueLabels === null || valueLabels === void 0 ? void 0 : valueLabels.collision.otherValueLabels) !== null && _a !== void 0 ? _a : {
109
+ mode: 'none'
110
+ },
111
+ chartBlock: chartBlockConfig[chartOrientation]
112
+ }
113
+ };
114
+ }
115
+ static getChartBlockSidesOptions(canvasModel) {
116
+ return {
117
+ hasCollisionLeft: (labelClientRect) => hasCollisionLeftSide(labelClientRect, canvasModel.getMargin()),
118
+ shiftLeft: (labelClientRect) => shiftCoordinateXLeft(labelClientRect),
119
+ hasCollisionRight: (labelClientRect) => hasCollisionRightSide(labelClientRect, canvasModel.getBlockSize(), canvasModel.getMargin()),
120
+ shiftRight: (labelClientRect) => shiftCoordinateXRight(labelClientRect),
121
+ hasCollisionTop: (labelClientRect) => hasCollisionTopSide(labelClientRect, canvasModel.getMargin()),
122
+ shiftTop: (labelClientRect) => shiftCoordinateYTop(labelClientRect),
123
+ hasCollisionBottom: (labelClientRect) => hasCollisionBottomSide(labelClientRect, canvasModel.getBlockSize(), canvasModel.getMargin()),
124
+ shiftBottom: (labelClientRect) => shiftCoordinateYBottom(labelClientRect)
125
+ };
126
+ }
64
127
  }
@@ -16,4 +16,5 @@ export declare class TwoDimMarginModel {
16
16
  private recalcVerticalMarginByAxisLabelHeight;
17
17
  private recalcHorizontalMarginByAxisLabelWidth;
18
18
  private recalcMarginBySecondaryAxisLabelSize;
19
+ private recalcVerticalMarginWithValueLabelsOn;
19
20
  }
@@ -3,6 +3,8 @@ import { TwoDimLegendModel } from "../../featuresModel/legendModel/twoDimLegendM
3
3
  import { keyAxisLabelHorizontalLog, keyAxisLabelVerticalLog } from "../../featuresModel/scaleModel/scaleAxisRecalcer";
4
4
  import { AxisType } from "../../modelBuilder";
5
5
  import { TwoDimensionalModel } from "../../notations/twoDimensionalModel";
6
+ import { ModelHelper } from "../../helpers/modelHelper";
7
+ import { OFFSET_SIZE_PX } from "../../featuresModel/valueLabelsModel/valueLabelsModel";
6
8
  export const AXIS_HORIZONTAL_LABEL_PADDING = 20;
7
9
  export const AXIS_VERTICAL_LABEL_PADDING = 8;
8
10
  export class TwoDimMarginModel {
@@ -27,6 +29,9 @@ export class TwoDimMarginModel {
27
29
  const secondaryLabelSize = this.getMaxLabelSizeSecondary(modelInstance);
28
30
  this.recalcMarginBySecondaryAxisLabelSize(secondaryLabelSize, canvasModel);
29
31
  }
32
+ if (this.configReader.isValueLabelsOn() && this.configReader.options.orientation === 'vertical') {
33
+ this.recalcVerticalMarginWithValueLabelsOn(canvasModel);
34
+ }
30
35
  }
31
36
  recalcMarginByVerticalAxisLabel(modelInstance) {
32
37
  if (this.configReader.options.orientation === 'vertical') {
@@ -101,4 +106,13 @@ export class TwoDimMarginModel {
101
106
  canvasModel.increaseMarginSide(secondaryOrient, sizeMap[this.configReader.options.orientation]);
102
107
  }
103
108
  }
109
+ recalcVerticalMarginWithValueLabelsOn(canvasModel) {
110
+ const keyAxisOrient = AxisModel.getAxisOrient(AxisType.Key, this.configReader.options.orientation, this.configReader.options.axis.key.position);
111
+ const valueLabelFontSize = ModelHelper.getFontSizeCssValue('--value-label-font-size', 10);
112
+ const axisMarginMapping = {
113
+ top: "bottom",
114
+ bottom: "top"
115
+ };
116
+ canvasModel.increaseMarginSide(axisMarginMapping[keyAxisOrient], valueLabelFontSize + OFFSET_SIZE_PX);
117
+ }
104
118
  }
@@ -136,6 +136,10 @@ export interface AxisModelOptions {
136
136
  ticks: AxisTicksModel;
137
137
  labels: AxisLabelModel;
138
138
  line: AxisLineModel;
139
+ browserTooltip: AxisBrowserTooltipModel;
140
+ }
141
+ export interface AxisBrowserTooltipModel {
142
+ format: (value: number | string) => string | number;
139
143
  }
140
144
  export interface AxisLineModel {
141
145
  visible: boolean;
@@ -230,17 +234,18 @@ export interface OtherValueLables {
230
234
  mode: ValueLabelsCollisionMode;
231
235
  }
232
236
  export interface ValueLabelsChartBlock {
233
- left: {
234
- mode: "none" | "shift";
235
- hasCollision: (labelClientRect: BoundingRect) => boolean;
236
- shiftCoordinate: (labelClientRect: BoundingRect) => void;
237
- };
238
- right: {
239
- mode: "none" | "shift";
240
- hasCollision: (labelClientRect: BoundingRect) => boolean;
241
- shiftCoordinate: (labelClientRect: BoundingRect) => void;
242
- };
243
- }
237
+ left: ValueLabelsChartBlockSide;
238
+ right: ValueLabelsChartBlockSide;
239
+ top: ValueLabelsChartBlockSide;
240
+ bottom: ValueLabelsChartBlockSide;
241
+ }
242
+ export declare type ValueLabelsChartBlockSide = {
243
+ mode: "shift";
244
+ hasCollision: (labelClientRect: BoundingRect) => boolean;
245
+ shiftCoordinate: (labelClientRect: BoundingRect) => void;
246
+ } | {
247
+ mode: "none";
248
+ };
244
249
  export interface DonutChartSettings extends Omit<DonutOptionsCanvas, "aggregatorPad" | "thickness"> {
245
250
  aggregator: DonutAggregatorModel;
246
251
  thickness: DonutThicknessOptions;
@@ -21,6 +21,8 @@ export declare class TwoDimConfigReader implements BaseConfigReader {
21
21
  }[];
22
22
  containsSecondaryAxis(): boolean;
23
23
  getValueLabelFormatterForChart(chartIndex: number): ValueLabelsFormatter;
24
+ calculateDefaultAxisLabelFormatter(): AxisLabelFormatter;
25
+ isValueLabelsOn(): boolean;
24
26
  private calculateBiggestValueAndDecremented;
25
27
  private calculateAxisLabelFormatter;
26
28
  }
@@ -71,6 +71,13 @@ export class TwoDimConfigReader {
71
71
  const valueFieldFormat = chart.data.valueFields[0].format;
72
72
  return (v) => this.designerConfig.dataFormat.formatters(v, { type: valueFieldFormat });
73
73
  }
74
+ calculateDefaultAxisLabelFormatter() {
75
+ const valueFieldFormat = this.options.charts[0].data.valueFields[0].format;
76
+ return (v) => this.designerConfig.dataFormat.formatters(v, { type: valueFieldFormat });
77
+ }
78
+ isValueLabelsOn() {
79
+ return this.options.charts.some(chart => { var _a; return (_a = chart.valueLabels) === null || _a === void 0 ? void 0 : _a.on; });
80
+ }
74
81
  calculateBiggestValueAndDecremented(repository, domain, fields) {
75
82
  const resolvedDomain = getResolvedDomain(domain, repository.getRawRows());
76
83
  if (resolvedDomain && resolvedDomain.end !== -1) {
@@ -82,8 +89,7 @@ export class TwoDimConfigReader {
82
89
  var _a, _b;
83
90
  if ((_a = axisValue.labels) === null || _a === void 0 ? void 0 : _a.format)
84
91
  return (_b = axisValue.labels) === null || _b === void 0 ? void 0 : _b.format;
85
- const valueFieldFormat = this.options.charts[0].data.valueFields[0].format;
86
- return (v) => this.designerConfig.dataFormat.formatters(v, { type: valueFieldFormat });
92
+ return this.calculateDefaultAxisLabelFormatter();
87
93
  }
88
94
  }
89
95
  export class PolarConfigReader {
@@ -1,4 +1,4 @@
1
- import { AreaChartViewOptions, BarBorderRadius, ChartLegendModel, ChartStyle, GradientId, LineLikeChartDashOptions, LineLikeChartShapeOptions, Orient, TwoDimensionalBarLikeChartViewModel } from "../../model";
1
+ import { AreaChartViewOptions, BarBorderRadius, ChartLegendModel, ChartStyle, GradientId, LineLikeChartDashOptions, LineLikeChartShapeOptions, Orient, TwoDimensionalBarLikeChartViewModel, TwoDimensionalChartLegendLineModel } from "../../model";
2
2
  import { ChartOrientation, MdtChartsLineLikeChartDashedStyles, MdtChartsTwoDimensionalChart, TwoDimensionalChartType } from "../../../config/config";
3
3
  import { MdtChartsLineLikeChartShape } from "../../../designer/designerConfig";
4
4
  export declare const LINE_CHART_DEFAULT_WIDTH = 2;
@@ -7,6 +7,7 @@ export declare function parseDashStyles(configOptions?: MdtChartsLineLikeChartDa
7
7
  export declare function getBarViewOptions(chart: MdtChartsTwoDimensionalChart, keyAxisOrient: Orient): TwoDimensionalBarLikeChartViewModel;
8
8
  export declare function getSegmentedRadiusValues(segmentsLength: number, segmentIndex: number, keyAxisOrient: Orient, defaultRadius: number): BarBorderRadius;
9
9
  export declare function getLegendMarkerOptions(chart: MdtChartsTwoDimensionalChart): ChartLegendModel;
10
+ export declare function getLineViewOptions(chart: MdtChartsTwoDimensionalChart): TwoDimensionalChartLegendLineModel;
10
11
  export declare function getWidthOfLegendMarkerByType(chartType: TwoDimensionalChartType): number;
11
12
  export declare function getAreaViewOptions(chart: MdtChartsTwoDimensionalChart, chartIndex: number, style: ChartStyle): AreaChartViewOptions;
12
13
  export declare function getGradientId(chartIndex: number, subIndex: number): GradientId;
@@ -78,25 +78,44 @@ export function getSegmentedRadiusValues(segmentsLength, segmentIndex, keyAxisOr
78
78
  export function getLegendMarkerOptions(chart) {
79
79
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
80
80
  const shapeByType = {
81
- area: "default",
81
+ area: "line",
82
82
  bar: "bar",
83
83
  line: "line",
84
- dot: "default"
84
+ dot: (_c = (_b = (_a = chart.dotLikeStyles) === null || _a === void 0 ? void 0 : _a.shape) === null || _b === void 0 ? void 0 : _b.type) !== null && _c !== void 0 ? _c : "line"
85
85
  };
86
86
  return {
87
87
  markerShape: shapeByType[chart.type],
88
88
  barViewOptions: {
89
- hatch: { on: (_c = (_b = (_a = chart.barStyles) === null || _a === void 0 ? void 0 : _a.hatch) === null || _b === void 0 ? void 0 : _b.on) !== null && _c !== void 0 ? _c : false },
90
- borderRadius: getRadiusValues((_f = (_e = (_d = chart.barStyles) === null || _d === void 0 ? void 0 : _d.borderRadius) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : BAR_CHART_BORDER_RADIUS_DEFAULT),
89
+ hatch: { on: (_f = (_e = (_d = chart.barStyles) === null || _d === void 0 ? void 0 : _d.hatch) === null || _e === void 0 ? void 0 : _e.on) !== null && _f !== void 0 ? _f : false },
90
+ borderRadius: getRadiusValues((_j = (_h = (_g = chart.barStyles) === null || _g === void 0 ? void 0 : _g.borderRadius) === null || _h === void 0 ? void 0 : _h.value) !== null && _j !== void 0 ? _j : BAR_CHART_BORDER_RADIUS_DEFAULT),
91
91
  width: getWidthOfLegendMarkerByType("bar")
92
92
  },
93
- lineViewOptions: {
94
- dashedStyles: parseDashStyles((_g = chart.lineStyles) === null || _g === void 0 ? void 0 : _g.dash),
95
- strokeWidth: (_j = (_h = chart.lineStyles) === null || _h === void 0 ? void 0 : _h.width) !== null && _j !== void 0 ? _j : LINE_CHART_DEFAULT_WIDTH,
96
- length: getWidthOfLegendMarkerByType("line")
97
- }
93
+ lineViewOptions: getLineViewOptions(chart)
98
94
  };
99
95
  }
96
+ export function getLineViewOptions(chart) {
97
+ var _a, _b, _c, _d, _e, _f;
98
+ switch (chart.type) {
99
+ case "dot":
100
+ return {
101
+ dashedStyles: { on: false, dashSize: 0, gapSize: 0 },
102
+ strokeWidth: (_c = (_b = (_a = chart.dotLikeStyles) === null || _a === void 0 ? void 0 : _a.shape) === null || _b === void 0 ? void 0 : _b.width) !== null && _c !== void 0 ? _c : LINE_CHART_DEFAULT_WIDTH,
103
+ length: getWidthOfLegendMarkerByType("line")
104
+ };
105
+ case "area":
106
+ return {
107
+ dashedStyles: { on: false, dashSize: 0, gapSize: 0 },
108
+ strokeWidth: LINE_CHART_DEFAULT_WIDTH,
109
+ length: getWidthOfLegendMarkerByType("line")
110
+ };
111
+ default:
112
+ return {
113
+ dashedStyles: parseDashStyles((_d = chart.lineStyles) === null || _d === void 0 ? void 0 : _d.dash),
114
+ strokeWidth: (_f = (_e = chart.lineStyles) === null || _e === void 0 ? void 0 : _e.width) !== null && _f !== void 0 ? _f : LINE_CHART_DEFAULT_WIDTH,
115
+ length: getWidthOfLegendMarkerByType("line")
116
+ };
117
+ }
118
+ }
100
119
  export function getWidthOfLegendMarkerByType(chartType) {
101
120
  if (chartType === "bar")
102
121
  return 8;
@@ -18,5 +18,4 @@ export declare class TwoDimensionalModel {
18
18
  private static getEmbeddedLabelType;
19
19
  private static getAdditionalElements;
20
20
  private static getChartsByTypes;
21
- private static getValueLabels;
22
21
  }
@@ -5,7 +5,7 @@ import { ScaleAxisRecalcer } from "../featuresModel/scaleModel/scaleAxisRecalcer
5
5
  import { ScaleModel } from "../featuresModel/scaleModel/scaleModel";
6
6
  import { getAreaViewOptions, getBarViewOptions, getLegendMarkerOptions, LINE_CHART_DEFAULT_WIDTH, parseDashStyles, parseShape } from "./twoDimensional/styles";
7
7
  import { getResolvedTitle } from "../../model/featuresModel/titleModel";
8
- import { calculateValueLabelAlignment, getValueLabelX, getValueLabelY, hasCollisionLeftSide, hasCollisionRightSide, shiftCoordinateXLeft, shiftCoordinateXRight } from "../../model/featuresModel/valueLabelsModel/valueLabelsModel";
8
+ import { calculateValueLabelAlignment, getValueLabelX, getValueLabelY } from "../../model/featuresModel/valueLabelsModel/valueLabelsModel";
9
9
  import { TwoDimensionalModelHelper } from "../helpers/twoDimensionalModelHelper";
10
10
  export class TwoDimensionalModel {
11
11
  static getOptions(configReader, designerConfig, modelInstance) {
@@ -23,20 +23,21 @@ export class TwoDimensionalModel {
23
23
  }
24
24
  const keyAxis = AxisModel.getKeyAxis(options, modelInstance.dataModel.repository.getScopedFullSource(), designerConfig.canvas.axisLabel, canvasModel, designerConfig.elementsOptions.tooltip, () => scaleValueInfo.scaleFn(0));
25
25
  const charts = this.getChartsModel(options.charts, configReader, options.orientation, designerConfig, modelInstance.dataModel.repository, keyAxis.orient, canvasModel, options.data.keyField.name);
26
+ const defaultFormatter = configReader.calculateDefaultAxisLabelFormatter();
26
27
  return {
27
28
  legend: canvasModel.legendCanvas.getModel(),
28
29
  title: getResolvedTitle(options.title, modelInstance.dataModel.repository.getRawRows()),
29
30
  selectable: !!options.selectable,
30
31
  orient: options.orientation,
31
32
  scale: Object.assign({ key: scaleModel.getScaleKey(modelInstance.dataModel.getAllowableKeys(), options.orientation, canvasModel, options.charts, this.getChartsByTypes(options.charts, ['bar', 'dot'])), value: scaleValueInfo.scale }, (configReader.containsSecondaryAxis() && { valueSecondary: secondaryScaleValueInfo.scale })),
32
- axis: Object.assign({ key: keyAxis, value: AxisModel.getMainValueAxis(options.orientation, options.axis.value.position, options.axis.value, designerConfig.canvas.axisLabel, canvasModel) }, (configReader.containsSecondaryAxis() && { valueSecondary: AxisModel.getSecondaryValueAxis(options.orientation, options.axis.value.position, options.axis.valueSecondary, designerConfig.canvas.axisLabel, canvasModel) })),
33
+ axis: Object.assign({ key: keyAxis, value: AxisModel.getMainValueAxis(defaultFormatter, options.orientation, options.axis.value.position, options.axis.value, designerConfig.canvas.axisLabel, canvasModel) }, (configReader.containsSecondaryAxis() && { valueSecondary: AxisModel.getSecondaryValueAxis(defaultFormatter, options.orientation, options.axis.value.position, options.axis.valueSecondary, designerConfig.canvas.axisLabel, canvasModel) })),
33
34
  type: options.type,
34
35
  data: Object.assign({}, options.data),
35
36
  charts,
36
37
  additionalElements: this.getAdditionalElements(options),
37
38
  tooltip: options.tooltip,
38
39
  chartSettings: this.getChartsSettings(designerConfig.canvas.chartOptions, options.orientation),
39
- valueLabels: this.getValueLabels(options.valueLabels, canvasModel),
40
+ valueLabels: TwoDimensionalModelHelper.getValueLabels(options.valueLabels, canvasModel, options.orientation),
40
41
  defs: {
41
42
  gradients: TwoDimensionalModelHelper.getGradientDefs(charts, keyAxis.orient, options.orientation)
42
43
  }
@@ -115,7 +116,7 @@ export class TwoDimensionalModel {
115
116
  type: "line",
116
117
  handleEndCoordinate: (v) => v + 2,
117
118
  handleStartCoordinate: (v) => v - 2,
118
- width: (_s = (_r = (_q = chart.dotLikeStyles) === null || _q === void 0 ? void 0 : _q.shape) === null || _r === void 0 ? void 0 : _r.width) !== null && _s !== void 0 ? _s : 2
119
+ width: (_s = (_r = (_q = chart.dotLikeStyles) === null || _q === void 0 ? void 0 : _q.shape) === null || _r === void 0 ? void 0 : _r.width) !== null && _s !== void 0 ? _s : LINE_CHART_DEFAULT_WIDTH
119
120
  }
120
121
  }
121
122
  });
@@ -150,26 +151,4 @@ export class TwoDimensionalModel {
150
151
  static getChartsByTypes(charts, types) {
151
152
  return charts.filter(chart => types.includes(chart.type));
152
153
  }
153
- static getValueLabels(valueLabels, canvasModel) {
154
- var _a;
155
- return {
156
- collision: {
157
- otherValueLables: (_a = valueLabels === null || valueLabels === void 0 ? void 0 : valueLabels.collision.otherValueLabels) !== null && _a !== void 0 ? _a : {
158
- mode: 'none'
159
- },
160
- chartBlock: {
161
- left: {
162
- mode: 'shift',
163
- hasCollision: (labelClientRect) => hasCollisionLeftSide(labelClientRect, canvasModel.getMargin()),
164
- shiftCoordinate: (labelClientRect) => shiftCoordinateXRight(labelClientRect),
165
- },
166
- right: {
167
- mode: 'shift',
168
- hasCollision: (labelClientRect) => hasCollisionRightSide(labelClientRect, canvasModel.getBlockSize(), canvasModel.getMargin()),
169
- shiftCoordinate: (labelClientRect) => shiftCoordinateXLeft(labelClientRect),
170
- }
171
- }
172
- },
173
- };
174
- }
175
154
  }
@@ -1,5 +1,7 @@
1
1
  :root {
2
2
  --chart-base-font-size: 12px;
3
+ --value-label-font-size: 10px;
4
+ --chart-title-font-size: 16px;
3
5
  }
4
6
 
5
7
  .wrapper {
@@ -271,7 +273,7 @@
271
273
  font-family: "Roboto", sans-serif;
272
274
  font-style: normal;
273
275
  font-weight: 500;
274
- font-size: 18px;
276
+ font-size: var(--chart-title-font-size);
275
277
  line-height: 140.62%;
276
278
  cursor: default;
277
279
  }
@@ -290,6 +292,6 @@
290
292
  /* Value Labels */
291
293
  .mdt-charts-value-label {
292
294
  opacity: 0.5;
293
- font-size: 10px;
295
+ font-size: var(--value-label-font-size);
294
296
  letter-spacing: -0.4px;
295
297
  }
@@ -1,5 +1,7 @@
1
1
  :root {
2
2
  --chart-base-font-size: 12px;
3
+ --value-label-font-size: 10px;
4
+ --chart-title-font-size: 16px;
3
5
  }
4
6
 
5
7
  .wrapper {
@@ -271,7 +273,7 @@
271
273
  font-family: "Roboto", sans-serif;
272
274
  font-style: normal;
273
275
  font-weight: 500;
274
- font-size: 18px;
276
+ font-size: var(--chart-title-font-size);
275
277
  line-height: 140.62%;
276
278
  cursor: default;
277
279
  }
@@ -290,6 +292,6 @@
290
292
  /* Value Labels */
291
293
  .mdt-charts-value-label {
292
294
  opacity: 0.5;
293
- font-size: 10px;
295
+ font-size: var(--value-label-font-size);
294
296
  letter-spacing: -0.4px;
295
297
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdt-charts",
3
- "version": "1.23.2",
3
+ "version": "1.24.0",
4
4
  "description": "",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {