Skip to content

Commit

Permalink
docs: 📚️ update layout demos (#1553)
Browse files Browse the repository at this point in the history
  • Loading branch information
NewByVector authored Nov 16, 2021
1 parent 3151152 commit 3eab73b
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 59 deletions.
2 changes: 1 addition & 1 deletion packages/x6-vector/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.2.4",
"version": "1.2.5",
"name": "@antv/x6-vector",
"description": "Lightweight library for manipulating and animating SVG.",
"main": "lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion sites/x6-sites/examples/animation/smil/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"zh": "沿路径运动",
"en": "Animate Along Path"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_43231b/afts/img/A*WKlrTLW6zN0AAAAAAAAAAAAAARQnAQ"
"screenshot": "https://gw.alipayobjects.com/mdn/rms_43231b/afts/img/A*Cpd6QbQPqGcAAAAAAAAAAAAAARQnAQ"
}
]
}
15 changes: 9 additions & 6 deletions sites/x6-sites/examples/layout/general/demo/circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@ const data: Model.FromJSONData = {
nodes: [],
}

for (let i = 1; i <= 24; i++) {
for (let i = 1; i <= 16; i++) {
data.nodes!.push({
id: `${i}`,
shape: 'rect',
width: 24,
height: 24,
label: '💜',
shape: 'circle',
width: 30,
height: 30,
label: `${i}`,
attrs: {
body: {
stroke: 'transparent',
fill: '#5F95FF',
},
label: {
fill: '#fff',
},
},
})
}

const graph = new Graph({
container: document.getElementById('container')!,
grid: true,
})

const circularLayout = new CircularLayout({
Expand Down
13 changes: 6 additions & 7 deletions sites/x6-sites/examples/layout/general/demo/dagre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ const edges = [
for (let i = 1; i <= 12; i++) {
data.nodes!.push({
id: `${i}`,
shape: 'rect',
width: 60,
height: 30,
shape: 'circle',
width: 32,
height: 32,
label: i,
attrs: {
body: {
fill: '#855af2',
fill: '#5F95FF',
stroke: 'transparent',
},
label: {
Expand All @@ -44,16 +44,15 @@ edges.forEach((edge: [string, string]) => {
target: edge[1],
attrs: {
line: {
stroke: '#fd6d6f',
strokeWidth: 1,
stroke: '#A2B1C3',
strokeWidth: 2,
},
},
})
})

const graph = new Graph({
container: document.getElementById('container')!,
grid: true,
})

const dagreLayout = new DagreLayout({
Expand Down
16 changes: 9 additions & 7 deletions sites/x6-sites/examples/layout/general/demo/ellipse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ for (let i = 1; i <= 20; i++) {
height: 26,
attrs: {
body: {
d:
'M0,-9.898961565145173L2.222455340918111,-3.0589473502942863L9.41447190108659,-3.058947350294287L3.596008280084239,1.1684139180159865L5.818463621002351,8.008428132866873L4.440892098500626e-16,3.7810668645565997L-5.8184636210023495,8.008428132866873L-3.5960082800842383,1.1684139180159867L-9.41447190108659,-3.058947350294285L-2.2224553409181116,-3.058947350294286Z',
fill: '#ffffff',
stroke: '#8921e0',
d: 'M0,-9.898961565145173L2.222455340918111,-3.0589473502942863L9.41447190108659,-3.058947350294287L3.596008280084239,1.1684139180159865L5.818463621002351,8.008428132866873L4.440892098500626e-16,3.7810668645565997L-5.8184636210023495,8.008428132866873L-3.5960082800842383,1.1684139180159867L-9.41447190108659,-3.058947350294285L-2.2224553409181116,-3.058947350294286Z',
fill: '#EFF4FF',
stroke: '#5F95FF',
},
},
})
Expand All @@ -31,7 +30,11 @@ function layout(nodes: Node.Metadata[]) {

nodes.forEach((node: Node.Metadata, index: number) => {
const angle = stepAngle * index
const p = start.clone().rotate(-angle, center).scale(ratio, 1, center).round()
const p = start
.clone()
.rotate(-angle, center)
.scale(ratio, 1, center)
.round()
node.x = p.x
node.y = p.y
})
Expand All @@ -41,7 +44,6 @@ function layout(nodes: Node.Metadata[]) {

const graph = new Graph({
container: document.getElementById('container')!,
grid: true,
})

graph.fromJSON(layout(nodes))
graph.fromJSON(layout(nodes))
7 changes: 3 additions & 4 deletions sites/x6-sites/examples/layout/general/demo/force.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ForceLayout } from '@antv/layout'

const graph = new Graph({
container: document.getElementById('container')!,
grid: true,
})

const originData = {
Expand Down Expand Up @@ -61,7 +60,7 @@ const getModelFromOriginData = (data: typeof originData) => {
y: item.y,
attrs: {
body: {
fill: '#855af2',
fill: '#5F95FF',
stroke: 'transparent',
},
},
Expand All @@ -73,8 +72,8 @@ const getModelFromOriginData = (data: typeof originData) => {
target: item.target,
attrs: {
line: {
stroke: '#ccc',
strokeWidth: 1,
stroke: '#A2B1C3',
strokeWidth: 2,
targetMarker: null,
},
},
Expand Down
27 changes: 4 additions & 23 deletions sites/x6-sites/examples/layout/general/demo/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,7 @@ const data: Model.FromJSONData = {
edges: [],
}
const keyPoints = [
20,
12,
12,
4,
18,
12,
12,
6,
16,
17,
17,
10,
10,
3,
3,
2,
2,
9,
9,
10,
20, 12, 12, 4, 18, 12, 12, 6, 16, 17, 17, 10, 10, 3, 3, 2, 2, 9, 9, 10,
]

for (let i = 1; i <= 21; i++) {
Expand All @@ -36,7 +17,7 @@ for (let i = 1; i <= 21; i++) {
height: 32,
attrs: {
body: {
fill: keyPoints.includes(i) ? '#fd6d6f' : '#855af2',
fill: '#5F95FF',
stroke: 'transparent',
},
label: {
Expand All @@ -53,7 +34,8 @@ for (let i = 0; i < keyPoints.length; i += 2) {
target: `${keyPoints[i + 1]}`,
attrs: {
line: {
stroke: '#fd6d6f',
stroke: '#A2B1C3',
strokeWidth: 2,
targetMarker: null,
},
},
Expand All @@ -62,7 +44,6 @@ for (let i = 0; i < keyPoints.length; i += 2) {

const graph = new Graph({
container: document.getElementById('container')!,
grid: true,
})

const gridLayout = new GridLayout({
Expand Down
10 changes: 5 additions & 5 deletions sites/x6-sites/examples/layout/general/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@
"zh": "网格布局",
"en": "Grid"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_43231b/afts/img/A*z0iOR7n6Wn0AAAAAAAAAAAAAARQnAQ"
"screenshot": "https://gw.alipayobjects.com/mdn/rms_43231b/afts/img/A*14yLQY9-FQ0AAAAAAAAAAAAAARQnAQ"
},
{
"filename": "circle.ts",
"title": {
"zh": "环形布局",
"en": "Circular"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_43231b/afts/img/A*25RuSq-VelIAAAAAAAAAAAAAARQnAQ"
"screenshot": "https://gw.alipayobjects.com/mdn/rms_43231b/afts/img/A*8IF1SYl7wrwAAAAAAAAAAAAAARQnAQ"
},
{
"filename": "dagre.ts",
"title": {
"zh": "Dagre",
"en": "Dagre"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_43231b/afts/img/A*m03UQYWtLjwAAAAAAAAAAAAAARQnAQ"
"screenshot": "https://gw.alipayobjects.com/mdn/rms_43231b/afts/img/A*D-QDTo_YzQgAAAAAAAAAAAAAARQnAQ"
},
{
"filename": "ellipse.ts",
"title": {
"zh": "椭圆布局",
"en": "Ellipse"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_43231b/afts/img/A*oP93S7a2H-sAAAAAAAAAAAAAARQnAQ"
"screenshot": "https://gw.alipayobjects.com/mdn/rms_43231b/afts/img/A*Er8NQ7Qsap8AAAAAAAAAAAAAARQnAQ"
},
{
"filename": "force.ts",
"title": {
"zh": "力导向布局",
"en": "Force"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_43231b/afts/img/A*1yboRpsGdBYAAAAAAAAAAAAAARQnAQ"
"screenshot": "https://gw.alipayobjects.com/mdn/rms_43231b/afts/img/A*0HvAR6qMEf8AAAAAAAAAAAAAARQnAQ"
}
]
}
2 changes: 1 addition & 1 deletion sites/x6-sites/examples/layout/tree/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"zh": "脑图树",
"en": "Mindmap"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_43231b/afts/img/A*iPDwRpBeLvQAAAAAAAAAAAAAARQnAQ"
"screenshot": "https://gw.alipayobjects.com/mdn/rms_43231b/afts/img/A*qSgRR7R6O6MAAAAAAAAAAAAAARQnAQ"
}
]
}
7 changes: 3 additions & 4 deletions sites/x6-sites/examples/layout/tree/demo/mindmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Hierarchy from '@antv/hierarchy'

const graph = new Graph({
container: document.getElementById('container')!,
grid: true,
connecting: {
connector: 'smooth',
},
Expand All @@ -21,7 +20,7 @@ fetch('../data/algorithm-category.json')
return 16
},
getHGap() {
return 100
return 80
},
getVGap() {
return 1
Expand All @@ -43,7 +42,7 @@ fetch('../data/algorithm-category.json')
height: 16,
attrs: {
body: {
fill: '#855af2',
fill: '#5F95FF',
stroke: 'transparent',
},
},
Expand All @@ -56,7 +55,7 @@ fetch('../data/algorithm-category.json')
target: `${item.id}`,
attrs: {
line: {
stroke: '#ccc',
stroke: '#A2B1C3',
strokeWidth: 1,
targetMarker: null,
},
Expand Down

0 comments on commit 3eab73b

Please sign in to comment.