@guardian/interactive-component-library 0.1.0-alpha.24 → 0.1.0-alpha.26
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", {
|
|
@@ -3121,18 +3132,19 @@ function Modal({
|
|
|
3121
3132
|
})
|
|
3122
3133
|
}), document.body);
|
|
3123
3134
|
}
|
|
3124
|
-
const container = "
|
|
3125
|
-
const button$1 = "
|
|
3126
|
-
const icon = "
|
|
3127
|
-
const title$1 = "
|
|
3128
|
-
const popout = "
|
|
3129
|
-
const hint = "
|
|
3130
|
-
const
|
|
3131
|
-
const
|
|
3132
|
-
const
|
|
3133
|
-
const
|
|
3134
|
-
const
|
|
3135
|
-
const
|
|
3135
|
+
const container = "_container_1enis_1";
|
|
3136
|
+
const button$1 = "_button_1enis_6";
|
|
3137
|
+
const icon = "_icon_1enis_22";
|
|
3138
|
+
const title$1 = "_title_1enis_27";
|
|
3139
|
+
const popout = "_popout_1enis_34";
|
|
3140
|
+
const hint = "_hint_1enis_51";
|
|
3141
|
+
const groupHeader = "_groupHeader_1enis_58";
|
|
3142
|
+
const option = "_option_1enis_65";
|
|
3143
|
+
const optionIcon = "_optionIcon_1enis_86";
|
|
3144
|
+
const optionTitle = "_optionTitle_1enis_91";
|
|
3145
|
+
const optionDescription = "_optionDescription_1enis_99";
|
|
3146
|
+
const checkmark = "_checkmark_1enis_106";
|
|
3147
|
+
const checkmarkPath = "_checkmarkPath_1enis_112";
|
|
3136
3148
|
const styles$2 = {
|
|
3137
3149
|
container,
|
|
3138
3150
|
button: button$1,
|
|
@@ -3140,6 +3152,7 @@ const styles$2 = {
|
|
|
3140
3152
|
title: title$1,
|
|
3141
3153
|
popout,
|
|
3142
3154
|
hint,
|
|
3155
|
+
groupHeader,
|
|
3143
3156
|
option,
|
|
3144
3157
|
optionIcon,
|
|
3145
3158
|
optionTitle,
|
|
@@ -3164,10 +3177,29 @@ function Dropdown({
|
|
|
3164
3177
|
if (collapseOnSelect)
|
|
3165
3178
|
setExpanded(false);
|
|
3166
3179
|
}, [onSelect]);
|
|
3180
|
+
const optionGroups = useMemo(() => {
|
|
3181
|
+
const containsOptionGroups = "options" in options[0];
|
|
3182
|
+
if (!containsOptionGroups) {
|
|
3183
|
+
return [{
|
|
3184
|
+
options
|
|
3185
|
+
}];
|
|
3186
|
+
}
|
|
3187
|
+
let optionIndex = 0;
|
|
3188
|
+
for (const group2 of options) {
|
|
3189
|
+
for (const option2 of group2.options) {
|
|
3190
|
+
option2.index = optionIndex;
|
|
3191
|
+
optionIndex++;
|
|
3192
|
+
}
|
|
3193
|
+
}
|
|
3194
|
+
return options;
|
|
3195
|
+
}, options);
|
|
3196
|
+
const flatOptions = useMemo(() => {
|
|
3197
|
+
return optionGroups.map((group2) => group2.options).flat();
|
|
3198
|
+
}, [optionGroups]);
|
|
3167
3199
|
const iconForSelectedOption = useMemo(() => {
|
|
3168
|
-
const selectedOption =
|
|
3200
|
+
const selectedOption = flatOptions[selectedIndex];
|
|
3169
3201
|
return selectedOption.icon;
|
|
3170
|
-
}, [
|
|
3202
|
+
}, [flatOptions, selectedIndex]);
|
|
3171
3203
|
return jsxs("div", {
|
|
3172
3204
|
className: styles$2.container,
|
|
3173
3205
|
children: [jsxs("button", {
|
|
@@ -3192,9 +3224,28 @@ function Dropdown({
|
|
|
3192
3224
|
children: [hint2 && jsx("p", {
|
|
3193
3225
|
className: styles$2.hint,
|
|
3194
3226
|
children: hint2
|
|
3195
|
-
}),
|
|
3227
|
+
}), optionGroups.map((group2) => jsx(OptionGroup, {
|
|
3228
|
+
...group2,
|
|
3229
|
+
selectedIndex,
|
|
3230
|
+
onOptionClick
|
|
3231
|
+
}))]
|
|
3232
|
+
})]
|
|
3233
|
+
});
|
|
3234
|
+
}
|
|
3235
|
+
function OptionGroup({
|
|
3236
|
+
title: title2,
|
|
3237
|
+
options,
|
|
3238
|
+
selectedIndex,
|
|
3239
|
+
onOptionClick
|
|
3240
|
+
}) {
|
|
3241
|
+
return jsxs(Fragment, {
|
|
3242
|
+
children: [title2 && jsx("p", {
|
|
3243
|
+
className: styles$2.groupHeader,
|
|
3244
|
+
children: title2
|
|
3245
|
+
}), options.map((option2) => {
|
|
3246
|
+
return jsxs("button", {
|
|
3196
3247
|
className: styles$2.option,
|
|
3197
|
-
onClick: () => onOptionClick(option2,
|
|
3248
|
+
onClick: () => onOptionClick(option2, option2.index),
|
|
3198
3249
|
children: [jsx("img", {
|
|
3199
3250
|
src: option2.icon,
|
|
3200
3251
|
className: styles$2.optionIcon
|
|
@@ -3207,11 +3258,11 @@ function Dropdown({
|
|
|
3207
3258
|
className: styles$2.optionDescription,
|
|
3208
3259
|
children: option2.description
|
|
3209
3260
|
})]
|
|
3210
|
-
}),
|
|
3261
|
+
}), option2.index === selectedIndex && jsx("div", {
|
|
3211
3262
|
className: styles$2.checkmark,
|
|
3212
3263
|
children: jsx(Checkmark, {})
|
|
3213
3264
|
})]
|
|
3214
|
-
}, option2.title)
|
|
3265
|
+
}, option2.title);
|
|
3215
3266
|
})]
|
|
3216
3267
|
});
|
|
3217
3268
|
}
|
|
@@ -3230,15 +3281,15 @@ function Checkmark() {
|
|
|
3230
3281
|
})
|
|
3231
3282
|
});
|
|
3232
3283
|
}
|
|
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 = "
|
|
3284
|
+
const coalitionsWrapper = "_coalitionsWrapper_4egbd_9";
|
|
3285
|
+
const coalitionsContainer = "_coalitionsContainer_4egbd_14";
|
|
3286
|
+
const coalition = "_coalition_4egbd_9";
|
|
3287
|
+
const title = "_title_4egbd_27";
|
|
3288
|
+
const description = "_description_4egbd_28";
|
|
3289
|
+
const thresholdText = "_thresholdText_4egbd_43";
|
|
3290
|
+
const thresholdTextBold = "_thresholdTextBold_4egbd_54";
|
|
3291
|
+
const thresholdDot = "_thresholdDot_4egbd_61";
|
|
3292
|
+
const thresholdLine = "_thresholdLine_4egbd_62";
|
|
3242
3293
|
const defaultStyles = {
|
|
3243
3294
|
coalitionsWrapper,
|
|
3244
3295
|
coalitionsContainer,
|
|
@@ -3260,7 +3311,8 @@ function CoalitionsTracker({
|
|
|
3260
3311
|
abbreviationAccessor = "abbreviation",
|
|
3261
3312
|
thresholdTextBold: thresholdTextBold2,
|
|
3262
3313
|
thresholdText: thresholdText2,
|
|
3263
|
-
styles: styles2
|
|
3314
|
+
styles: styles2,
|
|
3315
|
+
labelOverlapConfig = LabelOverlapConfig
|
|
3264
3316
|
}) {
|
|
3265
3317
|
const wrapperRef = useRef(null);
|
|
3266
3318
|
const thresholdTextRef = useRef(null);
|
|
@@ -3314,6 +3366,8 @@ function CoalitionsTracker({
|
|
|
3314
3366
|
},
|
|
3315
3367
|
children: list.description
|
|
3316
3368
|
}), jsx(StackedBar, {
|
|
3369
|
+
labelOverlapConfig,
|
|
3370
|
+
labelType: LabelType.hanging,
|
|
3317
3371
|
stack: list.stack,
|
|
3318
3372
|
width: list.width,
|
|
3319
3373
|
height: barChartHeight,
|
|
@@ -3645,6 +3699,7 @@ export {
|
|
|
3645
3699
|
GradientIcon,
|
|
3646
3700
|
GridType,
|
|
3647
3701
|
InfoButton,
|
|
3702
|
+
LabelOverlapConfig,
|
|
3648
3703
|
LabelType,
|
|
3649
3704
|
LegendItem,
|
|
3650
3705
|
Map$1 as Map,
|