Skip to content
New issue

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

feat: tooltip plugin #5573

Merged
merged 7 commits into from Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/g6/__tests__/demo/case/index.ts
Expand Up @@ -44,6 +44,7 @@ export * from './layout-radial-prevent-overlap';
export * from './layout-radial-prevent-overlap-unstrict';
export * from './layout-radial-sort';
export * from './plugin-grid-line';
export * from './plugin-tooltip';
export * from './plugin-watermark';
export * from './plugin-watermark-image';
export * from './theme';
Expand Down
55 changes: 55 additions & 0 deletions packages/g6/__tests__/demo/case/plugin-tooltip.ts
@@ -0,0 +1,55 @@
import { Graph } from '@/src';
import data from '@@/dataset/combo.json';
import { isObject } from '@antv/util';
import type { STDTestCase } from '../types';

export const pluginTooltip: STDTestCase = async (context) => {
const graph = new Graph({
...context,
data,
layout: {
type: 'combo-combined',
comboPadding: 2,
},
behaviors: ['drag-canvas', 'drag-element'],
node: {
style: {
labelText: (d) => d.id,
},
},
plugins: [
{
key: 'tooltip',
type: 'tooltip',
trigger: 'click',
getContent: (evt: any, items: any[]) => {
return `<div>${items[0].id || items[0].source + ' --> ' + items[0].target}</div>`;
},
},
],
autoFit: 'view',
});

await graph.render();

pluginTooltip.form = (panel) => {
const config = {
trigger: 'click',
};
return [
panel
.add(config, 'trigger', ['hover', 'click'])
.name('Change Trigger Method')
.onChange((trigger: string) => {
graph.setPlugins((plugins) =>
plugins.map((plugin) => {
if (isObject(plugin) && plugin.type === 'tooltip') return { ...plugin, trigger };
return plugin;
}),
);
}),
];
};

return graph;
};