mirror of
https://github.com/TBEDP/datavjs.git
synced 2025-12-08 19:45:52 +00:00
Update tree
This commit is contained in:
parent
6997fcef98
commit
5cc1abb3f5
@ -1,4 +1,7 @@
|
||||
/*global EventProxy, d3, Raphael, $ */
|
||||
/*!
|
||||
* Tree的兼容性定义
|
||||
*/
|
||||
;(function (name, definition) {
|
||||
if (typeof define === 'function') {
|
||||
define(definition);
|
||||
@ -9,6 +12,18 @@
|
||||
var DataV = require('DataV');
|
||||
var theme = DataV.Themes;
|
||||
|
||||
/**
|
||||
* Tree的构造函数
|
||||
* Examples:
|
||||
* ```
|
||||
* var tree = new Tree("container");
|
||||
* tree.setSource(source);
|
||||
* tree.render();
|
||||
* ```
|
||||
* Options:
|
||||
* - `width`: 画布的宽度
|
||||
* - `height`: 画布的高度
|
||||
*/
|
||||
var Tree = DataV.extend(DataV.Chart, {
|
||||
initialize: function (node, options) {
|
||||
this.type = "Tree";
|
||||
@ -31,6 +46,25 @@
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 饼图纬度描述
|
||||
*/
|
||||
Tree.dimension = {};
|
||||
/**
|
||||
* ID标签
|
||||
*/
|
||||
Tree.dimension.id = {
|
||||
type: "string",
|
||||
required: true
|
||||
};
|
||||
/**
|
||||
* 父ID标签
|
||||
*/
|
||||
Tree.dimension.pid = {
|
||||
type: "string",
|
||||
required: true
|
||||
};
|
||||
|
||||
Tree.prototype.hierarchyTableToJson = function (table) {
|
||||
if (table[0][0] === "ID") {
|
||||
table = table.slice(1);
|
||||
@ -39,6 +73,14 @@
|
||||
var rootID;
|
||||
var hierarchy = {};
|
||||
var addlink = {}; //for multi-fathernode
|
||||
// var ids = _.pluck(table, 0);
|
||||
// var pids = _.pluck(table, 3);
|
||||
// var roots = _.difference(pids, ids);
|
||||
// if (roots.length === 0) {
|
||||
// throw new Error("root node is empty");
|
||||
// } else if (roots.length > 1) {
|
||||
// throw new Error("root nodes are too many");
|
||||
// }
|
||||
|
||||
table.forEach(function (d, i) {
|
||||
if (d[0] === "") {
|
||||
@ -74,13 +116,13 @@
|
||||
table.forEach(function (d, i) {
|
||||
if (d[3]) {
|
||||
var record;
|
||||
var ids = d[3].split('.');
|
||||
var ids = d[3].split(',');
|
||||
if (ids.length === 1) {
|
||||
record = hierarchy[d[3]];
|
||||
record.child.push(d[0]);
|
||||
} else {
|
||||
record = hierarchy[ids[0]];
|
||||
record.child.push(d[0]);
|
||||
record.child.push(d[0]);
|
||||
addlink[d[0]] = {child: [], path: [], pnode: []};
|
||||
|
||||
var j, length;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user