fixed bug and optimization

This commit is contained in:
jiaming 2018-12-12 18:47:13 +08:00
parent 8f0affe692
commit 1acb4e7943
1 changed files with 11 additions and 6 deletions

View File

@ -3,6 +3,9 @@
<div class="canvas-container"> <div class="canvas-container">
<canvas :ref="ref" /> <canvas :ref="ref" />
</div> </div>
<loading v-if="!data" />
<div v-if="data.labelLine" class="label-line"> <div v-if="data.labelLine" class="label-line">
<div class="label-item" v-for="(label, i) in data.labelLine" :key="label + i"> <div class="label-item" v-for="(label, i) in data.labelLine" :key="label + i">
<div :style="`background-color: ${data.color[i % data.color.length]};`"></div> <div :style="`background-color: ${data.color[i % data.color.length]};`"></div>
@ -41,9 +44,9 @@ export default {
}, },
watch: { watch: {
data (d) { data (d) {
const { draw } = this const { init } = this
d && draw() d && init()
} }
}, },
methods: { methods: {
@ -112,8 +115,8 @@ export default {
let [unsetMax, unsetMin] = [false, false] let [unsetMax, unsetMin] = [false, false]
!max && (max = Math.max(...data.map(({ data: td }) => Math.max(...td)))) && (unsetMax = true) !max && max !== 0 && (max = Math.max(...data.map(({ data: td }) => Math.max(...td)))) && (unsetMax = true)
!min && (min = Math.min(...data.map(({ data: td }) => Math.min(...filterNull(td))))) && (unsetMin = true) !min && min !== 0 && (min = Math.min(...data.map(({ data: td }) => Math.min(...filterNull(td))))) && (unsetMin = true)
let minus = max - min let minus = max - min
@ -209,8 +212,10 @@ export default {
const minus = max - min const minus = max - min
const numberData = data.map(({ data: td }) => ({ data: td.map(v => ((!v && v === 0) || v) ? Number(v) : NaN) }))
this.valuePointsData = this.valuePointsData =
data.map(({ data: td }) => numberData.map(({ data: td }) =>
td.map((v, i) => td.map((v, i) =>
Number.isFinite(v) Number.isFinite(v)
? [xPos[i], axisOriginPos[1] - (v - min) / minus * axisWH[1]] ? [xPos[i], axisOriginPos[1] - (v - min) / minus * axisWH[1]]
@ -223,7 +228,7 @@ export default {
const colorNum = color.length const colorNum = color.length
const columnWidth = rowColumnSize[1] const columnWidth = rowColumnSize[1] / 3 * 2
const offset = columnWidth / 2 const offset = columnWidth / 2