@gravity-ui/charts 1.3.0 → 1.3.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.
@@ -21,7 +21,9 @@ export function preparePieData(args) {
21
21
  ? preparedSeries[0].states.hover.halo.size
22
22
  : 0;
23
23
  const maxRadius = Math.min(boundsWidth, boundsHeight) / 2 - haloSize;
24
+ const minRadius = maxRadius * 0.3;
24
25
  const groupedPieSeries = group(preparedSeries, (pieSeries) => pieSeries.stackId);
26
+ let maxMissingWidth = 0;
25
27
  const prepareItem = (stackId, items) => {
26
28
  var _a;
27
29
  const series = items[0];
@@ -173,12 +175,16 @@ export function preparePieData(args) {
173
175
  if (dataLabels.allowOverlap || !overlap) {
174
176
  const left = getLeftPosition(label);
175
177
  if (Math.abs(left) > boundsWidth / 2) {
176
- label.maxWidth = label.size.width - (Math.abs(left) - boundsWidth / 2);
178
+ const overflow = Math.abs(left) - boundsWidth / 2;
179
+ label.maxWidth = label.size.width - overflow;
180
+ maxMissingWidth = Math.max(maxMissingWidth, overflow);
177
181
  }
178
182
  else {
179
183
  const right = left + label.size.width;
180
184
  if (right > boundsWidth / 2) {
181
- label.maxWidth = label.size.width - (right - boundsWidth / 2);
185
+ const overflow = right - boundsWidth / 2;
186
+ label.maxWidth = label.size.width - overflow;
187
+ maxMissingWidth = Math.max(maxMissingWidth, overflow);
182
188
  }
183
189
  }
184
190
  if (shouldUseHtml) {
@@ -237,6 +243,18 @@ export function preparePieData(args) {
237
243
  data.labels = labels;
238
244
  data.htmlLabels = htmlLabels;
239
245
  data.connectors = connectors;
246
+ if (maxMissingWidth > 0) {
247
+ const { dataLabels } = items[0];
248
+ if (dataLabels.enabled) {
249
+ data.segments.forEach((s) => {
250
+ s.data.radius = Math.max(minRadius, s.data.radius - maxMissingWidth);
251
+ });
252
+ const finalLabels = prepareLabels({ data, series: items });
253
+ data.labels = finalLabels.labels;
254
+ data.htmlLabels = finalLabels.htmlLabels;
255
+ data.connectors = finalLabels.connectors;
256
+ }
257
+ }
240
258
  return data;
241
259
  });
242
260
  }
@@ -60,7 +60,7 @@ function renderLabels(selection, { labels, style = {}, attrs = {}, }) {
60
60
  .append('tspan')
61
61
  .attr('x', 0)
62
62
  .attr('dy', 0)
63
- .text((d) => d);
63
+ .html((d) => d);
64
64
  return text;
65
65
  }
66
66
  export function getLabelsSize({ labels, style, rotation, html, }) {
@@ -21,7 +21,9 @@ export function preparePieData(args) {
21
21
  ? preparedSeries[0].states.hover.halo.size
22
22
  : 0;
23
23
  const maxRadius = Math.min(boundsWidth, boundsHeight) / 2 - haloSize;
24
+ const minRadius = maxRadius * 0.3;
24
25
  const groupedPieSeries = group(preparedSeries, (pieSeries) => pieSeries.stackId);
26
+ let maxMissingWidth = 0;
25
27
  const prepareItem = (stackId, items) => {
26
28
  var _a;
27
29
  const series = items[0];
@@ -173,12 +175,16 @@ export function preparePieData(args) {
173
175
  if (dataLabels.allowOverlap || !overlap) {
174
176
  const left = getLeftPosition(label);
175
177
  if (Math.abs(left) > boundsWidth / 2) {
176
- label.maxWidth = label.size.width - (Math.abs(left) - boundsWidth / 2);
178
+ const overflow = Math.abs(left) - boundsWidth / 2;
179
+ label.maxWidth = label.size.width - overflow;
180
+ maxMissingWidth = Math.max(maxMissingWidth, overflow);
177
181
  }
178
182
  else {
179
183
  const right = left + label.size.width;
180
184
  if (right > boundsWidth / 2) {
181
- label.maxWidth = label.size.width - (right - boundsWidth / 2);
185
+ const overflow = right - boundsWidth / 2;
186
+ label.maxWidth = label.size.width - overflow;
187
+ maxMissingWidth = Math.max(maxMissingWidth, overflow);
182
188
  }
183
189
  }
184
190
  if (shouldUseHtml) {
@@ -237,6 +243,18 @@ export function preparePieData(args) {
237
243
  data.labels = labels;
238
244
  data.htmlLabels = htmlLabels;
239
245
  data.connectors = connectors;
246
+ if (maxMissingWidth > 0) {
247
+ const { dataLabels } = items[0];
248
+ if (dataLabels.enabled) {
249
+ data.segments.forEach((s) => {
250
+ s.data.radius = Math.max(minRadius, s.data.radius - maxMissingWidth);
251
+ });
252
+ const finalLabels = prepareLabels({ data, series: items });
253
+ data.labels = finalLabels.labels;
254
+ data.htmlLabels = finalLabels.htmlLabels;
255
+ data.connectors = finalLabels.connectors;
256
+ }
257
+ }
240
258
  return data;
241
259
  });
242
260
  }
@@ -60,7 +60,7 @@ function renderLabels(selection, { labels, style = {}, attrs = {}, }) {
60
60
  .append('tspan')
61
61
  .attr('x', 0)
62
62
  .attr('dy', 0)
63
- .text((d) => d);
63
+ .html((d) => d);
64
64
  return text;
65
65
  }
66
66
  export function getLabelsSize({ labels, style, rotation, html, }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/charts",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "React component used to render charts",
5
5
  "license": "MIT",
6
6
  "main": "dist/cjs/index.js",