Global

Methods

getContainerSize(el) → {Object}

Description:
  • 取得echarts容器可用尺寸,量測方式與echarts(zrender)相同,即clientWidth/clientHeight扣除padding(parseInt),見zrender/lib/canvas/helper.js之getSize, 供v-domresize之getSize與圖表getWidth()、getHeight()比較,容器寬高為小數時(例如百分比寬度)亦不誤判

Source:
Example
//容器clientWidth為1000、padding左右各20.7px
console.log(getContainerSize(el))
// => { width: 960, height: 300 }
Parameters:
Name Type Description
el HTMLElement

輸入容器元素

Returns:

回傳物件{width,height},單位px,不小於0

Type
Object

iniEcharts() → {Object}

Description:
  • 初始化echarts, 直接引用echarts與echarts-gl不使用cdn

    echarts採全量引入(import 'echarts'), 已自動註冊全部內建圖表(line, bar, pie, scatter, radar, heatmap, tree, treemap, sunburst, parallel, custom等) 與全部內建組件(title, legend, tooltip, toolbox, dataZoom, visualMap, grid, polar, geo等), 故使用時不須另外呼叫echarts.use註冊

    echarts-gl為3D擴充模組, 匯入時即自行向echarts註冊bar3D, line3D, scatter3D, surface, lines3D等圖表, 以及grid3D, geo3D, globe等座標系, 其package.json已正確宣告sideEffects白名單(index.js與lib/export/all.js等), 故純副作用引入不會被tree-shaking移除

    注意: echarts-gl之esm原始碼含無副檔名之深層引用(如'zrender/lib/core/LRU', 'echarts/lib/util/layout'), 而echarts與zrender之package.json exports末端為萬用對應"./": "./", 依Node規範解析結果不補副檔名, 故打包工具須具備[深層子路徑補.js重試]之解析能力(webpack內建此行為; rollup需由w-package-tools之rollupFile提供)

Source:
Example
import iniEcharts from 'w-echarts-vue/src/js/iniEcharts.mjs'

let echarts = iniEcharts()
echarts.registerTheme('myTheme', { ... })
Returns:

回傳echarts命名空間物件

Type
Object

isPropUnchanged(nv, ov) → {Boolean}

Description:
  • 判斷prop新舊值是否視為未變更,供watcher略過無實質變化之觸發

    父組件於模板以物件字面值傳入prop時(例如:theme="{ color: [...] }"),每次重繪皆產生新物件(參照不同),故內容相同時視為未變更; 新舊值為同一物件時,代表由deep watcher偵測到物件內部異動,視為已變更

Source:
Example
console.log(isPropUnchanged({ renderer: 'svg' }, { renderer: 'svg' }))
// => true

let o = { renderer: 'svg' }
console.log(isPropUnchanged(o, o))
// => false

console.log(isPropUnchanged('dark', ''))
// => false
Parameters:
Name Type Description
nv *

輸入新值

ov *

輸入舊值

Returns:

回傳是否視為未變更布林值

Type
Boolean

parseAutoresize(autoresize) → {Object}

Description:
  • 解析組件之autoresize設定

Source:
Example
console.log(parseAutoresize(true))
// => { enabled: true, throttle: 100, onResize: null }

console.log(parseAutoresize({ throttle: 50 }))
// => { enabled: true, throttle: 50, onResize: null }

console.log(parseAutoresize(false))
// => { enabled: false, throttle: 100, onResize: null }
Parameters:
Name Type Description
autoresize Boolean | Object

輸入autoresize設定,為布林值或物件{throttle,onResize}

Returns:

回傳物件{enabled,throttle,onResize},enabled為是否啟用布林值,throttle為節流毫秒數(取整,未給或非有限數字時為100,0或負數為0即不節流),onResize為函數或null

Type
Object