Skip to content

Commit

Permalink
✨ feat(common): update dark style of graph studio shape
Browse files Browse the repository at this point in the history
  • Loading branch information
萌萌的老胖子 committed Apr 17, 2020
1 parent 8cdc46a commit faa9e7d
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 31 deletions.
7 changes: 7 additions & 0 deletions packages/graphin/src/controller/register.ts
Expand Up @@ -7,6 +7,7 @@ import CircleNode from '../shape/render/CircleNode';

import RegisterLineEdge from '../shape/g6/LineEdge';
import RegisterCanonicalLineEdge from '../shape/graph-studio/LineEdge';
import RegisterCanonicalLoopEdge from '../shape/graph-studio/LoopEdge';
import RegisterCanonicalCircleNode from '../shape/graph-studio/CircleNode';
import RegisterCanonicalRectNode from '../shape/graph-studio/RectNode';
import RegisterCanonicalHexagonNode from '../shape/graph-studio/HexagonNode';
Expand Down Expand Up @@ -65,6 +66,12 @@ const defaultRegister = {
RegisterCanonicalLineEdge(G6);
},
},
{
name: 'CanonicalLoopEdge',
register: () => {
RegisterCanonicalLoopEdge(G6);
},
},
];
},
behavior: () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/graphin/src/shape/graph-studio/CircleNode.ts
Expand Up @@ -153,14 +153,14 @@ export default (g6: any) => {

const targetAttrs = {
border: {
stroke: data.style?.dark ? '#1E202D' : color.normal,
stroke: color.normal,
lineWidth: 2,
},
selected: {
r: 0,
},
inner: {
fill: data.style?.dark ? '#1E202D' : color.dark,
fill: color.dark,
},
icon: {
fill: data.style?.dark ? '#8D93B0' : '#FFFFFF',
Expand All @@ -169,7 +169,7 @@ export default (g6: any) => {
fill: data.style?.dark ? '#8D93B0' : '#FFFFFF',
},
children: {
fill: data.style?.dark ? '#1E202D' : color.normal,
fill: color.normal,
},
childrenIcon: {
fill: data.style?.dark ? '#8D93B0' : '#FFFFFF',
Expand All @@ -186,11 +186,11 @@ export default (g6: any) => {
}

if (name === EnumNodeAndEdgeStatus.DARK && value) {
targetAttrs.border.stroke = '#1E202D';
targetAttrs.inner.fill = '#1E202D';
targetAttrs.border.stroke = GREY.dark;
targetAttrs.inner.fill = GREY.dark;
targetAttrs.icon.fill = '#8D93B0';
targetAttrs.label.fill = '#8D93B0';
targetAttrs.children.fill = '#1E202D';
targetAttrs.children.fill = GREY.normal;
targetAttrs.childrenIcon.fill = '#8D93B0';
}

Expand Down
12 changes: 6 additions & 6 deletions packages/graphin/src/shape/graph-studio/HexagonNode.ts
Expand Up @@ -163,14 +163,14 @@ export default (g6: any) => {

const targetAttrs = {
border: {
stroke: data.style?.dark ? '#1E202D' : color.normal,
stroke: color.normal,
lineWidth: 2,
},
selected: {
points: [] as number[][],
},
inner: {
fill: data.style?.dark ? '#1E202D' : color.dark,
fill: color.dark,
},
icon: {
fill: data.style?.dark ? '#8D93B0' : '#FFFFFF',
Expand All @@ -179,7 +179,7 @@ export default (g6: any) => {
fill: data.style?.dark ? '#8D93B0' : '#FFFFFF',
},
children: {
fill: data.style?.dark ? '#1E202D' : color.normal,
fill: color.normal,
},
childrenIcon: {
fill: data.style?.dark ? '#8D93B0' : '#FFFFFF',
Expand All @@ -196,11 +196,11 @@ export default (g6: any) => {
}

if (name === EnumNodeAndEdgeStatus.DARK && value) {
targetAttrs.border.stroke = '#1E202D';
targetAttrs.inner.fill = '#1E202D';
targetAttrs.border.stroke = GREY.dark;
targetAttrs.inner.fill = GREY.dark;
targetAttrs.icon.fill = '#8D93B0';
targetAttrs.label.fill = '#8D93B0';
targetAttrs.children.fill = '#1E202D';
targetAttrs.children.fill = GREY.normal;
targetAttrs.childrenIcon.fill = '#8D93B0';
}

Expand Down
2 changes: 1 addition & 1 deletion packages/graphin/src/shape/graph-studio/LineEdge.ts
Expand Up @@ -142,7 +142,7 @@ export default (g6: any) => {
}
if (name === EnumNodeAndEdgeStatus.DARK && value) {
targetAttrs.main = {
stroke: '#2C2F40',
stroke: GREY.dark,
lineWidth: 1,
endArrow: {
d: 2,
Expand Down
184 changes: 184 additions & 0 deletions packages/graphin/src/shape/graph-studio/LoopEdge.ts
@@ -0,0 +1,184 @@
import { G } from '@antv/g6/types/g';
import G6 from '@antv/g6';
import { G6Edge, G6Node } from '../../types';
import { normalizeColor } from './utils';
import {
EDGE_LINE_DEFAULT_COLOR,
EDGE_LABEL_DEFAULT_COLOR,
HIDDEN_LABEL_COLOR,
GREY,
EnumNodeAndEdgeStatus,
} from './constants';

const PADDING = 2;
const RADIO = 0.75;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export default (g6: any) => {
g6.registerEdge(
'CanonicalLoopEdge',
{
draw(cfg: G6Edge, group: G.Group) {
const hasLabel = cfg.label;
const { startPoint, endPoint } = cfg;
const d = (cfg.style?.line.width || 1) + 1;

const target = cfg.sourceNode.get('model') as G6Node;
let size = (target.style?.nodeSize || 0) > 28 ? (target.style?.nodeSize as number) : 28;
size = size * RADIO;

const attrs = {
path: [
['M', startPoint.x - size / 2 - PADDING, startPoint.y - (Math.sqrt(3) / 2) * size - PADDING],
[
'A',
size,
size,
0,
1,
1,
startPoint.x + size / 2 + PADDING,
startPoint.y - (Math.sqrt(3) / 2) * size - PADDING,
],
],
};

const lineColor = cfg.style?.line.color ? normalizeColor(cfg.style?.line.color) : EDGE_LINE_DEFAULT_COLOR;
const labelColor = cfg.style?.label?.color ? normalizeColor(cfg.style?.label?.color) : EDGE_LABEL_DEFAULT_COLOR;

group.addShape('path', {
attrs: {
id: 'selected',
...attrs,
lineWidth: 1,
stroke: '#000',
opacity: 0.05,
},
});

const key = group.addShape('path', {
attrs: {
id: 'main',
...attrs,
lineAppendWidth: 4,
stroke: cfg.style?.dark ? GREY.dark : lineColor.dark,
lineWidth: cfg.style?.dark ? 1 : cfg.style?.line.width || 1,
lineDash: cfg.style?.line.dash,
endArrow: {
d,
path: `M ${d},0 L -${d},-${d} L -${d},${d} Z`,
},
},
});

if (hasLabel) {
const label = group.addShape('text', {
attrs: {
id: 'label',
x: 0,
y: 0,
fontSize: cfg.style?.label?.size || 10,
text: cfg.label,
textAlign: 'center',
fontFamily: cfg.style?.label?.family,
fill: cfg.style?.dark ? HIDDEN_LABEL_COLOR.normal : labelColor.dark,
},
});
label.rotate(
endPoint.x - startPoint.x === 0
? Math.PI / 2
: Math.atan((endPoint.y - startPoint.y) / (endPoint.x - startPoint.x)),
);
label.translate((startPoint.x + endPoint.x) / 2, (startPoint.y + endPoint.y) / 2);
label.translate(-5, -5);
}
return key;
},
setState(name: EnumNodeAndEdgeStatus, value: string, edge: G6.Edge) {
if (!name) return;
const data: G6Edge = edge.get('model');
const mainShape = edge
.getContainer()
.get('children')
.find((item: G.Shape) => item.attr().id === 'main');
const selectedShape = edge
.getContainer()
.get('children')
.find((item: G.Shape) => item.attr().id === 'selected');
const textShape = edge
.getContainer()
.get('children')
.find((item: G.Shape) => item.attr().id === 'label');
const d = (data.style?.line.width || 1) + 1;
const basicLineWidth = data.style?.dark ? 1 : data.style?.line.width || 1;
const lineColor = data.style?.line.color ? normalizeColor(data.style?.line.color) : EDGE_LINE_DEFAULT_COLOR;
const labelColor = data.style?.label?.color
? normalizeColor(data.style?.label?.color)
: EDGE_LABEL_DEFAULT_COLOR;

const targetAttrs = {
main: {},
selected: {},
text: {},
};

targetAttrs.main = {
stroke: data.style?.dark ? GREY.dark : lineColor.dark,
lineWidth: basicLineWidth,
endArrow: {
d,
path: `M ${d},0 L -${d},-${d} L -${d},${d} Z`,
},
};
targetAttrs.selected = {
lineWidth: 0,
};
targetAttrs.text = {
fill: data.style?.dark ? HIDDEN_LABEL_COLOR.normal : labelColor.dark,
};

if (name === EnumNodeAndEdgeStatus.HOVERED && value) {
const deltaD = d + 1;
targetAttrs.main = {
lineWidth: basicLineWidth + 1,
endArrow: {
d: deltaD,
path: `M ${deltaD},0 L -${deltaD},-${deltaD} L -${deltaD},${deltaD} Z`,
},
};
}
if ((name === EnumNodeAndEdgeStatus.SELECTED && value) || (name === EnumNodeAndEdgeStatus.LIGHT && value)) {
const deltaD = d + 1;
targetAttrs.main = {
lineWidth: basicLineWidth + 1,
endArrow: {
d: deltaD,
path: `M ${deltaD},0 L -${deltaD},-${deltaD} L -${deltaD},${deltaD} Z`,
},
};
targetAttrs.selected = {
lineWidth: basicLineWidth + 10,
};
}
if (name === EnumNodeAndEdgeStatus.DARK && value) {
targetAttrs.main = {
stroke: GREY.dark,
lineWidth: 1,
endArrow: {
d: 2,
path: 'M 2,0 L -2,-2 L -2,2 Z',
},
};
targetAttrs.text = {
fill: '#8D93B0',
};
}

mainShape.attr(targetAttrs.main);
selectedShape.attr(targetAttrs.selected);
if (textShape) textShape.attr(targetAttrs.text);
},
},
'single-edge',
);
};
4 changes: 2 additions & 2 deletions packages/graphin/src/shape/graph-studio/PointNode.ts
Expand Up @@ -60,7 +60,7 @@ export default (g6: any) => {

const targetAttrs = {
floor: {
stroke: data.style?.dark ? '#1E202D' : color.dark,
stroke: color.dark,
},
selected: {
r: 0,
Expand All @@ -76,7 +76,7 @@ export default (g6: any) => {
};
}
if (name === EnumNodeAndEdgeStatus.DARK && value) {
targetAttrs.floor.stroke = '#1E202D';
targetAttrs.floor.stroke = GREY.dark;
targetAttrs.text.fill = '#8D93B0';
}
floor.attr(targetAttrs.floor);
Expand Down
18 changes: 9 additions & 9 deletions packages/graphin/src/shape/graph-studio/RectNode.ts
Expand Up @@ -33,7 +33,7 @@ export default (g6: any) => {
y: 0,
width: outerSize,
height: outerSize,
stroke: cfg.style?.dark ? '#1E202D' : color.normal,
stroke: color.normal,
lineWidth: 2,
},
});
Expand Down Expand Up @@ -64,7 +64,7 @@ export default (g6: any) => {
y: 0,
width: innerSize,
height: innerSize,
fill: cfg.style?.dark ? '#1E202D' : color.dark,
fill: color.dark,
},
});
inner.addShape('text', {
Expand Down Expand Up @@ -114,7 +114,7 @@ export default (g6: any) => {
y: 0,
width: 12,
height: 12,
fill: cfg.style?.dark ? '#1E202D' : color.normal,
fill: color.normal,
},
});
children.addShape('text', {
Expand Down Expand Up @@ -159,15 +159,15 @@ export default (g6: any) => {

const targetAttrs = {
border: {
stroke: data.style?.dark ? '#1E202D' : color.normal,
stroke: color.normal,
lineWidth: 2,
},
selected: {
width: 0,
height: 0,
},
inner: {
fill: data.style?.dark ? '#1E202D' : color.dark,
fill: color.dark,
},
icon: {
fill: data.style?.dark ? '#8D93B0' : '#FFFFFF',
Expand All @@ -176,7 +176,7 @@ export default (g6: any) => {
fill: data.style?.dark ? '#8D93B0' : '#FFFFFF',
},
children: {
fill: data.style?.dark ? '#1E202D' : color.normal,
fill: color.normal,
},
childrenIcon: {
fill: data.style?.dark ? '#8D93B0' : '#FFFFFF',
Expand All @@ -195,11 +195,11 @@ export default (g6: any) => {
}

if (name === EnumNodeAndEdgeStatus.DARK && value) {
targetAttrs.border.stroke = '#1E202D';
targetAttrs.inner.fill = '#1E202D';
targetAttrs.border.stroke = GREY.dark;
targetAttrs.inner.fill = GREY.dark;
targetAttrs.icon.fill = '#8D93B0';
targetAttrs.label.fill = '#8D93B0';
targetAttrs.children.fill = '#1E202D';
targetAttrs.children.fill = GREY.normal;
targetAttrs.childrenIcon.fill = '#8D93B0';
}

Expand Down

0 comments on commit faa9e7d

Please sign in to comment.