-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: fix error in cylinder shape (#3335)
- Loading branch information
1 parent
c76a23b
commit ab0c7fe
Showing
4 changed files
with
145 additions
and
33 deletions.
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
sites/x6-sites/examples/node/custom-node/demo/cylinder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import { Graph, NumberExt } from '@antv/x6' | ||
|
||
Graph.registerNode('cylinder', { | ||
markup: [ | ||
{ | ||
tagName: 'path', | ||
selector: 'body', | ||
}, | ||
{ | ||
tagName: 'ellipse', | ||
selector: 'top', | ||
}, | ||
{ | ||
tagName: 'text', | ||
selector: 'label', | ||
}, | ||
], | ||
attrs: { | ||
body: { | ||
fill: '#ffffff', | ||
stroke: '#333333', | ||
strokeWidth: 2, | ||
lateral: 10, | ||
}, | ||
top: { | ||
fill: '#ffffff', | ||
stroke: '#333333', | ||
strokeWidth: 2, | ||
refCx: '50%', | ||
refRx: '50%', | ||
cy: 10, | ||
ry: 10, | ||
}, | ||
}, | ||
attrHooks: { | ||
lateral: { | ||
set(t: number | string, { refBBox }) { | ||
const isPercentage = NumberExt.isPercentage(t) | ||
if (isPercentage) { | ||
// eslint-disable-next-line | ||
t = parseFloat(t as string) / 100 | ||
} | ||
|
||
const x = refBBox.x | ||
const y = refBBox.y | ||
const w = refBBox.width | ||
const h = refBBox.height | ||
|
||
// curve control point variables | ||
const rx = w / 2 | ||
const ry = isPercentage ? h * (t as number) : (t as number) | ||
|
||
const kappa = 0.551784 | ||
const cx = kappa * rx | ||
const cy = kappa * ry | ||
|
||
// shape variables | ||
const xLeft = x | ||
const xCenter = x + w / 2 | ||
const xRight = x + w | ||
|
||
const ySideTop = y + ry | ||
const yCurveTop = ySideTop - ry | ||
const ySideBottom = y + h - ry | ||
const yCurveBottom = y + h | ||
|
||
// return calculated shape | ||
const data = [ | ||
'M', | ||
xLeft, | ||
ySideTop, | ||
'L', | ||
xLeft, | ||
ySideBottom, | ||
'C', | ||
x, | ||
ySideBottom + cy, | ||
xCenter - cx, | ||
yCurveBottom, | ||
xCenter, | ||
yCurveBottom, | ||
'C', | ||
xCenter + cx, | ||
yCurveBottom, | ||
xRight, | ||
ySideBottom + cy, | ||
xRight, | ||
ySideBottom, | ||
'L', | ||
xRight, | ||
ySideTop, | ||
'C', | ||
xRight, | ||
ySideTop - cy, | ||
xCenter + cx, | ||
yCurveTop, | ||
xCenter, | ||
yCurveTop, | ||
'C', | ||
xCenter - cx, | ||
yCurveTop, | ||
xLeft, | ||
ySideTop - cy, | ||
xLeft, | ||
ySideTop, | ||
'Z', | ||
] | ||
|
||
return { d: data.join(' ') } | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
const graph = new Graph({ | ||
container: document.getElementById('container'), | ||
grid: true, | ||
}) | ||
|
||
graph.addNode({ | ||
shape: 'cylinder', | ||
x: 320, | ||
y: 120, | ||
width: 80, | ||
height: 120, | ||
label: 'cylinder', | ||
attrs: { | ||
top: { | ||
fill: '#fe854f', | ||
fillOpacity: 0.5, | ||
}, | ||
body: { | ||
fill: '#ED8A19', | ||
fillOpacity: 0.8, | ||
}, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters