treemapAction.js 1.1 KB
Newer Older
P
pah100 已提交
1 2 3 4
/**
 * @file Treemap action
 */

S
sushuang 已提交
5 6
import echarts from '../../echarts';
import helper from './helper';
P
pah100 已提交
7

S
sushuang 已提交
8
var noop = function () {};
P
pah100 已提交
9

S
sushuang 已提交
10 11 12 13 14
var actionTypes = [
    'treemapZoomToNode',
    'treemapRender',
    'treemapMove'
];
P
pah100 已提交
15

S
sushuang 已提交
16 17 18 19 20 21 22 23 24 25 26 27
for (var i = 0; i < actionTypes.length; i++) {
    echarts.registerAction({type: actionTypes[i], update: 'updateView'}, noop);
}

echarts.registerAction(
    {type: 'treemapRootToNode', update: 'updateView'},
    function (payload, ecModel) {

        ecModel.eachComponent(
            {mainType: 'series', subType: 'treemap', query: payload},
            handleRootToNode
        );
P
pah100 已提交
28

S
sushuang 已提交
29 30 31 32 33 34 35 36
        function handleRootToNode(model, index) {
            var targetInfo = helper.retrieveTargetInfo(payload, model);

            if (targetInfo) {
                var originViewRoot = model.getViewRoot();
                if (originViewRoot) {
                    payload.direction = helper.aboveViewRoot(originViewRoot, targetInfo.node)
                        ? 'rollUp' : 'drillDown';
P
pah100 已提交
37
                }
S
sushuang 已提交
38
                model.resetViewRoot(targetInfo.node);
P
pah100 已提交
39
            }
P
pah100 已提交
40
        }
S
sushuang 已提交
41 42
    }
);