Files
supersonic/webapp/packages/supersonic-fe/src/pages/SemanticModel/SemanticGraph/components/ToolTips.tsx
tristanliu 078a81038f [improvement][semantic-fe] Added an editing component to set filtering rules for Q&A. Now, the SQL editor will be accompanied by a list for display and control, to resolve ambiguity when using comma-separated values.
[improvement][semantic-fe] Improved validation logic and prompt copywriting for data source/dimension/metric editing and creation.
[improvement][semantic-fe] Improved user experience for visual modeling. Now, when using the legend to control the display/hide of data sources and their associated metric dimensions, the canvas will be re-layout based on the activated data source in the legend.

Co-authored-by: tristanliu <tristanliu@tencent.com>
2023-07-21 15:30:38 +08:00

64 lines
1.5 KiB
TypeScript

import G6 from '@antv/g6';
import moment from 'moment';
const initTooltips = () => {
const tooltip = new G6.Tooltip({
offsetX: 10,
offsetY: 10,
fixToNode: [1, 0.5],
// 允许出现 tooltip 的 item 类型
itemTypes: ['node'],
// 自定义 tooltip 内容
getContent: (e) => {
const outDiv = document.createElement('div');
outDiv.style.width = 'fit-content';
outDiv.style.height = 'fit-content';
const model = e!.item!.getModel();
const { name, bizName, createdBy, updatedAt, description } = model;
const list = [
{
label: '名称:',
value: name,
},
{
label: '字段:',
value: bizName,
},
{
label: '创建人:',
value: createdBy,
},
{
label: '更新时间:',
value: updatedAt ? moment(updatedAt).format('YYYY-MM-DD HH:mm:ss') : '',
},
{
label: '描述:',
value: description,
},
];
const listHtml = list.reduce((htmlString, item) => {
const { label, value } = item;
if (value) {
htmlString += `<p style="margin-bottom:0">
<span>${label} </span>
<span>${value}</span>
</p>`;
}
return htmlString;
}, '');
const html = `<div>
${listHtml}
</div>`;
if (e!.item!.getType() === 'node') {
outDiv.innerHTML = html;
}
return outDiv;
},
});
return tooltip;
};
export default initTooltips;