Merge pull request #3057 from antvis/support-ssr-detecting

feat: support ssr detecting
This commit is contained in:
Yanyan Wang 2021-07-30 16:05:14 +08:00 committed by GitHub
commit 177080c155
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 17 deletions

View File

@ -4,7 +4,8 @@ import insertCss from 'insert-css';
import { IAbstractGraph as IGraph, IG6GraphEvent, Item } from '@antv/g6-core'; import { IAbstractGraph as IGraph, IG6GraphEvent, Item } from '@antv/g6-core';
import Base, { IPluginBaseConfig } from '../base'; import Base, { IPluginBaseConfig } from '../base';
insertCss(` typeof document !== 'undefined' &&
insertCss(`
.g6-component-contextmenu { .g6-component-contextmenu {
border: 1px solid #e2e2e2; border: 1px solid #e2e2e2;
border-radius: 4px; border-radius: 4px;
@ -57,7 +58,7 @@ export default class Menu extends Base {
return true; return true;
}, },
itemTypes: ['node', 'edge', 'combo'], itemTypes: ['node', 'edge', 'combo'],
trigger: 'contextmenu' trigger: 'contextmenu',
}; };
} }
@ -65,8 +66,8 @@ export default class Menu extends Base {
public getEvents() { public getEvents() {
if (this.get('trigger') === 'click') { if (this.get('trigger') === 'click') {
return { return {
click: 'onMenuShow' click: 'onMenuShow',
} };
} }
return { return {
contextmenu: 'onMenuShow', contextmenu: 'onMenuShow',

View File

@ -7,7 +7,8 @@ import insertCss from 'insert-css';
const DELTA = 0.05; const DELTA = 0.05;
insertCss(` typeof document !== 'undefined' &&
insertCss(`
.g6-component-toolbar { .g6-component-toolbar {
position: absolute; position: absolute;
list-style-type: none; list-style-type: none;

View File

@ -4,7 +4,8 @@ import insertCss from 'insert-css';
import { IG6GraphEvent, Item, IAbstractGraph as IGraph } from '@antv/g6-core'; import { IG6GraphEvent, Item, IAbstractGraph as IGraph } from '@antv/g6-core';
import Base, { IPluginBaseConfig } from '../base'; import Base, { IPluginBaseConfig } from '../base';
insertCss(` typeof document !== 'undefined' &&
insertCss(`
.g6-component-tooltip { .g6-component-tooltip {
border: 1px solid #e2e2e2; border: 1px solid #e2e2e2;
border-radius: 4px; border-radius: 4px;
@ -53,7 +54,7 @@ export default class Tooltip extends Base {
}, },
itemTypes: ['node', 'edge', 'combo'], itemTypes: ['node', 'edge', 'combo'],
trigger: 'mouseenter', trigger: 'mouseenter',
fixToNode: undefined fixToNode: undefined,
}; };
} }
@ -67,7 +68,7 @@ export default class Tooltip extends Base {
'canvas:click': 'onMouseLeave', 'canvas:click': 'onMouseLeave',
afterremoveitem: 'onMouseLeave', afterremoveitem: 'onMouseLeave',
contextmenu: 'onMouseLeave', contextmenu: 'onMouseLeave',
'drag': 'onMouseLeave', drag: 'onMouseLeave',
}; };
} }
return { return {
@ -102,14 +103,14 @@ export default class Tooltip extends Base {
container.appendChild(tooltip); container.appendChild(tooltip);
if (self.get('trigger') !== 'click') { if (self.get('trigger') !== 'click') {
tooltip.addEventListener('mouseenter', e => { tooltip.addEventListener('mouseenter', (e) => {
modifyCSS(tooltip, { modifyCSS(tooltip, {
visibility: 'visible', visibility: 'visible',
display: 'unset', display: 'unset',
}); });
}); });
tooltip.addEventListener('mouseleave', e => { tooltip.addEventListener('mouseleave', (e) => {
self.hideTooltip() self.hideTooltip();
}); });
} }
self.set('tooltip', tooltip); self.set('tooltip', tooltip);
@ -210,22 +211,28 @@ export default class Tooltip extends Base {
const fixToNode = this.get('fixToNode'); const fixToNode = this.get('fixToNode');
const { item } = e; const { item } = e;
if (item.getType && item.getType() === 'node' && fixToNode && isArray(fixToNode) && fixToNode.length >= 2) { if (
item.getType &&
item.getType() === 'node' &&
fixToNode &&
isArray(fixToNode) &&
fixToNode.length >= 2
) {
const itemBBox = item.getBBox(); const itemBBox = item.getBBox();
point = { point = {
x: itemBBox.minX + itemBBox.width * fixToNode[0], x: itemBBox.minX + itemBBox.width * fixToNode[0],
y: itemBBox.minY + itemBBox.height * fixToNode[1] y: itemBBox.minY + itemBBox.height * fixToNode[1],
}; };
} }
const { x, y } = graph.getCanvasByPoint(point.x, point.y); const { x, y } = graph.getCanvasByPoint(point.x, point.y);
const graphContainer = graph.getContainer(); const graphContainer = graph.getContainer();
const res = { const res = {
x: x + graphContainer.offsetLeft + offsetX, x: x + graphContainer.offsetLeft + offsetX,
y: y + graphContainer.offsetTop + offsetY y: y + graphContainer.offsetTop + offsetY,
} };
// 先修改为 visible 方可正确计算 bbox // 先修改为 visible 方可正确计算 bbox
modifyCSS(tooltip, { modifyCSS(tooltip, {
@ -233,7 +240,7 @@ export default class Tooltip extends Base {
display: 'unset', display: 'unset',
}); });
const bbox = tooltip.getBoundingClientRect(); const bbox = tooltip.getBoundingClientRect();
if (x + bbox.width + offsetX > width) { if (x + bbox.width + offsetX > width) {
res.x -= bbox.width + offsetX; res.x -= bbox.width + offsetX;
} }