From c7e2ec8567f8c494e57771295dc1c6ccf3e0cdb0 Mon Sep 17 00:00:00 2001
From: quietcoder <1642965215@qq.com>
Date: Wed, 14 Jun 2017 15:37:54 +0800
Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E5=8E=BB?=
=?UTF-8?q?=E9=99=A4SIGN=E5=8F=98=E9=87=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
examples/test-data/bar.js | 2 +-
examples/test-data/funnel.js | 2 +-
examples/test-data/histogram.js | 2 +-
src/bar/bar.js | 71 ++++++++++++++++----------------
src/chart/index.vue | 11 ++++-
src/echarts-base.js | 30 ++++++--------
src/funnel/funnel.js | 38 +++++++----------
src/index.es.js | 17 +++++++-
src/index.js | 17 +++++++-
src/line/line.js | 72 +++++++++++++++++----------------
src/mixins.js | 4 +-
src/pie/pie.js | 38 +++++++++++++----
src/radar/radar.js | 15 +++----
src/util.js | 18 ++++-----
src/waterfall/waterfall.js | 58 +++++++++++++++++++++-----
15 files changed, 242 insertions(+), 153 deletions(-)
diff --git a/examples/test-data/bar.js b/examples/test-data/bar.js
index 0cc8028..492f300 100644
--- a/examples/test-data/bar.js
+++ b/examples/test-data/bar.js
@@ -31,7 +31,7 @@ export default {
]
},
settings: {
- xAxisType: ['KMB', 'normal'],
+ xAxisType: ['KMB', 'percent'],
xAxisName: ['余额', '年龄'],
axisSite: {
top: ['年龄']
diff --git a/examples/test-data/funnel.js b/examples/test-data/funnel.js
index de9d927..15f12c7 100644
--- a/examples/test-data/funnel.js
+++ b/examples/test-data/funnel.js
@@ -31,7 +31,7 @@ export default {
}
},
{
- name: '漏斗图',
+ name: '指定数据类型漏斗图',
data: {
columns: ['状态', '数值'],
rows: [
diff --git a/examples/test-data/histogram.js b/examples/test-data/histogram.js
index ca02e34..a366aab 100644
--- a/examples/test-data/histogram.js
+++ b/examples/test-data/histogram.js
@@ -31,7 +31,7 @@ export default {
]
},
settings: {
- yAxisType: ['KMB', 'normal'],
+ yAxisType: ['KMB', 'percent'],
yAxisName: ['余额', '年龄'],
axisSite: {
right: ['年龄']
diff --git a/src/bar/bar.js b/src/bar/bar.js
index f293c6f..c6ce905 100755
--- a/src/bar/bar.js
+++ b/src/bar/bar.js
@@ -1,23 +1,9 @@
-import { SIGN, getLegendName, itemPoint } from '../echarts-base'
+import { itemPoint } from '../echarts-base'
import { getFormated, getStackMap } from '../util'
import 'echarts/lib/chart/bar'
-function getBarLegends ({ metrics, axisSite, meaAxisType, isHistogram }) {
- let legends = []
-
- const formatter = getLegendName
- const secondAxis = isHistogram ? axisSite.right : axisSite.top
- metrics.forEach(item => {
- let legendItem = ~secondAxis.indexOf(item)
- ? `${item}${SIGN}${meaAxisType[1]}`
- : `${item}${SIGN}${meaAxisType[0]}`
- legends.push(legendItem)
- })
-
- return legends.length ? { data: legends, formatter } : false
-}
-
-function getBarDimAxis ({ rows, dimAxisName, dimension, axisVisible }) {
+function getBarDimAxis (args) {
+ const { rows, dimAxisName, dimension, axisVisible } = args
return dimension.map(item => ({
type: 'category',
name: dimAxisName,
@@ -33,8 +19,15 @@ function getBarDimAxis ({ rows, dimAxisName, dimension, axisVisible }) {
}))
}
-function getBarMeaAxis ({ columns, meaAxisName, metrics, meaAxisType, axisVisible }) {
- const meaAxisBase = { type: 'value', axisTick: { show: false }, show: axisVisible }
+function getBarMeaAxis (args) {
+ const { meaAxisName, meaAxisType, axisVisible } = args
+ const meaAxisBase = {
+ type: 'value',
+ axisTick: {
+ show: false
+ },
+ show: axisVisible
+ }
let meaAxis = []
for (let i = 0; i < 2; i++) {
@@ -55,17 +48,21 @@ function getBarMeaAxis ({ columns, meaAxisName, metrics, meaAxisType, axisVisibl
return meaAxis
}
-function getBarTooltip () {
+function getBarTooltip (args) {
+ const { axisSite, isHistogram, meaAxisType } = args
+ const secondAxis = isHistogram ? axisSite.right : axisSite.top
return {
trigger: 'axis',
formatter (items) {
let tpl = []
- const title = String(items[0].name).split(SIGN)[0]
- tpl.push(`${title}
`)
+ tpl.push(`${items[0].name}
`)
items.forEach(item => {
- const [name, type] = item.seriesName.split(SIGN)
+ const seriesName = item.seriesName
+ const type = ~secondAxis.indexOf(seriesName)
+ ? meaAxisType[1]
+ : meaAxisType[0]
tpl.push(itemPoint(item.color))
- tpl.push(`${name}: `)
+ tpl.push(`${seriesName}: `)
tpl.push(getFormated(item.value, type))
tpl.push('
')
})
@@ -75,7 +72,8 @@ function getBarTooltip () {
}
}
-function getBarSeries ({ rows, metrics, stack, axisSite, meaAxisType, isHistogram }) {
+function getBarSeries (args) {
+ const { rows, metrics, stack, axisSite, isHistogram } = args
let series = []
const seriesTemp = {}
const secondAxis = isHistogram ? axisSite.right : axisSite.top
@@ -88,9 +86,7 @@ function getBarSeries ({ rows, metrics, stack, axisSite, meaAxisType, isHistogra
})
})
series = Object.keys(seriesTemp).map(item => {
- let itemName = ~secondAxis.indexOf(item)
- ? `${item}${SIGN}${meaAxisType[1]}`
- : `${item}${SIGN}${meaAxisType[0]}`
+ let itemName = item
const seriesItem = {
name: itemName,
type: 'bar',
@@ -105,6 +101,7 @@ function getBarSeries ({ rows, metrics, stack, axisSite, meaAxisType, isHistogra
return series.length ? series : false
}
+
const bar = (columns, rows, settings, status) => {
const {
axisSite = { top: [] },
@@ -124,11 +121,12 @@ const bar = (columns, rows, settings, status) => {
const dimAxisName = settings.yAxisName || ''
const isHistogram = false
- const legend = legendVisible && getBarLegends({ metrics, axisSite, meaAxisType, isHistogram })
+ const legend = legendVisible && { data: metrics }
const yAxis = getBarDimAxis({ rows, dimAxisName, dimension, axisVisible })
- const xAxis = getBarMeaAxis({ columns, meaAxisName, metrics, meaAxisType, axisVisible })
- const series = getBarSeries({ rows, metrics, stack, axisSite, meaAxisType, isHistogram })
- const tooltip = tooltipVisible && getBarTooltip()
+ const xAxis = getBarMeaAxis({ meaAxisName, meaAxisType, axisVisible })
+ const series = getBarSeries({ rows, metrics, stack, axisSite, isHistogram })
+ const tooltipParams = { axisSite, isHistogram, meaAxisType }
+ const tooltip = tooltipVisible && getBarTooltip(tooltipParams)
const options = { legend, yAxis, series, xAxis, tooltip }
return options
}
@@ -152,11 +150,12 @@ const histogram = (columns, rows, settings, status) => {
const dimAxisName = settings.xAxisName || ''
const isHistogram = true
- const legend = legendVisible && getBarLegends({ metrics, axisSite, meaAxisType, isHistogram })
+ const legend = legendVisible && { data: metrics }
const xAxis = getBarDimAxis({ rows, dimAxisName, dimension, axisVisible })
- const yAxis = getBarMeaAxis({ columns, meaAxisName, metrics, meaAxisType, axisVisible })
- const series = getBarSeries({ rows, metrics, stack, axisSite, meaAxisType, isHistogram })
- const tooltip = tooltipVisible && getBarTooltip()
+ const yAxis = getBarMeaAxis({ meaAxisName, meaAxisType, axisVisible })
+ const series = getBarSeries({ rows, metrics, stack, axisSite, isHistogram })
+ const tooltipParams = { axisSite, isHistogram, meaAxisType }
+ const tooltip = tooltipVisible && getBarTooltip(tooltipParams)
const options = { legend, yAxis, series, xAxis, tooltip }
return options
}
diff --git a/src/chart/index.vue b/src/chart/index.vue
index df6feb0..5e814cf 100644
--- a/src/chart/index.vue
+++ b/src/chart/index.vue
@@ -15,7 +15,16 @@ export default {
name: 'VeChart',
mixins: [chartMixin],
created () {
- this.chartLib = { bar, histogram, line, pie, ring, funnel, radar, waterfall }
+ this.chartLib = {
+ bar,
+ histogram,
+ line,
+ pie,
+ ring,
+ funnel,
+ radar,
+ waterfall
+ }
this.chartHandler = this.chartLib[this.settings.type]
this.echartsLib = echarts
}
diff --git a/src/echarts-base.js b/src/echarts-base.js
index 12d15ea..e728752 100644
--- a/src/echarts-base.js
+++ b/src/echarts-base.js
@@ -2,22 +2,6 @@ import echarts from 'echarts/lib/echarts'
import 'echarts/lib/component/tooltip'
import 'echarts/lib/component/legend'
-const SIGN = '@_@'
-const getLegendName = (item) => item.split(SIGN)[0]
-
-const itemPoint = (color) => {
- return [
- ''
- ].join('')
-}
-
echarts.registerTheme('ve-chart', {
color: [
'#19d4ae', '#5ab1ef', '#fa6e86',
@@ -44,5 +28,17 @@ echarts.registerTheme('ve-chart', {
}
})
-export { SIGN, itemPoint, getLegendName }
+export const itemPoint = (color) => {
+ return [
+ ''
+ ].join('')
+}
+
export default echarts
diff --git a/src/funnel/funnel.js b/src/funnel/funnel.js
index 2a8f360..5bd29fe 100755
--- a/src/funnel/funnel.js
+++ b/src/funnel/funnel.js
@@ -1,36 +1,25 @@
-import { SIGN, itemPoint, getLegendName } from '../echarts-base'
+import { itemPoint } from '../echarts-base'
import { getFormated, clone } from '../util'
import 'echarts/lib/chart/funnel'
-function getFunnelTooltip () {
+function getFunnelTooltip (dataType) {
return {
trigger: 'item',
formatter (item) {
let tpl = []
- const name = item.name.split(SIGN)[0]
- const type = item.name.split(SIGN)[1]
tpl.push(itemPoint(item.color))
- tpl.push(`${name}: ${getFormated(item.data.realValue, type)}`)
+ tpl.push(`${item.name}: ${getFormated(item.data.realValue, dataType)}`)
return tpl.join('')
}
}
}
-function getFunnelLegend ({ dimension, metrics, rows, sequence, dataType }) {
- const legendData = sequence.map(item => {
- return `${item}${SIGN}${dataType}`
+function getFunnelSeries (args) {
+ const { dimension, metrics, rows, sequence, ascending } = args
+ let series = { type: 'funnel' }
+ rows.sort((a, b) => {
+ return sequence.indexOf(a[dimension]) - sequence.indexOf(b[dimension])
})
- const formatter = getLegendName
-
- return { data: legendData, formatter }
-}
-
-function getFunnelSeries ({ dimension, metrics, rows, sequence, dataType, ascending }) {
- let series = {
- type: 'funnel',
- label: { normal: { formatter (item) { return item.name.split(SIGN)[0] } } }
- }
- rows.sort((a, b) => sequence.indexOf(a[dimension]) - sequence.indexOf(b[dimension]))
let falseFunnel = false
rows.some((row, index) => {
@@ -44,13 +33,13 @@ function getFunnelSeries ({ dimension, metrics, rows, sequence, dataType, ascend
if (falseFunnel) {
series.data = rows.slice().reverse().map((row, index) => ({
- name: `${row[dimension]}${SIGN}${dataType}`,
+ name: row[dimension],
value: (index + 1) * step,
realValue: row[metrics]
}))
} else {
series.data = rows.map(row => ({
- name: `${row[dimension]}${SIGN}${dataType}`,
+ name: row[dimension],
value: row[metrics],
realValue: row[metrics]
}))
@@ -79,9 +68,10 @@ const funnel = (outerColumns, outerRows, settings, status) => {
metrics = metricsTemp[0]
}
- const tooltip = tooltipVisible && getFunnelTooltip()
- const legend = legendVisible && getFunnelLegend({ dimension, metrics, rows, sequence, dataType })
- const series = getFunnelSeries({ dimension, metrics, rows, sequence, dataType, ascending })
+ const tooltip = tooltipVisible && getFunnelTooltip(dataType)
+ const legend = legendVisible && { data: sequence }
+ const seriesParams = { dimension, metrics, rows, sequence, ascending }
+ const series = getFunnelSeries(seriesParams)
const options = { tooltip, legend, series }
return options
}
diff --git a/src/index.es.js b/src/index.es.js
index d9942c3..afb280d 100644
--- a/src/index.es.js
+++ b/src/index.es.js
@@ -21,7 +21,20 @@ const components = [
]
function install (Vue, _) {
- components.forEach(component => { Vue.component(component.name, component) })
+ components.forEach(component => {
+ Vue.component(component.name, component)
+ })
}
-export { VeBar, VeHistogram, VeRing, VeLine, VePie, VeWaterfall, VeFunnel, VeRadar, VeChart, install }
+export {
+ VeBar,
+ VeHistogram,
+ VeRing,
+ VeLine,
+ VePie,
+ VeWaterfall,
+ VeFunnel,
+ VeRadar,
+ VeChart,
+ install
+}
diff --git a/src/index.js b/src/index.js
index 7014816..82a404f 100755
--- a/src/index.js
+++ b/src/index.js
@@ -27,11 +27,24 @@ const components = [
]
function install (Vue, _) {
- components.forEach(component => { Vue.component(component.name, component) })
+ components.forEach(component => {
+ Vue.component(component.name, component)
+ })
}
if (typeof window !== 'undefined' && window.Vue) {
install(window.Vue)
}
-export default { VeBar, VeHistogram, VeRing, VeLine, VePie, VeWaterfall, VeFunnel, VeRadar, VeChart, install }
+export default {
+ VeBar,
+ VeHistogram,
+ VeRing,
+ VeLine,
+ VePie,
+ VeWaterfall,
+ VeFunnel,
+ VeRadar,
+ VeChart,
+ install
+}
diff --git a/src/line/line.js b/src/line/line.js
index fd3ac0c..f6c5c95 100755
--- a/src/line/line.js
+++ b/src/line/line.js
@@ -1,23 +1,9 @@
-import { SIGN, getLegendName, itemPoint } from '../echarts-base'
+import { itemPoint } from '../echarts-base'
import { getFormated, getStackMap } from '../util'
import 'echarts/lib/chart/line'
-function getLineLegends ({ metrics, axisSite, yAxisType }) {
- let legends = []
-
- const formatter = getLegendName
-
- metrics.forEach(item => {
- let legendItem = ~axisSite.right.indexOf(item)
- ? `${item}${SIGN}${yAxisType[1]}`
- : `${item}${SIGN}${yAxisType[0]}`
- legends.push(legendItem)
- })
-
- return legends.length ? { data: legends, formatter } : false
-}
-
-function getLineXAxis ({ dimension, rows, xAxisName, axisVisible }) {
+function getLineXAxis (args) {
+ const { dimension, rows, xAxisName, axisVisible } = args
return dimension.map((item, index) => ({
type: 'category',
nameLocation: 'middle',
@@ -35,7 +21,14 @@ function getLineXAxis ({ dimension, rows, xAxisName, axisVisible }) {
}))
}
-function getLineSeries ({ rows, axisSite, yAxisType, dimension, metrics, area, stack }) {
+function getLineSeries (args) {
+ const {
+ rows,
+ axisSite,
+ metrics,
+ area,
+ stack
+ } = args
let series = []
const dataTemp = {}
const stackMap = stack && getStackMap(stack)
@@ -53,14 +46,7 @@ function getLineSeries ({ rows, axisSite, yAxisType, dimension, metrics, area, s
}
if (area) seriesItem.areaStyle = { normal: {} }
-
- if (~axisSite.right.indexOf(item)) {
- seriesItem.yAxisIndex = 1
- seriesItem.name = `${item}${SIGN}${yAxisType[1]}`
- } else {
- seriesItem.yAxisIndex = 0
- seriesItem.name = `${item}${SIGN}${yAxisType[0]}`
- }
+ seriesItem.yAxisIndex = ~axisSite.right.indexOf(item) ? 1 : 0
if (stack && stackMap[item]) seriesItem.stack = stackMap[item]
@@ -69,8 +55,15 @@ function getLineSeries ({ rows, axisSite, yAxisType, dimension, metrics, area, s
return series.length ? series : false
}
-function getLineYAxis ({ yAxisName, yAxisType, axisVisible }) {
- const yAxisBase = { type: 'value', axisTick: { show: false }, show: axisVisible }
+function getLineYAxis (args) {
+ const { yAxisName, yAxisType, axisVisible } = args
+ const yAxisBase = {
+ type: 'value',
+ axisTick: {
+ show: false
+ },
+ show: axisVisible
+ }
let yAxis = []
for (let i = 0; i < 2; i++) {
if (yAxisType[i]) {
@@ -89,7 +82,7 @@ function getLineYAxis ({ yAxisName, yAxisType, axisVisible }) {
return yAxis
}
-function getLineTooltip () {
+function getLineTooltip (axisSite, yAxisType) {
return {
trigger: 'axis',
formatter (items) {
@@ -97,10 +90,12 @@ function getLineTooltip () {
tpl.push(`${items[0].name}
`)
items.forEach(item => {
let showData
- const [name, type] = item.seriesName.split(SIGN)
+ const type = ~axisSite.right.indexOf(item.seriesName)
+ ? yAxisType[1]
+ : yAxisType[0]
showData = getFormated(item.data, type)
tpl.push(itemPoint(item.color))
- tpl.push(`${name}: ${showData}`)
+ tpl.push(`${item.seriesName}: ${showData}`)
tpl.push('
')
})
return tpl.join('')
@@ -128,11 +123,20 @@ const line = (columns, rows, settings, status) => {
metrics.splice(columns.indexOf(dimension[0]), 1)
}
- const legend = legendVisible && getLineLegends({ metrics, axisSite, yAxisType })
- const tooltip = tooltipVisible && getLineTooltip()
+ const legend = legendVisible && { data: metrics }
+ const tooltip = tooltipVisible && getLineTooltip(axisSite, yAxisType)
const xAxis = getLineXAxis({ dimension, rows, xAxisName, axisVisible })
const yAxis = getLineYAxis({ yAxisName, yAxisType, axisVisible })
- const series = getLineSeries({ rows, stack, axisSite, yAxisType, dimension, metrics, area })
+ const seriesParams = {
+ rows,
+ stack,
+ axisSite,
+ yAxisType,
+ dimension,
+ metrics,
+ area
+ }
+ const series = getLineSeries(seriesParams)
if (!xAxis || !series) return false
let options = { legend, xAxis, series, yAxis, tooltip }
diff --git a/src/mixins.js b/src/mixins.js
index c847e6d..6f63123 100644
--- a/src/mixins.js
+++ b/src/mixins.js
@@ -43,7 +43,9 @@ const chartMixin = {
methods: {
dataHandler (data) {
if (!this.chartHandler) return
- if (!data || !Array.isArray(data.columns) || !Array.isArray(data.rows)) return false
+ if (!data ||
+ !Array.isArray(data.columns) ||
+ !Array.isArray(data.rows)) return false
const { columns, rows } = data
const status = {
tooltipVisible: this.tooltipVisible,
diff --git a/src/pie/pie.js b/src/pie/pie.js
index c4878ab..913cc07 100644
--- a/src/pie/pie.js
+++ b/src/pie/pie.js
@@ -8,8 +8,15 @@ const pieOffsetY = 200
function getPieSeries (args) {
const {
- rows, dataType, percentShow, dimension, metrics,
- radius, offsetY, selectedMode, hoverAnimation
+ rows,
+ dataType,
+ percentShow,
+ dimension,
+ metrics,
+ radius,
+ offsetY,
+ selectedMode,
+ hoverAnimation
} = args
let series = {
@@ -34,12 +41,16 @@ function getPieSeries (args) {
}
}
}
- series.data = rows.map(row => ({ name: row[dimension], value: row[metrics] }))
+ series.data = rows.map(row => ({
+ name: row[dimension],
+ value: row[metrics]
+ }))
return series
}
-function getPieLegend ({ rows, dimension, legendLimit }) {
+function getPieLegend (args) {
+ const { rows, dimension, legendLimit } = args
let legend = rows.map(row => row[dimension])
return legend.length
? { data: legend, show: legend.length < legendLimit }
@@ -72,15 +83,26 @@ const pie = (columns, rows, settings, status, isRing) => {
hoverAnimation = true
} = settings
const { tooltipVisible, legendVisible } = status
- const series = getPieSeries({
- rows, dataType, percentShow, dimension, metrics, radius, offsetY, selectedMode, hoverAnimation
- })
+ const seriesParams = {
+ rows,
+ dataType,
+ percentShow,
+ dimension,
+ metrics,
+ radius,
+ offsetY,
+ selectedMode,
+ hoverAnimation
+ }
+ const series = getPieSeries(seriesParams)
const legend = legendVisible && getPieLegend({ rows, dimension, legendLimit })
const tooltip = tooltipVisible && getPieTooltip(dataType)
const options = { series, legend, tooltip }
return options
}
-const ring = (columns, rows, settings, status) => pie(columns, rows, settings, status, true)
+const ring = (columns, rows, settings, status) => {
+ return pie(columns, rows, settings, status, true)
+}
export { pie, ring }
diff --git a/src/radar/radar.js b/src/radar/radar.js
index 5db09fc..34f5a68 100755
--- a/src/radar/radar.js
+++ b/src/radar/radar.js
@@ -2,13 +2,13 @@ import { itemPoint } from '../echarts-base'
import { getFormated } from '../util'
import 'echarts/lib/chart/radar'
-function getRadarLegend ({ rows, dimension }) {
+function getRadarLegend (rows, dimension) {
let legendData = rows.map(row => row[dimension])
return { data: legendData }
}
-function getRadarTooltip ({ dataType, radar }) {
+function getRadarTooltip (dataType, radar) {
const typeTemp = []
const nameTemp = []
radar.indicator.map((item, index) => {
@@ -29,7 +29,7 @@ function getRadarTooltip ({ dataType, radar }) {
}
}
-function getRadarSetting ({ rows, dimension, metrics }) {
+function getRadarSetting (rows, metrics) {
const settingBase = {
indicator: [],
shape: 'circle',
@@ -54,7 +54,8 @@ function getRadarSetting ({ rows, dimension, metrics }) {
return settingBase
}
-function getRadarSeries ({ rows, dimension, metrics, radar }) {
+function getRadarSeries (args) {
+ const { rows, dimension, metrics, radar } = args
let radarIndexObj = {}
radar.indicator.forEach((item, index) => {
radarIndexObj[item.name] = index
@@ -88,9 +89,9 @@ const radar = (columns, rows, settings, status) => {
} else {
metrics.splice(columns.indexOf(dimension), 1)
}
- const legend = legendVisible && getRadarLegend({ rows, dimension })
- const radar = getRadarSetting({ rows, dimension, metrics })
- const tooltip = tooltipVisible && getRadarTooltip({ dataType, radar })
+ const legend = legendVisible && getRadarLegend(rows, dimension)
+ const radar = getRadarSetting(rows, metrics)
+ const tooltip = tooltipVisible && getRadarTooltip(dataType, radar)
const series = getRadarSeries({ rows, dimension, metrics, radar })
const options = { legend, tooltip, radar, series }
return options
diff --git a/src/util.js b/src/util.js
index d09ee10..be86574 100644
--- a/src/util.js
+++ b/src/util.js
@@ -1,4 +1,4 @@
-const numberFormat = (val, digits = 2) => {
+export const numberFormat = (val, digits = 2) => {
if (isNaN(+val)) return val
let symbolMap = [
@@ -19,11 +19,13 @@ const numberFormat = (val, digits = 2) => {
return val.toString()
}
-const formatTausends = (num) => {
- return String(num).replace(/^(\s+|-)?\d+(?=.?\d*($|\s))/g, (m) => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','))
+export const formatTausends = (num) => {
+ return String(num).replace(/^(\s+|-)?\d+(?=.?\d*($|\s))/g, (m) => {
+ return m.replace(/(?=(?!\b)(\d{3})+$)/g, ',')
+ })
}
-const getFormated = (val, type) => {
+export const getFormated = (val, type) => {
switch (type) {
case 'KMB': return numberFormat(val)
case 'percent': return `${parseFloat((val * 100).toFixed(2))}%`
@@ -32,14 +34,14 @@ const getFormated = (val, type) => {
}
}
-const getLineKB = (s, v) => {
+export const getLineKB = (s, v) => {
const result = []
result[0] = (s[1] - s[0]) / (v[1] - v[0])
result[1] = s[0] - result[0] * v[0]
return result
}
-const getStackMap = (stack) => {
+export const getStackMap = (stack) => {
const stackMap = {}
Object.keys(stack).forEach(item => {
stack[item].forEach(name => {
@@ -49,6 +51,4 @@ const getStackMap = (stack) => {
return stackMap
}
-const clone = (v) => JSON.parse(JSON.stringify(v))
-
-export { numberFormat, formatTausends, getFormated, getLineKB, clone, getStackMap }
+export const clone = (v) => JSON.parse(JSON.stringify(v))
diff --git a/src/waterfall/waterfall.js b/src/waterfall/waterfall.js
index 7cae83a..9ba3b7c 100644
--- a/src/waterfall/waterfall.js
+++ b/src/waterfall/waterfall.js
@@ -15,9 +15,20 @@ function getWaterfallTooltip (dataType) {
}
}
-function getWaterfallXAxis ({ dimension, rows, remainStatus, totalName, remainName, xAxisName, axisVisible }) {
+function getWaterfallXAxis (args) {
+ const {
+ dimension,
+ rows,
+ remainStatus,
+ totalName,
+ remainName,
+ xAxisName,
+ axisVisible
+ } = args
let xAxisData = [totalName].concat(rows.map(row => row[dimension]))
- if (remainStatus === 'have-remain') xAxisData = xAxisData.concat([remainName])
+ if (remainStatus === 'have-remain') {
+ xAxisData = xAxisData.concat([remainName])
+ }
return {
type: 'category',
@@ -28,7 +39,8 @@ function getWaterfallXAxis ({ dimension, rows, remainStatus, totalName, remainNa
}
}
-function getWaterfallYAxis ({ dataType, yAxisName, axisVisible }) {
+function getWaterfallYAxis (args) {
+ const { dataType, yAxisName, axisVisible } = args
return {
type: 'value',
name: yAxisName,
@@ -42,7 +54,15 @@ function getWaterfallYAxis ({ dataType, yAxisName, axisVisible }) {
}
}
-function getWaterfallSeries ({ dataType, rows, dimension, metrics, totalNum, remainStatus, dataSum }) {
+function getWaterfallSeries (args) {
+ const {
+ dataType,
+ rows,
+ metrics,
+ totalNum,
+ remainStatus,
+ dataSum
+ } = args
const seriesBase = { type: 'bar', stack: '总量' }
let dataSumTemp = dataSum
let totalNumTemp = totalNum
@@ -90,7 +110,7 @@ function getWaterfallSeries ({ dataType, rows, dimension, metrics, totalNum, rem
return series
}
-function getWaterfallRemainStatus ({ dataSum, totalNum }) {
+function getWaterfallRemainStatus (dataSum, totalNum) {
if (!totalNum) return 'not-total'
return totalNum > dataSum ? 'have-remain' : 'none-remain'
}
@@ -111,11 +131,31 @@ const waterfall = (columns, rows, settings, status) => {
const metrics = metricsTemp[0]
const yAxisName = metrics
const tooltip = tooltipVisible && getWaterfallTooltip(dataType)
- const dataSum = rows.reduce((pre, cur) => pre + Number(cur[metrics]), 0).toFixed(2)
- const remainStatus = getWaterfallRemainStatus({ dataSum, dimension, totalNum })
- const xAxis = getWaterfallXAxis({ dimension, rows, remainStatus, totalName, remainName, xAxisName, axisVisible })
+ const dataSum = rows.reduce((pre, cur) => {
+ return pre + Number(cur[metrics])
+ }, 0).toFixed(2)
+ const remainStatus = getWaterfallRemainStatus(dataSum, totalNum)
+ const xAxisParams = {
+ dimension,
+ rows,
+ remainStatus,
+ totalName,
+ remainName,
+ xAxisName,
+ axisVisible
+ }
+ const xAxis = getWaterfallXAxis(xAxisParams)
const yAxis = getWaterfallYAxis({ dataType, yAxisName, axisVisible })
- const series = getWaterfallSeries({ dataType, rows, dimension, metrics, totalNum, remainStatus, dataSum })
+ const seriesParams = {
+ dataType,
+ rows,
+ dimension,
+ metrics,
+ totalNum,
+ remainStatus,
+ dataSum
+ }
+ const series = getWaterfallSeries(seriesParams)
const options = { tooltip, xAxis, yAxis, series }
return options
}
From 12d4d8d2b692647fe951712073294deee0881759 Mon Sep 17 00:00:00 2001
From: quietcoder <1642965215@qq.com>
Date: Wed, 14 Jun 2017 16:29:56 +0800
Subject: [PATCH 2/6] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=8A=98?=
=?UTF-8?q?=E7=BA=BF=E5=9B=BEscale,=20min,=20max=E9=85=8D=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/line.md | 5 +++++
docs/props.md | 6 ++----
examples/test-data/line.js | 39 ++++++++++++++++++++++++++++++++++++++
src/line/line.js | 33 +++++++++++++++++++++++++-------
4 files changed, 72 insertions(+), 11 deletions(-)
diff --git a/docs/line.md b/docs/line.md
index 6e3bd67..2c4613a 100644
--- a/docs/line.md
+++ b/docs/line.md
@@ -15,7 +15,12 @@
| axisSite | 指标所在的轴 | Object | 默认不在right轴的指标都在left轴 |
| stack | 堆叠选项 | Object | - |
| area | 是否展示为面积图 | Boolean | 默认为false |
+| scale | 是否是脱离 0 值比例 | Object | 设置成 true 后坐标刻度不会
强制包含零刻度,默认都是 false |
+| min | 左右坐标轴最小值 | Array | - |
+| max | 左右坐标轴最大值 | Array | - |
> 备注1. axisSite 可以设置 left 和 right,例如示例所示 `axisSite: { right: ['占比'] }` 即将占比的数据置于右轴上。
> 备注2. stack 用于将两数据堆叠起来,例如实例中所示`stack: { '销售额': ['销售额-1季度', '销售额-2季度'] }` 即将'销售额-1季度', '销售额-2季度'相应的数据堆叠在一起。
+
+> 备注3. min和max的值可以直接设置为数字,例如:`[100, 300]`;也可以设置为`['dataMin', 'dataMin']`, `['dataMax', 'dataMax']`,此时表示使用该坐标轴上的最小值或最大值为最小或最大刻度。
diff --git a/docs/props.md b/docs/props.md
index b79debe..5f8cd81 100644
--- a/docs/props.md
+++ b/docs/props.md
@@ -13,11 +13,9 @@ V-Charts 的属性分为两种,一种是全部图表都具有的属性,例
| height | 图表高度 | String | 默认 400px |
| settings | 图表配置项 | Object | 内容参考图表具体的配置 |
| colors | 颜色列表 | Array | 默认
`['#19d4ae', '#5ab1ef', '#fa6e86',`
` '#ffb980', '#0067a6', '#c4b4e4',`
` '#d87a80', '#9cbbff', '#d9d0c7',`
` '#87a997', '#d49ea2', '#5b4947']` |
-| tooltip-visible | 是否显示提示框 | Boolean | 默认为 false,
设置为true时需要额外引入
'echarts/lib/component/tooltip' |
-| legend-visible | 是否显示Legend | Boolean | 默认为 false,
设置为true时需要额外引入
'echarts/lib/component/legend' |
-| axis-visible | 是否显示坐标轴 | Boolean | 默认为 true |
+| tooltip-visible | 是否显示提示框 | Boolean | 默认为 true |
+| legend-visible | 是否显示Legend | Boolean | 默认为 true |
| grid | 网格配置 | Object | 内容参考
http://echarts.baidu.com/option.html#grid |
-| scale | 是否是脱离 0 值比例 | Object | 设置成 true 后坐标刻度不会
强制包含零刻度,默认都是 false |
| events | 为图表绑定事件 | Object | 内容为包含事件名-事件处理函数的对象,例如
`{ click: function (e) { console.log(e) }}` |
| before-config | 对数据提前进行额外的处理 | Function | 在数据转化为配置项开始前触发
参数为 data
需返回表格数据
| after-config | 对生成好的echarts配置
进行额外的处理 | Function | 在数据转化为配置项结束后触发
参数为 options
需返回 echarts 配置
diff --git a/examples/test-data/line.js b/examples/test-data/line.js
index 1667e18..da76cb8 100644
--- a/examples/test-data/line.js
+++ b/examples/test-data/line.js
@@ -74,6 +74,45 @@ export default {
metrics: ['余额']
}
},
+ {
+ name: '设置scale',
+ data: {
+ columns: ['日期', '余额', '比率'],
+ rows: [
+ { '日期': '1-1', '余额': 1232, '比率': 0.1 },
+ { '日期': '1-2', '余额': 1223, '比率': 0.2 },
+ { '日期': '1-3', '余额': 2123, '比率': 0.3 },
+ { '日期': '1-4', '余额': 4123, '比率': 0.4 },
+ { '日期': '1-5', '余额': 3123, '比率': 0.5 },
+ { '日期': '1-6', '余额': 7123, '比率': 0.6 }
+ ]
+ },
+ settings: {
+ dimension: ['比率'],
+ metrics: ['余额'],
+ scale: [true, true]
+ }
+ },
+ {
+ name: '设置min max',
+ data: {
+ columns: ['日期', '余额', '比率'],
+ rows: [
+ { '日期': '1-1', '余额': 1232, '比率': 0.1 },
+ { '日期': '1-2', '余额': 1223, '比率': 0.2 },
+ { '日期': '1-3', '余额': 2123, '比率': 0.3 },
+ { '日期': '1-4', '余额': 4123, '比率': 0.4 },
+ { '日期': '1-5', '余额': 3123, '比率': 0.5 },
+ { '日期': '1-6', '余额': 7123, '比率': 0.6 }
+ ]
+ },
+ settings: {
+ dimension: ['比率'],
+ metrics: ['余额'],
+ min: [1000],
+ max: [5000]
+ }
+ },
{
name: '面积图',
data: {
diff --git a/src/line/line.js b/src/line/line.js
index f6c5c95..c88d549 100755
--- a/src/line/line.js
+++ b/src/line/line.js
@@ -56,7 +56,14 @@ function getLineSeries (args) {
}
function getLineYAxis (args) {
- const { yAxisName, yAxisType, axisVisible } = args
+ const {
+ yAxisName,
+ yAxisType,
+ axisVisible,
+ scale,
+ min,
+ max
+ } = args
const yAxisBase = {
type: 'value',
axisTick: {
@@ -78,6 +85,9 @@ function getLineYAxis (args) {
yAxis[i] = Object.assign({}, yAxisBase)
}
yAxis[i].name = yAxisName[i] || ''
+ yAxis[i].scale = scale[i] || false
+ yAxis[i].min = min[i] || null
+ yAxis[i].max = max[i] || null
}
return yAxis
}
@@ -112,7 +122,10 @@ const line = (columns, rows, settings, status) => {
xAxisName = [],
axisVisible = true,
area,
- stack
+ stack,
+ scale = [false, false],
+ min = [null, null],
+ max = [null, null]
} = settings
const { tooltipVisible, legendVisible } = status
let metrics = columns.slice()
@@ -126,15 +139,21 @@ const line = (columns, rows, settings, status) => {
const legend = legendVisible && { data: metrics }
const tooltip = tooltipVisible && getLineTooltip(axisSite, yAxisType)
const xAxis = getLineXAxis({ dimension, rows, xAxisName, axisVisible })
- const yAxis = getLineYAxis({ yAxisName, yAxisType, axisVisible })
+ const yAxisParams = {
+ yAxisName,
+ yAxisType,
+ axisVisible,
+ scale,
+ min,
+ max
+ }
+ const yAxis = getLineYAxis(yAxisParams)
const seriesParams = {
rows,
- stack,
axisSite,
- yAxisType,
- dimension,
metrics,
- area
+ area,
+ stack
}
const series = getLineSeries(seriesParams)
if (!xAxis || !series) return false
From 64ae0878b57f6a263223fdf7a9283d5c8bb329bd Mon Sep 17 00:00:00 2001
From: quietcoder <1642965215@qq.com>
Date: Wed, 14 Jun 2017 17:48:43 +0800
Subject: [PATCH 3/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=EF=BC=9A=E5=9B=BE?=
=?UTF-8?q?=E4=BE=8B=E4=BD=8D=E7=BD=AE=E9=85=8D=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/props.md | 3 ++-
examples/pages/toggle.vue | 16 +++++++++++-----
package.json | 2 +-
src/funnel/funnel.js | 6 +++---
src/mixins.js | 10 +++++++++-
5 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/docs/props.md b/docs/props.md
index 5f8cd81..f6eec83 100644
--- a/docs/props.md
+++ b/docs/props.md
@@ -14,7 +14,8 @@ V-Charts 的属性分为两种,一种是全部图表都具有的属性,例
| settings | 图表配置项 | Object | 内容参考图表具体的配置 |
| colors | 颜色列表 | Array | 默认
`['#19d4ae', '#5ab1ef', '#fa6e86',`
` '#ffb980', '#0067a6', '#c4b4e4',`
` '#d87a80', '#9cbbff', '#d9d0c7',`
` '#87a997', '#d49ea2', '#5b4947']` |
| tooltip-visible | 是否显示提示框 | Boolean | 默认为 true |
-| legend-visible | 是否显示Legend | Boolean | 默认为 true |
+| legend-visible | 是否显示图例 | Boolean | 默认为 true |
+| legend-position | 图例显示位置 | String | 可选`'left', 'top', 'right', 'bottom'` |
| grid | 网格配置 | Object | 内容参考
http://echarts.baidu.com/option.html#grid |
| events | 为图表绑定事件 | Object | 内容为包含事件名-事件处理函数的对象,例如
`{ click: function (e) { console.log(e) }}` |
| before-config | 对数据提前进行额外的处理 | Function | 在数据转化为配置项开始前触发
参数为 data
需返回表格数据
diff --git a/examples/pages/toggle.vue b/examples/pages/toggle.vue
index bf6fb3e..fb7b3b0 100644
--- a/examples/pages/toggle.vue
+++ b/examples/pages/toggle.vue
@@ -2,7 +2,13 @@
{{ contentList[0] }}
-代码示例
+
-
-
diff --git a/examples/pages/item.vue b/examples/pages/item.vue
deleted file mode 100644
index 95eccc7..0000000
--- a/examples/pages/item.vue
+++ /dev/null
@@ -1,152 +0,0 @@
-
- chartData
-chartSettings
-配置项 | -简介 | -类型 | -示例 | -备注 | -
---|---|---|---|---|
{{ property.name }} | -{{ property.intro }} | -{{ property.type }} | -{{ property.example }} | -{{ property.remark }} | -
现有的图表种类有折线图(line),饼图(pie),条形图(bar),柱状图(histogram),环图(ring),瀑布图(waterfall),漏斗图(funnel),雷达图(radar)
-