Skip to content

Commit

Permalink
feat:绘制特殊形状箭头图形。
Browse files Browse the repository at this point in the history
  • Loading branch information
OXOYO committed Dec 26, 2019
1 parent 48d1bc3 commit 7c8654d
Show file tree
Hide file tree
Showing 10 changed files with 774 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/components/Editor/config/materials.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ export default [
label: 'Arrow Left',
enable: true,
width: 80,
height: 80,
height: 60,
minWidth: 40,
minHeight: 40,
anchorPoints: anchorPoints,
Expand All @@ -467,7 +467,7 @@ export default [
label: 'Arrow Right',
enable: true,
width: 80,
height: 80,
height: 60,
minWidth: 40,
minHeight: 40,
anchorPoints: anchorPoints,
Expand All @@ -478,7 +478,7 @@ export default [
shape: 'arrow-up',
label: 'Arrow Up',
enable: true,
width: 80,
width: 60,
height: 80,
minWidth: 40,
minHeight: 40,
Expand Down Expand Up @@ -526,17 +526,17 @@ export default [
shape: 'callout-double-arrow',
label: 'Callout Double Arrow',
enable: true,
width: 80,
height: 80,
minWidth: 40,
minHeight: 40,
width: 60,
height: 100,
minWidth: 60,
minHeight: 100,
anchorPoints: anchorPoints,
shapeControl: shapeControl,
icon: `<g><g></g><g><g transform="translate(0.5,0.5)" style="visibility: visible;"><path d="M 13.16 8.09 L 13.16 6.69 L 10.64 6.69 L 15.96 1.4 L 21.28 6.69 L 18.76 6.69 L 18.76 8.09 L 22.96 8.09 L 22.96 22.01 L 18.76 22.01 L 18.76 23.41 L 21.28 23.41 L 15.96 28.56 L 10.64 23.41 L 13.16 23.41 L 13.16 22.01 L 8.96 22.01 L 8.96 8.09 Z" fill="#ffffff" stroke="#000000" stroke-width="1.3" stroke-miterlimit="10" pointer-events="all"></path></g></g><g></g><g></g></g>`
},
{
shape: 'callout-quad-arrow',
label: 'Callout Auad Arrow',
label: 'Callout Quad Arrow',
enable: true,
width: 80,
height: 80,
Expand Down
12 changes: 6 additions & 6 deletions src/global/g6/node/arrow/arrow-down.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ export default {
// 计算箭头
let { L1, L7 } = utils.node.computed({
deg: 85,
L1: 30,
L7: 10
L1: height / 3,
L7: width / 4
})
// 箭头顶点
let P0 = {
x: 0,
y: height / 2
}

// 左顶点
// 左下顶点
let P1 = {
x: -width / 2,
y: P0.y - L1
}
// 左中
// 左下中
let P2 = {
x: P0.x - L7,
y: P1.y
Expand All @@ -53,12 +53,12 @@ export default {
x: P0.x + L7,
y: -height / 2
}
// 右中
// 右下中
let P5 = {
x: P4.x,
y: P2.y
}
// 右顶点
// 右下顶点
let P6 = {
x: width / 2,
y: P1.y
Expand Down
90 changes: 90 additions & 0 deletions src/global/g6/node/arrow/arrow-left.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* Created by OXOYO on 2019/12/26.
*
* 左箭头
*/

import Global from '@antv/g6/src/global'
import Util from '@antv/g6/src/util'
import base from '../base'
import utils from '../../utils'

export default {
name: 'arrow-left',
extendName: 'single-shape',
options: {
...base,
shapeType: 'path',
getShapeStyle (cfg) {
const size = this.getSize(cfg)
const width = size[0]
const height = size[1]
const x = 0 - width / 2
const y = 0 - height / 2
// 计算箭头
let { L1, L7 } = utils.node.computed({
deg: 85,
L1: width / 3,
L7: height / 4
})
// 箭头顶点
let P0 = {
x: -width / 2,
y: 0
}

// 左上顶点
let P1 = {
x: -width / 2 + L1,
y: height / 2
}
// 左上中
let P2 = {
x: -width / 2 + L1,
y: L7
}
// 右上
let P3 = {
x: width / 2,
y: L7
}
// 右下
let P4 = {
x: width / 2,
y: -L7
}
// 左下中
let P5 = {
x: -width / 2 + L1,
y: -L7
}
// 左下顶点
let P6 = {
x: -width / 2 + L1,
y: -height / 2
}

const path = [
[ 'M', P0.x, P0.y ],
[ 'L', P1.x, P1.y ],
[ 'L', P2.x, P2.y ],
[ 'L', P3.x, P3.y ],
[ 'L', P4.x, P4.y ],
[ 'L', P5.x, P5.y ],
[ 'L', P6.x, P6.y ],
[ 'Z' ]
]
const color = cfg.color || Global.defaultNode.color
const style = Util.mix({}, Global.defaultNode.style, {
// 节点的位置在上层确定,所以这里仅使用相对位置即可
x,
y,
width,
height,
path,
stroke: color
}, cfg.style)
return style
}
}
}
90 changes: 90 additions & 0 deletions src/global/g6/node/arrow/arrow-right.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* Created by OXOYO on 2019/12/26.
*
* 右箭头
*/

import Global from '@antv/g6/src/global'
import Util from '@antv/g6/src/util'
import base from '../base'
import utils from '../../utils'

export default {
name: 'arrow-right',
extendName: 'single-shape',
options: {
...base,
shapeType: 'path',
getShapeStyle (cfg) {
const size = this.getSize(cfg)
const width = size[0]
const height = size[1]
const x = 0 - width / 2
const y = 0 - height / 2
// 计算箭头
let { L1, L7 } = utils.node.computed({
deg: 85,
L1: width / 3,
L7: height / 4
})
// 箭头顶点
let P0 = {
x: width / 2,
y: 0
}

// 右下顶点
let P1 = {
x: width / 2 - L1,
y: height / 2
}
// 右下中
let P2 = {
x: width / 2 - L1,
y: L7
}
// 左下
let P3 = {
x: -width / 2,
y: L7
}
// 左上
let P4 = {
x: -width / 2,
y: -L7
}
// 有下中
let P5 = {
x: width / 2 - L1,
y: -L7
}
// 右上顶点
let P6 = {
x: width / 2 - L1,
y: -height / 2
}

const path = [
[ 'M', P0.x, P0.y ],
[ 'L', P1.x, P1.y ],
[ 'L', P2.x, P2.y ],
[ 'L', P3.x, P3.y ],
[ 'L', P4.x, P4.y ],
[ 'L', P5.x, P5.y ],
[ 'L', P6.x, P6.y ],
[ 'Z' ]
]
const color = cfg.color || Global.defaultNode.color
const style = Util.mix({}, Global.defaultNode.style, {
// 节点的位置在上层确定,所以这里仅使用相对位置即可
x,
y,
width,
height,
path,
stroke: color
}, cfg.style)
return style
}
}
}
90 changes: 90 additions & 0 deletions src/global/g6/node/arrow/arrow-up.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* Created by OXOYO on 2019/12/26.
*
* 上箭头
*/

import Global from '@antv/g6/src/global'
import Util from '@antv/g6/src/util'
import base from '../base'
import utils from '../../utils'

export default {
name: 'arrow-up',
extendName: 'single-shape',
options: {
...base,
shapeType: 'path',
getShapeStyle (cfg) {
const size = this.getSize(cfg)
const width = size[0]
const height = size[1]
const x = 0 - width / 2
const y = 0 - height / 2
// 计算箭头
let { L1, L7 } = utils.node.computed({
deg: 85,
L1: height / 3,
L7: width / 4
})
// 箭头顶点
let P0 = {
x: 0,
y: -height / 2
}

// 右上顶点
let P1 = {
x: width / 2,
y: -height / 2 + L1
}
// 右上中
let P2 = {
x: L7,
y: P1.y
}
// 右下
let P3 = {
x: L7,
y: height / 2
}
// 左下
let P4 = {
x: -L7,
y: height / 2
}
// 左上中
let P5 = {
x: P4.x,
y: P2.y
}
// 左顶点
let P6 = {
x: -width / 2,
y: P1.y
}

const path = [
[ 'M', P0.x, P0.y ],
[ 'L', P1.x, P1.y ],
[ 'L', P2.x, P2.y ],
[ 'L', P3.x, P3.y ],
[ 'L', P4.x, P4.y ],
[ 'L', P5.x, P5.y ],
[ 'L', P6.x, P6.y ],
[ 'Z' ]
]
const color = cfg.color || Global.defaultNode.color
const style = Util.mix({}, Global.defaultNode.style, {
// 节点的位置在上层确定,所以这里仅使用相对位置即可
x,
y,
width,
height,
path,
stroke: color
}, cfg.style)
return style
}
}
}
Loading

0 comments on commit 7c8654d

Please sign in to comment.