@guardian/interactive-component-library 0.1.0-alpha.24 → 0.1.0-alpha.25

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.
@@ -150,6 +150,8 @@
150
150
  backgroundRect
151
151
  };
152
152
  function preventOverlap(labelPositions, iteration = 0, labelSize = 12, coordinate = "y", moveBothLabels = true) {
153
+ const maxIterations = 10;
154
+ let totalOverlap = 0;
153
155
  for (let index2 = 1; index2 < labelPositions.length; index2++) {
154
156
  const previousElement = labelPositions[index2 - 1];
155
157
  const element = labelPositions[index2];
@@ -163,8 +165,12 @@
163
165
  } else {
164
166
  previousElement[coordinate] -= overlap;
165
167
  }
166
- return labelPositions;
168
+ totalOverlap += overlap;
167
169
  }
170
+ if (totalOverlap > 0 && iteration < maxIterations) {
171
+ return preventOverlap(labelPositions, iteration + 1, labelSize, coordinate, moveBothLabels);
172
+ }
173
+ return labelPositions;
168
174
  }
169
175
  function uniqueBy(array, key) {
170
176
  return [...array.reduce((map, d2) => map.set(d2[key], d2), /* @__PURE__ */ new Map()).values()];
@@ -187,6 +193,10 @@
187
193
  hanging: "hanging",
188
194
  inline: "inline"
189
195
  };
196
+ const LabelOverlapConfig = {
197
+ labelSize: 20,
198
+ moveBothLabels: false
199
+ };
190
200
  function StackedBar({
191
201
  stack,
192
202
  width,
@@ -195,7 +205,8 @@
195
205
  labelType = LabelType.inline,
196
206
  showBackgroundRect = false,
197
207
  createSVG = true,
198
- styles: styles2
208
+ styles: styles2,
209
+ labelOverlapConfig = LabelOverlapConfig
199
210
  }) {
200
211
  const rectElements = hooks.useRef([]);
201
212
  const textElements = hooks.useRef([]);
@@ -256,7 +267,7 @@
256
267
  totalW += itemWidth;
257
268
  return labelConfig;
258
269
  });
259
- return preventOverlap(labels, 0, 20, "x", false);
270
+ return preventOverlap(labels, 0, labelOverlapConfig.labelSize, "x", labelOverlapConfig.moveBothLabels);
260
271
  }, [stack, height, width]);
261
272
  const backgroundRect2 = jsxRuntime.jsx("g", {
262
273
  children: jsxRuntime.jsx("rect", {
@@ -3228,15 +3239,15 @@
3228
3239
  })
3229
3240
  });
3230
3241
  }
3231
- const coalitionsWrapper = "_coalitionsWrapper_1ahqy_9";
3232
- const coalitionsContainer = "_coalitionsContainer_1ahqy_14";
3233
- const coalition = "_coalition_1ahqy_9";
3234
- const title = "_title_1ahqy_27";
3235
- const description = "_description_1ahqy_28";
3236
- const thresholdText = "_thresholdText_1ahqy_43";
3237
- const thresholdTextBold = "_thresholdTextBold_1ahqy_54";
3238
- const thresholdDot = "_thresholdDot_1ahqy_61";
3239
- const thresholdLine = "_thresholdLine_1ahqy_61";
3242
+ const coalitionsWrapper = "_coalitionsWrapper_4egbd_9";
3243
+ const coalitionsContainer = "_coalitionsContainer_4egbd_14";
3244
+ const coalition = "_coalition_4egbd_9";
3245
+ const title = "_title_4egbd_27";
3246
+ const description = "_description_4egbd_28";
3247
+ const thresholdText = "_thresholdText_4egbd_43";
3248
+ const thresholdTextBold = "_thresholdTextBold_4egbd_54";
3249
+ const thresholdDot = "_thresholdDot_4egbd_61";
3250
+ const thresholdLine = "_thresholdLine_4egbd_62";
3240
3251
  const defaultStyles = {
3241
3252
  coalitionsWrapper,
3242
3253
  coalitionsContainer,
@@ -3258,7 +3269,8 @@
3258
3269
  abbreviationAccessor = "abbreviation",
3259
3270
  thresholdTextBold: thresholdTextBold2,
3260
3271
  thresholdText: thresholdText2,
3261
- styles: styles2
3272
+ styles: styles2,
3273
+ labelOverlapConfig = LabelOverlapConfig
3262
3274
  }) {
3263
3275
  const wrapperRef = hooks.useRef(null);
3264
3276
  const thresholdTextRef = hooks.useRef(null);
@@ -3312,6 +3324,8 @@
3312
3324
  },
3313
3325
  children: list.description
3314
3326
  }), jsxRuntime.jsx(StackedBar, {
3327
+ labelOverlapConfig,
3328
+ labelType: LabelType.hanging,
3315
3329
  stack: list.stack,
3316
3330
  width: list.width,
3317
3331
  height: barChartHeight,
@@ -3642,6 +3656,7 @@
3642
3656
  exports2.GradientIcon = GradientIcon;
3643
3657
  exports2.GridType = GridType;
3644
3658
  exports2.InfoButton = InfoButton;
3659
+ exports2.LabelOverlapConfig = LabelOverlapConfig;
3645
3660
  exports2.LabelType = LabelType;
3646
3661
  exports2.LegendItem = LegendItem;
3647
3662
  exports2.Map = Map$1;