Skip to content

Commit 294a473

Browse files
committed
🐛 Update gridlines on container size change
1 parent 647c782 commit 294a473

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

packages/lib/src/components/core/lume-axis/lume-axis.vue

+22-10
Original file line numberDiff line numberDiff line change
@@ -274,18 +274,25 @@ function getTextNode(index: number) {
274274
275275
function setTicks() {
276276
ticksWithAttributes.value = ticks.value.map(
277-
(tick: string | number, index: number) => {
278-
return {
279-
value: formatTick(tick),
280-
group: mixins.getTickGroupAttributes(tick, index),
281-
ghost: mixins.getTickGhostAttributes(getTextNode(index)),
282-
label: mixins.getTickLabelAttributes(),
283-
gridline: mixins.getGridLinesAttributes(),
284-
};
285-
}
277+
(tick: string | number, index: number) => ({
278+
value: formatTick(tick),
279+
group: mixins.getTickGroupAttributes(tick, index),
280+
ghost: mixins.getTickGhostAttributes(getTextNode(index)),
281+
label: mixins.getTickLabelAttributes(),
282+
gridline: mixins.getGridLinesAttributes(),
283+
})
286284
);
287285
}
288286
287+
function updateGridlines() {
288+
if (ticksWithAttributes.value) {
289+
ticksWithAttributes.value.map((tick) => {
290+
tick.gridline = mixins.getGridLinesAttributes();
291+
return tick;
292+
});
293+
}
294+
}
295+
289296
function init() {
290297
if (!scale.value) return;
291298
@@ -308,12 +315,17 @@ function init() {
308315
// Setup watcher to get new mixins if scale changes (i.e. vertical to horizontal)
309316
watch(scale, init, { flush: 'sync', immediate: true });
310317
311-
// Re-render after scale changes (new containerSize, new balebs, scale override, etc.)
318+
// Re-render after scale changes (new containerSize, new values, scale override, etc.)
312319
watch(scale, setTicks, { immediate: true });
313320
// Re-render after `tickRefs` is defined (to grab text width)
314321
watch(tickRefs, setTicks);
315322
316323
watch(axisSize, (size) => emit('lume__internal--axis-size', size));
317324
325+
// Re-calculate gridlines when container size changes
326+
// This is needed for cases where the container width changes, so the Y gridlines need to update,
327+
// but the Y scale doesn't change since the height is the same
328+
watch(props.containerSize, updateGridlines);
329+
318330
onMounted(() => svgCheck(root.value));
319331
</script>

0 commit comments

Comments
 (0)