fix: 🐛 fix type error

This commit is contained in:
vector
2021-04-13 13:37:36 +08:00
parent fa3303715f
commit 30ca7a9281
19 changed files with 262 additions and 230 deletions

View File

@ -1,4 +1,9 @@
import { NumberExt, Shape, Path, Point } from '@antv/x6'
import { NumberExt, Shape, Path, Point, JSONObject } from '@antv/x6'
interface KnobsAttrValue extends JSONObject {
round: boolean | string | number
ridge: boolean | string | number
}
Shape.Path.define({
shape: 'flowchart_card',
@ -18,14 +23,9 @@ Shape.Path.define({
},
attrHooks: {
knobs: {
set(
v: {
round: boolean | string | number
ridge: boolean | string | number
},
{ refBBox },
) {
if (typeof v === 'object') {
set(val, { refBBox }) {
if (typeof val === 'object') {
const v = val as KnobsAttrValue
const dim = Math.min(refBBox.width, refBBox.height)
let round: number
let ridge: number

View File

@ -1,4 +1,9 @@
import { NumberExt, Shape, Path, Line, Point } from '@antv/x6'
import { NumberExt, Shape, Path, Line, Point, JSONObject } from '@antv/x6'
interface KnobsAttrValue extends JSONObject {
round: boolean | string | number
ridge: boolean | string | number
}
Shape.Path.define({
shape: 'flowchart_data',
@ -18,14 +23,9 @@ Shape.Path.define({
},
attrHooks: {
knobs: {
set(
v: {
round: boolean | string | number
ridge: boolean | string | number
},
{ refBBox },
) {
if (typeof v === 'object') {
set(val, { refBBox }) {
if (typeof val === 'object') {
const v = val as KnobsAttrValue
const dim = Math.min(refBBox.width, refBBox.height)
let round: number
let ridge: number

View File

@ -15,30 +15,37 @@ Shape.Path.define({
},
attrHooks: {
ridge: {
set(v: number, { refBBox }) {
const { width, height } = refBBox
const round = 5
const ridge = v * height
const path = new Path()
.moveTo(width - round, 0)
.arcTo(round, round, 0, 0, 1, width, round)
.lineTo(width, height - ridge / 2)
.quadTo(
(3 * width) / 4,
height - 1.4 * ridge,
width / 2,
height - ridge / 2,
)
.quadTo(width / 4, height - ridge * (1 - 1.4), 0, height - ridge / 2)
set(v, { refBBox }) {
if (typeof v === 'number') {
const { width, height } = refBBox
const round = 5
const ridge = v * height
const path = new Path()
.moveTo(width - round, 0)
.arcTo(round, round, 0, 0, 1, width, round)
.lineTo(width, height - ridge / 2)
.quadTo(
(3 * width) / 4,
height - 1.4 * ridge,
width / 2,
height - ridge / 2,
)
.quadTo(
width / 4,
height - ridge * (1 - 1.4),
0,
height - ridge / 2,
)
if (ridge / 2 > round) {
path.lineTo(0, ridge / 2)
}
if (ridge / 2 > round) {
path.lineTo(0, ridge / 2)
}
path.lineTo(0, round).arcTo(round, round, 0, 0, 1, round, 0).close()
path.lineTo(0, round).arcTo(round, round, 0, 0, 1, round, 0).close()
return {
d: path.serialize(),
return {
d: path.serialize(),
}
}
},
},

View File

@ -47,29 +47,35 @@ Shape.Path.define({
},
attrHooks: {
round: {
set(v: number, { refBBox }) {
const { width, height } = refBBox
const r = Math.min(width / 2, height / 2, v)
return {
rx: r,
ry: r,
set(v, { refBBox }) {
if (typeof v === 'number') {
const { width, height } = refBBox
const r = Math.min(width / 2, height / 2, v)
return {
rx: r,
ry: r,
}
}
},
},
hPos: {
set(v: number, { cell, refBBox }) {
const { width, height } = refBBox
const round = cell.attr<number>('bg/round')
const offset = NumberExt.clamp(v, round, height - round)
return { d: `M 0 ${offset} L ${width} ${offset}` }
set(v, { cell, refBBox }) {
if (typeof v === 'number') {
const { width, height } = refBBox
const round = cell.attr<number>('bg/round')
const offset = NumberExt.clamp(v, round, height - round)
return { d: `M 0 ${offset} L ${width} ${offset}` }
}
},
},
vPos: {
set(v: number, { cell, refBBox }) {
const { width, height } = refBBox
const round = cell.attr<number>('bg/round')
const offset = NumberExt.clamp(v, round, width - round)
return { d: `M ${offset} 0 L ${offset} ${height}` }
set(v, { cell, refBBox }) {
if (typeof v === 'number') {
const { width, height } = refBBox
const round = cell.attr<number>('bg/round')
const offset = NumberExt.clamp(v, round, width - round)
return { d: `M ${offset} 0 L ${offset} ${height}` }
}
},
},
},

View File

@ -1,4 +1,9 @@
import { NumberExt, Shape, Path, Line } from '@antv/x6'
import { NumberExt, Shape, Path, Line, JSONObject } from '@antv/x6'
interface KnobsAttrValue extends JSONObject {
round: boolean | string | number
ridge: boolean | string | number
}
Shape.Path.define({
shape: 'flowchart_manual_input',
@ -18,14 +23,9 @@ Shape.Path.define({
},
attrHooks: {
knobs: {
set(
v: {
round: boolean | string | number
ridge: boolean | string | number
},
{ refBBox },
) {
if (typeof v === 'object') {
set(val, { refBBox }) {
if (typeof val === 'object') {
const v = val as KnobsAttrValue
const { width, height } = refBBox
const dim = Math.min(width, height)
let round: number

View File

@ -1,4 +1,9 @@
import { NumberExt, Shape, Path, Line, Point } from '@antv/x6'
import { NumberExt, Shape, Path, Line, Point, JSONObject } from '@antv/x6'
interface KnobsAttrValue extends JSONObject {
round: boolean | string | number
ridge: boolean | string | number
}
Shape.Path.define({
title: 'Manual Operation',
@ -19,14 +24,9 @@ Shape.Path.define({
},
attrHooks: {
knobs: {
set(
v: {
round: boolean | string | number
ridge: boolean | string | number
},
{ refBBox },
) {
if (typeof v === 'object') {
set(val, { refBBox }) {
if (typeof val === 'object') {
const v = val as KnobsAttrValue
const { width, height } = refBBox
const dim = Math.min(width, height)
let round: number

View File

@ -16,26 +16,28 @@ Shape.Path.define({
},
attrHooks: {
round: {
set(v: number, { refBBox }) {
const { width, height } = refBBox
const dim = Math.min(width, height)
let round = NumberExt.normalizePercentage(v, dim)
if (round > dim / 2) {
round = dim / 2
}
set(v, { refBBox }) {
if (typeof v === 'number') {
const { width, height } = refBBox
const dim = Math.min(width, height)
let round = NumberExt.normalizePercentage(v, dim)
if (round > dim / 2) {
round = dim / 2
}
const points: Point.PointData[] = [
[0, 0],
[width, 0],
[width / 2, height],
]
const points: Point.PointData[] = [
[0, 0],
[width, 0],
[width / 2, height],
]
return {
d: Path.drawPoints(points, {
round,
close: true,
initialMove: true,
}),
return {
d: Path.drawPoints(points, {
round,
close: true,
initialMove: true,
}),
}
}
},
},

View File

@ -52,48 +52,55 @@ Shape.Path.define({
},
attrHooks: {
ridge: {
set(v: number, { refBBox, attrs }) {
const width = refBBox.width * 0.9
const height = refBBox.height * 0.9
set(v, { refBBox, attrs }) {
if (typeof v === 'number') {
const width = refBBox.width * 0.9
const height = refBBox.height * 0.9
let offsetX = 0
let offsetY = 0
let offsetX = 0
let offsetY = 0
const z = attrs.z as number
if (z === 0) {
offsetX = 0
offsetY = refBBox.height * 0.1
} else if (z === 1) {
offsetX = refBBox.width * 0.05
offsetY = refBBox.height * 0.05
} else if (z === 2) {
offsetX = refBBox.width * 0.1
offsetY = 0
}
const z = attrs.z as number
if (z === 0) {
offsetX = 0
offsetY = refBBox.height * 0.1
} else if (z === 1) {
offsetX = refBBox.width * 0.05
offsetY = refBBox.height * 0.05
} else if (z === 2) {
offsetX = refBBox.width * 0.1
offsetY = 0
}
const round = 5
const ridge = v * height
const round = 5
const ridge = v * height
const path = new Path()
.moveTo(width - round, 0)
.arcTo(round, round, 0, 0, 1, width, round)
.lineTo(width, height - ridge / 2)
.quadTo(
(3 * width) / 4,
height - 1.4 * ridge,
width / 2,
height - ridge / 2,
)
.quadTo(width / 4, height - ridge * (1 - 1.4), 0, height - ridge / 2)
const path = new Path()
.moveTo(width - round, 0)
.arcTo(round, round, 0, 0, 1, width, round)
.lineTo(width, height - ridge / 2)
.quadTo(
(3 * width) / 4,
height - 1.4 * ridge,
width / 2,
height - ridge / 2,
)
.quadTo(
width / 4,
height - ridge * (1 - 1.4),
0,
height - ridge / 2,
)
if (ridge / 2 > round) {
path.lineTo(0, ridge / 2)
}
if (ridge / 2 > round) {
path.lineTo(0, ridge / 2)
}
path.lineTo(0, round).arcTo(round, round, 0, 0, 1, round, 0).close()
path.lineTo(0, round).arcTo(round, round, 0, 0, 1, round, 0).close()
return {
d: path.translate(offsetX, offsetY).serialize(),
return {
d: path.translate(offsetX, offsetY).serialize(),
}
}
},
},

View File

@ -16,34 +16,36 @@ Shape.Path.define({
},
attrHooks: {
ridge: {
set(v: number, { refBBox }) {
const { width, height } = refBBox
let ridge = v < 1 ? NumberExt.normalizePercentage(v, height) : height
if (ridge > height) {
ridge = height
}
set(v, { refBBox }) {
if (typeof v === 'number') {
const { width, height } = refBBox
let ridge = v < 1 ? NumberExt.normalizePercentage(v, height) : height
if (ridge > height) {
ridge = height
}
const points: Point.PointData[] = []
if (ridge === 0) {
points.push([0, 0], [width, 0], [width / 2, height])
} else if (ridge === height) {
points.push([0, 0], [width, 0], [width, height], [0, height])
} else {
points.push(
[0, 0],
[width, 0],
[width, ridge],
[width / 2, height],
[0, ridge],
)
}
const points: Point.PointData[] = []
if (ridge === 0) {
points.push([0, 0], [width, 0], [width / 2, height])
} else if (ridge === height) {
points.push([0, 0], [width, 0], [width, height], [0, height])
} else {
points.push(
[0, 0],
[width, 0],
[width, ridge],
[width / 2, height],
[0, ridge],
)
}
return {
d: Path.drawPoints(points, {
round: 0,
close: true,
initialMove: true,
}),
return {
d: Path.drawPoints(points, {
round: 0,
close: true,
initialMove: true,
}),
}
}
},
},

View File

@ -48,13 +48,13 @@ Shape.Path.define({
},
attrHooks: {
hPath: {
set(v: number, { refBBox }) {
set(v, { refBBox }) {
const { width, height } = refBBox
return { d: `M 0 ${height / 2} L ${width} ${height / 2}` }
},
},
vPath: {
set(v: number, { refBBox }) {
set(v, { refBBox }) {
const { width, height } = refBBox
return { d: `M ${width / 2} 0 L ${width / 2} ${height}` }
},

View File

@ -16,25 +16,27 @@ Shape.Path.define({
},
attrHooks: {
ridge: {
set(v: number, { refBBox }) {
const { width, height } = refBBox
let ridge = NumberExt.normalizePercentage(v, height)
if (ridge > height / 2) {
ridge = height / 2
}
set(v, { refBBox }) {
if (typeof v === 'number') {
const { width, height } = refBBox
let ridge = NumberExt.normalizePercentage(v, height)
if (ridge > height / 2) {
ridge = height / 2
}
const r = width * 0.7
const r = width * 0.7
return {
d: new Path()
.moveTo(0, ridge)
.arcTo(r, r, 0, 0, 0, width / 2, ridge)
.arcTo(r, r, 0, 0, 1, width, ridge)
.lineTo(width, height - ridge)
.arcTo(r, r, 0, 0, 0, width / 2, height - ridge)
.arcTo(r, r, 0, 0, 1, 0, height - ridge)
.lineTo(0, ridge)
.serialize(),
return {
d: new Path()
.moveTo(0, ridge)
.arcTo(r, r, 0, 0, 0, width / 2, ridge)
.arcTo(r, r, 0, 0, 1, width, ridge)
.lineTo(width, height - ridge)
.arcTo(r, r, 0, 0, 0, width / 2, height - ridge)
.arcTo(r, r, 0, 0, 1, 0, height - ridge)
.lineTo(0, ridge)
.serialize(),
}
}
},
},

View File

@ -20,43 +20,47 @@ Shape.Path.define({
},
attrHooks: {
round: {
set(v: number, { refBBox }) {
const { width, height } = refBBox
const dim = Math.min(width, height)
let round = dim * v
if (round > dim / 2) {
round = dim / 2
}
return {
rx: round,
ry: round,
set(v, { refBBox }) {
if (typeof v === 'number') {
const { width, height } = refBBox
const dim = Math.min(width, height)
let round = dim * v
if (round > dim / 2) {
round = dim / 2
}
return {
rx: round,
ry: round,
}
}
},
},
ridge: {
set(v: number, { refBBox }) {
const { width, height } = refBBox
let ridge = width * v
if (ridge > width / 2) {
ridge = width / 2
}
set(v, { refBBox }) {
if (typeof v === 'number') {
const { width, height } = refBBox
let ridge = width * v
if (ridge > width / 2) {
ridge = width / 2
}
const data = [
'M',
ridge,
0,
'L',
ridge,
height,
'M',
width - ridge,
0,
width - ridge,
height,
]
const data = [
'M',
ridge,
0,
'L',
ridge,
height,
'M',
width - ridge,
0,
width - ridge,
height,
]
return {
d: data.join(' '),
return {
d: data.join(' '),
}
}
},
},

View File

@ -1,4 +1,9 @@
import { NumberExt, Shape, Path, Point } from '@antv/x6'
import { NumberExt, Shape, Path, Point, JSONObject } from '@antv/x6'
interface KnobsAttrValue extends JSONObject {
round: boolean | string | number
ridge: boolean | string | number
}
Shape.Path.define({
title: 'Preparation',
@ -19,14 +24,9 @@ Shape.Path.define({
},
attrHooks: {
knobs: {
set(
v: {
round: boolean | string | number
ridge: boolean | string | number
},
{ refBBox },
) {
if (typeof v === 'object') {
set(val, { refBBox }) {
if (typeof val === 'object') {
const v = val as KnobsAttrValue
const { width, height } = refBBox
const dim = Math.min(width, height)
let round: number

View File

@ -16,11 +16,13 @@ Shape.Path.define({
},
attrHooks: {
round: {
set(v: number, { refBBox }) {
const { width, height } = refBBox
const dim = Math.min(width, height)
const round = v * dim
return { rx: round, ry: round }
set(v, { refBBox }) {
if (typeof v === 'number') {
const { width, height } = refBBox
const dim = Math.min(width, height)
const round = v * dim
return { rx: round, ry: round }
}
},
},
},

View File

@ -23,7 +23,7 @@ Shape.Path.define({
},
attrHooks: {
line: {
set(v: number, { refBBox }) {
set(v, { refBBox }) {
const { width, height } = refBBox
return { d: `M ${width / 2} ${height} L ${width} ${height}` }
},

View File

@ -16,7 +16,7 @@ Shape.Path.define({
},
attrHooks: {
line: {
set(v: number, { refBBox }) {
set(v, { refBBox }) {
const { width, height } = refBBox
const outline = Path.drawPoints(
[

View File

@ -16,7 +16,7 @@ Shape.Path.define({
},
attrHooks: {
draw: {
set(v: number, { refBBox }) {
set(v, { refBBox }) {
const { width, height } = refBBox
const sx = width / 96.51
const sy = height / 60

View File

@ -16,7 +16,7 @@ Shape.Path.define({
},
attrHooks: {
draw: {
set(v: number, { refBBox }) {
set(v, { refBBox }) {
const { width, height } = refBBox
const sx = width / 98
const sy = height / 60

View File

@ -1,4 +1,10 @@
import { NumberExt, Shape, Path } from '@antv/x6'
import { NumberExt, Shape, Path, JSONObject } from '@antv/x6'
interface KnobsAttrValue extends JSONObject {
tail: number
ridgeX: number
ridgeY: number
}
Shape.Path.define({
title: 'Transfer',
@ -20,15 +26,9 @@ Shape.Path.define({
},
attrHooks: {
knobs: {
set(
v: {
tail: number
ridgeX: number
ridgeY: number
},
{ refBBox },
) {
if (typeof v === 'object') {
set(val, { refBBox }) {
if (typeof val === 'object') {
const v = val as KnobsAttrValue
const { width, height } = refBBox
const tail = NumberExt.clamp(width * v.tail, 0, v.ridgeX * width)
const ridgeX = NumberExt.clamp(