Skip to content

Commit 8e146dc

Browse files
author
林舸
committed
fix: axis render error
1 parent 3b50d7b commit 8e146dc

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/component",
3-
"version": "2.1.8",
3+
"version": "2.1.11",
44
"description": "Visualization components for AntV, based on G.",
55
"license": "MIT",
66
"main": "lib/index.js",

src/ui/axis/guides/labels.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
wrapIt,
2424
renderHtmlExtDo,
2525
parseHeightFromHTML,
26+
omit,
2627
} from '../../../util';
2728
import { CLASS_NAMES } from '../constant';
2829
import { processOverlap } from '../overlap';
@@ -183,8 +184,14 @@ function renderHTMLLabel(datum: AxisDatum, index: number, data: AxisDatum[], att
183184
});
184185
}
185186

187+
const STYLE_OMIT_MAP = {
188+
html: ['fill'],
189+
text: [],
190+
};
191+
186192
function applyTextStyle(node: DisplayObject, style: Partial<TextStyleProps>) {
187-
if (['text', 'html'].includes(node.nodeName)) node.attr(style);
193+
if (['text', 'html'].includes(node.nodeName))
194+
node.attr(omit(style, STYLE_OMIT_MAP[node.nodeName as keyof typeof STYLE_OMIT_MAP]));
188195
}
189196

190197
function overlapHandler(attr: Required<AxisStyleProps>, main: DisplayObject) {
@@ -233,6 +240,14 @@ function renderLabel(
233240
...getLabelStyle(datum.value, rotate, attr),
234241
...labelStyle,
235242
});
243+
244+
// For HTML labels, adjust x position to center align.
245+
if (label.nodeName === 'html') {
246+
const bbox = label.getBBox();
247+
const currentX = label.style.x || 0;
248+
label.attr('x', currentX - bbox.width / 2);
249+
}
250+
236251
container.attr(groupStyle);
237252
return label;
238253
}

src/util/extend-display-object.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,13 @@ export function renderExtDo(el: ExtendDisplayObject): DisplayObject {
1111

1212
export function renderHtmlExtDo(el: ExtendDisplayObject, style: Partial<HTMLStyleProps>): DisplayObject {
1313
if (typeof el === 'function') return el();
14-
return isString(el) || isNumber(el) ? new HTML({ style: { ...style, innerHTML: String(el) } }) : el;
14+
return isString(el) || isNumber(el)
15+
? new HTML({
16+
style: {
17+
pointerEvents: 'auto',
18+
...style,
19+
innerHTML: el as string | HTMLElement,
20+
},
21+
})
22+
: el;
1523
}

0 commit comments

Comments
 (0)