diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..8248ef3 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,26 @@ +# 2.0.0-alpha (2019-06-25) + +### Perfect + +- **SVG:** Refactoring **borderbox** and **decoration** components with SVG (Volume dropped to 6%). +- **charts:** New charting component that supports **animation**. +- **compatibility:** Better data compatibility. + +### New + +- **digitalFlop** +- **flylineChart** +- **borderBox** +- **decoration** + +### Components + +- **prefix:** Components add **dv** prefix to prevent conflicts. + +```html + + + + + +``` diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1a36e9f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2019-present, JiaMing + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 776097c..f989193 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,20 @@ -# DataV +

DataV

-# Version 1.1.1 +

+ + LICENSE + x + + LICENSE + +

-## Vue 大屏数据展示组件库 +

Vue large screen data display component library

-## Vue Large screen data display component library +### Install with npm -[文档官网](http://datav.jiaminghi.com/) +```shell +$ npm install @jiaminghi/data-view +``` -[Document of official website](http://datav.jiaminghi.com/) - -[项目地址](https://github.com/jiaming743/DataV) - -[Project address](https://github.com/jiaming743/DataV) \ No newline at end of file +Detailed documents and examples can be viewed on the [HomePage](http://datav.jiaminghi.com). diff --git a/components/activeRingChart/index.vue b/components/activeRingChart/index.vue new file mode 100644 index 0000000..ec126d8 --- /dev/null +++ b/components/activeRingChart/index.vue @@ -0,0 +1,302 @@ + + + + + diff --git a/components/arcRingChart/index.vue b/components/arcRingChart/index.vue deleted file mode 100644 index 726616c..0000000 --- a/components/arcRingChart/index.vue +++ /dev/null @@ -1,339 +0,0 @@ - - - - - diff --git a/components/borderBox1/img/border.gif b/components/borderBox1/img/border.gif deleted file mode 100644 index dc03198..0000000 Binary files a/components/borderBox1/img/border.gif and /dev/null differ diff --git a/components/borderBox1/index.vue b/components/borderBox1/index.vue index d66181b..39fee34 100644 --- a/components/borderBox1/index.vue +++ b/components/borderBox1/index.vue @@ -1,54 +1,99 @@ diff --git a/components/borderBox2/index.vue b/components/borderBox2/index.vue index f3c24c4..e2b65a4 100644 --- a/components/borderBox2/index.vue +++ b/components/borderBox2/index.vue @@ -11,19 +11,21 @@ - +
+ +
diff --git a/components/borderBox5/index.vue b/components/borderBox5/index.vue index 2b3d2ad..4474034 100644 --- a/components/borderBox5/index.vue +++ b/components/borderBox5/index.vue @@ -11,30 +11,37 @@ - +
+ +
diff --git a/components/borderBox6/index.vue b/components/borderBox6/index.vue index 3deea5e..753f1c7 100644 --- a/components/borderBox6/index.vue +++ b/components/borderBox6/index.vue @@ -19,19 +19,21 @@ - +
+ +
+ + diff --git a/components/capsuleChart/index.vue b/components/capsuleChart/index.vue deleted file mode 100644 index 96e65be..0000000 --- a/components/capsuleChart/index.vue +++ /dev/null @@ -1,167 +0,0 @@ - - - - - diff --git a/components/charts/index.vue b/components/charts/index.vue new file mode 100644 index 0000000..4c38de0 --- /dev/null +++ b/components/charts/index.vue @@ -0,0 +1,87 @@ + + + + + diff --git a/components/columnChart/index.vue b/components/columnChart/index.vue deleted file mode 100644 index 67ba53e..0000000 --- a/components/columnChart/index.vue +++ /dev/null @@ -1,620 +0,0 @@ - - - - - diff --git a/components/concentricArcChart/index.vue b/components/concentricArcChart/index.vue deleted file mode 100644 index 0c182f5..0000000 --- a/components/concentricArcChart/index.vue +++ /dev/null @@ -1,179 +0,0 @@ - - - - - diff --git a/components/decoration1/img/decoration.gif b/components/decoration1/img/decoration.gif deleted file mode 100644 index 8040434..0000000 Binary files a/components/decoration1/img/decoration.gif and /dev/null differ diff --git a/components/decoration1/index.vue b/components/decoration1/index.vue index a90a31f..424bc3a 100644 --- a/components/decoration1/index.vue +++ b/components/decoration1/index.vue @@ -1,20 +1,177 @@ diff --git a/components/decoration2/index.vue b/components/decoration2/index.vue index 7665f9c..e689080 100644 --- a/components/decoration2/index.vue +++ b/components/decoration2/index.vue @@ -1,77 +1,101 @@ - diff --git a/components/decoration3/img/decoration.gif b/components/decoration3/img/decoration.gif deleted file mode 100644 index 35b143e..0000000 Binary files a/components/decoration3/img/decoration.gif and /dev/null differ diff --git a/components/decoration3/index.vue b/components/decoration3/index.vue index ce5ec5a..6a795a2 100644 --- a/components/decoration3/index.vue +++ b/components/decoration3/index.vue @@ -1,20 +1,108 @@ diff --git a/components/decoration4/index.vue b/components/decoration4/index.vue index e848b6b..67c1181 100644 --- a/components/decoration4/index.vue +++ b/components/decoration4/index.vue @@ -1,92 +1,66 @@ diff --git a/components/decoration6/img/decoration.gif b/components/decoration6/img/decoration.gif deleted file mode 100644 index a8efdb1..0000000 Binary files a/components/decoration6/img/decoration.gif and /dev/null differ diff --git a/components/decoration6/index.vue b/components/decoration6/index.vue index c29644b..67d2d7f 100644 --- a/components/decoration6/index.vue +++ b/components/decoration6/index.vue @@ -1,20 +1,133 @@ diff --git a/components/decoration7/img/decoration.png b/components/decoration7/img/decoration.png deleted file mode 100644 index 7404336..0000000 Binary files a/components/decoration7/img/decoration.png and /dev/null differ diff --git a/components/decoration7/index.vue b/components/decoration7/index.vue index 92fd037..68264e1 100644 --- a/components/decoration7/index.vue +++ b/components/decoration7/index.vue @@ -1,8 +1,34 @@ @@ -13,14 +39,11 @@ export default { diff --git a/components/decoration8/index.vue b/components/decoration8/index.vue new file mode 100644 index 0000000..ad8be06 --- /dev/null +++ b/components/decoration8/index.vue @@ -0,0 +1,63 @@ + + + + + diff --git a/components/digitalFlop/index.vue b/components/digitalFlop/index.vue new file mode 100644 index 0000000..eae06f7 --- /dev/null +++ b/components/digitalFlop/index.vue @@ -0,0 +1,194 @@ + + + + + diff --git a/components/flylineChart/index.vue b/components/flylineChart/index.vue new file mode 100644 index 0000000..be7284b --- /dev/null +++ b/components/flylineChart/index.vue @@ -0,0 +1,509 @@ + + + + + diff --git a/components/forSlot/index.vue b/components/forSlot/index.vue deleted file mode 100644 index 8d14a66..0000000 --- a/components/forSlot/index.vue +++ /dev/null @@ -1,21 +0,0 @@ - - - - - diff --git a/components/index.js b/components/index.js index 5a74b12..4f68ee7 100644 --- a/components/index.js +++ b/components/index.js @@ -1,3 +1,7 @@ +import fullScreenContainer from './fullScreenContainer' +import loading from './loading/index.vue' + +// border box import borderBox1 from './borderBox1/index' import borderBox2 from './borderBox2/index' import borderBox3 from './borderBox3/index' @@ -5,7 +9,9 @@ import borderBox4 from './borderBox4/index' import borderBox5 from './borderBox5/index' import borderBox6 from './borderBox6/index' import borderBox7 from './borderBox7/index' +import borderBox8 from './borderBox8/index' +// decoration import decoration1 from './decoration1/index' import decoration2 from './decoration2/index' import decoration3 from './decoration3/index' @@ -13,61 +19,51 @@ import decoration4 from './decoration4/index' import decoration5 from './decoration5/index' import decoration6 from './decoration6/index' import decoration7 from './decoration7/index' -import loading from './loading/index.vue' +import decoration8 from './decoration8/index' -import capsuleChart from './capsuleChart/index.vue' -import ringChart from './ringChart/index.vue' -import polylineChart from './polylineChart/index.vue' -import concentricArcChart from './concentricArcChart/index.vue' -import arcRingChart from './arcRingChart/index.vue' -import radarChart from './radarChart/index.vue' -import columnChart from './columnChart/index.vue' -import pointChart from './pointChart/index.vue' +// charts +import charts from './charts/index.vue' -import numberShow from './numberShow/index.vue' -import percentPond from './percentPond/index.vue' -import percentArc from './percentArc/index.vue' +import activeRingChart from './activeRingChart' import waterLevelPond from './waterLevelPond/index.vue' +import percentPond from './percentPond/index.vue' +import flylineChart from './flylineChart' +import digitalFlop from './digitalFlop' import scrollBoard from './scrollBoard/index.vue' -import fullScreenContainer from './fullScreenContainer' -import labelLine from './labelLine' -import forSlot from './forSlot' - export default function (Vue) { - Vue.component('borderBox1', borderBox1) - Vue.component('borderBox2', borderBox2) - Vue.component('borderBox3', borderBox3) - Vue.component('borderBox4', borderBox4) - Vue.component('borderBox5', borderBox5) - Vue.component('borderBox6', borderBox6) - Vue.component('borderBox7', borderBox7) + Vue.component('dvFullScreenContainer', fullScreenContainer) - Vue.component('decoration1', decoration1) - Vue.component('decoration2', decoration2) - Vue.component('decoration3', decoration3) - Vue.component('decoration4', decoration4) - Vue.component('decoration5', decoration5) - Vue.component('decoration6', decoration6) - Vue.component('decoration7', decoration7) - Vue.component('loading', loading) + Vue.component('dvLoading', loading) - Vue.component('capsuleChart', capsuleChart) - Vue.component('polylineChart', polylineChart) - Vue.component('ringChart', ringChart) - Vue.component('concentricArcChart', concentricArcChart) - Vue.component('arcRingChart', arcRingChart) - Vue.component('radarChart', radarChart) - Vue.component('columnChart', columnChart) - Vue.component('pointChart', pointChart) + // border box + Vue.component('dvBorderBox1', borderBox1) + Vue.component('dvBorderBox2', borderBox2) + Vue.component('dvBorderBox3', borderBox3) + Vue.component('dvBorderBox4', borderBox4) + Vue.component('dvBorderBox5', borderBox5) + Vue.component('dvBorderBox6', borderBox6) + Vue.component('dvBorderBox7', borderBox7) + Vue.component('dvBorderBox8', borderBox8) - Vue.component('numberShow', numberShow) - Vue.component('percentPond', percentPond) - Vue.component('percentArc', percentArc) - Vue.component('waterLevelPond', waterLevelPond) - Vue.component('scrollBoard', scrollBoard) + // decoration + Vue.component('dvDecoration1', decoration1) + Vue.component('dvDecoration2', decoration2) + Vue.component('dvDecoration3', decoration3) + Vue.component('dvDecoration4', decoration4) + Vue.component('dvDecoration5', decoration5) + Vue.component('dvDecoration6', decoration6) + Vue.component('dvDecoration7', decoration7) + Vue.component('dvDecoration8', decoration8) - Vue.component('fullScreenContainer', fullScreenContainer) - Vue.component('labelLine', labelLine) - Vue.component('forSlot', forSlot) + // charts + Vue.component('dvCharts', charts) + + Vue.component('dvActiveRingChart', activeRingChart) + Vue.component('dvWaterLevelPond', waterLevelPond) + Vue.component('dvPercentPond', percentPond) + Vue.component('dvFlylineChart', flylineChart) + Vue.component('dvDigitalFlop', digitalFlop) + + // Vue.component('dvScrollBoard', scrollBoard) } diff --git a/components/labelLine/index.vue b/components/labelLine/index.vue deleted file mode 100644 index 9419b83..0000000 --- a/components/labelLine/index.vue +++ /dev/null @@ -1,96 +0,0 @@ - - - - - diff --git a/components/loading/img/loading.png b/components/loading/img/loading.png deleted file mode 100644 index cde0453..0000000 Binary files a/components/loading/img/loading.png and /dev/null differ diff --git a/components/loading/index.vue b/components/loading/index.vue index 6a8aa26..31b7664 100644 --- a/components/loading/index.vue +++ b/components/loading/index.vue @@ -1,6 +1,59 @@ @@ -11,29 +64,17 @@ export default { diff --git a/components/numberShow/index.vue b/components/numberShow/index.vue deleted file mode 100644 index 7b202de..0000000 --- a/components/numberShow/index.vue +++ /dev/null @@ -1,33 +0,0 @@ - - - - - diff --git a/components/percentArc/index.vue b/components/percentArc/index.vue deleted file mode 100644 index 0d578f4..0000000 --- a/components/percentArc/index.vue +++ /dev/null @@ -1,222 +0,0 @@ - - - - - diff --git a/components/percentPond/index.vue b/components/percentPond/index.vue index 4737a7f..a6cc9f8 100644 --- a/components/percentPond/index.vue +++ b/components/percentPond/index.vue @@ -1,76 +1,246 @@ diff --git a/components/pointChart/index.vue b/components/pointChart/index.vue deleted file mode 100644 index 0484a7d..0000000 --- a/components/pointChart/index.vue +++ /dev/null @@ -1,175 +0,0 @@ - - - - - diff --git a/components/polylineChart/index.vue b/components/polylineChart/index.vue deleted file mode 100644 index ae83841..0000000 --- a/components/polylineChart/index.vue +++ /dev/null @@ -1,281 +0,0 @@ - - - - - diff --git a/components/radarChart/index.vue b/components/radarChart/index.vue deleted file mode 100644 index 08ffa07..0000000 --- a/components/radarChart/index.vue +++ /dev/null @@ -1,558 +0,0 @@ - - - - - diff --git a/components/ringChart/index.vue b/components/ringChart/index.vue deleted file mode 100644 index 143eb0e..0000000 --- a/components/ringChart/index.vue +++ /dev/null @@ -1,434 +0,0 @@ - - - - - diff --git a/components/waterLevelPond/index.vue b/components/waterLevelPond/index.vue index e4e6d1d..b87de46 100644 --- a/components/waterLevelPond/index.vue +++ b/components/waterLevelPond/index.vue @@ -1,272 +1,306 @@ diff --git a/config/index.js b/config/index.js deleted file mode 100644 index b1c6ea4..0000000 --- a/config/index.js +++ /dev/null @@ -1 +0,0 @@ -export default {} diff --git a/index.js b/index.js index 79429ca..d7d2441 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,5 @@ import components from './components/index' -import plugins from './plugins' - export default function (Vue) { components(Vue) - plugins(Vue) } diff --git a/mixins/borderBoxMixin.js b/mixins/autoResize.js similarity index 79% rename from mixins/borderBoxMixin.js rename to mixins/autoResize.js index e3cf84a..4f8a10f 100644 --- a/mixins/borderBoxMixin.js +++ b/mixins/autoResize.js @@ -12,17 +12,19 @@ export default { } }, methods: { - async init () { - const { initWH, getDebounceInitWHFun, bindDomResizeCallback } = this + async autoResizeMixinInit () { + const { initWH, getDebounceInitWHFun, bindDomResizeCallback, afterAutoResizeMixinInit } = this await initWH() getDebounceInitWHFun() bindDomResizeCallback() + + if (typeof afterAutoResizeMixinInit === 'function') afterAutoResizeMixinInit() }, initWH () { - const { $nextTick, $refs, ref } = this + const { $nextTick, $refs, ref, onResize } = this return new Promise(resolve => { $nextTick(e => { @@ -31,6 +33,8 @@ export default { this.width = dom.clientWidth this.height = dom.clientHeight + if (typeof onResize === 'function') onResize() + resolve() }) }) @@ -58,9 +62,9 @@ export default { } }, mounted () { - const { init } = this + const { autoResizeMixinInit } = this - init() + autoResizeMixinInit() }, beforeDestroyed () { const { unbindDomResizeCallback } = this diff --git a/mixins/axisMixin.js b/mixins/axisMixin.js deleted file mode 100644 index fa072a6..0000000 --- a/mixins/axisMixin.js +++ /dev/null @@ -1,672 +0,0 @@ -export default { - data () { - return { - // config able - defaultAxisFontSize: 10, - defaultAxisFontFamily: 'Arial', - - defaultAxisLineColor: '#666', - defaultGridLineColor: '#666', - defaultAxisTagColor: '#666', - defaultAxisUnitColor: '#666', - - defaultGridLineDash: [2, 2], - - defaultNoAxisLine: false, - defaultNoAxisTag: false, - - defaultXAxisOffset: 20, - defaultAxisLineTagGap: 5, - - // after merge - axisFontSize: 0, - axisFontFamily: '', - - axisLineColor: '', - gridLineColor: '', - axisTagColor: '', - axisUnitColor: '', - - gridLineDash: [], - - noAxisLine: '', - noAxisTag: '', - - // calc data - valueMaxMin: [], - agValueMaxMin: [], - - valueAxisMaxMin: [], - agValueAxisMaxMin: [], - - valueAxisTag: [], - agValueAxisTag: [], - - labelAxisTag: [], - agLabelAxisTag: [], - - xAxisTagBA: ['', ''], - agXAxisTagBA: ['', ''], - yAxisTagBA: ['', ''], - agYAxisTagBA: ['', ''], - - addBAValueAxisTag: [], - addBAAGValueAxisTag: [], - - addBALabelAxisTag: [], - addBAAGLabelAxisTag: [], - - axisUnit: [], - - axisOffset: [], - - axisOriginPos: [], - axisWH: [], - - axisAnglePos: {}, - - valueAxisTagPos: [], - agValueAxisTagPos: [], - - labelAxisTagPos: [], - agLabelAxisTagPos: [], - - tagAlign: {} - } - }, - methods: { - initAxis () { - const { calcValuesMaxMin, calcValueAxisData, calcLabelAxisData } = this - - calcValuesMaxMin() - - calcValueAxisData() - - calcLabelAxisData() - - const { calcTagBA, calcAddBATag, calcAxisUnit } = this - - calcTagBA() - - calcAddBATag() - - calcAxisUnit() - - const { calcAxisFontData, calcAxisColor, calcGridLineDash } = this - - calcAxisFontData() - - calcAxisColor() - - calcGridLineDash() - - const { calcAxisLineTagStatus, calcAxisOffset, calcAxisAreaData } = this - - calcAxisLineTagStatus() - - calcAxisOffset() - - calcAxisAreaData() - - const { calcAxisAnglePos, calcValueAxisTagPos, calcLabelAxisTagPos } = this - - calcAxisAnglePos() - - calcValueAxisTagPos() - - calcLabelAxisTagPos() - - const { calcTagAlign } = this - - calcTagAlign() - }, - calcValuesMaxMin () { - const { data: { series }, calcValueMaxMin } = this - - const valueSeries = series.filter(({ againstAxis }) => !againstAxis) - - if (valueSeries.length) this.valueMaxMin = calcValueMaxMin(valueSeries) - - const agValueSeries = series.filter(({ againstAxis }) => againstAxis) - - if (agValueSeries.length) this.agValueMaxMin = calcValueMaxMin(agValueSeries) - }, - calcValueMaxMin (series) { - const { mulValueAdd, calcMulValueAdd, getArrayMax, getArrayMin } = this - - let valueSeries = series.map(({ value }) => value) - - const min = getArrayMin(valueSeries) - - mulValueAdd && (valueSeries = calcMulValueAdd(valueSeries)) - - const max = getArrayMax(valueSeries) - - return [max, min] - }, - calcMulValueAdd (values) { - const { multipleSum, filterNull } = this - - return values.map(series => - filterNull(series).map(n => - n instanceof Array ? multipleSum(...filterNull(n)) : n)) - }, - calcValueAxisData () { - const { horizon, data: { x, ax, y, ay }, calcValueAxisTag } = this - - const { valueMaxMin, agValueMaxMin, getValueAxisMaxMin } = this - - const valueAxis = horizon ? [x, ax] : [y, ay] - - if (valueMaxMin.length) { - const valueAxisTag = this.valueAxisTag = calcValueAxisTag(valueMaxMin, valueAxis[0]) - - this.valueAxisMaxMin = getValueAxisMaxMin(valueAxisTag) - } - - if (agValueMaxMin.length) { - const agValueAxisTag = this.agValueAxisTag = calcValueAxisTag(agValueMaxMin, valueAxis[1]) - - this.agValueAxisMaxMin = getValueAxisMaxMin(agValueAxisTag) - } - }, - calcValueAxisTag ([vmax, vmin], { max, min, num, fixed, tags } = {}) { - if (tags) return tags - - let [trueMax, trueMin] = [max, min] - - if (vmax === 0 && vmin === 0) vmax = 8 - - const thirdValueMinus = parseInt((vmax - vmin) / 3) - - !max && (max !== 0) && (trueMax = vmax + thirdValueMinus) - !min && (min !== 0) && (trueMin = vmin - thirdValueMinus) - - const trueMinus = trueMax - trueMin - - !num && trueMinus < 9 && (num = Math.ceil(trueMinus) + 1) - !num && (num = 10) - - const valueGap = trueMinus / (num - 1) - - return Array(num).fill(0).map((t, i) => - (trueMin + i * valueGap).toFixed(fixed)) - }, - getValueAxisMaxMin (valueTag) { - const lastIndex = valueTag.length - 1 - - return [ - parseFloat(valueTag[lastIndex]), - parseFloat(valueTag[0]) - ] - }, - calcLabelAxisData () { - const { horizon, data: { x, ax, y, ay } } = this - - const labelAxis = horizon ? [y, ay] : [x, ax] - - if (labelAxis[0] && labelAxis[0].tags) this.labelAxisTag = labelAxis[0].tags - - if (labelAxis[1] && labelAxis[1].tags) this.agLabelAxisTag = labelAxis[1].tags - }, - calcTagBA () { - const { data: { x, ax, y, ay } } = this - - if (x && x.tagBefore) this.xAxisTagBA[0] = x.tagBefore - if (ax && ax.tagBefore) this.agXAxisTagBA[0] = ax.tagBefore - if (y && y.tagBefore) this.yAxisTagBA[0] = y.tagBefore - if (ay && ay.tagBefore) this.agYAxisTagBA[0] = ay.tagBefore - - if (x && x.tagAfter) this.xAxisTagBA[1] = x.tagAfter - if (ax && ax.tagAfter) this.agXAxisTagBA[1] = ax.tagAfter - if (y && y.tagAfter) this.yAxisTagBA[1] = y.tagAfter - if (ay && ay.tagAfter) this.agYAxisTagBA[1] = ay.tagAfter - }, - calcAddBATag () { - const { xAxisTagBA, agXAxisTagBA, yAxisTagBA, agYAxisTagBA } = this - - const { valueAxisTag, agValueAxisTag, labelAxisTag, agLabelAxisTag } = this - - const { horizon, addBATag } = this - - const valueTagBA = horizon ? [xAxisTagBA, agXAxisTagBA] : [yAxisTagBA, agYAxisTagBA] - - const labelTagBA = horizon ? [yAxisTagBA, agYAxisTagBA] : [xAxisTagBA, agXAxisTagBA] - - if (valueAxisTag.length) this.addBAValueAxisTag = addBATag(valueAxisTag, valueTagBA[0]) - if (agValueAxisTag.length) this.addBAAGValueAxisTag = addBATag(agValueAxisTag, valueTagBA[1]) - if (labelAxisTag.length) this.addBALabelAxisTag = addBATag(labelAxisTag, labelTagBA[0]) - if (agLabelAxisTag.length) this.addBAAGLabelAxisTag = addBATag(agLabelAxisTag, labelTagBA[1]) - }, - addBATag (tags, ba) { - return tags.map(tag => tag ? `${ba[0]}${tag}${ba[1]}` : tag) - }, - calcAxisUnit () { - const { data: { x, ax, y, ay } } = this - - if (x && x.unit) this.axisUnit[0] = x.unit - if (ax && ax.unit) this.axisUnit[1] = ax.unit - if (y && y.unit) this.axisUnit[2] = y.unit - if (ay && ay.unit) this.axisUnit[3] = ay.unit - }, - calcAxisFontData () { - const { defaultAxisFontSize, defaultAxisFontFamily, data } = this - - const { fontSize, fontFamily, axisFontSize, axisFontFamily }= data - - this.axisFontSize = axisFontSize || fontSize || defaultAxisFontSize - - this.axisFontFamily = axisFontFamily || fontFamily || defaultAxisFontFamily - }, - calcAxisColor () { - const { data, defaultAxisTagColor, defaultAxisLineColor, defaultGridLineColor } = this - - const { axisTagColor, axisLineColor, gridLineColor } = data - - this.axisTagColor = axisTagColor || defaultAxisTagColor - - this.axisLineColor = axisLineColor || defaultAxisLineColor - - this.gridLineColor = gridLineColor || defaultGridLineColor - }, - calcGridLineDash () { - const { data, defaultGridLineDash } = this - - const { gridLineDash } = data - - if (gridLineDash instanceof Array) { - this.gridLineDash = gridLineDash - } else if (gridLineDash) { - this.gridLineDash = defaultGridLineDash - } else { - this.gridLineDash = [10, 0] - } - }, - calcAxisLineTagStatus () { - const { defaultNoAxisLine, defaultNoAxisTag, data } = this - - const { noAxisLine, noAxisTag } = data - - this.noAxisLine = noAxisLine || defaultNoAxisLine - - this.noAxisTag = noAxisTag || defaultNoAxisTag - }, - calcAxisOffset () { - const { horizon, axisUnit, defaultXAxisOffset } = this - - const { addBAValueAxisTag, addBAAGValueAxisTag, addBALabelAxisTag, addBAAGLabelAxisTag } = this - - const { axisFontSize, axisFontFamily, defaultAxisLineTagGap } = this - - const { data: { x, ax, y, ay } } = this - - const { ctx, canvas: { getTextsWidth }, boundaryGap } = this - - ctx.font = `${axisFontSize}px ${axisFontFamily}` - - this.axisOffset[0] = (ax && ax.offset) || defaultXAxisOffset - this.axisOffset[2] = (x && x.offset) || defaultXAxisOffset - - const horizonAxisTags = horizon - ? [addBALabelAxisTag, addBAAGLabelAxisTag] - : [addBAValueAxisTag, addBAAGValueAxisTag] - - this.axisOffset[3] = (y && y.offset) || - Math.max(...getTextsWidth(ctx, [axisUnit[2] || '']), - ...getTextsWidth(ctx, horizonAxisTags[0].length ? horizonAxisTags[0] : 0)) + defaultAxisLineTagGap - - // axis offset 1 - const xAxisTags = horizon ? addBAValueAxisTag : addBALabelAxisTag - - let xAxisTagsHalfWidth = 0 - - xAxisTags.length && (xAxisTagsHalfWidth = ctx.measureText(xAxisTags.length - 1).width / 2) - - let rightOffset = Math.max(...getTextsWidth(ctx, [axisUnit[3] || '']), - ...getTextsWidth(ctx, [axisUnit[0] || '']), - ...getTextsWidth(ctx, horizonAxisTags[1].length ? horizonAxisTags[1] : [''])) + defaultAxisLineTagGap - - ;(!boundaryGap || horizon) && (rightOffset += (xAxisTagsHalfWidth + 5)) - - this.axisOffset[1] = (ay && ay.offset) || rightOffset - - if (y && y.noTag) this.axisOffset[3] = 1 - if (ay && ay.noTag) this.axisOffset[1] = 1 - }, - calcAxisAreaData () { - const { canvasWH, axisOffset, axisWH, axisOriginPos } = this - - axisWH[0] = canvasWH[0] - axisOffset[1] - axisOffset[3] - axisWH[1] = canvasWH[1] - axisOffset[0] - axisOffset[2] - - axisOriginPos[0] = axisOffset[3] - axisOriginPos[1] = axisWH[1] + axisOffset[0] - }, - calcAxisAnglePos () { - const { axisWH, axisOriginPos, axisAnglePos } = this - - axisAnglePos.leftTop = [axisOriginPos[0], axisOriginPos[1] - axisWH[1]] - axisAnglePos.rightTop = [axisOriginPos[0] + axisWH[0], axisOriginPos[1] - axisWH[1]] - - axisAnglePos.leftBottom = axisOriginPos - axisAnglePos.rightBottom = [axisOriginPos[0] + axisWH[0], axisOriginPos[1]] - }, - calcValueAxisTagPos () { - const { horizon, axisOriginPos, axisAnglePos } = this - - const { valueAxisTag, agValueAxisTag, getValueAxisTagPos } = this - - if (valueAxisTag) this.valueAxisTagPos = getValueAxisTagPos(valueAxisTag, axisOriginPos) - - const basePoint = horizon ? axisAnglePos.leftTop : axisAnglePos.rightBottom - - if (agValueAxisTag) this.agValueAxisTagPos = getValueAxisTagPos(agValueAxisTag, basePoint) - }, - getValueAxisTagPos (tags, [x, y]) { - const { horizon, axisWH } = this - - const tagsNum = tags.length - - const areaLength = horizon ? axisWH[0] : axisWH[1] - - const tagGap = areaLength / (tagsNum - 1) - - return new Array(tagsNum).fill(0).map((t, i) => - horizon ? [x + tagGap * i, y] : [x, y - tagGap * i]) - }, - calcLabelAxisTagPos () { - const { horizon, getLabelAxisTagPos, axisAnglePos } = this - - const { labelAxisTag, agLabelAxisTag, axisOriginPos } = this - - if (labelAxisTag.length) this.labelAxisTagPos = getLabelAxisTagPos(labelAxisTag, axisOriginPos) - - const basePoint = horizon ? axisAnglePos.rightBottom : axisAnglePos.leftTop - - if (agLabelAxisTag.length) this.agLabelAxisTagPos = getLabelAxisTagPos(agLabelAxisTag, basePoint) - }, - getLabelAxisTagPos (tags, [x, y]) { - const { horizon, axisWH, boundaryGap } = this - - const tagsNum = tags.length - - const areaLength = horizon ? axisWH[1] : axisWH[0] - - let gapColumnNum = boundaryGap ? tagsNum : tagsNum - 1 - - gapColumnNum === 0 && (gapColumnNum = 1) - - const tagGap = areaLength / gapColumnNum - - const halfGap = tagGap / 2 - - const tempPos = new Array(tagsNum).fill(0) - - if (boundaryGap) { - return tempPos.map((t, i) => - horizon ? [x, y - (tagGap * i) - halfGap] : [x + (tagGap * i) + halfGap, y]) - } - - if (!boundaryGap) { - return tempPos.map((t, i) => - horizon ? [x, y + tagGap * i] : [x + tagGap * i, y]) - } - }, - calcTagAlign () { - const { tagAlign } = this - - tagAlign.x = ['center', 'top'] - tagAlign.y = ['right', 'middle'] - tagAlign.ax = ['center', 'bottom'] - tagAlign.ay = ['left', 'middle'] - }, - drawAxis () { - const { drawAxisLine, drawAxisTag, drawAxisUnit } = this - - drawAxisLine() - - drawAxisTag() - - drawAxisUnit() - - const { drawAxisGrid } = this - - drawAxisGrid() - }, - drawAxisLine () { - const { noAxisLine } = this - - if (noAxisLine) return - - const { ctx, horizon, axisOriginPos, axisAnglePos } = this - - const { axisLineColor, agValueAxisTag, agLabelAxisTag } = this - - const { data: { x, ax, y, ay } } = this - - ctx.lineWidth = 1 - - if (!x || !x.noAxisLine) { - ctx.strokeStyle = (x && x.axisLineColor) || axisLineColor - ctx.beginPath() - ctx.moveTo(...axisOriginPos) - ctx.lineTo(...axisAnglePos.rightBottom) - ctx.stroke() - } - - if (!y || !y.noAxisLine) { - ctx.strokeStyle = (y && y.axisLineColor) || axisLineColor - ctx.beginPath() - ctx.moveTo(...axisOriginPos) - ctx.lineTo(...axisAnglePos.leftTop) - ctx.stroke() - } - - const agValueAxis = horizon ? ay : ax - - if (agValueAxisTag.length && (!agValueAxis || !agValueAxis.noAxisLine)) { - ctx.strokeStyle = (agValueAxis && agValueAxis.axisLineColor) || axisLineColor - ctx.beginPath() - ctx.moveTo(...(horizon ? axisAnglePos.leftTop : axisAnglePos.rightTop)) - ctx.lineTo(...(horizon ? axisAnglePos.rightTop : axisAnglePos.rightBottom)) - ctx.stroke() - } - - const agLebalAxis = horizon ? ax : ay - - if (agLabelAxisTag.length && (!agLebalAxis || !agLebalAxis.noAxisLine)) { - ctx.strokeStyle = (agLebalAxis && agLebalAxis.axisLineColor) || axisLineColor - ctx.beginPath() - ctx.moveTo(...(horizon ? axisAnglePos.rightTop : axisAnglePos.leftTop)) - ctx.lineTo(...(horizon ? axisAnglePos.rightBottom : axisAnglePos.rightTop)) - ctx.stroke() - } - }, - drawAxisTag () { - const { noAxisTag } = this - - if (noAxisTag) return - - const { horizon, tagAlign, defaultAxisLineTagGap: offset } = this - - const { data: { x, ax, y, ay }, drawAxisSeriesTag } = this - - const xAxis = horizon ? ['addBAValueAxisTag', 'valueAxisTagPos'] : ['addBALabelAxisTag', 'labelAxisTagPos'] - const yAxis = horizon ? ['addBALabelAxisTag', 'labelAxisTagPos'] : ['addBAValueAxisTag', 'valueAxisTagPos'] - const agXAxis = horizon ? ['addBAAGValueAxisTag', 'agValueAxisTagPos'] : ['addBAAGLabelAxisTag', 'agLabelAxisTagPos'] - const agYAxis = horizon ? ['addBAAGLabelAxisTag', 'agLabelAxisTagPos'] : ['addBAAGValueAxisTag', 'agValueAxisTagPos'] - - if (!x || !x.noAxisTag) drawAxisSeriesTag(...xAxis.map(td => this[td]), x, tagAlign.x, [0, offset], x && x.rotate) - if (!y || !y.noAxisTag) drawAxisSeriesTag(...yAxis.map(td => this[td]), y, tagAlign.y, [-offset, 0]) - if (!ax || !ax.noAxisTag) drawAxisSeriesTag(...agXAxis.map(td => this[td]), ax, tagAlign.ax, [0, -offset]) - if (!ay || !ay.noAxisTag) drawAxisSeriesTag(...agYAxis.map(td => this[td]), ay, tagAlign.ay, [offset, 0]) - }, - drawAxisSeriesTag (tags, tagPos, { fontSize, fontFamily, tagColor } = {}, align, offset, rotate = false) { - const { ctx, axisFontSize, axisFontFamily, axisTagColor, drawColors } = this - - let color = tagColor || axisTagColor - - color === 'colors' && (color = drawColors) - - const colorNum = color.length - - const mulColor = color instanceof Array - - ctx.font = `${fontSize || axisFontSize}px ${fontFamily || axisFontFamily}` - - !mulColor && (ctx.fillStyle = color) - - ctx.textAlign = align[0] - ctx.textBaseline = align[1] - - tags.forEach((tag, i) => { - if (!tag && tag !== 0) return - - const currentPos = [tagPos[i][0] + offset[0], tagPos[i][1] + offset[1]] - - mulColor && (ctx.fillStyle = color[i % colorNum]) - - if (rotate) { - ctx.textAlign = 'left' - ctx.textBaseline = 'top' - - ctx.save() - ctx.translate(...currentPos) - ctx.rotate(rotate * Math.PI / 180) - } - - ctx.fillText(tag, ...(rotate ? [0, 0] : currentPos)) - - if (rotate) ctx.restore() - }) - }, - drawAxisUnit () { - const { noAxisTag } = this - - if (noAxisTag) return - - const { axisOriginPos, canvasWH, drawUnit, defaultAxisLineTagGap } = this - - const { data: { x, ax, y, ay }, axisAnglePos } = this - - if (x) { - const pos = [canvasWH[0], axisOriginPos[1] + defaultAxisLineTagGap] - drawUnit(x, pos, ['right', 'top']) - } - - if (ax) { - const pos = [canvasWH[0], axisAnglePos.rightTop[1] - defaultAxisLineTagGap] - drawUnit(ax, pos, ['right', 'bottom']) - } - - if (y) { - const pos = [axisOriginPos[0] - defaultAxisLineTagGap, 0] - drawUnit(y, pos, ['right', 'top']) - } - - if (ay) { - const pos = [axisAnglePos.rightTop[0] + defaultAxisLineTagGap, 0] - drawUnit(ay, pos, ['left', 'top']) - } - }, - drawUnit ({ unit, unitColor, fontSize, fontFamily }, pos, align) { - const { axisTagColor, axisFontSize, axisFontFamily } = this - - const { ctx } = this - - if (!unit) return - - ctx.font = `${fontSize || axisFontSize}px ${fontFamily || axisFontFamily}` - - ctx.fillStyle = unitColor || axisTagColor - - ctx.textAlign = align[0] - ctx.textBaseline = align[1] - - ctx.fillText(unit, ...pos) - }, - drawAxisGrid () { - const { valueAxisTagPos, agValueAxisTagPos, labelAxisTagPos, agLabelAxisTagPos } = this - - const { valueAxisTag, agValueAxisTag, labelAxisTag, agLabelAxisTag } = this - - const { data: { x, ax, y, ay }, horizon, drawGrid, boundaryGap } = this - - const xAxis = horizon ? [valueAxisTag, valueAxisTagPos] : [labelAxisTag, labelAxisTagPos] - - let xBELineStatus = [false, false] - - if (horizon) { - xBELineStatus = [true, false] - } else { - xBELineStatus = boundaryGap ? [false, false] : [true, true] - } - - if (xAxis[0].length) drawGrid(x, ...xAxis, false, false, true, ...xBELineStatus) - - const yAxis = horizon ? [labelAxisTag, labelAxisTagPos] : [valueAxisTag, valueAxisTagPos] - - if (yAxis[0].length) drawGrid(y, ...yAxis, true, true, false, !horizon) - - const agXAxis = horizon ? [agValueAxisTag, agValueAxisTagPos] : [agLabelAxisTag, agLabelAxisTagPos] - - if (agXAxis[0].length) drawGrid(ax, ...agXAxis, false, false, false, ...(boundaryGap ? [false, false] : [true, true])) - - const agYAxis = horizon ? [agLabelAxisTag, agLabelAxisTagPos] : [agValueAxisTag, agValueAxisTagPos] - - if (agYAxis[0].length) drawGrid(ay, ...agYAxis, true, false, false, true) - }, - drawGrid (axis = {}, gridTag, gridPos, horizon = true, right = true, top = true, noFirst = false, noLast = false) { - const { grid, gridLineColor: cGLC, gridLineDash: cGLD } = axis - - if (!grid) return - - const { gridLineColor, gridLineDash, defaultGridLineDash } = this - - const { ctx, drawColors, axisWH } = this - - let trueGridLineDash = gridLineDash - - if (cGLD instanceof Array) { - trueGridLineDash = cGLD - } else if (cGLD === true) { - trueGridLineDash = defaultGridLineDash - } - - ctx.setLineDash(trueGridLineDash) - - let color = cGLC || gridLineColor - - color === 'colors' && (color = drawColors) - - const mulColor = color instanceof Array - - const colorNum = color.length - - !mulColor && (ctx.strokeStyle = color) - - ctx.lineWidth = 1 - - const gridLastIndex = gridPos.length - 1 - - gridPos.forEach((pos, i) => { - if (!gridTag[i] && gridTag[i] !== 0) return - - if (i === 0 && noFirst) return - - if (i === gridLastIndex && noLast) return - - ctx.beginPath() - - mulColor && (ctx.strokeStyle = color[i % colorNum]) - - ctx.moveTo(...pos) - ctx.lineTo(...(horizon - ? [right ? pos[0] + axisWH[0] : pos[0] - axisWH[0], pos[1]] - : [pos[0], top ? pos[1] - axisWH[1] : pos[1] + axisWH[1]])) - - ctx.stroke() - }) - } - } -} diff --git a/mixins/canvasMixin.js b/mixins/canvasMixin.js deleted file mode 100644 index a29490a..0000000 --- a/mixins/canvasMixin.js +++ /dev/null @@ -1,43 +0,0 @@ -export default { - data () { - return { - canvasDom: '', - canvasWH: [0, 0], - ctx: '', - centerPos: [0, 0] - } - }, - methods: { - initCanvas () { - const { $nextTick } = this - - return new Promise(resolve => { - $nextTick(e => { - const { $refs, ref, labelRef, canvasWH, centerPos } = this - - const canvas = this.canvasDom = $refs[ref] - - this.labelDom = $refs[labelRef] - - canvasWH[0] = canvas.clientWidth - canvasWH[1] = canvas.clientHeight - - canvas.setAttribute('width', canvasWH[0]) - canvas.setAttribute('height', canvasWH[1]) - - this.ctx = canvas.getContext('2d') - - centerPos[0] = canvasWH[0] / 2 - centerPos[1] = canvasWH[1] / 2 - - resolve() - }) - }) - }, - clearCanvas () { - const { ctx, canvasWH } = this - - ctx.clearRect(0, 0, ...canvasWH) - } - } -} diff --git a/mixins/colorsMixin.js b/mixins/colorsMixin.js deleted file mode 100644 index 626b6c8..0000000 --- a/mixins/colorsMixin.js +++ /dev/null @@ -1,23 +0,0 @@ -export default { - data () { - return { - defaultColors: [ - '#9cf4a7', '#66d7ee', '#eee966', - '#a866ee', '#ee8f66', '#ee66aa' - ], - - drawColors: '', - - drawColorsMul: false - } - }, - methods: { - initColors () { - const { colors, defaultColors } = this - - const trueDrawColors = this.drawColors = colors || defaultColors - - this.drawColorsMul = trueDrawColors instanceof Array - } - } -} diff --git a/plugins/canvasExtend.js b/plugins/canvasExtend.js deleted file mode 100644 index 771075c..0000000 --- a/plugins/canvasExtend.js +++ /dev/null @@ -1,195 +0,0 @@ -import { filterNull } from './methodsExtend' - -export function drawLine (ctx, lineBegin, lineEnd, lineWidth = 2, lineColor = '#000', dashArray = [10, 0]) { - if (!ctx || !lineBegin || !lineEnd) return - - ctx.beginPath() - - ctx.moveTo(...lineBegin) - ctx.lineTo(...lineEnd) - - ctx.closePath() - - ctx.lineWidth = lineWidth - ctx.strokeStyle = lineColor - ctx.setLineDash(dashArray) - - ctx.stroke() -} - -export function drawPolylinePath (ctx, points, close = false, newPath = false) { - if (!ctx || !points.length) return - - newPath && ctx.beginPath() - - points.forEach((point, i) => - point && (i === 0 ? ctx.moveTo(...point) : ctx.lineTo(...point))) - - close && ctx.lineTo(...points[0]) -} - -export function drawPolyline (ctx, points, lineWidth = 2, lineColor = '#000', close = false, dashArray = [10, 0], newPath = false) { - if (!ctx || !points.length) return - - drawPolylinePath(ctx, points, close, newPath) - - ctx.lineWidth = lineWidth - ctx.strokeStyle = lineColor - ctx.setLineDash(dashArray) - - ctx.stroke() -} - -export function drawSmoothlinePath (ctx, points, close = false, newPath = false, moveTo = false) { - const canDrawPoints = filterNull(points) - - if (!ctx || canDrawPoints.length < 2) return - - close && canDrawPoints.push(canDrawPoints[0]) - - newPath && ctx.beginPath() - - if (canDrawPoints.length === 2) { - ctx.moveTo(...canDrawPoints[0]) - ctx.lineTo(...canDrawPoints[1]) - - return - } - - const lastPointIndex = canDrawPoints.length - 1 - - moveTo && ctx.moveTo(...canDrawPoints[0]) - - canDrawPoints.forEach((t, i) => - (i !== lastPointIndex) && drawBezierCurveLinePath(ctx, - ...getBezierCurveLineControlPoints(canDrawPoints, i, false), - canDrawPoints[i + 1])) -} - -export function getBezierCurveLineControlPoints (points, index, close = false, offsetA = 0.25, offsetB = 0.25) { - const pointNum = points.length - - if (pointNum < 3 || index >= pointNum) return - - let beforePointIndex = index - 1 - beforePointIndex < 0 && (beforePointIndex = (close ? pointNum + beforePointIndex : 0)) - - let afterPointIndex = index + 1 - afterPointIndex >= pointNum && (afterPointIndex = (close ? afterPointIndex - pointNum : pointNum - 1)) - - let afterNextPointIndex = index + 2 - afterNextPointIndex >= pointNum && (afterNextPointIndex = (close ? afterNextPointIndex - pointNum : pointNum - 1)) - - const pointBefore = points[beforePointIndex] - const pointMiddle = points[index] - const pointAfter = points[afterPointIndex] - const pointAfterNext = points[afterNextPointIndex] - - return [ - [ - pointMiddle[0] + offsetA * (pointAfter[0] - pointBefore[0]), - pointMiddle[1] + offsetA * (pointAfter[1] - pointBefore[1]) - ], - [ - pointAfter[0] - offsetB * (pointAfterNext[0] - pointMiddle[0]), - pointAfter[1] - offsetB * (pointAfterNext[1] - pointMiddle[1]) - ] - ] -} - -export function drawSmoothline (ctx, points, lineWidth = 2, lineColor = '#000', close = false, dashArray = [10, 0], newPath = false, moveTo = false) { - if (!ctx || points.length < 3) return - - drawSmoothlinePath(ctx, points, close, newPath, moveTo) - - ctx.lineWidth = lineWidth - ctx.strokeStyle = lineColor - ctx.setLineDash(dashArray) - - ctx.stroke() -} - -export function drawBezierCurveLinePath (ctx, ctlBefore, ctlAfter, end, newPath = false) { - if (!ctx || !ctlBefore || !ctlAfter || !end) return - - newPath && ctx.beginPath() - - ctx.bezierCurveTo(...ctlBefore, ...ctlAfter, ...end) -} - -export function drawPoints (ctx, points, radius = 10, color = '#000') { - points.forEach(point => { - if (!point) return - - ctx.beginPath() - - ctx.arc(...point, radius, 0, Math.PI * 2) - - ctx.fillStyle = color - - ctx.fill() - }) -} - -export function getLinearGradientColor (ctx, begin, end, color) { - if (!ctx || !begin || !end || !color.length) return - - let colors = color - - typeof colors === 'string' && (colors = [color, color]) - - const linearGradientColor = ctx.createLinearGradient(...begin, ...end) - - const colorGap = 1 / (colors.length - 1) - - colors.forEach((c, i) => linearGradientColor.addColorStop(colorGap * i, c)) - - return linearGradientColor -} - -export function getRadialGradientColor (ctx, origin, begin = 0, end = 100, color) { - if (!ctx || !origin || !color.length) return - - let colors = color - - typeof colors === 'string' && (colors = [color, color]) - - const radialGradientColor = ctx.createRadialGradient(...origin, begin, ...origin, end) - - const colorGap = 1 / (colors.length - 1) - - colors.forEach((c, i) => radialGradientColor.addColorStop(colorGap * i, c)) - - return radialGradientColor -} - -export function getCircleRadianPoint (x, y, radius, radian) { - const { sin, cos } = Math - - return [x + cos(radian) * radius, y + sin(radian) * radius] -} - -export function getTextsWidth (ctx, texts) { - if (!ctx || !texts) return - - return texts.map(text => ctx.measureText(text).width) -} - -const canvas = { - drawLine, - drawPolylinePath, - drawPolyline, - getBezierCurveLineControlPoints, - drawSmoothlinePath, - drawSmoothline, - drawBezierCurveLinePath, - drawPoints, - getLinearGradientColor, - getRadialGradientColor, - getCircleRadianPoint, - getTextsWidth -} - -export default function (Vue) { - Vue.prototype.canvas = canvas -} diff --git a/plugins/colorExtend.js b/plugins/colorExtend.js deleted file mode 100644 index b36887a..0000000 --- a/plugins/colorExtend.js +++ /dev/null @@ -1,53 +0,0 @@ -const hexReg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/ -const rgbReg = /^(rgb|rgba|RGB|RGBA)/ - -/** - * @description hex color to rgb / rgba color - * @param {string} rgba opacity - * @return {string} rgb / rgba color - */ -export function hexToRgb (hex, opacity) { - if (!hex || !hexReg.test(hex)) return false - - hex = hex.toLowerCase().replace('#', '') - - // deal 3bit hex color to 6bit hex color - hex.length === 3 && (hex = Array.from(hex).map(hexNum => hexNum + hexNum).join('')) - - let rgb = [] - - for (let i = 0; i < 6; i += 2) { - rgb.push(parseInt(`0x${hex.slice(i, i + 2)}`)) - } - - rgb = rgb.join(',') - - if (opacity) { - return `rgba(${rgb}, ${opacity})` - } else { - return `rgb(${rgb})` - } -} - -/** - * @description rgb / rgba color to hex color - * @return {string} hex color - */ -export function rgbToHex (rgb) { - if (!rgb || !rgbReg.test(rgb)) return false - - rgb = rgb.toLowerCase().replace(/rgb\(|rgba\(|\)/g, '').split(',').slice(0, 3) - - const hex = rgb.map((rgbNum) => Number(rgbNum).toString(16)).map((rgbNum) => rgbNum === '0' ? rgbNum + rgbNum : rgbNum).join('') - - return `#${hex}` -} - -const color = { - hexToRgb, - rgbToHex -} - -export default function (Vue) { - Vue.prototype.color = color -} diff --git a/plugins/index.js b/plugins/index.js deleted file mode 100644 index 0f18023..0000000 --- a/plugins/index.js +++ /dev/null @@ -1,11 +0,0 @@ -import methodsExtend from './methodsExtend' - -import canvasExtend from './canvasExtend' - -import colorExtend from './colorExtend' - -export default function (Vue) { - methodsExtend(Vue) - canvasExtend(Vue) - colorExtend(Vue) -} diff --git a/plugins/methodsExtend.js b/plugins/methodsExtend.js deleted file mode 100644 index ffb126d..0000000 --- a/plugins/methodsExtend.js +++ /dev/null @@ -1,155 +0,0 @@ -const { parse, stringify } = JSON - -export function deepClone (object) { - return parse(stringify(object)) -} - -export function deleteArrayAllItems (arrays) { - arrays.forEach(element => element.splice(0, element.length)) -} - -export function debounce (delay, callback) { - let lastTime - - return function () { - clearTimeout(lastTime) - - const [that, args] = [this, arguments] - - lastTime = setTimeout(() => { - callback.apply(that, args) - }, delay) - } -} - -export function randomExtend (minNum, maxNum) { - if (arguments.length === 1) { - return parseInt(Math.random() * minNum + 1, 10) - } else { - return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10) - } -} - -export function multipleSum (...num) { - let sum = 0 - - num.forEach(n => (sum += n)) - - return sum -} - -export function filterNull (arr) { - const tmpArr = [] - - arr.forEach(v => ((v || v === 0) && tmpArr.push(v))) - - return tmpArr -} - -export function getPointDistance (pointOne, pointTwo) { - const minusX = Math.abs(pointOne[0] - pointTwo[0]) - - const minusY = Math.abs(pointOne[1] - pointTwo[1]) - - return Math.sqrt(minusX * minusX + minusY * minusY) -} - -export function getPointToLineDistance (point, linePointOne, linePointTwo) { - const a = getPointDistance(point, linePointOne) - const b = getPointDistance(point, linePointTwo) - const c = getPointDistance(linePointOne, linePointTwo) - - return 0.5 * Math.sqrt((a + b + c) * (a + b - c) * (a + c - b) * (b + c - a)) / c -} - -export function getArrayMaxMin (array) { - if (!array) return false - - return [getArrayMax(array), getArrayMin(array)] -} - -export function getArrayMax (array) { - if (!array) return false - - return Math.max(...filterNull(array).map(n => - n instanceof Array ? getArrayMax(n) : n)) -} - -export function getArrayMin (array) { - if (!array) return false - - return Math.min(...filterNull(array).map(n => - n instanceof Array ? getArrayMin(n) : n)) -} - -export function getAxisPointsPos ([max, min], values, axisOriginPos, axisWH, tagPos, horizon) { - let minus = max - min - - minus === 0 && (minus = 1) - - return values.map((value, i) => { - if (!value && value !== 0) return false - - if (value instanceof Array) { - return value.map(v => - getAxisPointPos([max, min], v, axisOriginPos, axisWH, tagPos[i], horizon)) - } - - const percent = (value - min) / minus - - const length = percent * (horizon ? axisWH[0] : axisWH[1]) - - return horizon ? [ - axisOriginPos[0] + length, - tagPos[i][1] - ] : [ - tagPos[i][0], - axisOriginPos[1] - length - ] - }) -} - -export function getAxisPointPos ([max, min], value, axisOriginPos, axisWH, tagPos, horizon) { - if (!value && value !== 0) return false - - const minus = max - min - - const percent = (value - min) / minus - - const length = percent * (horizon ? axisWH[0] : axisWH[1]) - - return horizon ? [ - axisOriginPos[0] + length, - tagPos[1] - ] : [ - tagPos[0], - axisOriginPos[1] - length - ] -} - -export function observerDomResize (dom, callback) { - const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver - - const observer = new MutationObserver(callback) - - observer.observe(dom, { attributes: true, attributeFilter: ['style'], attributeOldValue: true }) - - return observer -} - -export default function (Vue) { - Vue.prototype.deepClone = deepClone - Vue.prototype.deleteArrayAllItems = deleteArrayAllItems - Vue.prototype.debounce = debounce - Vue.prototype.multipleSum = multipleSum - Vue.prototype.randomExtend = randomExtend - Vue.prototype.filterNull = filterNull - Vue.prototype.getPointDistance = getPointDistance - Vue.prototype.getPointToLineDistance = getPointToLineDistance - Vue.prototype.getArrayMaxMin = getArrayMaxMin - Vue.prototype.getArrayMax = getArrayMax - Vue.prototype.getArrayMin = getArrayMin - Vue.prototype.getAxisPointPos = getAxisPointPos - Vue.prototype.getAxisPointsPos = getAxisPointsPos - Vue.prototype.observerDomResize = observerDomResize -} diff --git a/util/index.js b/util/index.js new file mode 100644 index 0000000..0f4d67d --- /dev/null +++ b/util/index.js @@ -0,0 +1,7 @@ +export function randomExtend (minNum, maxNum) { + if (arguments.length === 1) { + return parseInt(Math.random() * minNum + 1, 10) + } else { + return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10) + } +}