Skip to content

Commit 9166b20

Browse files
committed
fix(Axis|Text): Improve Text y placement using lineHeight/capHeight and remove explicit adjustments, aligning with Html rendering
1 parent c1932c6 commit 9166b20

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

.changeset/twelve-frogs-agree.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'layerchart': patch
3+
---
4+
5+
fix(Axis|Text): Improve Text y placement using lineHeight/capHeight and remove explicit adjustments, aligning with Html rendering

packages/layerchart/src/lib/components/Axis.svelte

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,30 +264,28 @@
264264
return {
265265
textAnchor: 'middle',
266266
verticalAnchor: 'end',
267-
dy: -tickLength - 2, // manually adjusted until Text supports custom styles
267+
dy: -tickLength,
268268
};
269269
270270
case 'bottom':
271271
return {
272272
textAnchor: 'middle',
273273
verticalAnchor: 'start',
274-
dy: tickLength, // manually adjusted until Text supports custom styles
274+
dy: tickLength,
275275
};
276276
277277
case 'left':
278278
return {
279279
textAnchor: 'end',
280280
verticalAnchor: 'middle',
281281
dx: -tickLength,
282-
dy: -2, // manually adjusted until Text supports custom styles
283282
};
284283
285284
case 'right':
286285
return {
287286
textAnchor: 'start',
288287
verticalAnchor: 'middle',
289288
dx: tickLength,
290-
dy: -2, // manually adjusted until Text supports custom styles
291289
};
292290
293291
case 'angle':
@@ -302,7 +300,7 @@
302300
? 'end'
303301
: 'start',
304302
verticalAnchor: 'middle',
305-
dx: Math.sin(xValue) * (tickLength + 2),
303+
dx: Math.sin(xValue) * tickLength,
306304
dy: -Math.cos(xValue) * (tickLength + 4), // manually adjusted until Text supports custom styles
307305
};
308306
@@ -311,7 +309,6 @@
311309
textAnchor: 'middle',
312310
verticalAnchor: 'middle',
313311
dx: 2,
314-
dy: -2, // manually adjusted until Text supports custom styles
315312
};
316313
}
317314
}
@@ -416,7 +413,9 @@
416413
value: tickFormat(tick, index),
417414
...getDefaultTickLabelProps(tick),
418415
motion,
419-
lineHeight: '11px', // complement 10px text (until Text supports custom styles)
416+
// complement 10px text (until Text supports custom styles)
417+
capHeight: '7px',
418+
lineHeight: '11px',
420419
...tickLabelProps,
421420
class: cls(
422421
layerClass('axis-tick-label'),

packages/layerchart/src/lib/components/Text.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,11 @@
337337
338338
const startDy = $derived.by(() => {
339339
if (verticalAnchor === 'start') {
340-
return getPixelValue(capHeight);
340+
return getPixelValue(lineHeight);
341341
} else if (verticalAnchor === 'middle') {
342342
return ((lineCount - 1) / 2) * -getPixelValue(lineHeight) + getPixelValue(capHeight) / 2;
343343
} else {
344-
return (lineCount - 1) * -getPixelValue(lineHeight);
344+
return (lineCount - 1) * -getPixelValue(lineHeight) - getPixelValue(capHeight) / 2;
345345
}
346346
});
347347

0 commit comments

Comments
 (0)