mdt-charts 1.20.0 → 1.20.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 (57) hide show
  1. package/lib/config/config.d.ts +14 -0
  2. package/lib/engine/block/blockSvg.d.ts +1 -1
  3. package/lib/engine/block/blockSvg.js +1 -1
  4. package/lib/engine/elementHighlighter/elementHighlighter.d.ts +0 -1
  5. package/lib/engine/elementHighlighter/elementHighlighter.js +5 -8
  6. package/lib/engine/elementHighlighter/selectHighlighter.js +11 -10
  7. package/lib/engine/features/legend/legendMarkerCreator.js +1 -1
  8. package/lib/engine/features/markDots/markDot.d.ts +11 -3
  9. package/lib/engine/features/markDots/markDot.js +21 -10
  10. package/lib/engine/features/tolltip/tooltip.js +5 -4
  11. package/lib/engine/features/valueLabels/valueLabels.d.ts +45 -0
  12. package/lib/engine/features/valueLabels/valueLabels.js +139 -0
  13. package/lib/engine/features/valueLabels/valueLabelsHelper.d.ts +6 -0
  14. package/lib/engine/features/valueLabels/valueLabelsHelper.js +21 -0
  15. package/lib/engine/features/valueLabelsCollision/valueLabelsCollision.d.ts +23 -0
  16. package/lib/engine/features/valueLabelsCollision/valueLabelsCollision.js +24 -0
  17. package/lib/engine/features/valueLabelsCollision/valueLabelsCollisionHelper.d.ts +5 -0
  18. package/lib/engine/features/valueLabelsCollision/valueLabelsCollisionHelper.js +47 -0
  19. package/lib/engine/twoDimensionalNotation/area/area.d.ts +18 -11
  20. package/lib/engine/twoDimensionalNotation/area/area.js +32 -22
  21. package/lib/engine/twoDimensionalNotation/area/areaGenerator.d.ts +14 -0
  22. package/lib/engine/twoDimensionalNotation/area/areaGenerator.js +22 -0
  23. package/lib/engine/twoDimensionalNotation/area/areaHelper.d.ts +7 -7
  24. package/lib/engine/twoDimensionalNotation/area/areaHelper.js +30 -31
  25. package/lib/engine/twoDimensionalNotation/bar/barHelper.js +1 -1
  26. package/lib/engine/twoDimensionalNotation/bar/stackedData/dataStacker.d.ts +4 -2
  27. package/lib/engine/twoDimensionalNotation/bar/stackedData/dataStacker.js +2 -5
  28. package/lib/engine/twoDimensionalNotation/line/line.d.ts +0 -6
  29. package/lib/engine/twoDimensionalNotation/line/line.js +4 -4
  30. package/lib/engine/twoDimensionalNotation/line/lineGenerator.d.ts +4 -7
  31. package/lib/engine/twoDimensionalNotation/line/lineGenerator.js +2 -16
  32. package/lib/engine/twoDimensionalNotation/line/lineHelper.d.ts +4 -13
  33. package/lib/engine/twoDimensionalNotation/line/lineHelper.js +22 -10
  34. package/lib/engine/twoDimensionalNotation/lineLike/generatorFactory/lineLikeGeneratorFactory.d.ts +12 -0
  35. package/lib/engine/twoDimensionalNotation/lineLike/generatorFactory/lineLikeGeneratorFactory.js +1 -0
  36. package/lib/engine/twoDimensionalNotation/lineLike/generatorMiddleware/lineLikeGeneratorCurveMiddleware.d.ts +14 -0
  37. package/lib/engine/twoDimensionalNotation/lineLike/generatorMiddleware/lineLikeGeneratorCurveMiddleware.js +21 -0
  38. package/lib/engine/twoDimensionalNotation/lineLike/generatorMiddleware/lineLikeGeneratorDefineMiddleware.d.ts +20 -0
  39. package/lib/engine/twoDimensionalNotation/lineLike/generatorMiddleware/lineLikeGeneratorDefineMiddleware.js +9 -0
  40. package/lib/engine/twoDimensionalNotation/lineLike/generatorMiddleware/lineLikeGeneratorMiddleware.d.ts +5 -0
  41. package/lib/engine/twoDimensionalNotation/lineLike/generatorMiddleware/lineLikeGeneratorMiddleware.js +1 -0
  42. package/lib/engine/twoDimensionalNotation/twoDimensionalManager.d.ts +1 -0
  43. package/lib/engine/twoDimensionalNotation/twoDimensionalManager.js +19 -3
  44. package/lib/model/featuresModel/axisModel.js +3 -1
  45. package/lib/model/featuresModel/valueLabelsModel/valueLabelsModel.d.ts +9 -0
  46. package/lib/model/featuresModel/valueLabelsModel/valueLabelsModel.js +33 -0
  47. package/lib/model/helpers/modelHelper.d.ts +1 -0
  48. package/lib/model/helpers/modelHelper.js +3 -2
  49. package/lib/model/helpers/twoDimensionalModelHelper.d.ts +5 -0
  50. package/lib/model/helpers/twoDimensionalModelHelper.js +16 -0
  51. package/lib/model/model.d.ts +28 -5
  52. package/lib/model/modelInstance/configReader.d.ts +2 -1
  53. package/lib/model/modelInstance/configReader.js +17 -0
  54. package/lib/model/notations/twoDimensionalModel.js +24 -24
  55. package/package.json +1 -1
  56. /package/lib/engine/block/{defs.d.ts → defs/hatchPattern.d.ts} +0 -0
  57. /package/lib/engine/block/{defs.js → defs/hatchPattern.js} +0 -0
@@ -0,0 +1,9 @@
1
+ export class LineLikeGeneratorDefinedMiddleware {
2
+ constructor(options) {
3
+ this.options = options;
4
+ }
5
+ handle(generator) {
6
+ generator.defined(d => this.options.definedFn(this.options.dataRowGetter(d), this.options.valueFieldNameGetter(d)));
7
+ return generator;
8
+ }
9
+ }
@@ -0,0 +1,5 @@
1
+ import { Line as ILine, Area as IArea } from "d3-shape";
2
+ import { MdtChartsDataRow } from "../../../../config/config";
3
+ export interface LineLikeGeneratorMiddleware {
4
+ handle(generator: ILine<MdtChartsDataRow> | IArea<MdtChartsDataRow>): ILine<MdtChartsDataRow> | IArea<MdtChartsDataRow>;
5
+ }
@@ -4,6 +4,7 @@ import { Block } from "../block/block";
4
4
  import { ChartContentManager } from "../contentManager/contentManagerFactory";
5
5
  import { Engine } from "../engine";
6
6
  export declare class TwoDimensionalManager implements ChartContentManager {
7
+ private canvasValueLabels?;
7
8
  render(engine: Engine, model: Model<TwoDimensionalOptionsModel>): void;
8
9
  updateData(block: Block, model: Model<TwoDimensionalOptionsModel>, data: MdtChartsDataSource): void;
9
10
  updateColors(block: Block, model: Model<TwoDimensionalOptionsModel>): void;
@@ -13,6 +13,7 @@ import { Bar } from "./bar/bar";
13
13
  import { BarHelper } from "./bar/barHelper";
14
14
  import { TwoDimRecordOverflowAlert } from "./extenders/twoDimRecordOverflowAlert";
15
15
  import { Line } from "./line/line";
16
+ import { CanvasValueLabels } from "../../engine/features/valueLabels/valueLabels";
16
17
  export class TwoDimensionalManager {
17
18
  render(engine, model) {
18
19
  const options = model.options;
@@ -38,6 +39,19 @@ export class TwoDimensionalManager {
38
39
  if (e.target === engine.block.getSvg().node())
39
40
  engine.block.filterEventManager.clearKeysFor2D(options);
40
41
  });
42
+ this.canvasValueLabels = new CanvasValueLabels({
43
+ elementAccessors: {
44
+ getBlock: () => engine.block,
45
+ },
46
+ data: {
47
+ keyFieldName: options.data.keyField.name
48
+ },
49
+ canvas: {
50
+ keyAxisOrient: options.axis.key.orient,
51
+ valueLabels: options.valueLabels,
52
+ }
53
+ });
54
+ this.canvasValueLabels.render(scales, options.charts, engine.data, options.data);
41
55
  }
42
56
  updateData(block, model, data) {
43
57
  block.transitionManager.interruptTransitions();
@@ -63,6 +77,8 @@ export class TwoDimensionalManager {
63
77
  hidedRecordsAmount: model.dataSettings.scope.hidedRecordsAmount,
64
78
  chartOrientation: options.orient
65
79
  });
80
+ if (this.canvasValueLabels)
81
+ this.canvasValueLabels.update(scales, options.charts, data, model.options.data);
66
82
  }
67
83
  updateColors(block, model) {
68
84
  Legend.get().updateColors(block, model.options);
@@ -72,7 +88,7 @@ export class TwoDimensionalManager {
72
88
  else if (chart.type === 'line')
73
89
  Line.get({ staticSettings: model.options.chartSettings.lineLike }).updateColors(block, chart);
74
90
  else if (chart.type === 'area')
75
- Area.updateColors(block, chart);
91
+ Area.get({ staticSettings: model.options.chartSettings.lineLike }).updateColors(block, chart);
76
92
  });
77
93
  }
78
94
  renderCharts(block, charts, scales, data, dataOptions, margin, keyAxisOrient, chartSettings, blockSize) {
@@ -86,7 +102,7 @@ export class TwoDimensionalManager {
86
102
  else if (chart.type === 'line')
87
103
  Line.get({ staticSettings: chartSettings.lineLike }).render(block, chartScales, data[dataOptions.dataSource], dataOptions.keyField, margin, keyAxisOrient, chart);
88
104
  else if (chart.type === 'area')
89
- Area.render(block, chartScales, data[dataOptions.dataSource], dataOptions.keyField, margin, keyAxisOrient, chart, blockSize);
105
+ Area.get({ staticSettings: chartSettings.lineLike }).render(block, chartScales, data[dataOptions.dataSource], dataOptions.keyField, margin, keyAxisOrient, chart, blockSize);
90
106
  });
91
107
  EmbeddedLabels.raiseGroups(block);
92
108
  }
@@ -103,7 +119,7 @@ export class TwoDimensionalManager {
103
119
  proms = Line.get({ staticSettings: chartSettings.lineLike }).update(block, chartScales, data[dataOptions.dataSource], dataOptions.keyField, margin, keyAxisOrient, chart);
104
120
  }
105
121
  else if (chart.type === 'area') {
106
- proms = Area.update(block, chartScales, data[dataOptions.dataSource], dataOptions.keyField, margin, chart, keyAxisOrient, blockSize);
122
+ proms = Area.get({ staticSettings: chartSettings.lineLike }).update(block, chartScales, data[dataOptions.dataSource], dataOptions.keyField, margin, chart, keyAxisOrient, blockSize);
107
123
  }
108
124
  promises.push(...proms);
109
125
  });
@@ -19,7 +19,7 @@ export class AxisModel {
19
19
  cssClass: 'key-axis',
20
20
  ticks: axisConfig.ticks,
21
21
  labels: {
22
- maxSize: AxisModel.getLabelSizeLegacy(labelConfig.maxSize.main, data[dataOptions.dataSource].map(d => d[dataOptions.keyField.name])).width,
22
+ maxSize: AxisModel.getLabelSize(labelConfig.maxSize.main, data[dataOptions.dataSource].map(d => d[dataOptions.keyField.name])).width,
23
23
  position: AxisModel.getKeyAxisLabelPosition(canvasModel, DataManagerModel.getDataValuesByKeyField(data, dataOptions.dataSource, dataOptions.keyField.name).length, axisConfig),
24
24
  visible: !TwoDimensionalModel.getChartsEmbeddedLabelsFlag(charts, orientation),
25
25
  defaultTooltip: tooltipSettings.position === 'fixed',
@@ -137,6 +137,8 @@ export class AxisModel {
137
137
  const sign = Math.sign(value);
138
138
  if (absValue < 10)
139
139
  return value;
140
+ if (absValue < 100)
141
+ return sign * Math.floor(absValue / 10) * 10;
140
142
  const valueStr = absValue.toString();
141
143
  const firstTwoDigits = Math.floor(absValue / Math.pow(10, valueStr.length - 2));
142
144
  const roundedFirstTwoDigits = firstTwoDigits < 10 ? firstTwoDigits : Math.floor(firstTwoDigits / 5) * 5;
@@ -0,0 +1,9 @@
1
+ import { BlockMargin, Orient, ValueLabelAnchor, ValueLabelDominantBaseline } from "../../model";
2
+ interface ValueLabelAlignment {
3
+ dominantBaseline: ValueLabelDominantBaseline;
4
+ textAnchor: ValueLabelAnchor;
5
+ }
6
+ export declare function getValueLabelY(scaledValue: number, keyAxisOrient: Orient, margin: BlockMargin): number;
7
+ export declare function getValueLabelX(scaledValue: number, keyAxisOrient: Orient, margin: BlockMargin): number;
8
+ export declare function calculateValueLabelAlignment(keyAxisOrient: Orient): ValueLabelAlignment;
9
+ export {};
@@ -0,0 +1,33 @@
1
+ const OFFSET_SIZE_PX = 10;
2
+ export function getValueLabelY(scaledValue, keyAxisOrient, margin) {
3
+ switch (keyAxisOrient) {
4
+ case 'bottom':
5
+ return scaledValue - OFFSET_SIZE_PX + margin.top;
6
+ case 'top':
7
+ return scaledValue + OFFSET_SIZE_PX + margin.top;
8
+ default:
9
+ return scaledValue + margin.top;
10
+ }
11
+ }
12
+ export function getValueLabelX(scaledValue, keyAxisOrient, margin) {
13
+ switch (keyAxisOrient) {
14
+ case 'right':
15
+ return scaledValue - OFFSET_SIZE_PX + margin.left;
16
+ case 'left':
17
+ return scaledValue + OFFSET_SIZE_PX + margin.left;
18
+ default:
19
+ return scaledValue + margin.left;
20
+ }
21
+ }
22
+ export function calculateValueLabelAlignment(keyAxisOrient) {
23
+ switch (keyAxisOrient) {
24
+ case 'top':
25
+ return { dominantBaseline: "hanging", textAnchor: "middle" };
26
+ case "bottom":
27
+ return { dominantBaseline: "auto", textAnchor: "middle" };
28
+ case "left":
29
+ return { dominantBaseline: "middle", textAnchor: "start" };
30
+ case "right":
31
+ return { dominantBaseline: "middle", textAnchor: "end" };
32
+ }
33
+ }
@@ -1,4 +1,5 @@
1
1
  export declare class ModelHelper {
2
+ private static readonly defaultBaseFontSize;
2
3
  private static baseFontSize;
3
4
  private static getBaseFontSize;
4
5
  static getSum(items: number[]): number;
@@ -3,7 +3,7 @@ export class ModelHelper {
3
3
  static getBaseFontSize() {
4
4
  if (!this.baseFontSize)
5
5
  this.baseFontSize = parseInt(DomHelper.getCssPropertyValue(document.documentElement, '--chart-base-font-size'));
6
- return this.baseFontSize;
6
+ return (!this.baseFontSize || isNaN(this.baseFontSize)) ? this.defaultBaseFontSize : this.baseFontSize;
7
7
  }
8
8
  static getSum(items) {
9
9
  return items.reduce((acc, item) => acc + item, 0);
@@ -17,7 +17,7 @@ export class ModelHelper {
17
17
  // Number width == lower case letter width
18
18
  const fontSize = this.getBaseFontSize();
19
19
  let score = 0;
20
- const upperLetterScore = fontSize / 13;
20
+ const upperLetterScore = fontSize / 10;
21
21
  const lowerLetterScore = fontSize / 15;
22
22
  const digitScore = fontSize / 15;
23
23
  const otherSymbolScore = fontSize / 23;
@@ -37,3 +37,4 @@ export class ModelHelper {
37
37
  return score;
38
38
  }
39
39
  }
40
+ ModelHelper.defaultBaseFontSize = 13;
@@ -0,0 +1,5 @@
1
+ import { MdtChartsDataRow, MdtChartsTwoDimensionalChart } from "../../config/config";
2
+ import { MarkDotDatumItem } from "../model";
3
+ export declare class TwoDimensionalModelHelper {
4
+ static shouldMarkerShow(chart: MdtChartsTwoDimensionalChart, dataRows: MdtChartsDataRow[], valueFieldName: string, currentRow: MarkDotDatumItem, keyFieldName: string): boolean;
5
+ }
@@ -0,0 +1,16 @@
1
+ export class TwoDimensionalModelHelper {
2
+ static shouldMarkerShow(chart, dataRows, valueFieldName, currentRow, keyFieldName) {
3
+ if (chart.markers.show || dataRows.length === 1)
4
+ return true;
5
+ const rowIndex = dataRows.findIndex(row => row[keyFieldName] === currentRow[keyFieldName]);
6
+ if (rowIndex === -1)
7
+ return false;
8
+ const isFirst = rowIndex === 0;
9
+ const isLast = rowIndex === dataRows.length - 1;
10
+ const previousRow = dataRows[rowIndex - 1];
11
+ const nextRow = dataRows[rowIndex + 1];
12
+ const hasNullNeighborsRows = !isFirst && !isLast &&
13
+ (previousRow === null || previousRow === void 0 ? void 0 : previousRow[valueFieldName]) === null && (nextRow === null || nextRow === void 0 ? void 0 : nextRow[valueFieldName]) === null;
14
+ return (isFirst && (nextRow === null || nextRow === void 0 ? void 0 : nextRow[valueFieldName]) === null) || (isLast && (previousRow === null || previousRow === void 0 ? void 0 : previousRow[valueFieldName]) === null) || hasNullNeighborsRows;
15
+ }
16
+ }
@@ -1,4 +1,4 @@
1
- import { ChartOrientation, MdtChartsColorField, IntervalChartType, PolarChartType, Size, TooltipOptions, TwoDimensionalChartType, AxisLabelPosition, ShowTickFn, MdtChartsDataRow, TwoDimensionalValueGroup } from "../config/config";
1
+ import { ChartOrientation, MdtChartsColorField, IntervalChartType, PolarChartType, Size, TooltipOptions, TwoDimensionalChartType, AxisLabelPosition, ShowTickFn, MdtChartsDataRow, TwoDimensionalValueGroup, ValueLabelsCollision } from "../config/config";
2
2
  import { DataType, DonutOptionsCanvas, Formatter, StaticLegendBlockCanvas, TooltipSettings, Transitions } from "../designer/designerConfig";
3
3
  declare type AxisType = "key" | "value";
4
4
  export declare type Orient = "top" | "bottom" | "left" | "right";
@@ -10,6 +10,8 @@ export declare type DataOptions = {
10
10
  [option: string]: any;
11
11
  };
12
12
  export declare type UnitsFromConfig = "%" | "px";
13
+ export declare type ValueLabelAnchor = "start" | "middle" | "end";
14
+ export declare type ValueLabelDominantBaseline = "hanging" | "middle" | "auto";
13
15
  export declare type OptionsModel = TwoDimensionalOptionsModel | PolarOptionsModel | IntervalOptionsModel;
14
16
  export interface Model<O = OptionsModel> {
15
17
  blockCanvas: BlockCanvas;
@@ -49,6 +51,7 @@ export interface TwoDimensionalOptionsModel extends GraphicNotationOptionsModel
49
51
  additionalElements: AdditionalElementsOptions;
50
52
  orient: ChartOrientation;
51
53
  chartSettings: TwoDimChartElementsSettings;
54
+ valueLabels: TwoDimensionalValueLabels;
52
55
  }
53
56
  export interface PolarOptionsModel extends GraphicNotationOptionsModel {
54
57
  type: "polar";
@@ -171,6 +174,9 @@ interface LineLikeChartCurveOptions {
171
174
  interface BarLikeChartHatchOptions {
172
175
  on: boolean;
173
176
  }
177
+ export interface TwoDimensionalValueLabels {
178
+ collision: ValueLabelsCollision;
179
+ }
174
180
  export interface DonutChartSettings extends Omit<DonutOptionsCanvas, "aggregatorPad" | "thickness"> {
175
181
  aggregator: DonutAggregatorModel;
176
182
  thickness: DonutThicknessOptions;
@@ -215,14 +221,14 @@ export interface TwoDimensionalChartLegendLineModel extends Omit<TwoDimensionalL
215
221
  width: number;
216
222
  }
217
223
  interface TwoDimensionalLineLikeChartModel {
218
- lineViewOptions: TwoDimensionalLineLikeChartViewModel;
224
+ lineLikeViewOptions: TwoDimensionalLineLikeChartViewModel;
219
225
  markersOptions: MarkersOptions;
220
226
  }
221
227
  interface TwoDimensionalLineLikeChartViewModel {
222
228
  dashedStyles: LineLikeChartDashOptions;
223
- renderForKey: LineLikeChartRenderOptions;
229
+ renderForKey: LineLikeChartRenderFn;
224
230
  }
225
- export declare type LineLikeChartRenderOptions = (dataRow: MdtChartsDataRow, valueFieldName: string) => boolean;
231
+ export declare type LineLikeChartRenderFn = (dataRow: MdtChartsDataRow, valueFieldName: string) => boolean;
226
232
  interface TwoDimensionalBarLikeChartModel {
227
233
  barViewOptions: TwoDimensionalBarLikeChartViewModel;
228
234
  }
@@ -236,6 +242,7 @@ export interface TwoDimensionalChartModel extends ChartModel, TwoDimensionalLine
236
242
  embeddedLabels: EmbeddedLabelTypeModel;
237
243
  isSegmented: boolean;
238
244
  legend: ChartLegendModel;
245
+ valueLabels?: TwoDimChartValueLabelsOptions;
239
246
  }
240
247
  export interface IntervalChartModel extends Omit<ChartModel, "legend"> {
241
248
  type: IntervalChartType;
@@ -253,10 +260,26 @@ export interface TwoDimensionalChartDataModel {
253
260
  export interface ValueField extends Field {
254
261
  title: string;
255
262
  }
256
- export interface MarkersOptions {
263
+ export interface TwoDimChartValueLabelsOptions {
257
264
  show: boolean;
265
+ handleX: (scaledValue: number) => number;
266
+ handleY: (scaledValue: number) => number;
267
+ textAnchor: ValueLabelAnchor;
268
+ dominantBaseline: ValueLabelDominantBaseline;
269
+ format: ValueLabelsFormatter;
270
+ }
271
+ export declare type ValueLabelsFormatter = (value: number) => string;
272
+ export interface MarkersOptions {
273
+ show: MarkersOptionsShow;
258
274
  styles: MarkersStyleOptions;
259
275
  }
276
+ export declare type MarkDotDatumItem = MdtChartsDataRow | {
277
+ "1": any;
278
+ } & Array<number>;
279
+ export declare type MarkersOptionsShow = (options: {
280
+ row: MarkDotDatumItem;
281
+ valueFieldName: string;
282
+ }) => boolean;
260
283
  export interface MarkersStyleOptions {
261
284
  highlighted: MarkerStyle;
262
285
  normal: MarkerStyle;
@@ -1,4 +1,4 @@
1
- import { AxisLabelFormatter, MdtChartsConfig, MdtChartsField, MdtChartsFieldName, MdtChartsTwoDimensionalOptions, TwoDimensionalChartType, TwoDimensionalValueGroup } from "../../config/config";
1
+ import { AxisLabelFormatter, MdtChartsConfig, MdtChartsField, MdtChartsFieldName, MdtChartsTwoDimensionalOptions, TwoDimensionalChartType, TwoDimensionalValueGroup, ValueLabelsFormatter } from "../../config/config";
2
2
  import { DesignerConfig } from "../../designer/designerConfig";
3
3
  import { DataRepositoryModel } from "../../model/modelInstance/dataModel/dataRepository";
4
4
  interface BaseConfigReader {
@@ -20,6 +20,7 @@ export declare class TwoDimConfigReader implements BaseConfigReader {
20
20
  chartType: TwoDimensionalChartType;
21
21
  }[];
22
22
  containsSecondaryAxis(): boolean;
23
+ getValueLabelFormatterForChart(chartIndex: number): ValueLabelsFormatter;
23
24
  private calculateBiggestValueAndDecremented;
24
25
  private calculateAxisLabelFormatter;
25
26
  }
@@ -54,6 +54,23 @@ export class TwoDimConfigReader {
54
54
  containsSecondaryAxis() {
55
55
  return !!this.options.axis.valueSecondary && this.options.charts.some(chart => chart.data.valueGroup === 'secondary');
56
56
  }
57
+ getValueLabelFormatterForChart(chartIndex) {
58
+ var _a, _b, _c;
59
+ const chart = this.options.charts[chartIndex];
60
+ const axis = this.options.axis;
61
+ if (chart.valueLabels.format)
62
+ return chart.valueLabels.format;
63
+ if (chart.data.valueGroup === "secondary") {
64
+ if ((_a = axis.valueSecondary.labels) === null || _a === void 0 ? void 0 : _a.format)
65
+ return axis.valueSecondary.labels.format;
66
+ else if ((_b = axis.value.labels) === null || _b === void 0 ? void 0 : _b.format)
67
+ return axis.value.labels.format;
68
+ }
69
+ else if ((_c = axis.value.labels) === null || _c === void 0 ? void 0 : _c.format)
70
+ return axis.value.labels.format;
71
+ const valueFieldFormat = chart.data.valueFields[0].format;
72
+ return (v) => this.designerConfig.dataFormat.formatters(v, { type: valueFieldFormat });
73
+ }
57
74
  calculateBiggestValueAndDecremented(repository, domain, fields) {
58
75
  const resolvedDomain = getResolvedDomain(domain, repository.getRawRows());
59
76
  if (resolvedDomain && resolvedDomain.end !== -1) {
@@ -5,12 +5,14 @@ import { ScaleAxisRecalcer } from "../featuresModel/scaleModel/scaleAxisRecalcer
5
5
  import { ScaleModel } from "../featuresModel/scaleModel/scaleModel";
6
6
  import { getLegendMarkerOptions, parseDashStyles, parseShape } from "./twoDimensional/styles";
7
7
  import { getResolvedTitle } from "../../model/featuresModel/titleModel";
8
+ import { calculateValueLabelAlignment, getValueLabelX, getValueLabelY } from "../../model/featuresModel/valueLabelsModel/valueLabelsModel";
9
+ import { TwoDimensionalModelHelper } from "../helpers/twoDimensionalModelHelper";
8
10
  export class TwoDimensionalModel {
9
11
  static getOptions(configReader, designerConfig, modelInstance) {
12
+ var _a;
10
13
  let secondaryScaleValueInfo;
11
14
  const options = configReader.options;
12
15
  const canvasModel = modelInstance.canvasModel;
13
- const resolvedTitle = getResolvedTitle(options.title, modelInstance.dataModel.repository.getRawRows());
14
16
  const scaleModel = new ScaleModel();
15
17
  const scaleMarginRecalcer = new ScaleAxisRecalcer(() => scaleModel.getScaleLinear(options, modelInstance.dataModel.repository.getScopedRows(), canvasModel, configReader));
16
18
  scaleMarginRecalcer.recalculateMargin(canvasModel, options.orientation, options.axis.key);
@@ -20,19 +22,21 @@ export class TwoDimensionalModel {
20
22
  secondaryScaleMarginRecalcer.recalculateMargin(canvasModel, options.orientation, options.axis.key);
21
23
  secondaryScaleValueInfo = secondaryScaleMarginRecalcer.getScaleValue();
22
24
  }
25
+ const keyAxis = AxisModel.getKeyAxis(options, modelInstance.dataModel.repository.getScopedFullSource(), designerConfig.canvas.axisLabel, canvasModel, designerConfig.elementsOptions.tooltip, () => scaleValueInfo.scaleFn(0));
23
26
  return {
24
27
  legend: canvasModel.legendCanvas.getModel(),
25
- title: resolvedTitle,
28
+ title: getResolvedTitle(options.title, modelInstance.dataModel.repository.getRawRows()),
26
29
  selectable: !!options.selectable,
27
30
  orient: options.orientation,
28
31
  scale: Object.assign({ key: scaleModel.getScaleKey(modelInstance.dataModel.getAllowableKeys(), options.orientation, canvasModel, options.charts, this.getChartsByType(options.charts, 'bar')), value: scaleValueInfo.scale }, (configReader.containsSecondaryAxis() && { valueSecondary: secondaryScaleValueInfo.scale })),
29
- axis: Object.assign({ key: AxisModel.getKeyAxis(options, modelInstance.dataModel.repository.getScopedFullSource(), designerConfig.canvas.axisLabel, canvasModel, designerConfig.elementsOptions.tooltip, () => scaleValueInfo.scaleFn(0)), 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) })),
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) })),
30
33
  type: options.type,
31
34
  data: Object.assign({}, options.data),
32
- charts: this.getChartsModel(options.charts, options.orientation, designerConfig, modelInstance.dataModel.repository),
35
+ charts: this.getChartsModel(options.charts, configReader, options.orientation, designerConfig, modelInstance.dataModel.repository, keyAxis.orient, canvasModel, options.data.keyField.name),
33
36
  additionalElements: this.getAdditionalElements(options),
34
37
  tooltip: options.tooltip,
35
- chartSettings: this.getChartsSettings(designerConfig.canvas.chartOptions, options.orientation)
38
+ chartSettings: this.getChartsSettings(designerConfig.canvas.chartOptions, options.orientation),
39
+ valueLabels: (_a = options.valueLabels) !== null && _a !== void 0 ? _a : { collision: { mode: "none" } }
36
40
  };
37
41
  }
38
42
  static getChartsEmbeddedLabelsFlag(charts, chartOrientation) {
@@ -57,22 +61,14 @@ export class TwoDimensionalModel {
57
61
  lineLike: { shape: parseShape(chartOrientation, (_a = chartOptions.line) === null || _a === void 0 ? void 0 : _a.shape) }
58
62
  };
59
63
  }
60
- static getChartsModel(charts, chartOrientation, designerConfig, dataModelRep) {
64
+ static getChartsModel(charts, configReader, chartOrientation, designerConfig, dataModelRep, keyAxisOrient, canvasModel, keyFieldName) {
61
65
  const styleModel = new TwoDimensionalChartStyleModel(charts, designerConfig.chartStyle);
62
66
  this.sortCharts(charts);
63
67
  const chartsModel = [];
64
68
  charts.forEach((chart, index) => {
65
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
66
- chartsModel.push({
67
- type: chart.type,
68
- isSegmented: chart.isSegmented,
69
- data: Object.assign({}, chart.data),
70
- tooltip: chart.tooltip,
71
- cssClasses: ChartStyleModelService.getCssClasses(index),
72
- style: styleModel.getChartStyle(chart, index),
73
- embeddedLabels: this.getEmbeddedLabelType(chart, chartOrientation),
74
- markersOptions: {
75
- show: dataModelRep.getScopedRows().length === 1 ? true : chart.markers.show,
69
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
70
+ chartsModel.push(Object.assign({ type: chart.type, isSegmented: chart.isSegmented, data: Object.assign({}, chart.data), tooltip: chart.tooltip, cssClasses: ChartStyleModelService.getCssClasses(index), style: styleModel.getChartStyle(chart, index), embeddedLabels: this.getEmbeddedLabelType(chart, chartOrientation), markersOptions: {
71
+ show: ({ row, valueFieldName }) => TwoDimensionalModelHelper.shouldMarkerShow(chart, dataModelRep.getRawRows(), valueFieldName, row, keyFieldName),
76
72
  styles: {
77
73
  highlighted: {
78
74
  size: { radius: (_c = (_b = (_a = designerConfig.canvas.markers) === null || _a === void 0 ? void 0 : _a.highlighted) === null || _b === void 0 ? void 0 : _b.radius) !== null && _c !== void 0 ? _c : 4, borderSize: '3.5px' }
@@ -84,15 +80,19 @@ export class TwoDimensionalModel {
84
80
  }
85
81
  }
86
82
  }
87
- },
88
- lineViewOptions: {
83
+ }, lineLikeViewOptions: {
89
84
  dashedStyles: parseDashStyles((_k = chart.lineStyles) === null || _k === void 0 ? void 0 : _k.dash),
90
85
  renderForKey: (dataRow, valueFieldName) => dataRow[valueFieldName] !== null && dataRow[valueFieldName] !== undefined
91
- },
92
- barViewOptions: { hatch: { on: (_o = (_m = (_l = chart.barStyles) === null || _l === void 0 ? void 0 : _l.hatch) === null || _m === void 0 ? void 0 : _m.on) !== null && _o !== void 0 ? _o : false } },
93
- legend: getLegendMarkerOptions(chart),
94
- index
95
- });
86
+ }, barViewOptions: { hatch: { on: (_o = (_m = (_l = chart.barStyles) === null || _l === void 0 ? void 0 : _l.hatch) === null || _m === void 0 ? void 0 : _m.on) !== null && _o !== void 0 ? _o : false } }, legend: getLegendMarkerOptions(chart), index }, (((_p = chart.valueLabels) === null || _p === void 0 ? void 0 : _p.on) && {
87
+ valueLabels: {
88
+ show: true,
89
+ handleX: (scaledValue) => getValueLabelX(scaledValue, keyAxisOrient, canvasModel.getMargin()),
90
+ handleY: (scaledValue) => getValueLabelY(scaledValue, keyAxisOrient, canvasModel.getMargin()),
91
+ textAnchor: calculateValueLabelAlignment(keyAxisOrient).textAnchor,
92
+ dominantBaseline: calculateValueLabelAlignment(keyAxisOrient).dominantBaseline,
93
+ format: configReader.getValueLabelFormatterForChart(index),
94
+ }
95
+ })));
96
96
  });
97
97
  return chartsModel;
98
98
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdt-charts",
3
- "version": "1.20.0",
3
+ "version": "1.20.1",
4
4
  "description": "",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {