mdt-charts 1.33.3 → 1.34.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 (59) hide show
  1. package/lib/config/config.d.ts +25 -4
  2. package/lib/engine/features/axis/axis.d.ts +1 -0
  3. package/lib/engine/features/axis/axis.js +6 -2
  4. package/lib/engine/features/axis/axisHelper.js +1 -3
  5. package/lib/engine/features/groupLabels/groupLabels.d.ts +17 -0
  6. package/lib/engine/features/groupLabels/groupLabels.js +61 -0
  7. package/lib/engine/features/scale/scale.d.ts +3 -2
  8. package/lib/engine/features/scale/scale.js +11 -1
  9. package/lib/engine/features/valueLabels/valueLabels.d.ts +3 -3
  10. package/lib/engine/features/valueLabels/valueLabels.js +1 -1
  11. package/lib/engine/filterManager/filterEventManager.d.ts +1 -1
  12. package/lib/engine/filterManager/filterEventManager.js +1 -1
  13. package/lib/engine/twoDimensionalNotation/twoDimensionalManager.d.ts +1 -0
  14. package/lib/engine/twoDimensionalNotation/twoDimensionalManager.js +8 -0
  15. package/lib/model/featuresModel/axis/axisModel.d.ts +10 -10
  16. package/lib/model/featuresModel/axis/axisModel.js +10 -3
  17. package/lib/model/featuresModel/axis/axisModelService.js +2 -2
  18. package/lib/model/featuresModel/grouping/groupingLabels/groupingLabelsCoordinateHandlers.d.ts +20 -0
  19. package/lib/model/featuresModel/grouping/groupingLabels/groupingLabelsCoordinateHandlers.js +36 -0
  20. package/lib/model/featuresModel/grouping/groupingLabels/groupingLabelsScaler.d.ts +22 -0
  21. package/lib/model/featuresModel/grouping/groupingLabels/groupingLabelsScaler.js +49 -0
  22. package/lib/model/featuresModel/legendModel/legendModel.d.ts +1 -1
  23. package/lib/model/featuresModel/legendModel/legendModel.js +4 -4
  24. package/lib/model/featuresModel/legendModel/polarMarginCalculator.js +1 -1
  25. package/lib/model/featuresModel/legendModel/twoDimLegendModel.d.ts +1 -1
  26. package/lib/model/featuresModel/legendModel/twoDimLegendModel.js +5 -3
  27. package/lib/model/featuresModel/otherComponents.js +1 -2
  28. package/lib/model/featuresModel/scaleModel/scaleModel.d.ts +6 -3
  29. package/lib/model/featuresModel/scaleModel/scaleModel.js +49 -7
  30. package/lib/model/featuresModel/scaleModel/scaleModelServices.js +3 -3
  31. package/lib/model/featuresModel/tooltipModel/tooltipContentModel.js +3 -3
  32. package/lib/model/featuresModel/valueLabelsModel/valueLabelsModel.d.ts +3 -3
  33. package/lib/model/{EventEmitter.d.ts → helpers/eventEmitter.d.ts} +1 -1
  34. package/lib/model/helpers/twoDimensionalModelHelper.d.ts +1 -1
  35. package/lib/model/margin/marginModel.js +4 -4
  36. package/lib/model/margin/twoDim/twoDimMarginModel.d.ts +1 -1
  37. package/lib/model/margin/twoDim/twoDimMarginModel.js +6 -3
  38. package/lib/model/model.d.ts +51 -8
  39. package/lib/model/modelBuilder.js +2 -1
  40. package/lib/model/modelInstance/canvasModel/legendCanvasModel.d.ts +5 -0
  41. package/lib/model/modelInstance/canvasModel/legendCanvasModel.js +13 -0
  42. package/lib/model/modelInstance/canvasModel/titleCanvas.d.ts +3 -3
  43. package/lib/model/modelInstance/canvasModel/titleCanvas.js +21 -2
  44. package/lib/model/modelInstance/configReader/baseConfigReader.d.ts +6 -0
  45. package/lib/model/modelInstance/configReader/baseConfigReader.js +9 -0
  46. package/lib/model/modelInstance/configReader/polarConfigReader/polarConfigReader.d.ts +7 -0
  47. package/lib/model/modelInstance/configReader/polarConfigReader/polarConfigReader.js +8 -0
  48. package/lib/model/modelInstance/configReader/twoDimConfigReader.ts/groupingConfigReader/groupingConfigReader.d.ts +29 -0
  49. package/lib/model/modelInstance/configReader/twoDimConfigReader.ts/groupingConfigReader/groupingConfigReader.js +102 -0
  50. package/lib/model/modelInstance/{configReader.d.ts → configReader/twoDimConfigReader.ts/twoDimConfigReader.d.ts} +6 -13
  51. package/lib/model/modelInstance/{configReader.js → configReader/twoDimConfigReader.ts/twoDimConfigReader.js} +8 -19
  52. package/lib/model/modelInstance/modelInstance.js +1 -1
  53. package/lib/model/modelInstance/titleConfigReader.d.ts +2 -2
  54. package/lib/model/notations/twoDimensionalModel.d.ts +1 -1
  55. package/lib/model/notations/twoDimensionalModel.js +47 -2
  56. package/package.json +1 -1
  57. package/lib/model/featuresModel/titleModel.d.ts +0 -5
  58. package/lib/model/featuresModel/titleModel.js +0 -16
  59. /package/lib/model/{EventEmitter.js → helpers/eventEmitter.js} +0 -0
@@ -1,6 +1,6 @@
1
1
  declare type DataType = string;
2
2
  export declare type MdtChartsIconElement = () => HTMLElement;
3
- export declare type AxisPosition = "start" | "end";
3
+ export declare type ItemPositionByOrientation = "start" | "end";
4
4
  export declare type ChartOrientation = "vertical" | "horizontal";
5
5
  export declare type ChartNotation = "2d" | "polar";
6
6
  export declare type ChartType = "bar" | "line" | "area" | "donut" | "gantt";
@@ -53,6 +53,7 @@ export interface MdtChartsTwoDimensionalOptions extends GraphicNotationOptions {
53
53
  charts: MdtChartsTwoDimensionalChart[];
54
54
  orientation: ChartOrientation;
55
55
  valueLabels?: MdtChartsTwoDimensionalValueLabels;
56
+ grouping?: TwoDimGroupingOptions;
56
57
  }
57
58
  export interface MdtChartsPolarOptions extends GraphicNotationOptions {
58
59
  type: "polar";
@@ -97,8 +98,10 @@ export interface DataOptions {
97
98
  maxRecordsAmount?: number;
98
99
  }
99
100
  export declare type MdtChartsFieldName = string;
100
- export interface MdtChartsField {
101
+ export interface MdtChartsBaseField {
101
102
  name: MdtChartsFieldName;
103
+ }
104
+ export interface MdtChartsField extends MdtChartsBaseField {
102
105
  format: DataType;
103
106
  }
104
107
  export interface MdtChartsValueField extends MdtChartsField {
@@ -167,7 +170,7 @@ export interface TwoDimensionalAxis {
167
170
  export declare type NumberSecondaryAxisOptions = Omit<NumberAxisOptions, "position">;
168
171
  export interface AxisOptions {
169
172
  visibility: boolean;
170
- position: AxisPosition;
173
+ position: ItemPositionByOrientation;
171
174
  ticks: AxisTicks;
172
175
  line?: AxisLineOptions;
173
176
  }
@@ -202,8 +205,13 @@ export interface DiscreteAxisOptions extends AxisOptions {
202
205
  export interface MdtChartsDiscreteAxisLabel {
203
206
  position?: AxisLabelPosition;
204
207
  showRule?: MdtChartsShowAxisLabelRule;
208
+ format?: DiscreteAxisLabelFormatter;
205
209
  }
206
- export declare type ShowTickFn = (dataKey: string, index: number) => string | undefined;
210
+ export declare type DiscreteAxisLabelFormatter = (options: {
211
+ key: string;
212
+ dataRow: MdtChartsDataRow;
213
+ }) => string;
214
+ export declare type ShowTickFn = (dataKey: string, index: number) => boolean;
207
215
  export interface MdtChartsShowAxisLabelRule {
208
216
  spaceForOneLabel?: number;
209
217
  showTickFn?: ShowTickFn;
@@ -223,6 +231,19 @@ export interface ValueLabelsStyleOptions {
223
231
  fontSize?: number;
224
232
  color?: string;
225
233
  }
234
+ export interface TwoDimGroupingOptions {
235
+ items: TwoDimGroupingItem[];
236
+ }
237
+ export interface TwoDimGroupingItem {
238
+ data: TwoDimGroupingItemData;
239
+ labels?: TwoDimGroupingItemLabels;
240
+ }
241
+ interface TwoDimGroupingItemData {
242
+ field: MdtChartsField;
243
+ }
244
+ interface TwoDimGroupingItemLabels {
245
+ position?: ItemPositionByOrientation;
246
+ }
226
247
  interface MdtChartsLineLikeChart {
227
248
  markers: MarkersOptions;
228
249
  lineStyles?: MdtChartsLineLikeChartStyles;
@@ -12,4 +12,5 @@ export declare class Axis {
12
12
  private static updateValueAxis;
13
13
  private static updateKeyAxis;
14
14
  private static handleLabelsHighlight;
15
+ private static getKeyAxisTickFormat;
15
16
  }
@@ -38,7 +38,7 @@ export class Axis {
38
38
  if (axisOptions.type === "value" && scaleOptions.type === "linear")
39
39
  AxisHelper.setValueAxisLabelsSettings(axisGenerator, scaleOptions, axisOptions.labels);
40
40
  else
41
- axisGenerator.tickFormat(axisOptions.labels.showTick);
41
+ axisGenerator.tickFormat((d, i) => this.getKeyAxisTickFormat(d, i, axisOptions));
42
42
  const axisElement = block
43
43
  .getSvg()
44
44
  .append("g")
@@ -94,7 +94,7 @@ export class Axis {
94
94
  else if (axisOptions.orient === "top")
95
95
  axisGenerator.tickPadding(-6);
96
96
  }
97
- axisGenerator.tickFormat(axisOptions.labels.showTick);
97
+ axisGenerator.tickFormat((d, i) => this.getKeyAxisTickFormat(d, i, axisOptions));
98
98
  const axisElement = block.getSvg().select(`g.${axisOptions.cssClass}`);
99
99
  AxisLabelsEventManager.removeEvents(axisElement);
100
100
  if (axisOptions.orient === "left" || axisOptions.orient === "right") {
@@ -158,5 +158,9 @@ export class Axis {
158
158
  select(this).classed("mdt-charts-opacity-inactive", !isActive);
159
159
  });
160
160
  }
161
+ static getKeyAxisTickFormat(datumKey, index, axisOptions) {
162
+ const shouldBeShown = axisOptions.labels.showTick(datumKey, index);
163
+ return shouldBeShown ? axisOptions.labels.format({ key: datumKey }) : undefined;
164
+ }
161
165
  }
162
166
  Axis.axesClass = NamesHelper.getClassName("axis");
@@ -17,9 +17,7 @@ export class AxisHelper {
17
17
  axisGenerator.ticks(labelsOptions.tickAmountSettings.policy.amount);
18
18
  if (labelsOptions.tickAmountSettings.policy.type === "constant")
19
19
  axisGenerator.tickValues(labelsOptions.tickAmountSettings.policy.values);
20
- if (scaleOptions.type === "linear") {
21
- this.setNumTickFormat(axisGenerator, scaleOptions.formatter);
22
- }
20
+ this.setNumTickFormat(axisGenerator, scaleOptions.formatter);
23
21
  }
24
22
  static getBaseAxisGenerator(axisOptions, scale) {
25
23
  const axisGenerator = AxisHelper.getAxisByOrient(axisOptions.orient, scale);
@@ -0,0 +1,17 @@
1
+ import { TwoDimGroupingModel } from "../../../model/model";
2
+ import { Block } from "../../block/block";
3
+ interface GroupAxisLabelsOptions {
4
+ elementAccessors: {
5
+ getBlock: () => Block;
6
+ };
7
+ }
8
+ export declare class GroupAxisLabels {
9
+ private readonly options;
10
+ private readonly renderPipeline;
11
+ private groupsForLabels;
12
+ constructor(options: GroupAxisLabelsOptions);
13
+ render(model: TwoDimGroupingModel): void;
14
+ update(model: TwoDimGroupingModel): void;
15
+ private setAttrs;
16
+ }
17
+ export {};
@@ -0,0 +1,61 @@
1
+ import { Pipeline } from "../../helpers/pipeline/Pipeline";
2
+ export class GroupAxisLabels {
3
+ constructor(options) {
4
+ this.options = options;
5
+ this.renderPipeline = new Pipeline();
6
+ this.groupsForLabels = [];
7
+ this.renderPipeline.push((groupLabels, { item }) => {
8
+ return this.setAttrs(groupLabels.classed("group-label data-label", true), item);
9
+ });
10
+ }
11
+ render(model) {
12
+ if (!model.enabled)
13
+ return;
14
+ model.items.forEach((item, index) => {
15
+ const group = this.options.elementAccessors
16
+ .getBlock()
17
+ .getSvg()
18
+ .append("g")
19
+ .attr(`data-group-labels-index`, index);
20
+ this.groupsForLabels.push(group);
21
+ const labels = group
22
+ .selectAll("text")
23
+ .data(item.domain)
24
+ .enter()
25
+ .append("text")
26
+ .text((d) => d);
27
+ this.renderPipeline.execute(labels, { item });
28
+ });
29
+ }
30
+ update(model) {
31
+ if (!model.enabled)
32
+ return;
33
+ model.items.forEach((item, index) => {
34
+ const group = this.groupsForLabels[index];
35
+ if (!group)
36
+ return;
37
+ const existedLabels = group
38
+ .selectAll("text")
39
+ .data(item.domain)
40
+ .text((d) => d);
41
+ existedLabels.exit().remove();
42
+ const newLabels = existedLabels
43
+ .enter()
44
+ .append("text")
45
+ .text((d) => d);
46
+ this.renderPipeline.execute(newLabels, { item });
47
+ const animationName = "group-labels-updating";
48
+ this.setAttrs(existedLabels
49
+ .interrupt(animationName)
50
+ .transition(animationName)
51
+ .duration(this.options.elementAccessors.getBlock().transitionManager.durations.chartUpdate), item);
52
+ });
53
+ }
54
+ setAttrs(groupLabels, item) {
55
+ return groupLabels
56
+ .attr("x", (d) => item.coordinate.handleX(d))
57
+ .attr("y", (d) => item.coordinate.handleY(d))
58
+ .attr("text-anchor", item.textAnchor)
59
+ .attr("dominant-baseline", item.dominantBaseline);
60
+ }
61
+ }
@@ -1,6 +1,6 @@
1
- import { ScaleLinear } from "d3-scale";
1
+ import { ScaleBand, ScaleLinear } from "d3-scale";
2
2
  import { AxisScale } from "d3-axis";
3
- import { BarChartSettings, ScaleKeyModel, ScaleValueModel } from "../../../model/model";
3
+ import { BarChartSettings, ScaleBandModel, ScaleKeyModel, ScaleValueModel } from "../../../model/model";
4
4
  export interface Scales {
5
5
  key: AxisScale<any>;
6
6
  value: AxisScale<any>;
@@ -15,6 +15,7 @@ export declare class Scale {
15
15
  static getScaleBandWidth(scale: AxisScale<any>): number;
16
16
  static getScaleStep(scale: AxisScale<any>): number;
17
17
  static getScaledValue(scale: AxisScale<any>, value: any): number;
18
+ static getScaleBandNew(scaleKey: ScaleBandModel): ScaleBand<string>;
18
19
  private static getScaleBand;
19
20
  private static getScaleLinear;
20
21
  private static getScalePoint;
@@ -1,4 +1,5 @@
1
1
  import { scaleBand, scaleLinear, scalePoint } from "d3-scale";
2
+ //TODO: incapulate in model
2
3
  export class Scale {
3
4
  static getScales(scaleKey, scaleValue, bandSettings) {
4
5
  const scales = {
@@ -6,7 +7,8 @@ export class Scale {
6
7
  value: null
7
8
  };
8
9
  if (scaleKey.type === "band")
9
- scales.key = this.getScaleBand(scaleKey.domain, scaleKey.range, bandSettings, scaleKey.elementsAmount);
10
+ // scales.key = this.getScaleBand(scaleKey.domain, scaleKey.range, bandSettings, scaleKey.elementsAmount);
11
+ scales.key = this.getScaleBandNew(scaleKey);
10
12
  else if (scaleKey.type === "point")
11
13
  scales.key = this.getScalePoint(scaleKey.domain, scaleKey.range);
12
14
  scales.value = this.getScaleValue(scaleValue);
@@ -38,6 +40,14 @@ export class Scale {
38
40
  }
39
41
  return scale(value);
40
42
  }
43
+ static getScaleBandNew(scaleKey) {
44
+ return scaleBand()
45
+ .domain(scaleKey.domain)
46
+ .range([scaleKey.range.start, scaleKey.range.end])
47
+ .paddingInner(scaleKey.sizes.paddingInner / scaleKey.sizes.bandSize)
48
+ .paddingOuter(scaleKey.sizes.paddingOuter / scaleKey.sizes.recalculatedStepSize);
49
+ }
50
+ //TODO: remove after tests of new way to create scale band
41
51
  static getScaleBand(domain, range, bandSettings, elementsInGroupAmount) {
42
52
  const scale = scaleBand().domain(domain).range([range.start, range.end]);
43
53
  const bandSize = scale.bandwidth();
@@ -1,5 +1,5 @@
1
1
  import { Block } from "../../../engine/block/block";
2
- import { OptionsModelData, Orient, TwoDimChartValueLabelsOptions, TwoDimensionalChartModel, TwoDimensionalValueLabels, ValueLabelAnchor, ValueLabelDominantBaseline, ValueLabelsStyleModel } from "../../../model/model";
2
+ import { OptionsModelData, Orient, TwoDimChartValueLabelsOptions, TwoDimensionalChartModel, TwoDimensionalValueLabels, TextAnchor, DominantBaseline, ValueLabelsStyleModel } from "../../../model/model";
3
3
  import { MdtChartsDataRow, MdtChartsDataSource } from "../../../config/config";
4
4
  import { Scales, ScalesWithSecondary } from "../../../engine/features/scale/scale";
5
5
  export interface ValueLabelsOptions {
@@ -18,8 +18,8 @@ export interface ValueLabelsOptions {
18
18
  export interface ValueLabelAttrs {
19
19
  x: (data: MdtChartsDataRow) => number;
20
20
  y: (data: MdtChartsDataRow) => number;
21
- textAnchor: ValueLabelAnchor;
22
- dominantBaseline: ValueLabelDominantBaseline;
21
+ textAnchor: TextAnchor;
22
+ dominantBaseline: DominantBaseline;
23
23
  }
24
24
  export declare class ChartValueLabels {
25
25
  private readonly globalOptions;
@@ -92,7 +92,6 @@ export class ChartValueLabels {
92
92
  return block.selectAll(`.${ChartValueLabels.valueLabelClass}.${CLASSES.dataLabel}${Helper.getCssClassesLine(this.chart.cssClasses)}.chart-element-${vfIndex}`);
93
93
  }
94
94
  setAttrs(valueLabels, attrs, valueFieldName, dataRowAccessor, animate = false, onEndAnimation) {
95
- const animationName = "labels-updating";
96
95
  let selection = valueLabels
97
96
  .attr("dominant-baseline", attrs.dominantBaseline)
98
97
  .attr("text-anchor", attrs.textAnchor);
@@ -114,6 +113,7 @@ export class ChartValueLabels {
114
113
  selection.classed(ChartValueLabels.valueLabelHiddenClass, (d) => {
115
114
  return !this.options.showLabel({ row: dataRowAccessor(d), valueFieldName });
116
115
  });
116
+ const animationName = "labels-updating";
117
117
  if (animate) {
118
118
  selection = selection
119
119
  .interrupt(animationName)
@@ -2,7 +2,7 @@ import { AxisScale } from "d3-axis";
2
2
  import { MdtChartsDataRow, Size } from "../../config/config";
3
3
  import { BlockMargin, TwoDimensionalOptionsModel, PolarOptionsModel } from "../../model/model";
4
4
  import { Block } from "../block/block";
5
- import { EventEmitter } from "../../model/EventEmitter";
5
+ import { EventEmitter } from "../../model/helpers/eventEmitter";
6
6
  export declare type FilterCallback = (rows: MdtChartsDataRow[]) => void;
7
7
  export interface SelectDetails {
8
8
  multySelect: boolean;
@@ -4,7 +4,7 @@ import { TipBox } from "../features/tipBox/tipBox";
4
4
  import { TipBoxHelper } from "../features/tipBox/tipBoxHelper";
5
5
  import { Helper } from "../helpers/helper";
6
6
  import { Donut } from "../polarNotation/donut/donut";
7
- import { EventEmitter } from "../../model/EventEmitter";
7
+ import { EventEmitter } from "../../model/helpers/eventEmitter";
8
8
  export class FilterEventManager {
9
9
  constructor(callback, fullDataset, filtrable, keyFieldName, selectedIds = []) {
10
10
  this.callback = callback;
@@ -8,6 +8,7 @@ export declare class TwoDimensionalManager implements ChartContentManager {
8
8
  private canvasValueLabels?;
9
9
  private linearGradientDef?;
10
10
  private dotChart;
11
+ private groupLabels;
11
12
  render(engine: Engine, model: Model<TwoDimensionalOptionsModel>): void;
12
13
  updateData(block: Block, model: Model<TwoDimensionalOptionsModel>, data: MdtChartsDataSource): void;
13
14
  updateColors(block: Block, model: Model<TwoDimensionalOptionsModel>): void;
@@ -16,6 +16,7 @@ import { CanvasValueLabels } from "../../engine/features/valueLabels/valueLabels
16
16
  import { LinearGradientDef } from "../../engine/block/defs/LinearGradientDef";
17
17
  import { CanvasDotChart } from "./dot/dotChart";
18
18
  import { RecordOverflowAlertCore } from "../features/recordOverflowAlert/recordOverflowAlertCore";
19
+ import { GroupAxisLabels } from "../features/groupLabels/groupLabels";
19
20
  export class TwoDimensionalManager {
20
21
  render(engine, model) {
21
22
  const options = model.options;
@@ -38,6 +39,12 @@ export class TwoDimensionalManager {
38
39
  settings: options.chartSettings.bar
39
40
  }
40
41
  });
42
+ this.groupLabels = new GroupAxisLabels({
43
+ elementAccessors: {
44
+ getBlock: () => engine.block
45
+ }
46
+ });
47
+ this.groupLabels.render(options.grouping);
41
48
  this.renderCharts(engine.block, options.charts, scales, engine.data, options.data, model.chartBlock.margin, options.axis.key.orient, options.chartSettings, model.blockCanvas.size);
42
49
  Axis.raiseKeyAxis(engine.block, options.axis.key);
43
50
  engine.block.filterEventManager.registerEventFor2D(scales.key, model.chartBlock.margin, model.blockCanvas.size, options);
@@ -83,6 +90,7 @@ export class TwoDimensionalManager {
83
90
  block.scales = scales;
84
91
  Axis.update(block, scales, options.scale, options.axis, model.blockCanvas.size, keyDomainEquality);
85
92
  GridLine.update(block, options.additionalElements.gridLine, options.axis, model.blockCanvas.size, model.chartBlock.margin, scales);
93
+ this.groupLabels.update(options.grouping);
86
94
  const promises = this.updateCharts(block, options.charts, scales, data, model.options.data, model.chartBlock.margin, options.axis.key.orient, model.blockCanvas.size, options.chartSettings);
87
95
  Promise.all(promises).then(() => {
88
96
  block.filterEventManager.event2DUpdate(options);
@@ -1,5 +1,5 @@
1
- import { AxisPosition, ChartOrientation, MdtChartsDataSource, NumberAxisOptions, AxisLabelPosition, MdtChartsTwoDimensionalOptions, DiscreteAxisOptions, NumberSecondaryAxisOptions, AxisLabelFormatter } from "../../../config/config";
2
- import { AxisModelOptions, Orient, ScaleValueModel, TickAmountPolicy } from "../../model";
1
+ import { ItemPositionByOrientation, ChartOrientation, MdtChartsDataSource, NumberAxisOptions, AxisLabelPosition, MdtChartsTwoDimensionalOptions, DiscreteAxisOptions, NumberSecondaryAxisOptions, AxisLabelFormatter } from "../../../config/config";
2
+ import { AxisModelOptions, DiscreteAxisModelOptions, Orient, ScaleValueModel, TickAmountPolicy } from "../../model";
3
3
  import { AxisType } from "../../modelBuilder";
4
4
  import { AxisLabelCanvas, TooltipSettings } from "../../../designer/designerConfig";
5
5
  import { CanvasModel } from "../../modelInstance/canvasModel/canvasModel";
@@ -9,19 +9,19 @@ export interface LabelSize {
9
9
  }
10
10
  export declare const MINIMAL_VERTICAL_STEP_SIZE = 60;
11
11
  export declare const MINIMAL_HORIZONTAL_STEP_SIZE = 100;
12
- export declare const LABEL_ELEMENT_HEIGHT_PX = 17;
12
+ export declare const LABEL_ELEMENT_HEIGHT_PX = 14;
13
13
  export declare class AxisModel {
14
14
  private static service;
15
- static getKeyAxis(options: MdtChartsTwoDimensionalOptions, data: MdtChartsDataSource, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel, tooltipSettings: TooltipSettings, getZeroCoordinate?: () => number): AxisModelOptions;
16
- static getMainValueAxis(defaultFormatter: AxisLabelFormatter, orient: ChartOrientation, position: AxisPosition, axisConfig: NumberAxisOptions, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel, scaleInfo: ScaleValueModel): AxisModelOptions;
17
- static getSecondaryValueAxis(defaultFormatter: AxisLabelFormatter, orient: ChartOrientation, mainAxisPosition: AxisPosition, axisConfig: NumberSecondaryAxisOptions, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel, scaleInfo: ScaleValueModel): AxisModelOptions;
15
+ static getKeyAxis(options: MdtChartsTwoDimensionalOptions, data: MdtChartsDataSource, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel, tooltipSettings: TooltipSettings, getZeroCoordinate?: () => number): DiscreteAxisModelOptions;
16
+ static getMainValueAxis(defaultFormatter: AxisLabelFormatter, orient: ChartOrientation, position: ItemPositionByOrientation, axisConfig: NumberAxisOptions, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel, scaleInfo: ScaleValueModel): AxisModelOptions;
17
+ static getSecondaryValueAxis(defaultFormatter: AxisLabelFormatter, orient: ChartOrientation, mainAxisPosition: ItemPositionByOrientation, axisConfig: NumberSecondaryAxisOptions, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel, scaleInfo: ScaleValueModel): AxisModelOptions;
18
18
  private static getValueAxis;
19
19
  static getAxisLength(chartOrientation: ChartOrientation, canvasModel: CanvasModel): number;
20
- static getAxisOrient(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition): Orient;
21
- static getAxisTranslateX(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition, canvasModel: CanvasModel): number;
22
- static getAxisTranslateY(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition, canvasModel: CanvasModel): number;
20
+ static getAxisOrient(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: ItemPositionByOrientation): Orient;
21
+ static getAxisTranslateX(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: ItemPositionByOrientation, canvasModel: CanvasModel): number;
22
+ static getAxisTranslateY(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: ItemPositionByOrientation, canvasModel: CanvasModel): number;
23
23
  static getKeyAxisLabelPosition(canvasModel: CanvasModel, scopedDataLength: number, axisConfig?: DiscreteAxisOptions): AxisLabelPosition;
24
- static getLabelSize(labelMaxWidth: number, labelTexts: string[]): LabelSize;
24
+ static getLabelSize(labelMaxWidth: number, labelTexts: (string | number)[]): LabelSize;
25
25
  static getRoundValue(value: number): number;
26
26
  static getTickAmountPolicy(orient: ChartOrientation, axisConfig: NumberAxisOptions | NumberSecondaryAxisOptions, scaleInfo: ScaleValueModel): TickAmountPolicy;
27
27
  private static getKeyAxisTranslateModel;
@@ -5,7 +5,7 @@ import { TwoDimensionalModel } from "../../notations/twoDimensionalModel";
5
5
  import { AxisModelService, AxisModelTickCalculator, showAllTicks } from "./axisModelService";
6
6
  export const MINIMAL_VERTICAL_STEP_SIZE = 60;
7
7
  export const MINIMAL_HORIZONTAL_STEP_SIZE = 100;
8
- export const LABEL_ELEMENT_HEIGHT_PX = 17;
8
+ export const LABEL_ELEMENT_HEIGHT_PX = 14;
9
9
  const DEFAULT_AXIS_LINE_VISIBLE = true;
10
10
  export class AxisModel {
11
11
  static getKeyAxis(options, data, labelConfig, canvasModel, tooltipSettings, getZeroCoordinate) {
@@ -30,6 +30,13 @@ export class AxisModel {
30
30
  linearTickStep: MINIMAL_HORIZONTAL_STEP_SIZE,
31
31
  tickAmountSettings: {
32
32
  policy: { type: "auto" }
33
+ },
34
+ format: (options) => {
35
+ var _a;
36
+ const dataRow = data[dataOptions.dataSource].find((d) => d[dataOptions.keyField.name] === options.key);
37
+ if (dataRow && ((_a = axisConfig.labels) === null || _a === void 0 ? void 0 : _a.format))
38
+ return axisConfig.labels.format({ key: options.key, dataRow });
39
+ return options.key;
33
40
  }
34
41
  },
35
42
  visibility: axisConfig.visibility,
@@ -119,9 +126,9 @@ export class AxisModel {
119
126
  static getLabelSize(labelMaxWidth, labelTexts) {
120
127
  const ONE_UPPER_SYMBOL_WIDTH_PX = 8;
121
128
  const longestLabelLength = labelTexts.length
122
- ? Math.max(...labelTexts.map((t) => ModelHelper.getStringScore(t)))
129
+ ? Math.max(...labelTexts.map((t) => { var _a; return ModelHelper.getStringScore((_a = t === null || t === void 0 ? void 0 : t.toString()) !== null && _a !== void 0 ? _a : ""); }))
123
130
  : 0;
124
- const longestLabelWidth = ONE_UPPER_SYMBOL_WIDTH_PX * longestLabelLength;
131
+ const longestLabelWidth = Math.round(ONE_UPPER_SYMBOL_WIDTH_PX * longestLabelLength);
125
132
  return {
126
133
  height: LABEL_ELEMENT_HEIGHT_PX,
127
134
  width: longestLabelWidth > labelMaxWidth ? labelMaxWidth : longestLabelWidth
@@ -1,4 +1,4 @@
1
- export const showAllTicks = (d) => d;
1
+ export const showAllTicks = () => true;
2
2
  export class AxisModelService {
3
3
  getKeyAxisLabelPosition(chartBlockWidth, scopedDataLength, positionFromConfig) {
4
4
  if (positionFromConfig === "rotated" || positionFromConfig === "straight") {
@@ -26,7 +26,7 @@ export class AxisModelTickCalculator {
26
26
  return showAllTicks;
27
27
  let divider = Math.ceil(this.dataRows.length / allowedKeysAmount);
28
28
  return (d, i) => {
29
- return i % divider === 0 ? d : undefined;
29
+ return i % divider === 0;
30
30
  };
31
31
  }
32
32
  }
@@ -0,0 +1,20 @@
1
+ import { Orient } from "../../../model";
2
+ import { CanvasModel } from "../../../modelInstance/canvasModel/canvasModel";
3
+ interface GroupingLabelsCoordinateHandlerOptions {
4
+ orient: Orient;
5
+ sideIndex: number;
6
+ otherComponentSizes: {
7
+ titleTotalNeededSpace: number;
8
+ legendTotalNeededSpace: number;
9
+ };
10
+ }
11
+ export declare class GroupingLabelsCoordinateHandler {
12
+ private readonly canvasModel;
13
+ private readonly options;
14
+ private readonly staticCoordinate;
15
+ private readonly verticalLabelSize;
16
+ constructor(canvasModel: CanvasModel, options: GroupingLabelsCoordinateHandlerOptions);
17
+ handleX(scaledCoordinate: number): number;
18
+ handleY(scaledCoordinate: number): number;
19
+ }
20
+ export {};
@@ -0,0 +1,36 @@
1
+ export class GroupingLabelsCoordinateHandler {
2
+ constructor(canvasModel, options) {
3
+ this.canvasModel = canvasModel;
4
+ this.options = options;
5
+ this.verticalLabelSize = 20;
6
+ if (this.options.orient === "top")
7
+ this.staticCoordinate =
8
+ options.otherComponentSizes.titleTotalNeededSpace + this.verticalLabelSize * this.options.sideIndex;
9
+ if (this.options.orient === "bottom")
10
+ this.staticCoordinate =
11
+ this.canvasModel.getBlockSize().height -
12
+ options.otherComponentSizes.legendTotalNeededSpace -
13
+ this.verticalLabelSize * this.options.sideIndex;
14
+ //TODO: padding should be got from other components
15
+ if (this.options.orient === "left")
16
+ this.staticCoordinate = 20 * this.options.sideIndex;
17
+ if (this.options.orient === "right")
18
+ this.staticCoordinate = this.canvasModel.getBlockSize().width - 20 * this.options.sideIndex;
19
+ }
20
+ handleX(scaledCoordinate) {
21
+ let x;
22
+ if (this.options.orient === "top" || this.options.orient === "bottom")
23
+ x = scaledCoordinate + this.canvasModel.getMarginSide("left");
24
+ else
25
+ x = this.staticCoordinate;
26
+ return x;
27
+ }
28
+ handleY(scaledCoordinate) {
29
+ let y;
30
+ if (this.options.orient === "left" || this.options.orient === "right")
31
+ y = scaledCoordinate + this.canvasModel.getMarginSide("top");
32
+ else
33
+ y = this.staticCoordinate;
34
+ return y;
35
+ }
36
+ }
@@ -0,0 +1,22 @@
1
+ import { MdtChartsBaseField, MdtChartsDataRow } from "../../../../config/config";
2
+ import { GroupingLabelKey, RangeModel } from "../../../model";
3
+ interface GroupingLabelsCoordinateScalerOptions {
4
+ dataRows: MdtChartsDataRow[];
5
+ field: MdtChartsBaseField;
6
+ keyScaleInfo: KeyScaleInfoForGroupingLabelsScaler;
7
+ range: RangeModel;
8
+ }
9
+ export declare type KeyScaleInfoForGroupingLabelsScaler = {
10
+ type: "band";
11
+ keyAxisOuterPadding: number;
12
+ keyAxisInnerPadding: number;
13
+ } | {
14
+ type: "point";
15
+ };
16
+ export declare class GroupingLabelsCoordinateScaler {
17
+ private readonly options;
18
+ private readonly scaleFn;
19
+ constructor(options: GroupingLabelsCoordinateScalerOptions);
20
+ scaleForKey(groupingKey: GroupingLabelKey): number;
21
+ }
22
+ export {};
@@ -0,0 +1,49 @@
1
+ import { scaleOrdinal } from "d3-scale";
2
+ export class GroupingLabelsCoordinateScaler {
3
+ constructor(options) {
4
+ this.options = options;
5
+ let keyAxisInnerPadding = 0;
6
+ let keyAxisOuterPadding = 0;
7
+ if (this.options.keyScaleInfo.type === "band") {
8
+ keyAxisInnerPadding = this.options.keyScaleInfo.keyAxisInnerPadding;
9
+ keyAxisOuterPadding = this.options.keyScaleInfo.keyAxisOuterPadding;
10
+ }
11
+ else {
12
+ keyAxisInnerPadding =
13
+ (this.options.range.end - this.options.range.start) / (this.options.dataRows.length - 1);
14
+ keyAxisOuterPadding = 0;
15
+ }
16
+ const domainWithRowsCount = new Map();
17
+ this.options.dataRows.forEach((row) => {
18
+ const key = row[this.options.field.name];
19
+ if (key) {
20
+ if (domainWithRowsCount.has(key))
21
+ domainWithRowsCount.set(key, domainWithRowsCount.get(key) + 1);
22
+ else
23
+ domainWithRowsCount.set(key, 1);
24
+ }
25
+ });
26
+ const rangeOfKeyAxis = Math.abs(this.options.range.end - this.options.range.start) -
27
+ keyAxisOuterPadding * 2 -
28
+ keyAxisInnerPadding * (this.options.dataRows.length - 1);
29
+ const totalShares = Array.from(domainWithRowsCount.values()).reduce((acc, curr) => acc + curr, 0);
30
+ const oneShareSize = rangeOfKeyAxis / totalShares;
31
+ const coordinates = [];
32
+ let previousTotalShares = 0;
33
+ const rowsCounts = Array.from(domainWithRowsCount.values());
34
+ for (let rowIndex = 0; rowIndex < rowsCounts.length; rowIndex++) {
35
+ const rowsAmount = rowsCounts[rowIndex];
36
+ let previousShift = previousTotalShares * (oneShareSize + keyAxisInnerPadding);
37
+ const centerOfDomainItem = previousShift +
38
+ (rowsAmount * oneShareSize + (rowsAmount - 1) * keyAxisInnerPadding) / 2 +
39
+ keyAxisOuterPadding;
40
+ coordinates.push(centerOfDomainItem);
41
+ previousTotalShares += rowsAmount;
42
+ }
43
+ const d3Scale = scaleOrdinal(domainWithRowsCount.keys(), coordinates);
44
+ this.scaleFn = (key) => d3Scale(key);
45
+ }
46
+ scaleForKey(groupingKey) {
47
+ return this.scaleFn(groupingKey);
48
+ }
49
+ }
@@ -5,5 +5,5 @@ import { LegendItemsDirection } from "./legendCanvasModel";
5
5
  export declare class LegendModel {
6
6
  static getBaseLegendBlockModel(canvasModel: CanvasModel, legendConfig: LegendBlockCanvas): LegendBlockModel;
7
7
  static getLegendItemClass(itemsPosition: LegendItemsDirection): string;
8
- static appendToGlobalMarginValuesLegendMargin(canvasModel: CanvasModel, position: Orient, legendBlockModel: LegendBlockModel): void;
8
+ static getLegendTotalMargin(position: Orient, legendBlockModel: LegendBlockModel): number;
9
9
  }
@@ -1,7 +1,7 @@
1
1
  export class LegendModel {
2
2
  static getBaseLegendBlockModel(canvasModel, legendConfig) {
3
3
  var _a, _b;
4
- const mt = 20, mb = 20, ml = 20, mr = 20;
4
+ const mt = 20, mb = 20, ml = 20;
5
5
  return {
6
6
  coordinate: {
7
7
  left: {
@@ -33,11 +33,11 @@ export class LegendModel {
33
33
  static getLegendItemClass(itemsPosition) {
34
34
  return itemsPosition === "column" ? "legend-item-row" : "legend-item-inline";
35
35
  }
36
- static appendToGlobalMarginValuesLegendMargin(canvasModel, position, legendBlockModel) {
36
+ static getLegendTotalMargin(position, legendBlockModel) {
37
37
  const legendCoordinate = legendBlockModel.coordinate;
38
38
  if (position === "left" || position === "right")
39
- canvasModel.increaseMarginSide(position, legendCoordinate[position].margin.left + legendCoordinate[position].margin.right);
39
+ return legendCoordinate[position].margin.left + legendCoordinate[position].margin.right;
40
40
  else
41
- canvasModel.increaseMarginSide(position, legendCoordinate[position].margin.top + legendCoordinate[position].margin.bottom);
41
+ return legendCoordinate[position].margin.top + legendCoordinate[position].margin.bottom;
42
42
  }
43
43
  }
@@ -17,7 +17,7 @@ export class LegendPolarMarginCalculator {
17
17
  updateMarginObj(legendBlockModel, legendPosition, legendSize, canvasModel) {
18
18
  if (legendSize !== 0) {
19
19
  canvasModel.increaseMarginSide(legendPosition, legendSize);
20
- LegendModel.appendToGlobalMarginValuesLegendMargin(canvasModel, legendPosition, legendBlockModel);
20
+ canvasModel.increaseMarginSide(legendPosition, LegendModel.getLegendTotalMargin(legendPosition, legendBlockModel));
21
21
  }
22
22
  legendBlockModel.coordinate[legendPosition].size = legendSize;
23
23
  }
@@ -1,6 +1,6 @@
1
1
  import { MdtChartsTwoDimLegend } from "../../../config/config";
2
2
  import { LegendBlockModel } from "../../model";
3
- import { TwoDimConfigReader } from "../../modelInstance/configReader";
3
+ import { TwoDimConfigReader } from "../../modelInstance/configReader/twoDimConfigReader.ts/twoDimConfigReader";
4
4
  import { ModelInstance } from "../../modelInstance/modelInstance";
5
5
  export declare class TwoDimLegendModel {
6
6
  private configReader;
@@ -17,9 +17,11 @@ export class TwoDimLegendModel {
17
17
  markerSize: Object.assign(Object.assign({}, styledElementValues.defaultLegendMarkerSizes), { widthPx: getWidthOfLegendMarkerByType(i.chartType) }),
18
18
  wrapperSize: { marginRightPx: styledElementValues.legend.inlineItemWrapperMarginRightPx }
19
19
  })), "top", modelInstance.canvasModel.getBlockSize().width, legendBlockModel.static.maxLinesAmount * styledElementValues.legend.inlineLegendOneLineHeightPx).size.height;
20
- canvasModel.increaseMarginSide(legendPosition, legendSize);
21
- if (legendSize !== 0)
22
- LegendModel.appendToGlobalMarginValuesLegendMargin(canvasModel, legendPosition, legendBlockModel);
20
+ if (legendSize !== 0) {
21
+ const legendTotalMargin = LegendModel.getLegendTotalMargin(legendPosition, legendBlockModel);
22
+ modelInstance.canvasModel.legendCanvas.initSizeAndPad(legendSize, legendTotalMargin);
23
+ canvasModel.increaseMarginSide(legendPosition, modelInstance.canvasModel.legendCanvas.getAllNeededSpace());
24
+ }
23
25
  legendBlockModel.coordinate[legendPosition].size = legendSize;
24
26
  }
25
27
  }