Feat:修改更新节点当前应用样式的逻辑

This commit is contained in:
wanglin2 2024-08-29 22:01:05 +08:00
parent 06fb6245b7
commit ce49fcb511

View File

@ -64,8 +64,10 @@ class Style {
let themeConfig = this.ctx.mindMap.themeConfig let themeConfig = this.ctx.mindMap.themeConfig
// 三级及以下节点 // 三级及以下节点
let defaultConfig = themeConfig.node let defaultConfig = themeConfig.node
let useRoot = false
if (root || rootProp.includes(prop)) { if (root || rootProp.includes(prop)) {
// 直接使用最外层样式 // 直接使用最外层样式
useRoot = true
defaultConfig = themeConfig defaultConfig = themeConfig
} else if (this.ctx.isGeneralization) { } else if (this.ctx.isGeneralization) {
// 概要节点 // 概要节点
@ -78,21 +80,21 @@ class Style {
defaultConfig = themeConfig.second defaultConfig = themeConfig.second
} }
// 优先使用节点本身的样式 // 优先使用节点本身的样式
return this.getSelfStyle(prop) !== undefined const value =
? this.getSelfStyle(prop) this.getSelfStyle(prop) !== undefined
: defaultConfig[prop] ? this.getSelfStyle(prop)
: defaultConfig[prop]
if (!useRoot) {
this.addToEffectiveStyles({
[prop]: value
})
}
return value
} }
// 获取某个样式值 // 获取某个样式值
getStyle(prop, root) { getStyle(prop, root) {
const value = this.merge(prop, root) return this.merge(prop, root)
if (!root) {
const styles = {
[prop]: value
}
this.addToEffectiveStyles(styles)
}
return value
} }
// 获取自身自定义样式 // 获取自身自定义样式
@ -111,11 +113,7 @@ class Style {
// 矩形 // 矩形
rect(node) { rect(node) {
this.shape(node) this.shape(node)
const styles = { node.radius(this.merge('borderRadius'))
borderRadius: this.merge('borderRadius')
}
this.addToEffectiveStyles(styles)
node.radius(styles.borderRadius)
} }
// 形状 // 形状
@ -160,7 +158,6 @@ class Style {
width: styles.borderWidth, width: styles.borderWidth,
dasharray: styles.borderDasharray dasharray: styles.borderDasharray
}) })
this.addToEffectiveStyles(styles)
} }
// 文字 // 文字
@ -184,7 +181,6 @@ class Style {
'font-style': styles.fontStyle, 'font-style': styles.fontStyle,
'text-decoration': styles.textDecoration 'text-decoration': styles.textDecoration
}) })
this.addToEffectiveStyles(styles)
} }
// 生成内联样式 // 生成内联样式
@ -197,7 +193,6 @@ class Style {
fontStyle: this.merge('fontStyle'), fontStyle: this.merge('fontStyle'),
textDecoration: this.merge('textDecoration') textDecoration: this.merge('textDecoration')
} }
this.addToEffectiveStyles(styles)
return ` return `
color: ${styles.color}; color: ${styles.color};
font-family: ${styles.fontFamily}; font-family: ${styles.fontFamily};
@ -218,7 +213,6 @@ class Style {
fontStyle: this.merge('fontStyle'), fontStyle: this.merge('fontStyle'),
textDecoration: this.merge('textDecoration') textDecoration: this.merge('textDecoration')
} }
this.addToEffectiveStyles(styles)
return { return {
italic: styles.fontStyle === 'italic', italic: styles.fontStyle === 'italic',
bold: styles.fontWeight, bold: styles.fontWeight,
@ -238,7 +232,6 @@ class Style {
textDecoration: this.merge('textDecoration'), textDecoration: this.merge('textDecoration'),
lineHeight: this.merge('lineHeight') lineHeight: this.merge('lineHeight')
} }
this.addToEffectiveStyles(styles)
node.style.fontFamily = styles.fontFamily node.style.fontFamily = styles.fontFamily
node.style.fontSize = styles.fontSize * fontSizeScale + 'px' node.style.fontSize = styles.fontSize * fontSizeScale + 'px'
node.style.fontWeight = styles.fontWeight || 'normal' node.style.fontWeight = styles.fontWeight || 'normal'
@ -269,12 +262,8 @@ class Style {
// 内置图标 // 内置图标
iconNode(node) { iconNode(node) {
const styles = {
color: this.merge('color')
}
this.addToEffectiveStyles(styles)
node.attr({ node.attr({
fill: styles.color fill: this.merge('color')
}) })
} }