mdt-charts 1.41.0 → 1.42.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.
@@ -14,6 +14,6 @@ export interface SunburstChartValueLabelsConfig {
14
14
  };
15
15
  cssClass?: string;
16
16
  content?: (segment: {
17
- attachedDataRow: MdtChartsDataRow[];
17
+ attachedDataRows: MdtChartsDataRow[];
18
18
  }) => string;
19
19
  }
@@ -1,7 +1,7 @@
1
1
  import { interpolate } from "d3-interpolate";
2
2
  import { DonutHelper } from "./donutHelper";
3
3
  import { DomSelectionHelper } from "../../helpers/domSelectionHelper";
4
- import { SunburstSegmentLabel } from "../../sunburstNotation/sunburstSegmentLabel";
4
+ import { PolarLikeSegmentLabel } from "../polarLikeSegmentLabel/polarLikeSegmentLabel";
5
5
  export class Donut {
6
6
  static getAllArcGroups(block) {
7
7
  return block.getSvg().selectAll(`.${this.arcItemClass}`);
@@ -25,13 +25,14 @@ export class Donut {
25
25
  this.renderNewArcItems(arcGenerator, pieGenerator, donutBlock, chart.data.segments, chart.cssClasses);
26
26
  this.renderClonesG(donutBlock);
27
27
  if (chart.valueLabels.on) {
28
- this.segmentLabels = new SunburstSegmentLabel(donutBlock);
28
+ this.segmentLabels = new PolarLikeSegmentLabel(block);
29
29
  this.segmentLabels.render({
30
30
  sizesForGenerators: {
31
31
  innerRadius: chart.sizes.innerRadius,
32
32
  outerRadius: chart.sizes.outerRadius,
33
33
  padAngle: settings.padAngle
34
- }
34
+ },
35
+ wrapperTranslate: chart.sizes.translate
35
36
  }, chart.valueLabels.items);
36
37
  }
37
38
  }
@@ -82,7 +83,8 @@ export class Donut {
82
83
  innerRadius: chart.sizes.innerRadius,
83
84
  outerRadius: chart.sizes.outerRadius,
84
85
  padAngle: donutSettings.padAngle
85
- }
86
+ },
87
+ wrapperTranslate: chart.sizes.translate
86
88
  }, chart.valueLabels.items, block.transitionManager.durations.chartUpdate).then((labels) => labels.raise());
87
89
  promises.push(updateLabelsPromise);
88
90
  }
@@ -1,17 +1,21 @@
1
1
  import { PieArcDatum } from "d3-shape";
2
2
  import { BaseType, Selection } from "d3-selection";
3
- import { PolarSegmentLabelDataItem } from "../../model/modelTypes/valueLabelsModel";
3
+ import { PolarSegmentLabelDataItem } from "../../../model/modelTypes/valueLabelsModel";
4
+ import { DonutChartTranslateModel } from "../../../model/model";
5
+ import { Block } from "../../block/block";
4
6
  interface SunburstSegmentLabelOptions {
5
7
  sizesForGenerators: {
6
8
  innerRadius: number;
7
9
  outerRadius: number;
8
10
  padAngle?: number;
9
11
  };
12
+ wrapperTranslate: DonutChartTranslateModel;
10
13
  }
11
- export declare class SunburstSegmentLabel {
12
- private readonly parentSelection;
14
+ export declare class PolarLikeSegmentLabel {
15
+ private readonly block;
13
16
  private static readonly arcLabelClass;
14
- constructor(parentSelection: Selection<BaseType, unknown, BaseType, unknown>);
17
+ private readonly wrapperCssClassName;
18
+ constructor(block: Block, index?: number);
15
19
  render(options: SunburstSegmentLabelOptions, segments: PolarSegmentLabelDataItem[]): void;
16
20
  update(options: SunburstSegmentLabelOptions, segments: PolarSegmentLabelDataItem[], animationDuration: number): Promise<Selection<SVGTextElement, PieArcDatum<PolarSegmentLabelDataItem>, BaseType, unknown>>;
17
21
  private getTransformAttrValue;
@@ -1,14 +1,23 @@
1
1
  import { arc, pie } from "d3-shape";
2
2
  import { select } from "d3-selection";
3
3
  import { interpolate } from "d3-interpolate";
4
- import { DonutHelper } from "../polarNotation/donut/donutHelper";
5
- export class SunburstSegmentLabel {
6
- constructor(parentSelection) {
7
- this.parentSelection = parentSelection;
4
+ import { DonutHelper } from "../donut/donutHelper";
5
+ export class PolarLikeSegmentLabel {
6
+ constructor(block, index = 0) {
7
+ this.block = block;
8
+ this.wrapperCssClassName = `mdt-charts-donut-label-wrapper-${index}`;
8
9
  }
9
10
  render(options, segments) {
10
11
  const { arcGenerator, pieGenerator } = this.getGenerators(options);
11
- this.parentSelection
12
+ let parentSelection = this.block.getSvg().select(`.${this.wrapperCssClassName}`);
13
+ if (parentSelection.empty()) {
14
+ parentSelection = this.block
15
+ .getSvg()
16
+ .append("g")
17
+ .classed(this.wrapperCssClassName, true)
18
+ .attr("transform", `translate(${options.wrapperTranslate.x}, ${options.wrapperTranslate.y})`);
19
+ }
20
+ parentSelection
12
21
  .selectAll("text")
13
22
  .data(pieGenerator(segments), (d) => d.data.key)
14
23
  .enter()
@@ -16,7 +25,7 @@ export class SunburstSegmentLabel {
16
25
  .attr("transform", (d) => {
17
26
  return this.getTransformAttrValue(arcGenerator, d);
18
27
  })
19
- .classed(SunburstSegmentLabel.arcLabelClass, true)
28
+ .classed(PolarLikeSegmentLabel.arcLabelClass, true)
20
29
  .text((d) => d.data.textContent)
21
30
  .each(function (d) {
22
31
  if (d.data.cssClass)
@@ -25,17 +34,19 @@ export class SunburstSegmentLabel {
25
34
  });
26
35
  }
27
36
  update(options, segments, animationDuration) {
28
- const oldLabels = this.parentSelection
37
+ const parentSelection = this.block.getSvg().select(`.${this.wrapperCssClassName}`);
38
+ parentSelection.attr("transform", `translate(${options.wrapperTranslate.x}, ${options.wrapperTranslate.y})`);
39
+ const oldLabels = parentSelection
29
40
  .selectAll("text")
30
41
  .data()
31
42
  .map((d) => d.data);
32
43
  const valueLabelsZeroRows = DonutHelper.mergeDataWithZeros(segments, oldLabels);
33
44
  this.render(options, segments);
34
45
  const { arcGenerator, pieGenerator } = this.getGenerators(options);
35
- const labelsNewAndOld = this.parentSelection
46
+ const labelsNewAndOld = parentSelection
36
47
  .selectAll("text")
37
48
  .data(pieGenerator(valueLabelsZeroRows), (d) => d.data.key);
38
- const onlyNewLabels = this.parentSelection
49
+ const onlyNewLabels = parentSelection
39
50
  .selectAll("text")
40
51
  .data(pieGenerator(segments), (d) => d.data.key);
41
52
  onlyNewLabels.text((d) => d.data.textContent);
@@ -83,4 +94,4 @@ export class SunburstSegmentLabel {
83
94
  return { arcGenerator, pieGenerator };
84
95
  }
85
96
  }
86
- SunburstSegmentLabel.arcLabelClass = "mdt-charts-arc-label";
97
+ PolarLikeSegmentLabel.arcLabelClass = "mdt-charts-arc-label";
@@ -1,7 +1,7 @@
1
1
  import { arc, pie } from "d3-shape";
2
2
  import { merge } from "d3-array";
3
3
  import { interpolate } from "d3-interpolate";
4
- import { SunburstSegmentLabel } from "./sunburstSegmentLabel";
4
+ import { PolarLikeSegmentLabel } from "../polarNotation/polarLikeSegmentLabel/polarLikeSegmentLabel";
5
5
  export class Sunburst {
6
6
  constructor(block) {
7
7
  this.block = block;
@@ -28,14 +28,17 @@ export class Sunburst {
28
28
  .attr("y", level.sizes.translate.y)
29
29
  .attr("transform", `translate(${level.sizes.translate.x}, ${level.sizes.translate.y})`);
30
30
  this.renderNewArcItems(levelDonutBlock, pieGenerator, arcGenerator, level.segments);
31
+ });
32
+ levels.forEach((level, levelIndex) => {
31
33
  if (level.valueLabels.on) {
32
- this.sunburstSegmentLabels[levelIndex] = new SunburstSegmentLabel(levelDonutBlock);
34
+ this.sunburstSegmentLabels[levelIndex] = new PolarLikeSegmentLabel(this.block, levelIndex);
33
35
  this.sunburstSegmentLabels[levelIndex].render({
34
36
  sizesForGenerators: {
35
37
  innerRadius: level.sizes.innerRadius,
36
38
  outerRadius: level.sizes.outerRadius,
37
39
  padAngle: this.pagAngle
38
- }
40
+ },
41
+ wrapperTranslate: level.sizes.translate
39
42
  }, level.valueLabels.items);
40
43
  }
41
44
  });
@@ -85,7 +88,8 @@ export class Sunburst {
85
88
  innerRadius: level.sizes.innerRadius,
86
89
  outerRadius: level.sizes.outerRadius,
87
90
  padAngle: this.pagAngle
88
- }
91
+ },
92
+ wrapperTranslate: level.sizes.translate
89
93
  }, level.valueLabels.items, this.block.transitionManager.durations.chartUpdate)
90
94
  .then(() => undefined);
91
95
  promises.push(updateLabelsPromise);
@@ -96,7 +96,7 @@ export class LevelModelBuilder {
96
96
  rotation: (_b = (_a = level.valueLabels) === null || _a === void 0 ? void 0 : _a.rotation) !== null && _b !== void 0 ? _b : { type: "tangential" },
97
97
  cssClass: (_c = level.valueLabels) === null || _c === void 0 ? void 0 : _c.cssClass,
98
98
  textContent: (_f = (_e = (_d = level.valueLabels) === null || _d === void 0 ? void 0 : _d.content) === null || _e === void 0 ? void 0 : _e.call(_d, {
99
- attachedDataRow: segment.attachedDataRows
99
+ attachedDataRows: segment.attachedDataRows
100
100
  })) !== null && _f !== void 0 ? _f : segment.key.toString()
101
101
  };
102
102
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdt-charts",
3
- "version": "1.41.0",
3
+ "version": "1.42.0",
4
4
  "description": "",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {