Skip to content

Commit edb1f4b

Browse files
committed
refactor(canvas_bbox dark_theme): add validation for padding
1 parent 0f39133 commit edb1f4b

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/lib/axes/axis_utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,10 @@ export const getMaxBboxDimensions = (
180180
const prevLabelWidth = acc.maxLabelTextWidth;
181181
const prevLabelHeight = acc.maxLabelTextHeight;
182182
return {
183-
maxLabelBboxWidth: prevWidth > width ? prevWidth : width,
184-
maxLabelBboxHeight: prevHeight > height ? prevHeight : height,
185-
maxLabelTextWidth: prevLabelWidth > labelWidth ? prevLabelWidth : labelWidth,
186-
maxLabelTextHeight: prevLabelHeight > labelHeight ? prevLabelHeight : labelHeight,
183+
maxLabelBboxWidth: prevWidth > width ? prevWidth : width,
184+
maxLabelBboxHeight: prevHeight > height ? prevHeight : height,
185+
maxLabelTextWidth: prevLabelWidth > labelWidth ? prevLabelWidth : labelWidth,
186+
maxLabelTextHeight: prevLabelHeight > labelHeight ? prevLabelHeight : labelHeight,
187187
};
188188
};
189189

src/lib/axes/canvas_text_bbox_calculator.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export class CanvasTextBBoxCalculator implements BBoxCalculator {
2222
return none;
2323
}
2424

25+
// Avoid having negative padding that can obscure text
26+
if (padding < 1) {
27+
padding = 1;
28+
}
29+
2530
// We scale the text up to get a more accurate computation of the width of the text
2631
// because `measureText` can vary a lot between browsers.
2732
const scalingFactor = this.scaledFontSize / fontSize;

src/lib/themes/dark_theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const DARK_THEME: Theme = {
9191
fontFamily: `'Open Sans', Helvetica, Arial, sans-serif`,
9292
fontStyle: 'normal',
9393
fill: 'white',
94-
padding: 0,
94+
padding: 1,
9595
},
9696
tickLineStyle: {
9797
stroke: 'white',

0 commit comments

Comments
 (0)