@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.
|
@@ -152,6 +152,8 @@ const defaultStyles$t = {
|
|
|
152
152
|
backgroundRect
|
|
153
153
|
};
|
|
154
154
|
function preventOverlap(labelPositions, iteration = 0, labelSize = 12, coordinate = "y", moveBothLabels = true) {
|
|
155
|
+
const maxIterations = 10;
|
|
156
|
+
let totalOverlap = 0;
|
|
155
157
|
for (let index2 = 1; index2 < labelPositions.length; index2++) {
|
|
156
158
|
const previousElement = labelPositions[index2 - 1];
|
|
157
159
|
const element = labelPositions[index2];
|
|
@@ -165,8 +167,12 @@ function preventOverlap(labelPositions, iteration = 0, labelSize = 12, coordinat
|
|
|
165
167
|
} else {
|
|
166
168
|
previousElement[coordinate] -= overlap;
|
|
167
169
|
}
|
|
168
|
-
|
|
170
|
+
totalOverlap += overlap;
|
|
169
171
|
}
|
|
172
|
+
if (totalOverlap > 0 && iteration < maxIterations) {
|
|
173
|
+
return preventOverlap(labelPositions, iteration + 1, labelSize, coordinate, moveBothLabels);
|
|
174
|
+
}
|
|
175
|
+
return labelPositions;
|
|
170
176
|
}
|
|
171
177
|
function uniqueBy(array, key) {
|
|
172
178
|
return [...array.reduce((map, d2) => map.set(d2[key], d2), /* @__PURE__ */ new Map()).values()];
|
|
@@ -189,6 +195,10 @@ const LabelType = {
|
|
|
189
195
|
hanging: "hanging",
|
|
190
196
|
inline: "inline"
|
|
191
197
|
};
|
|
198
|
+
const LabelOverlapConfig = {
|
|
199
|
+
labelSize: 20,
|
|
200
|
+
moveBothLabels: false
|
|
201
|
+
};
|
|
192
202
|
function StackedBar({
|
|
193
203
|
stack,
|
|
194
204
|
width,
|
|
@@ -197,7 +207,8 @@ function StackedBar({
|
|
|
197
207
|
labelType = LabelType.inline,
|
|
198
208
|
showBackgroundRect = false,
|
|
199
209
|
createSVG = true,
|
|
200
|
-
styles: styles2
|
|
210
|
+
styles: styles2,
|
|
211
|
+
labelOverlapConfig = LabelOverlapConfig
|
|
201
212
|
}) {
|
|
202
213
|
const rectElements = useRef([]);
|
|
203
214
|
const textElements = useRef([]);
|
|
@@ -258,7 +269,7 @@ function StackedBar({
|
|
|
258
269
|
totalW += itemWidth;
|
|
259
270
|
return labelConfig;
|
|
260
271
|
});
|
|
261
|
-
return preventOverlap(labels, 0,
|
|
272
|
+
return preventOverlap(labels, 0, labelOverlapConfig.labelSize, "x", labelOverlapConfig.moveBothLabels);
|
|
262
273
|
}, [stack, height, width]);
|
|
263
274
|
const backgroundRect2 = jsx("g", {
|
|
264
275
|
children: jsx("rect", {
|
|
@@ -3230,15 +3241,15 @@ function Checkmark() {
|
|
|
3230
3241
|
})
|
|
3231
3242
|
});
|
|
3232
3243
|
}
|
|
3233
|
-
const coalitionsWrapper = "
|
|
3234
|
-
const coalitionsContainer = "
|
|
3235
|
-
const coalition = "
|
|
3236
|
-
const title = "
|
|
3237
|
-
const description = "
|
|
3238
|
-
const thresholdText = "
|
|
3239
|
-
const thresholdTextBold = "
|
|
3240
|
-
const thresholdDot = "
|
|
3241
|
-
const thresholdLine = "
|
|
3244
|
+
const coalitionsWrapper = "_coalitionsWrapper_4egbd_9";
|
|
3245
|
+
const coalitionsContainer = "_coalitionsContainer_4egbd_14";
|
|
3246
|
+
const coalition = "_coalition_4egbd_9";
|
|
3247
|
+
const title = "_title_4egbd_27";
|
|
3248
|
+
const description = "_description_4egbd_28";
|
|
3249
|
+
const thresholdText = "_thresholdText_4egbd_43";
|
|
3250
|
+
const thresholdTextBold = "_thresholdTextBold_4egbd_54";
|
|
3251
|
+
const thresholdDot = "_thresholdDot_4egbd_61";
|
|
3252
|
+
const thresholdLine = "_thresholdLine_4egbd_62";
|
|
3242
3253
|
const defaultStyles = {
|
|
3243
3254
|
coalitionsWrapper,
|
|
3244
3255
|
coalitionsContainer,
|
|
@@ -3260,7 +3271,8 @@ function CoalitionsTracker({
|
|
|
3260
3271
|
abbreviationAccessor = "abbreviation",
|
|
3261
3272
|
thresholdTextBold: thresholdTextBold2,
|
|
3262
3273
|
thresholdText: thresholdText2,
|
|
3263
|
-
styles: styles2
|
|
3274
|
+
styles: styles2,
|
|
3275
|
+
labelOverlapConfig = LabelOverlapConfig
|
|
3264
3276
|
}) {
|
|
3265
3277
|
const wrapperRef = useRef(null);
|
|
3266
3278
|
const thresholdTextRef = useRef(null);
|
|
@@ -3314,6 +3326,8 @@ function CoalitionsTracker({
|
|
|
3314
3326
|
},
|
|
3315
3327
|
children: list.description
|
|
3316
3328
|
}), jsx(StackedBar, {
|
|
3329
|
+
labelOverlapConfig,
|
|
3330
|
+
labelType: LabelType.hanging,
|
|
3317
3331
|
stack: list.stack,
|
|
3318
3332
|
width: list.width,
|
|
3319
3333
|
height: barChartHeight,
|
|
@@ -3645,6 +3659,7 @@ export {
|
|
|
3645
3659
|
GradientIcon,
|
|
3646
3660
|
GridType,
|
|
3647
3661
|
InfoButton,
|
|
3662
|
+
LabelOverlapConfig,
|
|
3648
3663
|
LabelType,
|
|
3649
3664
|
LegendItem,
|
|
3650
3665
|
Map$1 as Map,
|