We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
You can continue the conversation there. Go to discussion →
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V5 中 Tooltip 的 title 设置常量不生效,只有设置 datum 里面的属性才生效
datum
import { Chart } from '@antv/g2'; const chart = new Chart({ container: 'container', theme: 'classic', autoFit: true, }); chart .interval() .data({ type: 'fetch', value: 'https://gw.alipayobjects.com/os/bmw-prod/fb9db6b7-23a5-4c23-bbef-c54a55fee580.csv', }) .encode('x', 'letter') .encode('y', 'frequency') .axis('y', { labelFormatter: '.0%' }) .tooltip({ title: '12345678', items: [{ channel: 'x' }, { channel: 'y' }] }); chart.interaction('tooltip', { enterable: true }) chart.render();
看了下代码感觉是这里有一些问题
// src/runtime/transform.ts export function extractTooltip( I: number[], mark: G2Mark, context: TransformContext, ): [number[], G2Mark] { // ... const valueOf = (item) => { if (!item) return item; if (typeof item === 'string') { // 这里的 value 取的是 data 上面的属性,由于传入的 item 是常量,所以这里拿到的是 undefined return I.map((i) => ({ name: item, value: data[i][item] })) } // ... } // 导致在后面 initializeState 的时候,通过 titleOf 方法拿到的每个 element 上的 data 中的 title 就是 undefined // src/runtime/plot.ts initializeState function initializeState( // ... ) { // ... const titleOf = (i) => tooltip.title?.[i]?.value; // ... const visualData: Record<string, any>[] = I.map((d, i) => { const datum = { points: P[i], transform: T[i], index: d, markKey, viewKey: key, ...(tooltip && { // 这里拿到的 title 就是 undefined title: titleOf(d), items: itemsOf(d), }), }; // ... }
在最终绘制 Tooltip 的时候,会因为当前 hover 的 element 的数据中,title 为 undefined,而不展示提示框标题
Tooltip
element
title
The text was updated successfully, but these errors were encountered:
plot.ts 里面有 valueOf 方法,是否可以复用该方法拿到 Tooltip 的 title? 因为在 label 的绘制逻辑里,text 字段就是通过 valueOf 来取值,在类型是 string 的时候,常量和数据属性都可以获取到
valueOf
// runtime/plot.ts function valueOf( value: Primitive | ((d: any, i: number, array: any) => any), datum: Record<string, any>, i: number, data: Record<string, any>, ) { if (typeof value === 'function') return value(datum, i, data); if (typeof value !== 'string') return value; if (datum[value] !== undefined) return datum[value]; return value; }
Sorry, something went wrong.
No branches or pull requests
V5 中 Tooltip 的 title 设置常量不生效,只有设置
datum
里面的属性才生效看了下代码感觉是这里有一些问题
在最终绘制
Tooltip
的时候,会因为当前 hover 的element
的数据中,title
为 undefined,而不展示提示框标题The text was updated successfully, but these errors were encountered: