@@ -2,10 +2,10 @@ import { $prefix } from '../common/util'
22import { isObject } from '../common/type'
33import setExtend from '../common/extend'
44import { DEFAULT_COLORS , SAAS_DEFAULT_COLORS , SAAS_DEFAULT_SAME_COLORS , DEFAULT_THEME } from '../common/constants'
5- import IntegrateChart from '../base '
6- import BaiduMapChart from '../base /components/BaiduMapChart'
7- import AutonaviMapChart from '../base /components/AutonaviMapChart'
8- import cloneDeep from '../base /util/cloneDeep'
5+ import IntegrateChart from '@opentiny/huicharts '
6+ import BaiduMapChart from '@opentiny/huicharts /components/BaiduMapChart'
7+ import AutonaviMapChart from '@opentiny/huicharts /components/AutonaviMapChart'
8+ import cloneDeep from '@opentiny/huicharts /util/cloneDeep'
99import '@opentiny/vue-theme/chart-core/index.less'
1010
1111export default {
@@ -248,6 +248,12 @@ export default {
248248 this . integrateChart && this . integrateChart . echartsIns && this . integrateChart . echartsIns . resize ( )
249249 } )
250250 }
251+ } ,
252+ colors : {
253+ handler ( val ) {
254+ this . refreshChart ( )
255+ } ,
256+ deep : true
251257 }
252258 } ,
253259 methods : {
@@ -336,7 +342,15 @@ export default {
336342 } )
337343 }
338344 } ,
345+
346+ // 更新图表
339347 refreshChart ( ) {
348+ if ( ! this . option . theme ) {
349+ this . option . theme = 'cloud-light'
350+ }
351+ if ( Array . isArray ( this . colors ) && this . colors . length > 0 ) {
352+ option . color = cloneDeep ( this . colors )
353+ }
340354 const { data } = this
341355 if ( Object . keys ( this . options ) . length === 0 ) {
342356 this . updateChart ( data )
@@ -370,8 +384,21 @@ export default {
370384 } , this . changeDelay )
371385 this . eChartOption = this . integrateChart . eChartOption
372386 } ,
387+
388+ // 初始渲染图表
373389 renderChart ( option ) {
390+ // 设置默认theme为'cloud-light'
391+ if ( ! option . theme ) {
392+ option . theme = 'cloud-light'
393+ }
394+
395+ // 将外部colors放入配置项中
396+ if ( Array . isArray ( this . colors ) && this . colors . length > 0 ) {
397+ option . color = cloneDeep ( this . colors )
398+ }
374399 const plugins = this . plugins || { }
400+
401+ // 判断是否为huicharts自定义图表
375402 if ( this . isSelfChart ) {
376403 this . integrateChart . init ( this . $refs . chartRef )
377404 if ( this . colorMode !== 'default' ) {
@@ -382,25 +409,37 @@ export default {
382409 } else {
383410 this . selfSetting ( option )
384411 this . setAnimation ( option )
385- const themeName = this . themeName || this . theme || DEFAULT_THEME
386- this . integrateChart . init ( this . $refs . chartRef , themeName , this . initOpts )
412+
413+ // theme为ecahrts主题参数
414+ const theme = this . themeName || this . theme || DEFAULT_THEME
415+ this . integrateChart . init ( this . $refs . chartRef , this . initOpts , theme )
416+
417+ // 通过colorMode参数控制颜色
387418 if ( this . colorMode !== 'default' ) {
388419 option . color = this . computedChartColor ( )
389420 }
390421 this . integrateChart . setSimpleOption ( this . iChartName , option , plugins )
391422 this . $emit ( 'handle-color' , option . color )
392423 this . applyMarks ( this . integrateChart . eChartOption )
393424 }
425+
426+ // 判断extend,将extend放入配置项中
394427 if ( this . extend && Object . keys ( this . extend ) . length !== 0 ) {
395428 option . extend = this . applyExtend ( this . integrateChart . eChartOption )
396429 this . integrateChart . setSimpleOption ( this . iChartName , option , plugins )
397430 }
398431 this . integrateChart . render ( this . renderOption )
432+
433+ // 返回图表实例
399434 this . $emit ( 'ready' , this . integrateChart . echartsIns , option )
435+
436+ // 返回图表实例(仅一次)
400437 if ( ! this . once [ 'ready-once' ] ) {
401438 this . once [ 'ready-once' ] = true
402439 this . $emit ( 'ready-once' , this . integrateChart . echartsIns , option )
403440 }
441+
442+ // 赋值echartOption,方便用户获取
404443 this . eChartOption = this . integrateChart . eChartOption
405444 } ,
406445 addEvents ( val ) {
0 commit comments