123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- var zrUtil = require("zrender/lib/core/util");
- var SeriesModel = require("../../model/Series");
- var Tree = require("../../data/Tree");
- var Model = require("../../model/Model");
- var _format = require("../../util/format");
- var encodeHTML = _format.encodeHTML;
- var addCommas = _format.addCommas;
- var _treeHelper = require("../helper/treeHelper");
- var wrapTreePathInfo = _treeHelper.wrapTreePathInfo;
- var _default = SeriesModel.extend({
- type: 'series.treemap',
- layoutMode: 'box',
- dependencies: ['grid', 'polar'],
- preventUsingHoverLayer: true,
-
- _viewRoot: null,
- defaultOption: {
-
- progressive: 0,
-
-
- left: 'center',
- top: 'middle',
- right: null,
- bottom: null,
- width: '80%',
- height: '80%',
- sort: true,
-
-
- clipWindow: 'origin',
-
- squareRatio: 0.5 * (1 + Math.sqrt(5)),
-
- leafDepth: null,
-
-
- drillDownIcon: '▶',
-
-
- zoomToNodeRatio: 0.32 * 0.32,
-
-
- roam: true,
-
- nodeClick: 'zoomToNode',
-
-
-
-
- animation: true,
- animationDurationUpdate: 900,
- animationEasing: 'quinticInOut',
- breadcrumb: {
- show: true,
- height: 22,
- left: 'center',
- top: 'bottom',
-
-
- emptyItemWidth: 25,
-
- itemStyle: {
- color: 'rgba(0,0,0,0.7)',
-
- borderColor: 'rgba(255,255,255,0.7)',
- borderWidth: 1,
- shadowColor: 'rgba(150,150,150,1)',
- shadowBlur: 3,
- shadowOffsetX: 0,
- shadowOffsetY: 0,
- textStyle: {
- color: '#fff'
- }
- },
- emphasis: {
- textStyle: {}
- }
- },
- label: {
- show: true,
-
- distance: 0,
- padding: 5,
- position: 'inside',
-
-
- color: '#fff',
- ellipsis: true
-
- },
- upperLabel: {
-
- show: false,
- position: [0, '50%'],
- height: 20,
-
- color: '#fff',
- ellipsis: true,
-
- verticalAlign: 'middle'
- },
- itemStyle: {
- color: null,
-
- colorAlpha: null,
-
- colorSaturation: null,
-
- borderWidth: 0,
- gapWidth: 0,
- borderColor: '#fff',
- borderColorSaturation: null
-
-
- },
- emphasis: {
- upperLabel: {
- show: true,
- position: [0, '50%'],
- color: '#fff',
- ellipsis: true,
- verticalAlign: 'middle'
- }
- },
- visualDimension: 0,
-
- visualMin: null,
- visualMax: null,
- color: [],
-
-
-
-
-
-
-
-
-
-
- colorAlpha: null,
-
- colorSaturation: null,
-
- colorMappingBy: 'index',
-
- visibleMin: 10,
-
-
- childrenVisibleMin: null,
-
-
-
-
-
- levels: []
-
-
-
-
-
-
-
-
- },
-
- getInitialData: function (option, ecModel) {
-
- var root = {
- name: option.name,
- children: option.data
- };
- completeTreeValue(root);
- var levels = option.levels || [];
-
-
-
- var designatedVisualItemStyle = this.designatedVisualItemStyle = {};
- var designatedVisualModel = new Model({
- itemStyle: designatedVisualItemStyle
- }, this, ecModel);
- levels = option.levels = setDefault(levels, ecModel);
- var levelModels = zrUtil.map(levels || [], function (levelDefine) {
- return new Model(levelDefine, designatedVisualModel, ecModel);
- }, this);
-
-
- var tree = Tree.createTree(root, this, beforeLink);
- function beforeLink(nodeData) {
- nodeData.wrapMethod('getItemModel', function (model, idx) {
- var node = tree.getNodeByDataIndex(idx);
- var levelModel = levelModels[node.depth];
- model.parentModel = levelModel || designatedVisualModel;
- return model;
- });
- }
- return tree.data;
- },
- optionUpdated: function () {
- this.resetViewRoot();
- },
-
- formatTooltip: function (dataIndex) {
- var data = this.getData();
- var value = this.getRawValue(dataIndex);
- var formattedValue = zrUtil.isArray(value) ? addCommas(value[0]) : addCommas(value);
- var name = data.getName(dataIndex);
- return encodeHTML(name + ': ' + formattedValue);
- },
-
- getDataParams: function (dataIndex) {
- var params = SeriesModel.prototype.getDataParams.apply(this, arguments);
- var node = this.getData().tree.getNodeByDataIndex(dataIndex);
- params.treePathInfo = wrapTreePathInfo(node, this);
- return params;
- },
-
- setLayoutInfo: function (layoutInfo) {
-
- this.layoutInfo = this.layoutInfo || {};
- zrUtil.extend(this.layoutInfo, layoutInfo);
- },
-
- mapIdToIndex: function (id) {
-
-
-
-
-
-
-
-
- var idIndexMap = this._idIndexMap;
- if (!idIndexMap) {
- idIndexMap = this._idIndexMap = zrUtil.createHashMap();
-
- this._idIndexMapCount = 0;
- }
- var index = idIndexMap.get(id);
- if (index == null) {
- idIndexMap.set(id, index = this._idIndexMapCount++);
- }
- return index;
- },
- getViewRoot: function () {
- return this._viewRoot;
- },
-
- resetViewRoot: function (viewRoot) {
- viewRoot ? this._viewRoot = viewRoot : viewRoot = this._viewRoot;
- var root = this.getRawData().tree.root;
- if (!viewRoot || viewRoot !== root && !root.contains(viewRoot)) {
- this._viewRoot = root;
- }
- }
- });
- function completeTreeValue(dataNode) {
-
-
-
- var sum = 0;
- zrUtil.each(dataNode.children, function (child) {
- completeTreeValue(child);
- var childValue = child.value;
- zrUtil.isArray(childValue) && (childValue = childValue[0]);
- sum += childValue;
- });
- var thisValue = dataNode.value;
- if (zrUtil.isArray(thisValue)) {
- thisValue = thisValue[0];
- }
- if (thisValue == null || isNaN(thisValue)) {
- thisValue = sum;
- }
- if (thisValue < 0) {
- thisValue = 0;
- }
- zrUtil.isArray(dataNode.value) ? dataNode.value[0] = thisValue : dataNode.value = thisValue;
- }
- function setDefault(levels, ecModel) {
- var globalColorList = ecModel.get('color');
- if (!globalColorList) {
- return;
- }
- levels = levels || [];
- var hasColorDefine;
- zrUtil.each(levels, function (levelDefine) {
- var model = new Model(levelDefine);
- var modelColor = model.get('color');
- if (model.get('itemStyle.color') || modelColor && modelColor !== 'none') {
- hasColorDefine = true;
- }
- });
- if (!hasColorDefine) {
- var level0 = levels[0] || (levels[0] = {});
- level0.color = globalColorList.slice();
- }
- return levels;
- }
- module.exports = _default;
|