-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
quietcoder
committed
Oct 16, 2017
1 parent
688d0bf
commit 10d355f
Showing
11 changed files
with
226 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
### 桑基图 | ||
|
||
#### 示例 | ||
|
||
// TODO: add a jsfiddle demo | ||
|
||
#### 设置数据类型 | ||
|
||
<vuep template="#set-data-type"></vuep> | ||
|
||
<script v-pre type="text/x-template" id="set-data-type"> | ||
<template> | ||
<ve-sankey :data="chartData" :settings="chartSettings"></ve-sankey> | ||
</template> | ||
|
||
<script> | ||
module.exports = { | ||
created: function () { | ||
this.chartData = { | ||
columns: ['页面', '访问量'], | ||
rows: [ | ||
{ '页面': '首页', '访问量': 100000 }, | ||
{ '页面': '列表页a', '访问量': 20000 }, | ||
{ '页面': '列表页b', '访问量': 80000 }, | ||
{ '页面': '内容页a-1', '访问量': 10000 }, | ||
{ '页面': '内容页a-2', '访问量': 10000 }, | ||
{ '页面': '内容页b-1', '访问量': 60000 }, | ||
{ '页面': '内容页b-2', '访问量': 20000 } | ||
] | ||
} | ||
this.chartSettings = { | ||
links: [ | ||
{ source: '首页', target: '列表页a', value: 0.5 }, | ||
{ source: '首页', target: '列表页b', value: 0.5 }, | ||
{ source: '列表页a', target: '内容页a-1', value: 0.1 }, | ||
{ source: '列表页a', target: '内容页a-2', value: 0.4 }, | ||
{ source: '列表页b', target: '内容页b-1', value: 0.2 }, | ||
{ source: '列表页b', target: '内容页b-2', value: 0.3 } | ||
], | ||
dataType: ['KMB', 'percent'] | ||
} | ||
} | ||
} | ||
</script> | ||
</script> | ||
|
||
|
||
|
||
#### settings 配置项 | ||
|
||
| 配置项 | 简介 | 类型 | 备注 | | ||
| --- | --- | --- | --- | | ||
| dimension | 维度 | String | 默认columns第一项为维度 | | ||
| metrics | 指标 | String | 默认columns第二项为指标 | | ||
| dataType | 数据类型 | Array | 数组的第一项为item的数据类型,<br>第二项为line的数据类型,<br>可选值: KMB, normal, percent | | ||
| links | 节点间的关系数据 | Array | 内容参考[文档](http://echarts.baidu.com/option.html#series-sankey.links) | | ||
| digit | 设置数据类型为percent时保留的位数 | Number | 默认为2 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
export default { | ||
name: '桑基图', | ||
type: 'sankey', | ||
data: [ | ||
{ | ||
name: '基本桑基图', | ||
data: { | ||
columns: ['页面', '访问量'], | ||
rows: [ | ||
{ '页面': '首页', '访问量': 1000 }, | ||
{ '页面': '列表页a', '访问量': 200 }, | ||
{ '页面': '列表页b', '访问量': 800 }, | ||
{ '页面': '内容页a-1', '访问量': 100 }, | ||
{ '页面': '内容页a-2', '访问量': 100 }, | ||
{ '页面': '内容页b-1', '访问量': 600 }, | ||
{ '页面': '内容页b-2', '访问量': 200 } | ||
] | ||
}, | ||
settings: { | ||
links: [ | ||
{ source: '首页', target: '列表页a' }, | ||
{ source: '首页', target: '列表页b' }, | ||
{ source: '列表页a', target: '内容页a-1' }, | ||
{ source: '列表页a', target: '内容页a-2' }, | ||
{ source: '列表页b', target: '内容页b-1' }, | ||
{ source: '列表页b', target: '内容页b-2' } | ||
] | ||
} | ||
}, | ||
{ | ||
name: '设置数据类型桑基图', | ||
data: { | ||
columns: ['页面', '访问量'], | ||
rows: [ | ||
{ '页面': '首页', '访问量': 100000 }, | ||
{ '页面': '列表页a', '访问量': 20000 }, | ||
{ '页面': '列表页b', '访问量': 80000 }, | ||
{ '页面': '内容页a-1', '访问量': 10000 }, | ||
{ '页面': '内容页a-2', '访问量': 10000 }, | ||
{ '页面': '内容页b-1', '访问量': 60000 }, | ||
{ '页面': '内容页b-2', '访问量': 20000 } | ||
] | ||
}, | ||
settings: { | ||
links: [ | ||
{ source: '首页', target: '列表页a', value: 0.1 }, | ||
{ source: '首页', target: '列表页b', value: 0.1 }, | ||
{ source: '列表页a', target: '内容页a-1', value: 0.1 }, | ||
{ source: '列表页a', target: '内容页a-2', value: 0.1 }, | ||
{ source: '列表页b', target: '内容页b-1', value: 0.1 }, | ||
{ source: '列表页b', target: '内容页b-2', value: 0.1 } | ||
], | ||
dataType: ['KMB', 'percent'] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import echarts from '../../echarts-base' | ||
import { sankey } from './main' | ||
import Core from '../../core' | ||
export default { | ||
name: 'VeSankey', | ||
mixins: [Core], | ||
created () { | ||
this.chartHandler = sankey | ||
this.echartsLib = echarts | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { getFormated } from '../../utils' | ||
import 'echarts/lib/chart/sankey' | ||
|
||
function getTooltip (args) { | ||
const { | ||
itemDataType, | ||
linksDataType, | ||
digit | ||
} = args | ||
return { | ||
trigger: 'item', | ||
formatter (item) { | ||
const { data, marker, value, name } = item | ||
return data && data.source | ||
? `${name}: ${getFormated(value, linksDataType, digit)}` | ||
: `${marker} ${name}: ${getFormated(value, itemDataType, digit)}` | ||
} | ||
} | ||
} | ||
|
||
function getSeries (args) { | ||
const { | ||
rows, | ||
dimension, | ||
metrics, | ||
links, | ||
valueFull | ||
} = args | ||
const dataMap = {} | ||
const seriesData = rows.map(row => { | ||
dataMap[row[dimension]] = row[metrics] | ||
return { name: row[dimension], value: row[metrics] } | ||
}) | ||
let innerLinks = null | ||
|
||
if (!valueFull) { | ||
innerLinks = links.map(link => { | ||
return link.value == null | ||
? Object.assign({ value: dataMap[link.target] }, link) | ||
: link | ||
}) | ||
} else { | ||
innerLinks = links | ||
} | ||
|
||
const result = { | ||
type: 'sankey', | ||
data: seriesData, | ||
links: innerLinks | ||
} | ||
return [result] | ||
} | ||
|
||
export const sankey = (columns, rows, settings, extra) => { | ||
const { | ||
links, | ||
dimension = columns[0], | ||
metrics = columns[1], | ||
dataType = ['normal', 'normal'], | ||
digit = 2, | ||
valueFull = false | ||
} = settings | ||
|
||
if (!links) { | ||
console.warn('links is needed in settings!') | ||
return | ||
} | ||
|
||
const itemDataType = dataType[0] | ||
const linksDataType = dataType[1] | ||
const tooltip = getTooltip({ | ||
itemDataType, | ||
linksDataType, | ||
digit | ||
}) | ||
const series = getSeries({ | ||
rows, | ||
dimension, | ||
metrics, | ||
links, | ||
valueFull | ||
}) | ||
return { tooltip, series } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters