Feat:优化节点渐变背景逻辑
This commit is contained in:
parent
78d677a00c
commit
163ae6caae
@ -1,6 +1,6 @@
|
|||||||
import Style from './Style'
|
import Style from './Style'
|
||||||
import Shape from './Shape'
|
import Shape from './Shape'
|
||||||
import { G, ForeignObject, Rect, Defs } from '@svgdotjs/svg.js'
|
import { G, ForeignObject, Rect } from '@svgdotjs/svg.js'
|
||||||
import nodeGeneralizationMethods from './nodeGeneralization'
|
import nodeGeneralizationMethods from './nodeGeneralization'
|
||||||
import nodeExpandBtnMethods from './nodeExpandBtn'
|
import nodeExpandBtnMethods from './nodeExpandBtn'
|
||||||
import nodeCommandWrapsMethods from './nodeCommandWraps'
|
import nodeCommandWrapsMethods from './nodeCommandWraps'
|
||||||
@ -63,8 +63,6 @@ class Node {
|
|||||||
this.userList = []
|
this.userList = []
|
||||||
// 节点内容的容器
|
// 节点内容的容器
|
||||||
this.group = null
|
this.group = null
|
||||||
this.defsNode = null // 节点静态元素
|
|
||||||
this.gradientNode = null // 节点渐变背景
|
|
||||||
this.shapeNode = null // 节点形状节点
|
this.shapeNode = null // 节点形状节点
|
||||||
this.hoverNode = null // 节点hover和激活的节点
|
this.hoverNode = null // 节点hover和激活的节点
|
||||||
// 节点内容对象
|
// 节点内容对象
|
||||||
@ -301,17 +299,11 @@ class Node {
|
|||||||
let { paddingY } = this.getPaddingVale()
|
let { paddingY } = this.getPaddingVale()
|
||||||
const halfBorderWidth = this.getBorderWidth() / 2
|
const halfBorderWidth = this.getBorderWidth() / 2
|
||||||
paddingY += this.shapePadding.paddingY + halfBorderWidth
|
paddingY += this.shapePadding.paddingY + halfBorderWidth
|
||||||
// 节点静态元素
|
|
||||||
this.defsNode = new Defs()
|
|
||||||
// 节点渐变背景
|
|
||||||
this.gradientNode = this.style.createGradient()
|
|
||||||
this.defsNode.add(this.gradientNode)
|
|
||||||
this.group.add(this.defsNode)
|
|
||||||
// 节点形状
|
// 节点形状
|
||||||
this.shapeNode = this.shapeInstance.createShape()
|
this.shapeNode = this.shapeInstance.createShape()
|
||||||
this.shapeNode.addClass('smm-node-shape')
|
this.shapeNode.addClass('smm-node-shape')
|
||||||
this.shapeNode.translate(halfBorderWidth, halfBorderWidth)
|
this.shapeNode.translate(halfBorderWidth, halfBorderWidth)
|
||||||
this.style.shape(this.shapeNode, this.gradientNode.id())
|
this.style.shape(this.shapeNode)
|
||||||
this.group.add(this.shapeNode)
|
this.group.add(this.shapeNode)
|
||||||
// 渲染一个隐藏的矩形区域,用来触发展开收起按钮的显示
|
// 渲染一个隐藏的矩形区域,用来触发展开收起按钮的显示
|
||||||
this.renderExpandBtnPlaceholderRect()
|
this.renderExpandBtnPlaceholderRect()
|
||||||
@ -369,7 +361,9 @@ class Node {
|
|||||||
if (this._textData) {
|
if (this._textData) {
|
||||||
this._textData.node.attr('data-offsetx', textContentOffsetX)
|
this._textData.node.attr('data-offsetx', textContentOffsetX)
|
||||||
// 修复safari浏览器节点存在图标时文字位置不正确的问题
|
// 修复safari浏览器节点存在图标时文字位置不正确的问题
|
||||||
;(this._textData.nodeContent || this._textData.node).x(textContentOffsetX).y(0)
|
;(this._textData.nodeContent || this._textData.node)
|
||||||
|
.x(textContentOffsetX)
|
||||||
|
.y(0)
|
||||||
textContentNested.add(this._textData.node)
|
textContentNested.add(this._textData.node)
|
||||||
textContentOffsetX += this._textData.width + textContentItemMargin
|
textContentOffsetX += this._textData.width + textContentItemMargin
|
||||||
}
|
}
|
||||||
@ -719,6 +713,7 @@ class Node {
|
|||||||
if (this.parent) {
|
if (this.parent) {
|
||||||
this.parent.removeLine()
|
this.parent.removeLine()
|
||||||
}
|
}
|
||||||
|
this.style.onRemove()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 隐藏节点
|
// 隐藏节点
|
||||||
|
|||||||
@ -59,6 +59,8 @@ class Style {
|
|||||||
// 箭头图标
|
// 箭头图标
|
||||||
this._markerPath = null
|
this._markerPath = null
|
||||||
this._marker = null
|
this._marker = null
|
||||||
|
// 渐变背景
|
||||||
|
this._gradient = null
|
||||||
}
|
}
|
||||||
|
|
||||||
// 合并样式
|
// 合并样式
|
||||||
@ -90,14 +92,6 @@ class Style {
|
|||||||
return this.merge(prop, root)
|
return this.merge(prop, root)
|
||||||
}
|
}
|
||||||
|
|
||||||
createGradient() {
|
|
||||||
let gradient = new Gradient("linear")
|
|
||||||
gradient.id()
|
|
||||||
gradient.stop(0,this.merge('startColor'))
|
|
||||||
gradient.stop(1, this.merge('endColor'))
|
|
||||||
return gradient
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取自身自定义样式
|
// 获取自身自定义样式
|
||||||
getSelfStyle(prop) {
|
getSelfStyle(prop) {
|
||||||
return this.ctx.getData(prop)
|
return this.ctx.getData(prop)
|
||||||
@ -109,19 +103,22 @@ class Style {
|
|||||||
node.radius(this.merge('borderRadius'))
|
node.radius(this.merge('borderRadius'))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 矩形外的其他形状
|
// 形状
|
||||||
shape(node, uid) {
|
shape(node) {
|
||||||
if (this.merge('gradientStyle')) {
|
if (this.merge('gradientStyle')) {
|
||||||
node.fill('url(#' + uid + ')'
|
if (!this._gradient) {
|
||||||
)
|
this._gradient = this.ctx.nodeDraw.gradient('linear')
|
||||||
|
}
|
||||||
|
this._gradient.update(add => {
|
||||||
|
add.stop(0, this.merge('startColor'))
|
||||||
|
add.stop(1, this.merge('endColor'))
|
||||||
|
})
|
||||||
|
node.fill(this._gradient)
|
||||||
} else {
|
} else {
|
||||||
node.fill({
|
node.fill({
|
||||||
color: this.merge('fillColor')
|
color: this.merge('fillColor')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// node.fill({
|
|
||||||
// color: this.merge('fillColor')
|
|
||||||
// })
|
|
||||||
// 节点使用横线样式,不需要渲染非激活状态的边框样式
|
// 节点使用横线样式,不需要渲染非激活状态的边框样式
|
||||||
// if (
|
// if (
|
||||||
// !this.ctx.isRoot &&
|
// !this.ctx.isRoot &&
|
||||||
@ -290,6 +287,22 @@ class Style {
|
|||||||
color: hoverRectColor
|
color: hoverRectColor
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 所属节点被删除时的操作
|
||||||
|
onRemove() {
|
||||||
|
if (this._marker) {
|
||||||
|
this._marker.remove()
|
||||||
|
this._marker = null
|
||||||
|
}
|
||||||
|
if (this._markerPath) {
|
||||||
|
this._markerPath.remove()
|
||||||
|
this._markerPath = null
|
||||||
|
}
|
||||||
|
if (this._gradient) {
|
||||||
|
this._gradient.remove()
|
||||||
|
this._gradient = null
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Style.cacheStyle = null
|
Style.cacheStyle = null
|
||||||
|
|||||||
@ -131,6 +131,7 @@ function updateGeneralizationData() {
|
|||||||
function removeGeneralization() {
|
function removeGeneralization() {
|
||||||
if (this.isGeneralization) return
|
if (this.isGeneralization) return
|
||||||
this._generalizationList.forEach(item => {
|
this._generalizationList.forEach(item => {
|
||||||
|
item.generalizationNode.style.onRemove()
|
||||||
if (item.generalizationLine) {
|
if (item.generalizationLine) {
|
||||||
item.generalizationLine.remove()
|
item.generalizationLine.remove()
|
||||||
item.generalizationLine = null
|
item.generalizationLine = null
|
||||||
|
|||||||
@ -75,7 +75,7 @@ export default {
|
|||||||
textDecoration: 'none',
|
textDecoration: 'none',
|
||||||
gradientStyle: false,
|
gradientStyle: false,
|
||||||
startColor: '#549688',
|
startColor: '#549688',
|
||||||
endColor: '#fff',
|
endColor: '#fff'
|
||||||
},
|
},
|
||||||
// 二级节点样式
|
// 二级节点样式
|
||||||
second: {
|
second: {
|
||||||
@ -96,7 +96,7 @@ export default {
|
|||||||
textDecoration: 'none',
|
textDecoration: 'none',
|
||||||
gradientStyle: false,
|
gradientStyle: false,
|
||||||
startColor: '#549688',
|
startColor: '#549688',
|
||||||
endColor: '#fff',
|
endColor: '#fff'
|
||||||
},
|
},
|
||||||
// 三级及以下节点样式
|
// 三级及以下节点样式
|
||||||
node: {
|
node: {
|
||||||
@ -117,7 +117,7 @@ export default {
|
|||||||
textDecoration: 'none',
|
textDecoration: 'none',
|
||||||
gradientStyle: false,
|
gradientStyle: false,
|
||||||
startColor: '#549688',
|
startColor: '#549688',
|
||||||
endColor: '#fff',
|
endColor: '#fff'
|
||||||
},
|
},
|
||||||
// 概要节点样式
|
// 概要节点样式
|
||||||
generalization: {
|
generalization: {
|
||||||
@ -138,7 +138,7 @@ export default {
|
|||||||
textDecoration: 'none',
|
textDecoration: 'none',
|
||||||
gradientStyle: false,
|
gradientStyle: false,
|
||||||
startColor: '#549688',
|
startColor: '#549688',
|
||||||
endColor: '#fff',
|
endColor: '#fff'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +174,10 @@ const nodeSizeIndependenceList = [
|
|||||||
'backgroundPosition',
|
'backgroundPosition',
|
||||||
'backgroundSize',
|
'backgroundSize',
|
||||||
'rootLineKeepSameInCurve',
|
'rootLineKeepSameInCurve',
|
||||||
'showLineMarker'
|
'showLineMarker',
|
||||||
|
'gradientStyle',
|
||||||
|
'startColor',
|
||||||
|
'endColor'
|
||||||
]
|
]
|
||||||
export const checkIsNodeSizeIndependenceConfig = config => {
|
export const checkIsNodeSizeIndependenceConfig = config => {
|
||||||
let keys = Object.keys(config)
|
let keys = Object.keys(config)
|
||||||
|
|||||||
@ -202,7 +202,10 @@ export default {
|
|||||||
line: 'Line',
|
line: 'Line',
|
||||||
nodePadding: 'Node padding',
|
nodePadding: 'Node padding',
|
||||||
horizontal: 'Horizontal',
|
horizontal: 'Horizontal',
|
||||||
vertical: 'Vertical'
|
vertical: 'Vertical',
|
||||||
|
gradientStyle: 'Gradient',
|
||||||
|
startColor: 'Start',
|
||||||
|
endColor: 'End'
|
||||||
},
|
},
|
||||||
theme: {
|
theme: {
|
||||||
title: 'Theme',
|
title: 'Theme',
|
||||||
|
|||||||
@ -252,15 +252,10 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="rowItem">
|
<div class="rowItem">
|
||||||
<span class="name">{{ $t('style.gradientStyle') }}</span>
|
<span class="name">{{ $t('style.gradientStyle') }}</span>
|
||||||
<div
|
<el-checkbox
|
||||||
class="styleBtn"
|
v-model="style.gradientStyle"
|
||||||
:class="{
|
@change="update('gradientStyle')"
|
||||||
actived: style.gradientStyle === true
|
></el-checkbox>
|
||||||
}"
|
|
||||||
@click="toggleGradientStyle"
|
|
||||||
>
|
|
||||||
{{style.gradientStyle ? '渐变' : '单一'}}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="rowItem">
|
<div class="rowItem">
|
||||||
<span class="name">{{ $t('style.startColor') }}</span>
|
<span class="name">{{ $t('style.startColor') }}</span>
|
||||||
@ -284,10 +279,7 @@
|
|||||||
:style="{ backgroundColor: style.endColor }"
|
:style="{ backgroundColor: style.endColor }"
|
||||||
></span>
|
></span>
|
||||||
<el-popover ref="popover7" placement="bottom" trigger="hover">
|
<el-popover ref="popover7" placement="bottom" trigger="hover">
|
||||||
<Color
|
<Color :color="style.endColor" @change="changeEndColor"></Color>
|
||||||
:color="style.endColor"
|
|
||||||
@change="changeEndColor"
|
|
||||||
></Color>
|
|
||||||
</el-popover>
|
</el-popover>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -651,27 +643,13 @@ export default {
|
|||||||
this.update('fillColor')
|
this.update('fillColor')
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: lxr_cel
|
|
||||||
* @Date: 2024-01-02 10:28:17
|
|
||||||
* @Desc: 切换渐变背景
|
|
||||||
*/
|
|
||||||
toggleGradientStyle() {
|
|
||||||
if (this.style.gradientStyle === false) {
|
|
||||||
this.style.gradientStyle = true
|
|
||||||
} else {
|
|
||||||
this.style.gradientStyle = false
|
|
||||||
}
|
|
||||||
this.update('gradientStyle')
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: lxr_cel
|
* @Author: lxr_cel
|
||||||
* @Date: 2024-01-02 11:09:27
|
* @Date: 2024-01-02 11:09:27
|
||||||
* @Desc: 切换渐变开始颜色
|
* @Desc: 切换渐变开始颜色
|
||||||
*/
|
*/
|
||||||
changeStartColor(color) {
|
changeStartColor(color) {
|
||||||
this.style.startColor = color;
|
this.style.startColor = color
|
||||||
this.update('startColor')
|
this.update('startColor')
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -681,7 +659,7 @@ export default {
|
|||||||
* @Desc: 切换渐变结束颜色
|
* @Desc: 切换渐变结束颜色
|
||||||
*/
|
*/
|
||||||
changeEndColor(color) {
|
changeEndColor(color) {
|
||||||
this.style.endColor = color;
|
this.style.endColor = color
|
||||||
this.update('endColor')
|
this.update('endColor')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user