mdt-charts 1.11.1 → 1.12.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/lib/config/config.d.ts +25 -12
  2. package/lib/designer/designerConfig.d.ts +3 -5
  3. package/lib/engine/features/aggregator/aggregator.d.ts +8 -6
  4. package/lib/engine/features/aggregator/aggregator.js +45 -32
  5. package/lib/engine/features/legend/legend.d.ts +10 -1
  6. package/lib/engine/features/legend/legend.js +10 -22
  7. package/lib/engine/features/legend/legendHelper.d.ts +4 -5
  8. package/lib/engine/features/legend/legendHelper.js +19 -23
  9. package/lib/engine/features/legend/legendHelperService.d.ts +12 -0
  10. package/lib/engine/features/legend/legendHelperService.js +30 -0
  11. package/lib/engine/features/recordOverflowAlert/recordOverflowAlertCore.d.ts +28 -0
  12. package/lib/engine/features/recordOverflowAlert/recordOverflowAlertCore.js +50 -0
  13. package/lib/engine/intervalNotation/intervalManager.js +0 -3
  14. package/lib/engine/polarNotation/donut/donut.js +1 -1
  15. package/lib/engine/polarNotation/extenders/polarRecordOverflowAlert.d.ts +15 -0
  16. package/lib/engine/polarNotation/extenders/polarRecordOverflowAlert.js +40 -0
  17. package/lib/engine/polarNotation/polarManager.js +11 -6
  18. package/lib/engine/twoDimensionalNotation/extenders/twoDimRecordOverflowAlert.d.ts +15 -0
  19. package/lib/engine/twoDimensionalNotation/extenders/twoDimRecordOverflowAlert.js +32 -0
  20. package/lib/engine/twoDimensionalNotation/twoDimensionalManager.js +9 -3
  21. package/lib/model/chartStyleModel/TwoDimensionalChartStyleModel.d.ts +4 -4
  22. package/lib/model/{dataManagerModel.d.ts → dataManagerModel/dataManagerModel.d.ts} +18 -7
  23. package/lib/model/{dataManagerModel.js → dataManagerModel/dataManagerModel.js} +51 -45
  24. package/lib/model/dataManagerModel/dataManagerModelService.d.ts +5 -0
  25. package/lib/model/dataManagerModel/dataManagerModelService.js +28 -0
  26. package/lib/model/featuresModel/axisModel.d.ts +5 -4
  27. package/lib/model/featuresModel/axisModel.js +14 -12
  28. package/lib/model/featuresModel/axisModelService.d.ts +4 -0
  29. package/lib/model/featuresModel/axisModelService.js +11 -0
  30. package/lib/model/featuresModel/legendModel/legendCanvasModel.d.ts +4 -2
  31. package/lib/model/featuresModel/legendModel/legendCanvasModel.js +42 -29
  32. package/lib/model/featuresModel/legendModel/legendModel.d.ts +1 -4
  33. package/lib/model/featuresModel/legendModel/legendModel.js +15 -16
  34. package/lib/model/featuresModel/legendModel/polarMarginCalculator.d.ts +11 -0
  35. package/lib/model/featuresModel/legendModel/polarMarginCalculator.js +42 -0
  36. package/lib/model/featuresModel/scaleModel.d.ts +6 -6
  37. package/lib/model/featuresModel/titleModel.js +4 -4
  38. package/lib/model/marginModel.d.ts +3 -2
  39. package/lib/model/marginModel.js +11 -7
  40. package/lib/model/model.d.ts +19 -8
  41. package/lib/model/modelBuilder.js +9 -9
  42. package/lib/model/modelInstance/canvasModel/canvasModel.d.ts +2 -0
  43. package/lib/model/modelInstance/canvasModel/canvasModel.js +2 -0
  44. package/lib/model/modelInstance/canvasModel/legendCanvasModel.d.ts +7 -0
  45. package/lib/model/modelInstance/canvasModel/legendCanvasModel.js +13 -0
  46. package/lib/model/modelInstance/dataModel.d.ts +11 -0
  47. package/lib/model/modelInstance/dataModel.js +23 -0
  48. package/lib/model/modelInstance/modelInstance.d.ts +3 -0
  49. package/lib/model/modelInstance/modelInstance.js +7 -1
  50. package/lib/model/notations/intervalModel.d.ts +2 -2
  51. package/lib/model/notations/intervalModel.js +2 -3
  52. package/lib/model/notations/polar/donut/donutAggregatorService.d.ts +12 -0
  53. package/lib/model/notations/polar/donut/donutAggregatorService.js +25 -0
  54. package/lib/model/notations/polar/donut/donutModel.d.ts +10 -0
  55. package/lib/model/notations/polar/donut/donutModel.js +32 -0
  56. package/lib/model/notations/polar/donut/donutThicknessService.d.ts +9 -0
  57. package/lib/model/notations/polar/donut/donutThicknessService.js +30 -0
  58. package/lib/model/notations/polar/polarModel.d.ts +16 -0
  59. package/lib/model/notations/polar/polarModel.js +55 -0
  60. package/lib/model/notations/polarModel.d.ts +7 -1
  61. package/lib/model/notations/polarModel.js +24 -2
  62. package/lib/model/notations/twoDimensionalModel.d.ts +4 -4
  63. package/lib/model/notations/twoDimensionalModel.js +2 -3
  64. package/lib/style/charts-main.css +29 -9
  65. package/lib/style/charts-main.less +29 -9
  66. package/package.json +2 -2
  67. package/tsconfig.production.json +23 -0
  68. package/lib/engine/features/recordOverflowAlert/recordOverflowAlert.d.ts +0 -14
  69. package/lib/engine/features/recordOverflowAlert/recordOverflowAlert.js +0 -97
@@ -14,9 +14,10 @@ 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
- options: MdtChartsPolarOptions | MdtChartsTwoDimensionalOptions | IntervalOptions;
20
+ options: MdtChartsPolarOptions | MdtChartsTwoDimensionalOptions | MdtChartsIntervalOptions;
20
21
  }
21
22
  export interface ChartBlockCanvas {
22
23
  size: Size;
@@ -41,14 +42,14 @@ export interface MdtChartsTwoDimensionalOptions extends Options {
41
42
  type: '2d';
42
43
  axis: TwoDimensionalAxis;
43
44
  additionalElements: AdditionalElements;
44
- charts: TwoDimensionalChart[];
45
+ charts: MdtChartsTwoDimensionalChart[];
45
46
  orientation: ChartOrientation;
46
47
  }
47
48
  export interface MdtChartsPolarOptions extends Options {
48
49
  type: 'polar';
49
50
  chart: PolarChart;
50
51
  }
51
- export interface IntervalOptions extends Options {
52
+ export interface MdtChartsIntervalOptions extends Options {
52
53
  type: 'interval';
53
54
  axis: IntervalAxis;
54
55
  chart: IntervalChart;
@@ -61,15 +62,16 @@ export interface Legend {
61
62
  export interface DataOptions {
62
63
  dataSource: string;
63
64
  keyField: MdtChartsField;
65
+ maxRecordsAmount?: number;
64
66
  }
65
67
  export interface MdtChartsField {
66
68
  name: string;
67
69
  format: DataType;
68
70
  }
69
- export interface ValueField extends MdtChartsField {
71
+ export interface MdtChartsValueField extends MdtChartsField {
70
72
  title: string;
71
73
  }
72
- export interface TwoDimValueField extends ValueField {
74
+ export interface TwoDimValueField extends MdtChartsValueField {
73
75
  color?: string;
74
76
  }
75
77
  export interface TooltipOptions {
@@ -105,6 +107,10 @@ export interface NumberDomain {
105
107
  end: number;
106
108
  }
107
109
  export interface DiscreteAxisOptions extends AxisOptions {
110
+ labels?: MdtChartsDiscreteAxisLabel;
111
+ }
112
+ export interface MdtChartsDiscreteAxisLabel {
113
+ position?: AxisLabelPosition;
108
114
  }
109
115
  export interface IntervalAxis {
110
116
  key: DiscreteAxisOptions;
@@ -118,7 +124,7 @@ interface ChartSettings {
118
124
  interface Tooltip {
119
125
  show: boolean;
120
126
  }
121
- export interface TwoDimensionalChart extends ChartSettings {
127
+ export interface MdtChartsTwoDimensionalChart extends ChartSettings {
122
128
  type: TwoDimensionalChartType;
123
129
  data: TwoDimensionalChartData;
124
130
  embeddedLabels: EmbeddedLabelType;
@@ -128,7 +134,7 @@ export interface TwoDimensionalChart extends ChartSettings {
128
134
  export interface PolarChart extends ChartSettings {
129
135
  type: PolarChartType;
130
136
  data: PolarChartData;
131
- aggregator: MdtChartsPolarChartAggregator;
137
+ aggregator?: MdtChartsDonutAggregator;
132
138
  }
133
139
  export interface IntervalChart extends ChartSettings {
134
140
  type: IntervalChartType;
@@ -142,14 +148,21 @@ interface MarkersOptions {
142
148
  }
143
149
  export declare type MdtChartsColorField = string;
144
150
  export interface PolarChartData {
145
- valueField: ValueField;
151
+ valueField: MdtChartsValueField;
146
152
  colorField?: MdtChartsColorField;
147
153
  }
148
- export interface MdtChartsPolarChartAggregator {
149
- text: string;
154
+ export interface MdtChartsDonutAggregator {
155
+ content?: (model: MdtChartsAggregatorModel) => MdtChartsAggregatorContent;
156
+ }
157
+ export interface MdtChartsAggregatorModel {
158
+ data: MdtChartsDataRow[];
159
+ }
160
+ export interface MdtChartsAggregatorContent {
161
+ value: string | number;
162
+ title: string;
150
163
  }
151
164
  interface IntervalChartData {
152
- valueField1: ValueField;
153
- valueField2: ValueField;
165
+ valueField1: MdtChartsValueField;
166
+ valueField2: MdtChartsValueField;
154
167
  }
155
168
  export {};
@@ -4,7 +4,6 @@ export declare type DataTypeOptions = {
4
4
  };
5
5
  export declare type Formatter = (value: any, options?: any) => string;
6
6
  export declare type TooltipPosition = 'followCursor' | 'fixed';
7
- export declare type MdtChartsDonutThicknessUnit = "px" | "%";
8
7
  export interface DesignerConfig {
9
8
  canvas: Canvas;
10
9
  dataFormat: DataFormat;
@@ -50,10 +49,9 @@ export interface DonutOptionsCanvas {
50
49
  thickness: MdtChartsDonutThicknessOptions;
51
50
  }
52
51
  export interface MdtChartsDonutThicknessOptions {
53
- min: number;
54
- max: number;
55
- value: number;
56
- unit: MdtChartsDonutThicknessUnit;
52
+ min: number | string;
53
+ max: number | string;
54
+ value?: number | string;
57
55
  }
58
56
  interface DataFormat {
59
57
  formatters: Formatter;
@@ -1,23 +1,25 @@
1
- import { MdtChartsDataRow } from '../../../config/config';
2
1
  import { DataType } from '../../../designer/designerConfig';
3
- import { DonutChartAggreagorModel, Field } from "../../../model/model";
2
+ import { DonutAggregatorModel, Field } from "../../../model/model";
4
3
  import { Block } from "../../block/block";
5
4
  import { Translate } from "../../polarNotation/donut/donut";
6
5
  export interface AggregatorInfo {
7
6
  name: string;
8
- value: number;
7
+ value: number | string;
9
8
  format: DataType;
10
9
  margin: number;
11
10
  }
12
11
  export declare class Aggregator {
13
12
  static readonly aggregatorValueClass = "aggregator-value";
14
- private static readonly aggregatorNameClass;
13
+ private static readonly aggregatorTitleClass;
15
14
  private static readonly aggregatorObjectClass;
16
- static render(block: Block, data: MdtChartsDataRow[], valueField: Field, innerRadius: number, translate: Translate, fontSize: number, settings: DonutChartAggreagorModel): void;
17
- static update(block: Block, data: MdtChartsDataRow[], valueField: Field, settings: DonutChartAggreagorModel): void;
15
+ static render(block: Block, valueField: Field, innerRadius: number, translate: Translate, fontSize: number, settings: DonutAggregatorModel): void;
16
+ static update(block: Block, valueField: Field, settings: DonutAggregatorModel): void;
17
+ private static buildConfig;
18
18
  private static renderText;
19
+ private static formatValue;
19
20
  private static updateText;
20
21
  private static reCalculateAggregatorFontSize;
22
+ private static setTitleFontSize;
21
23
  private static renderAggregatorObject;
22
24
  private static renderWrapper;
23
25
  }
@@ -1,28 +1,25 @@
1
- import { sum } from 'd3-array';
2
1
  import { interpolateNumber } from 'd3-interpolate';
3
2
  import { Helper } from '../../helpers/helper';
4
3
  import { ValueFormatter } from '../../valueFormatter';
5
4
  export class Aggregator {
6
- static render(block, data, valueField, innerRadius, translate, fontSize, settings) {
7
- const aggregator = {
8
- name: settings.text,
9
- value: sum(data.map(d => d[valueField.name])),
10
- format: valueField.format,
11
- margin: settings.margin
12
- };
13
- this.renderText(block, innerRadius, aggregator, translate, fontSize);
5
+ static render(block, valueField, innerRadius, translate, fontSize, settings) {
6
+ const aggregator = this.buildConfig(valueField, settings);
7
+ this.renderText(block, innerRadius, aggregator, fontSize, translate);
8
+ }
9
+ static update(block, valueField, settings) {
10
+ const aggregator = this.buildConfig(valueField, settings);
11
+ this.updateText(block, aggregator, typeof aggregator.value === "string");
14
12
  }
15
- static update(block, data, valueField, settings) {
16
- const aggregator = {
17
- name: 'Сумма',
18
- value: sum(data.map(d => d[valueField.name])),
13
+ static buildConfig(valueField, settings) {
14
+ return {
15
+ name: settings.content.title,
16
+ value: settings.content.value,
19
17
  format: valueField.format,
20
18
  margin: settings.margin
21
19
  };
22
- this.updateText(block, aggregator);
23
20
  }
24
- static renderText(block, innerRadius, aggregatorInfo, translate, fontSize) {
25
- if (innerRadius > 50) {
21
+ static renderText(block, innerRadius, aggregatorInfo, fontSize, translate) {
22
+ if (innerRadius > 40) {
26
23
  const aggregatorObject = this.renderAggregatorObject(block, innerRadius, translate);
27
24
  const wrapper = this.renderWrapper(aggregatorObject);
28
25
  wrapper
@@ -30,46 +27,62 @@ export class Aggregator {
30
27
  .attr('class', this.aggregatorValueClass)
31
28
  .style('text-align', 'center')
32
29
  .style('font-size', `${fontSize}px`)
33
- .text(ValueFormatter.formatField(aggregatorInfo.format, aggregatorInfo.value));
30
+ .text(this.formatValue(aggregatorInfo.format, aggregatorInfo.value));
34
31
  wrapper
35
32
  .append('div')
36
- .attr('class', this.aggregatorNameClass)
33
+ .attr('class', this.aggregatorTitleClass)
37
34
  .attr('title', aggregatorInfo.name)
38
35
  .style('text-align', 'center')
39
- .style('font-size', '18px')
40
36
  .text(aggregatorInfo.name);
41
37
  this.reCalculateAggregatorFontSize(aggregatorObject.node().getBoundingClientRect().width, block, aggregatorInfo.margin);
42
38
  }
43
39
  }
44
- static updateText(block, newAggregator) {
40
+ static formatValue(format, value) {
41
+ if (typeof value === "string")
42
+ return value;
43
+ return ValueFormatter.formatField(format, value);
44
+ }
45
+ static updateText(block, newAggregator, withoutAnimation) {
45
46
  const aggregatorObject = block.getSvg()
46
47
  .select(`.${this.aggregatorObjectClass}`);
47
48
  const thisClass = this;
48
- block.getSvg()
49
- .select(`.${this.aggregatorValueClass}`)
49
+ const valueBlock = block.getSvg()
50
+ .select(`.${this.aggregatorValueClass}`);
51
+ if (withoutAnimation) {
52
+ valueBlock.text(this.formatValue(newAggregator.format, newAggregator.value));
53
+ return;
54
+ }
55
+ valueBlock
50
56
  .interrupt()
51
57
  .transition()
52
58
  .duration(block.transitionManager.durations.chartUpdate)
53
59
  .tween("text", function () {
60
+ const newValue = typeof newAggregator.value === "string" ? parseFloat(newAggregator.value) : newAggregator.value;
54
61
  const oldValue = Helper.parseFormattedToNumber(this.textContent, ',');
55
- const precision = Helper.calcDigitsAfterDot(newAggregator.value);
56
- const interpolateFunc = interpolateNumber(oldValue, newAggregator.value);
62
+ const precision = Helper.calcDigitsAfterDot(newValue);
63
+ const interpolateFunc = interpolateNumber(oldValue, newValue);
57
64
  return t => {
58
- this.textContent = ValueFormatter.formatField(newAggregator.format, (interpolateFunc(t)).toFixed(precision));
65
+ this.textContent = thisClass.formatValue(newAggregator.format, parseFloat((interpolateFunc(t)).toFixed(precision)));
59
66
  thisClass.reCalculateAggregatorFontSize(aggregatorObject.node().getBoundingClientRect().width, block, newAggregator.margin);
60
67
  };
61
68
  });
62
69
  }
63
70
  static reCalculateAggregatorFontSize(wrapperSize, block, pad) {
64
- const aggreggatorValue = block.getSvg()
71
+ const aggregatorValue = block.getSvg()
65
72
  .select(`.${this.aggregatorValueClass}`);
66
- let fontSize = parseInt(aggreggatorValue.style('font-size'));
67
- while (aggreggatorValue.node().getBoundingClientRect().width > wrapperSize - pad * 2 && fontSize > 15) {
68
- aggreggatorValue.style('font-size', `${fontSize -= 2}px`);
73
+ const aggregatorTitle = block.getSvg()
74
+ .select(`.${this.aggregatorTitleClass}`);
75
+ let fontSize = parseInt(aggregatorValue.style('font-size'));
76
+ while (aggregatorValue.node().getBoundingClientRect().width > wrapperSize - pad * 2 && fontSize > 12) {
77
+ aggregatorValue.style('font-size', `${fontSize -= 2}px`);
69
78
  }
70
- while (aggreggatorValue.node().getBoundingClientRect().width < wrapperSize - pad * 2 && fontSize < 60) {
71
- aggreggatorValue.style('font-size', `${fontSize += 2}px`);
79
+ while (aggregatorValue.node().getBoundingClientRect().width < wrapperSize - pad * 2 && fontSize < 60) {
80
+ aggregatorValue.style('font-size', `${fontSize += 2}px`);
72
81
  }
82
+ this.setTitleFontSize(aggregatorTitle, fontSize);
83
+ }
84
+ static setTitleFontSize(aggregatorTitle, valueFontSize) {
85
+ aggregatorTitle.style('font-size', `${Math.round(valueFontSize * 0.5)}px`);
73
86
  }
74
87
  static renderAggregatorObject(block, innerRadius, translate) {
75
88
  return block.getSvg()
@@ -94,5 +107,5 @@ export class Aggregator {
94
107
  }
95
108
  }
96
109
  Aggregator.aggregatorValueClass = 'aggregator-value';
97
- Aggregator.aggregatorNameClass = 'aggregator-name';
110
+ Aggregator.aggregatorTitleClass = 'aggregator-name';
98
111
  Aggregator.aggregatorObjectClass = 'aggregator-object';
@@ -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
+ }
@@ -0,0 +1,28 @@
1
+ import { Block } from "../../block/block";
2
+ export interface RecordOverflowAlertOptions {
3
+ hidedRecordsAmount: number;
4
+ text: RecordOverflowAlertText;
5
+ positionAttrs: AlertBlockPositionAttrs;
6
+ }
7
+ export interface RecordOverflowAlertText {
8
+ one: string;
9
+ twoToFour: string;
10
+ tenToTwenty: string;
11
+ other: string;
12
+ }
13
+ export interface AlertBlockPositionAttrs {
14
+ top?: string;
15
+ bottom?: string;
16
+ right?: string;
17
+ left?: string;
18
+ }
19
+ declare class RecordOverflowAlertCoreClass {
20
+ private readonly blockClass;
21
+ render(block: Block, options: RecordOverflowAlertOptions): void;
22
+ update(block: Block, options: RecordOverflowAlertOptions): void;
23
+ private getAlertText;
24
+ private getWordTextEndingByAmount;
25
+ private setAlertPosition;
26
+ }
27
+ export declare const RecordOverflowAlertCore: RecordOverflowAlertCoreClass;
28
+ export {};
@@ -0,0 +1,50 @@
1
+ class RecordOverflowAlertCoreClass {
2
+ constructor() {
3
+ this.blockClass = 'record-overflow-alert';
4
+ }
5
+ render(block, options) {
6
+ const alertBlock = block.getWrapper()
7
+ .append('div')
8
+ .attr('class', this.blockClass)
9
+ .text(this.getAlertText(options));
10
+ this.setAlertPosition(alertBlock, options.positionAttrs);
11
+ }
12
+ update(block, options) {
13
+ let alertBlock = block.getWrapper()
14
+ .select(`div.${this.blockClass}`);
15
+ if (alertBlock.empty()) {
16
+ if (options.hidedRecordsAmount === 0)
17
+ return;
18
+ else
19
+ this.render(block, options);
20
+ }
21
+ else {
22
+ if (options.hidedRecordsAmount === 0)
23
+ alertBlock.remove();
24
+ else
25
+ alertBlock.text(this.getAlertText(options));
26
+ }
27
+ }
28
+ getAlertText(options) {
29
+ return `+ ${options.hidedRecordsAmount} ${this.getWordTextEndingByAmount(options.hidedRecordsAmount, options.text)}`;
30
+ }
31
+ getWordTextEndingByAmount(hidedRecordsAmount, text) {
32
+ const lastDigit = hidedRecordsAmount % 10;
33
+ if (hidedRecordsAmount >= 10 && hidedRecordsAmount <= 20)
34
+ return text.tenToTwenty;
35
+ if (lastDigit === 1)
36
+ return text.one;
37
+ if (lastDigit >= 2 && lastDigit <= 4)
38
+ return text.twoToFour;
39
+ return text.other;
40
+ }
41
+ setAlertPosition(alertBlock, attrs) {
42
+ alertBlock
43
+ .style('position', 'absolute')
44
+ .style('left', attrs.left)
45
+ .style('right', attrs.right)
46
+ .style('top', attrs.top)
47
+ .style('bottom', attrs.bottom);
48
+ }
49
+ }
50
+ export const RecordOverflowAlertCore = new RecordOverflowAlertCoreClass();
@@ -1,7 +1,6 @@
1
1
  import { Axis } from "../features/axis/axis";
2
2
  import { GridLine } from "../features/gridLine/gridLine";
3
3
  import { Legend } from "../features/legend/legend";
4
- import { RecordOverflowAlert } from "../features/recordOverflowAlert/recordOverflowAlert";
5
4
  import { Scale } from "../features/scale/scale";
6
5
  import { Title } from "../features/title/title";
7
6
  import { Tooltip } from "../features/tolltip/tooltip";
@@ -17,8 +16,6 @@ export class IntervalManager {
17
16
  Title.render(block, options.title, model.otherComponents.titleBlock, model.blockCanvas.size);
18
17
  Legend.render(block, data, options, model);
19
18
  Tooltip.render(block, model, data, model.otherComponents.tooltipBlock, scales);
20
- if (model.dataSettings.scope.hidedRecordsAmount !== 0)
21
- RecordOverflowAlert.render(block, model.dataSettings.scope.hidedRecordsAmount, 'top', options.orient);
22
19
  }
23
20
  static renderCharts(block, charts, scales, data, dataOptions, margin, keyAxisOrient, chartSettings) {
24
21
  block.renderChartsBlock();
@@ -11,7 +11,7 @@ export class Donut {
11
11
  const arcGenerator = DonutHelper.getArcGenerator(outerRadius, innerRadius);
12
12
  const pieGenerator = DonutHelper.getPieGenerator(chart.data.valueField.name, settings.padAngle);
13
13
  const translateAttr = DonutHelper.getTranslate(margin, blockSize);
14
- Aggregator.render(block, data, chart.data.valueField, innerRadius, translateAttr, thickness, settings.aggregator);
14
+ Aggregator.render(block, chart.data.valueField, innerRadius, translateAttr, thickness, settings.aggregator);
15
15
  const donutBlock = block.getSvg()
16
16
  .append('g')
17
17
  .attr('class', this.donutBlockClass)
@@ -0,0 +1,15 @@
1
+ import { LegendPosition } from "../../../model/model";
2
+ import { Block } from "../../block/block";
3
+ interface PolarRecordOverflowAlertOptions {
4
+ hidedRecordsAmount: number;
5
+ legendPosition: LegendPosition;
6
+ }
7
+ declare class PolarRecordOverflowAlertClass {
8
+ private readonly text;
9
+ render(block: Block, options: PolarRecordOverflowAlertOptions): void;
10
+ update(block: Block, options: PolarRecordOverflowAlertOptions): void;
11
+ private buildCoreOptions;
12
+ private getPositionAttrs;
13
+ }
14
+ export declare const PolarRecordOverflowAlert: PolarRecordOverflowAlertClass;
15
+ export {};