Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chart): Fix chart dataZoom bug and colors bug #2513

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internals/cli/src/commands/build/build-entry-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const buildFullRuntime = (mode: RunTimeModeType) => {
.map((component) => {
if (component.includes('Hui')) {
return `${component}${joinStr}${component} as ${component
.replace('Huicharts', 'Charts')
.replace('Huicharts', 'Chart')
.trim()}${joinStr}${component} as Tiny${component.trim()}`
}
return `${component}${joinStr}${component} as Tiny${component.trim()}`
Expand All @@ -161,7 +161,7 @@ const buildFullRuntime = (mode: RunTimeModeType) => {
.map((component) => {
if (component.includes('Hui')) {
return `${component}${joinStr}${component
.replace('Huicharts', 'Charts')
.replace('Huicharts', 'Chart')
.trim()}: ${component}${joinStr}Tiny${component.trim()}: ${component}`
}
return `${component}${joinStr}Tiny${component.trim()}: ${component}`
Expand Down
6 changes: 3 additions & 3 deletions packages/vue/src/huicharts/huicharts-amap/src/AMapModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export default function extendComponentModel() {
},

setCenterAndZoom(center, zoom) {
this.option.center = center
this.option.zoom = zoom
this.huiChartOption.center = center
this.huiChartOption.zoom = zoom
},

centerOrZoomChanged(center, zoom) {
let option = this.option
let option = this.huiChartOption
return !(equal(center, option.center) && zoom === option.zoom)
},

Expand Down
12 changes: 6 additions & 6 deletions packages/vue/src/huicharts/huicharts-amap/src/autonavi-map.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export default {
methods: {
updateChart() {
if (this.options && Object.keys(this.options).length) {
this.option = { ...this.options, ...this.settings }
this.huiChartOption = { ...this.options, ...this.settings }
if (!this.tooltipVisible) {
this.option.tooltip = { show: false }
this.huiChartOption.tooltip = { show: false }
}

if (!this.legendVisible) {
this.option.legend = { show: false }
this.huiChartOption.legend = { show: false }
}

return
Expand All @@ -55,20 +55,20 @@ export default {
'backgroundColor',
'textStyle'
]
this.option = {
this.huiChartOption = {
...this.settings,
tooltip: this.tooltipVisible ? this.tooltip : { show: false },
series: this.series
}

echartsSettings.forEach((prop) => {
if (this[prop]) {
this.option[prop] = this[prop]
this.huiChartOption[prop] = this[prop]
}
})

if (!this.legendVisible) {
this.option.legend = { show: false }
this.huiChartOption.legend = { show: false }
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/huicharts/huicharts-bar/src/chart-bar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default {

const option = histogram(columns, rows, this.settings, extra, false)

this.option = {
this.huiChartOption = {
smooth: true,
...option,
direction: 'horizontal'
Expand Down
12 changes: 6 additions & 6 deletions packages/vue/src/huicharts/huicharts-bmap/src/baidu-map.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export default {
methods: {
updateChart() {
if (this.options && Object.keys(this.options).length) {
this.option = { ...this.options, ...this.settings }
this.huiChartOption = { ...this.options, ...this.settings }
if (!this.tooltipVisible) {
this.option.tooltip = { show: false }
this.huiChartOption.tooltip = { show: false }
}

if (!this.legendVisible) {
this.option.legend = { show: false }
this.huiChartOption.legend = { show: false }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consolidate duplicate legend visibility logic

The legend visibility check and setting is duplicated at the beginning and end of the method. This violates the DRY principle and could lead to maintenance issues.

Consider consolidating the legend visibility logic in one place:

  updateChart() {
    if (this.options && Object.keys(this.options).length) {
      this.huiChartOption = { ...this.options, ...this.settings }
      if (!this.tooltipVisible) {
        this.huiChartOption.tooltip = { show: false }
      }
+     if (!this.legendVisible) {
+       this.huiChartOption.legend = { show: false }
+     }
-     if (!this.legendVisible) {
-       this.huiChartOption.legend = { show: false }
-     }
      return
    }
    // ... rest of the code ...
-   if (!this.legendVisible) {
-     this.huiChartOption.legend = { show: false }
-   }
  }

Also applies to: 68-69

}

return
Expand All @@ -52,20 +52,20 @@ export default {
'backgroundColor',
'textStyle'
]
this.option = {
this.huiChartOption = {
...this.settings,
tooltip: this.tooltipVisible ? this.tooltip : { show: false },
series: this.series
}

echartsSettings.forEach((prop) => {
if (this[prop]) {
this.option[prop] = this[prop]
this.huiChartOption[prop] = this[prop]
}
})

if (!this.legendVisible) {
this.option.legend = { show: false }
this.huiChartOption.legend = { show: false }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default {
data: prepareBoxplotData && Array.isArray(data) ? data : null
}
const option = boxplot(columns, rows, this.settings, extra)
this.option = { ...option }
this.huiChartOption = { ...option }
},
prepareBoxplotData(data) {
return prepareBoxplotData(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default {
legendVisible: this.legendVisible,
t
}
this.option = candle(columns, rows, this.settings, extra)
this.huiChartOption = candle(columns, rows, this.settings, extra)
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions packages/vue/src/huicharts/huicharts-core/common/extend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ function removeNullKeys(obj) {
return obj
}

export default ({ option, extend }) => {
const cloneOption = cloneDeep(option)
export default ({ huiChartOption, extend }) => {
const cloneOption = cloneDeep(huiChartOption)
const mergeOption = removeNullKeys(cloneOption)
if (!extend) {
return
Expand Down Expand Up @@ -53,13 +53,17 @@ export default ({ option, extend }) => {
]
if (~attrList.indexOf(key)) {
// attrList,指定的key才能合并处理
mergeOption[key] = merge(mergeOption[key], value)
if (key === 'dataZoom') {
mergeOption[key] = value
} else {
mergeOption[key] = merge(mergeOption[key], value)
}
}
} else {
// 属性为对象(eg: tooltip)或包含对象的数组(eg: series)
if (isArr(mergeOption[key]) && isObject(mergeOption[key][0])) {
// 属性值是包含对象数组
mergeOption[key].forEach((option, i) => (mergeOption[key][i] = { ...option, ...value }))
mergeOption[key].forEach((huiChartOption, i) => (mergeOption[key][i] = { ...huiChartOption, ...value }))
} else if (isObject(mergeOption[key])) {
// 被替换属性值是对象
let optionBase = mergeOption[key]
Expand Down
Loading
Loading