@guardian/interactive-component-library 0.1.0-alpha.17 → 0.1.0-alpha.18
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "preact/jsx-runtime";
|
|
2
|
-
import { useRef,
|
|
2
|
+
import { useRef, useCallback, useEffect, useMemo, useState, useLayoutEffect, useContext, useImperativeHandle } from "preact/hooks";
|
|
3
3
|
import { render, createElement, cloneElement, createContext, toChildArray } from "preact";
|
|
4
4
|
import { useSyncExternalStore, createPortal, forwardRef } from "preact/compat";
|
|
5
5
|
import { scaleLinear as scaleLinear$1 } from "d3-scale";
|
|
@@ -112,25 +112,6 @@ const LegendItem = ({
|
|
|
112
112
|
})]
|
|
113
113
|
});
|
|
114
114
|
};
|
|
115
|
-
function isDarkColor(color) {
|
|
116
|
-
let r, g, b;
|
|
117
|
-
if (color.match(/^rgb/)) {
|
|
118
|
-
color = color.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/);
|
|
119
|
-
r = color[1];
|
|
120
|
-
g = color[2];
|
|
121
|
-
b = color[3];
|
|
122
|
-
} else {
|
|
123
|
-
color = +`0x${color.slice(1).replace(color.length < 5 && /./g, "$&$&")}`;
|
|
124
|
-
r = color >> 16;
|
|
125
|
-
g = color >> 8 & 255;
|
|
126
|
-
b = color & 255;
|
|
127
|
-
}
|
|
128
|
-
const hsp = Math.sqrt(0.299 * (r * r) + 0.587 * (g * g) + 0.114 * (b * b));
|
|
129
|
-
if (hsp > 140) {
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
return true;
|
|
133
|
-
}
|
|
134
115
|
const bar$2 = "_bar_wmb0k_1";
|
|
135
116
|
const label$1 = "_label_wmb0k_5";
|
|
136
117
|
const backgroundRect = "_backgroundRect_wmb0k_11";
|
|
@@ -143,30 +124,13 @@ function StackedBar({
|
|
|
143
124
|
stack,
|
|
144
125
|
width,
|
|
145
126
|
height,
|
|
127
|
+
hideLabels = true,
|
|
146
128
|
showBackgroundRect = false,
|
|
147
129
|
createSVG = true,
|
|
148
130
|
styles: styles2
|
|
149
131
|
}) {
|
|
150
132
|
const rectElements = useRef([]);
|
|
151
133
|
const textElements = useRef([]);
|
|
152
|
-
const [hideLabels, setHideLabels] = useState(true);
|
|
153
|
-
useLayoutEffect(() => {
|
|
154
|
-
for (let index2 = 0; index2 < stack.length; index2++) {
|
|
155
|
-
const rectElement = rectElements.current[index2];
|
|
156
|
-
const textElement = textElements.current[index2];
|
|
157
|
-
const paddingX = 8;
|
|
158
|
-
const hideText = textElement.getBBox().width + paddingX > rectElement.getBBox().width;
|
|
159
|
-
const rectStyle = window.getComputedStyle(rectElement);
|
|
160
|
-
const rectColor = rectStyle.getPropertyValue("fill");
|
|
161
|
-
const textColor = isDarkColor(rectColor) ? "#FFF" : "#121212";
|
|
162
|
-
textElement.style.fill = textColor;
|
|
163
|
-
if (hideText) {
|
|
164
|
-
setHideLabels(true);
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
setHideLabels(false);
|
|
169
|
-
}, [stack, width, height]);
|
|
170
134
|
styles2 = mergeStyles({
|
|
171
135
|
...defaultStyles$q
|
|
172
136
|
}, styles2);
|
|
@@ -184,7 +148,7 @@ function StackedBar({
|
|
|
184
148
|
fill: d2.fill
|
|
185
149
|
},
|
|
186
150
|
"shape-rendering": "crispEdges"
|
|
187
|
-
}), jsx("text", {
|
|
151
|
+
}), !hideLabels && jsx("text", {
|
|
188
152
|
ref: (element) => textElements.current[index2] = element,
|
|
189
153
|
x: itemWidth - 4,
|
|
190
154
|
y: height / 2,
|
|
@@ -193,7 +157,7 @@ function StackedBar({
|
|
|
193
157
|
"text-rendering": "optimizeLegibility",
|
|
194
158
|
className: styles2.label,
|
|
195
159
|
style: {
|
|
196
|
-
|
|
160
|
+
display: hideLabels ? "hidden" : "visible"
|
|
197
161
|
},
|
|
198
162
|
children: d2.label
|
|
199
163
|
})]
|
|
@@ -1772,7 +1736,7 @@ const ControlChange = ({
|
|
|
1772
1736
|
}
|
|
1773
1737
|
}) : jsx(CircleIcon, {
|
|
1774
1738
|
styles: {
|
|
1775
|
-
circle:
|
|
1739
|
+
circle: `fill-color--${next2}`
|
|
1776
1740
|
}
|
|
1777
1741
|
}), jsx("strong", {
|
|
1778
1742
|
className: styles2.text,
|
|
@@ -3158,15 +3122,15 @@ function Gradient() {
|
|
|
3158
3122
|
})]
|
|
3159
3123
|
});
|
|
3160
3124
|
}
|
|
3161
|
-
const ticker = "
|
|
3162
|
-
const tickerItems = "
|
|
3163
|
-
const tickerScroll = "
|
|
3164
|
-
const tickerItem = "
|
|
3165
|
-
const controls = "
|
|
3166
|
-
const gradient = "
|
|
3167
|
-
const buttons = "
|
|
3168
|
-
const button = "
|
|
3169
|
-
const buttonInner = "
|
|
3125
|
+
const ticker = "_ticker_2eemh_9";
|
|
3126
|
+
const tickerItems = "_tickerItems_2eemh_19";
|
|
3127
|
+
const tickerScroll = "_tickerScroll_2eemh_24";
|
|
3128
|
+
const tickerItem = "_tickerItem_2eemh_19";
|
|
3129
|
+
const controls = "_controls_2eemh_46";
|
|
3130
|
+
const gradient = "_gradient_2eemh_61";
|
|
3131
|
+
const buttons = "_buttons_2eemh_75";
|
|
3132
|
+
const button = "_button_2eemh_75";
|
|
3133
|
+
const buttonInner = "_buttonInner_2eemh_101";
|
|
3170
3134
|
const styles = {
|
|
3171
3135
|
ticker,
|
|
3172
3136
|
tickerItems,
|
|
@@ -3243,7 +3207,7 @@ function Ticker({
|
|
|
3243
3207
|
},
|
|
3244
3208
|
children: [jsx("div", {
|
|
3245
3209
|
className: styles.gradient,
|
|
3246
|
-
children:
|
|
3210
|
+
children: jsx(Gradient, {})
|
|
3247
3211
|
}), jsxs("div", {
|
|
3248
3212
|
className: styles.buttons,
|
|
3249
3213
|
children: [jsx(ArrowButton, {
|
|
@@ -3262,7 +3226,7 @@ function Ticker({
|
|
|
3262
3226
|
buttonInner: styles.buttonInner
|
|
3263
3227
|
},
|
|
3264
3228
|
onClick: toggleExpandedState,
|
|
3265
|
-
children: expanded ? "Show
|
|
3229
|
+
children: expanded ? "Show fewer" : `Show ${maxItems} most recent`
|
|
3266
3230
|
})
|
|
3267
3231
|
})]
|
|
3268
3232
|
})]
|