TreeView.js 22.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/

S
sushuang 已提交
20
import * as zrUtil from 'zrender/src/core/util';
S
sushuang 已提交
21
import * as graphic from '../../util/graphic';
S
sushuang 已提交
22 23
import SymbolClz from '../helper/Symbol';
import {radialCoordinate} from './layoutHelper';
S
sushuang 已提交
24
import * as echarts from '../../echarts';
P
pissang 已提交
25 26 27 28 29
import * as bbox from 'zrender/src/core/bbox';
import View from '../../coord/View';
import * as roamHelper from '../../component/helper/roamHelper';
import RoamController from '../../component/helper/RoamController';
import {onIrrelevantElement} from '../../component/helper/cursorHelper';
30
import { __DEV__ } from '../../config';
D
deqingli 已提交
31

32 33 34 35
var TreeShape = graphic.extendShape({
    shape: {
        parentPoint: [],
        childPoints: [],
36 37
        orient: '',
        splitLocation: 0
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    },

    buildPath: function (ctx, shape) {
        var ptMin = [Infinity, Infinity];
        var ptMax = [-Infinity, -Infinity];
        var points = shape.childPoints;
        for (var i = 0; i < points.length; i++) {
            var pt = points[i];
            if (pt[0] < ptMin[0]) {
                ptMin[0] = pt[0];
            }
            if (pt[0] > ptMax[0]) {
                ptMax[0] = pt[0];
            }
            if (pt[1] < ptMin[1]) {
                ptMin[1] = pt[1];
            }
            if (pt[1] > ptMax[1]) {
                ptMax[1] = pt[1];
            }
        }
        var parentPoint = shape.parentPoint;
        var orient = shape.orient;
61 62
        var location = shape.splitLocation;
        var midPoint = computeMidPoints(parentPoint, orient, ptMax, location);
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

         ctx.moveTo(parentPoint[0], parentPoint[1]);
         ctx.lineTo(midPoint[0], midPoint[1]);
         if (orient === 'TB' || orient === 'BT') {
             ctx.moveTo(ptMin[0], midPoint[1]);
             ctx.lineTo(ptMax[0], midPoint[1]);
         }
         else if (orient === 'LR' || orient === 'RL') {
             ctx.moveTo(midPoint[0], ptMin[1]);
             ctx.lineTo(midPoint[0], ptMax[1]);
         }
         for (var i = 0; i < points.length; i++) {
             var point = points[i];
             ctx.moveTo(point[0], point[1]);
             if (orient === 'TB' || orient === 'BT') {
                 ctx.lineTo(point[0], midPoint[1]);
             }
             else if (orient === 'LR' || orient === 'RL') {
                 ctx.lineTo(midPoint[0], point[1]);
             }
         }
    }
});

87
function computeMidPoints(parentPoint, orient, ptMax, location) {
88 89 90 91
    var midPoint = [];
    switch (orient) {
        case 'TB':
            midPoint[0] = parentPoint[0];
92
            midPoint[1] = parentPoint[1] + (ptMax[1] - parentPoint[1]) * location;
93 94 95
            break;
        case 'BT':
            midPoint[0] = parentPoint[0];
96
            midPoint[1] = ptMax[1] + (parentPoint[1] - ptMax[1]) * (1 - location);
97 98
            break;
        case 'LR':
99
            midPoint[0] = parentPoint[0] + (ptMax[0] - parentPoint[0]) * location;
100 101 102
            midPoint[1] = parentPoint[1];
            break;
        case 'RL':
103
            midPoint[0] = ptMax[0] + (parentPoint[0] - ptMax[0]) * (1 - location);
104 105 106 107 108
            midPoint[1] = parentPoint[1];
    }
    return midPoint;
}

S
sushuang 已提交
109
export default echarts.extendChartView({
D
deqingli 已提交
110

S
sushuang 已提交
111
    type: 'tree',
D
deqingli 已提交
112

S
sushuang 已提交
113 114 115 116 117 118 119
    /**
     * Init the chart
     * @override
     * @param  {module:echarts/model/Global} ecModel
     * @param  {module:echarts/ExtensionAPI} api
     */
    init: function (ecModel, api) {
D
deqingli 已提交
120

D
deqingli 已提交
121
        /**
S
sushuang 已提交
122 123
         * @private
         * @type {module:echarts/data/Tree}
D
deqingli 已提交
124
         */
S
sushuang 已提交
125
        this._oldTree;
D
deqingli 已提交
126

S
sushuang 已提交
127 128 129 130 131
        /**
         * @private
         * @type {module:zrender/container/Group}
         */
        this._mainGroup = new graphic.Group();
D
deqingli 已提交
132

D
deqingli 已提交
133 134 135 136
        /**
         * @private
         * @type {module:echarts/componet/helper/RoamController}
         */
P
pissang 已提交
137
        this._controller = new RoamController(api.getZr());
D
deqingli 已提交
138

P
pissang 已提交
139
        this._controllerHost = {target: this.group};
D
deqingli 已提交
140 141

        this.group.add(this._mainGroup);
S
sushuang 已提交
142
    },
D
deqingli 已提交
143

S
sushuang 已提交
144 145
    render: function (seriesModel, ecModel, api, payload) {
        var data = seriesModel.getData();
D
deqingli 已提交
146

S
sushuang 已提交
147
        var layoutInfo = seriesModel.layoutInfo;
D
deqingli 已提交
148

S
sushuang 已提交
149
        var group = this._mainGroup;
D
deqingli 已提交
150

S
sushuang 已提交
151
        var layout = seriesModel.get('layout');
D
deqingli 已提交
152

S
sushuang 已提交
153 154 155 156 157 158
        if (layout === 'radial') {
            group.attr('position', [layoutInfo.x + layoutInfo.width / 2, layoutInfo.y + layoutInfo.height / 2]);
        }
        else {
            group.attr('position', [layoutInfo.x, layoutInfo.y]);
        }
D
deqingli 已提交
159

160
        this._updateViewCoordSys(seriesModel, layoutInfo, layout);
P
pissang 已提交
161 162
        this._updateController(seriesModel, ecModel, api);

S
sushuang 已提交
163 164 165 166 167
        var oldData = this._data;

        var seriesScope = {
            expandAndCollapse: seriesModel.get('expandAndCollapse'),
            layout: layout,
168
            edgeShape: seriesModel.get('edgeShape'),
169
            edgeSplitLocation: seriesModel.get('edgeSplitLocation'),
170
            orient: seriesModel.getOrient(),
171
            curvature: seriesModel.get('lineStyle.curveness'),
S
sushuang 已提交
172 173 174 175 176 177 178 179 180 181
            symbolRotate: seriesModel.get('symbolRotate'),
            symbolOffset: seriesModel.get('symbolOffset'),
            hoverAnimation: seriesModel.get('hoverAnimation'),
            useNameLabel: true,
            fadeIn: true
        };

        data.diff(oldData)
            .add(function (newIdx) {
                if (symbolNeedsDraw(data, newIdx)) {
D
deqingli 已提交
182
                    // Create node and edge
S
sushuang 已提交
183 184 185 186 187 188
                    updateNode(data, newIdx, null, group, seriesModel, seriesScope);
                }
            })
            .update(function (newIdx, oldIdx) {
                var symbolEl = oldData.getItemGraphicEl(oldIdx);
                if (!symbolNeedsDraw(data, newIdx)) {
189
                    symbolEl && removeNode(oldData, oldIdx, symbolEl, group, seriesModel, seriesScope);
S
sushuang 已提交
190 191
                    return;
                }
D
deqingli 已提交
192
                // Update node and edge
S
sushuang 已提交
193 194 195 196
                updateNode(data, newIdx, symbolEl, group, seriesModel, seriesScope);
            })
            .remove(function (oldIdx) {
                var symbolEl = oldData.getItemGraphicEl(oldIdx);
197 198 199 200 201 202 203 204
                // When remove a collapsed node of subtree, since the collapsed
                // node haven't been initialized with a symbol element,
                // you can't found it's symbol element through index.
                // so if we want to remove the symbol element we should insure
                // that the symbol element is not null.
                if (symbolEl) {
                    removeNode(oldData, oldIdx, symbolEl, group, seriesModel, seriesScope);
                }
S
sushuang 已提交
205 206 207
            })
            .execute();

P
pissang 已提交
208 209 210 211
        this._nodeScaleRatio = seriesModel.get('nodeScaleRatio');

        this._updateNodeAndLinkScale(seriesModel);

S
sushuang 已提交
212 213 214 215 216 217 218
        if (seriesScope.expandAndCollapse === true) {
            data.eachItemGraphicEl(function (el, dataIndex) {
                el.off('click').on('click', function () {
                    api.dispatchAction({
                        type: 'treeExpandAndCollapse',
                        seriesId: seriesModel.id,
                        dataIndex: dataIndex
D
deqingli 已提交
219
                    });
D
deqingli 已提交
220
                });
S
sushuang 已提交
221 222 223 224
            });
        }
        this._data = data;
    },
D
deqingli 已提交
225

226
    _updateViewCoordSys: function (seriesModel) {
P
pissang 已提交
227
        var data = seriesModel.getData();
228 229 230 231 232 233
        var points = [];
        data.each(function (idx) {
            var layout = data.getItemLayout(idx);
            if (layout && !isNaN(layout.x) && !isNaN(layout.y)) {
                points.push([+layout.x, +layout.y]);
            }
P
pissang 已提交
234 235 236 237
        });
        var min = [];
        var max = [];
        bbox.fromPoints(points, min, max);
238

D
deqingli 已提交
239
        // If don't Store min max when collapse the root node after roam,
240
        // the root node will disappear.
241 242 243
        var oldMin = this._min;
        var oldMax = this._max;

P
pissang 已提交
244 245
        // If width or height is 0
        if (max[0] - min[0] === 0) {
246 247
            min[0] = oldMin ? oldMin[0] : min[0] - 1;
            max[0] = oldMax ? oldMax[0] : max[0] + 1;
P
pissang 已提交
248 249
        }
        if (max[1] - min[1] === 0) {
250 251
            min[1] = oldMin ? oldMin[1] : min[1] - 1;
            max[1] = oldMax ? oldMax[1] : max[1] + 1;
P
pissang 已提交
252 253 254 255 256 257 258 259 260 261
        }

        var viewCoordSys = seriesModel.coordinateSystem = new View();
        viewCoordSys.zoomLimit = seriesModel.get('scaleLimit');

        viewCoordSys.setBoundingRect(min[0], min[1], max[0] - min[0], max[1] - min[1]);

        viewCoordSys.setCenter(seriesModel.get('center'));
        viewCoordSys.setZoom(seriesModel.get('zoom'));

D
deqingli 已提交
262
        // Here we use viewCoordSys just for computing the 'position' and 'scale' of the group
263 264 265 266 267
        this.group.attr({
            position: viewCoordSys.position,
            scale: viewCoordSys.scale
        });

P
pissang 已提交
268
        this._viewCoordSys = viewCoordSys;
269 270
        this._min = min;
        this._max = max;
P
pissang 已提交
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
    },

    _updateController: function (seriesModel, ecModel, api) {
        var controller = this._controller;
        var controllerHost = this._controllerHost;
        var group = this.group;
        controller.setPointerChecker(function (e, x, y) {
            var rect = group.getBoundingRect();
            rect.applyTransform(group.transform);
            return rect.contain(x, y)
                && !onIrrelevantElement(e, api, seriesModel);
        });

        controller.enable(seriesModel.get('roam'));
        controllerHost.zoomLimit = seriesModel.get('scaleLimit');
        controllerHost.zoom = seriesModel.coordinateSystem.getZoom();

D
deqingli 已提交
288 289 290
        controller
            .off('pan')
            .off('zoom')
291 292
            .on('pan', function (e) {
                roamHelper.updateViewOnPan(controllerHost, e.dx, e.dy);
P
pissang 已提交
293 294 295
                api.dispatchAction({
                    seriesId: seriesModel.id,
                    type: 'treeRoam',
296 297
                    dx: e.dx,
                    dy: e.dy
P
pissang 已提交
298 299
                });
            }, this)
300 301
            .on('zoom', function (e) {
                roamHelper.updateViewOnZoom(controllerHost, e.scale, e.originX, e.originY);
P
pissang 已提交
302 303 304
                api.dispatchAction({
                    seriesId: seriesModel.id,
                    type: 'treeRoam',
305 306 307
                    zoom: e.scale,
                    originX: e.originX,
                    originY: e.originY
P
pissang 已提交
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
                });
                this._updateNodeAndLinkScale(seriesModel);
            }, this);
    },

    _updateNodeAndLinkScale: function (seriesModel) {
        var data = seriesModel.getData();

        var nodeScale = this._getNodeGlobalScale(seriesModel);
        var invScale = [nodeScale, nodeScale];

        data.eachItemGraphicEl(function (el, idx) {
            el.attr('scale', invScale);
        });
    },

    _getNodeGlobalScale: function (seriesModel) {
        var coordSys = seriesModel.coordinateSystem;
        if (coordSys.type !== 'view') {
            return 1;
        }

        var nodeScaleRatio = this._nodeScaleRatio;

        var groupScale = coordSys.scale;
        var groupZoom = (groupScale && groupScale[0]) || 1;
        // Scale node when zoom changes
        var roamZoom = coordSys.getZoom();
        var nodeScale = (roamZoom - 1) * nodeScaleRatio + 1;

        return nodeScale / groupZoom;
    },

    dispose: function () {
        this._controller && this._controller.dispose();
        this._controllerHost = {};
    },
D
deqingli 已提交
345

S
sushuang 已提交
346 347 348 349
    remove: function () {
        this._mainGroup.removeAll();
        this._data = null;
    }
D
deqingli 已提交
350

S
sushuang 已提交
351
});
D
deqingli 已提交
352

S
sushuang 已提交
353 354
function symbolNeedsDraw(data, dataIndex) {
    var layout = data.getItemLayout(dataIndex);
D
deqingli 已提交
355

S
sushuang 已提交
356 357 358 359
    return layout
        && !isNaN(layout.x) && !isNaN(layout.y)
        && data.getItemVisual(dataIndex, 'symbol') !== 'none';
}
D
deqingli 已提交
360

S
sushuang 已提交
361 362
function getTreeNodeStyle(node, itemModel, seriesScope) {
    seriesScope.itemModel = itemModel;
363 364 365 366 367
    seriesScope.itemStyle = itemModel.getModel('itemStyle').getItemStyle();
    seriesScope.hoverItemStyle = itemModel.getModel('emphasis.itemStyle').getItemStyle();
    seriesScope.lineStyle = itemModel.getModel('lineStyle').getLineStyle();
    seriesScope.labelModel = itemModel.getModel('label');
    seriesScope.hoverLabelModel = itemModel.getModel('emphasis.label');
D
deqingli 已提交
368

S
sushuang 已提交
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
    if (node.isExpand === false && node.children.length !== 0) {
        seriesScope.symbolInnerColor = seriesScope.itemStyle.fill;
    }
    else {
        seriesScope.symbolInnerColor = '#fff';
    }

    return seriesScope;
}

function updateNode(data, dataIndex, symbolEl, group, seriesModel, seriesScope) {
    var isInit = !symbolEl;
    var node = data.tree.getNodeByDataIndex(dataIndex);
    var itemModel = node.getModel();
    var seriesScope = getTreeNodeStyle(node, itemModel, seriesScope);
    var virtualRoot = data.tree.root;

    var source = node.parentNode === virtualRoot ? node : node.parentNode || node;
    var sourceSymbolEl = data.getItemGraphicEl(source.dataIndex);
    var sourceLayout = source.getLayout();
    var sourceOldLayout = sourceSymbolEl
        ? {
            x: sourceSymbolEl.position[0],
            y: sourceSymbolEl.position[1],
            rawX: sourceSymbolEl.__radialOldRawX,
            rawY: sourceSymbolEl.__radialOldRawY
D
deqingli 已提交
395
        }
S
sushuang 已提交
396 397
        : sourceLayout;
    var targetLayout = node.getLayout();
D
deqingli 已提交
398

S
sushuang 已提交
399 400 401 402 403 404
    if (isInit) {
        symbolEl = new SymbolClz(data, dataIndex, seriesScope);
        symbolEl.attr('position', [sourceOldLayout.x, sourceOldLayout.y]);
    }
    else {
        symbolEl.updateData(data, dataIndex, seriesScope);
D
deqingli 已提交
405 406
    }

S
sushuang 已提交
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
    symbolEl.__radialOldRawX = symbolEl.__radialRawX;
    symbolEl.__radialOldRawY = symbolEl.__radialRawY;
    symbolEl.__radialRawX = targetLayout.rawX;
    symbolEl.__radialRawY = targetLayout.rawY;

    group.add(symbolEl);
    data.setItemGraphicEl(dataIndex, symbolEl);
    graphic.updateProps(symbolEl, {
        position: [targetLayout.x, targetLayout.y]
    }, seriesModel);

    var symbolPath = symbolEl.getSymbolPath();

    if (seriesScope.layout === 'radial') {
        var realRoot = virtualRoot.children[0];
        var rootLayout = realRoot.getLayout();
        var length = realRoot.children.length;
        var rad;
        var isLeft;

        if (targetLayout.x === rootLayout.x && node.isExpand === true) {
            var center = {};
            center.x = (realRoot.children[0].getLayout().x + realRoot.children[length - 1].getLayout().x) / 2;
            center.y = (realRoot.children[0].getLayout().y + realRoot.children[length - 1].getLayout().y) / 2;
            rad = Math.atan2(center.y - rootLayout.y, center.x - rootLayout.x);
            if (rad < 0) {
                rad = Math.PI * 2 + rad;
            }
            isLeft = center.x < rootLayout.x;
            if (isLeft) {
                rad = rad - Math.PI;
D
deqingli 已提交
438
            }
S
sushuang 已提交
439 440
        }
        else {
S
sushuang 已提交
441 442 443 444 445 446
            rad = Math.atan2(targetLayout.y - rootLayout.y, targetLayout.x - rootLayout.x);
            if (rad < 0) {
                rad = Math.PI * 2 + rad;
            }
            if (node.children.length === 0 || (node.children.length !== 0 && node.isExpand === false)) {
                isLeft = targetLayout.x < rootLayout.x;
447 448 449 450 451
                if (isLeft) {
                    rad = rad - Math.PI;
                }
            }
            else {
S
sushuang 已提交
452 453 454
                isLeft = targetLayout.x > rootLayout.x;
                if (!isLeft) {
                    rad = rad - Math.PI;
455 456
                }
            }
S
sushuang 已提交
457 458 459
        }

        var textPosition = isLeft ? 'left' : 'right';
D
deqingli 已提交
460 461 462
        var rotate = seriesScope.labelModel.get('rotate');
        var labelRotateRadian = rotate * (Math.PI / 180);

S
sushuang 已提交
463
        symbolPath.setStyle({
D
deqingli 已提交
464 465
            textPosition: seriesScope.labelModel.get('position') || textPosition,
            textRotation: rotate == null ? -rad : labelRotateRadian,
S
sushuang 已提交
466 467 468 469
            textOrigin: 'center',
            verticalAlign: 'middle'
        });
    }
D
deqingli 已提交
470

471
    drawEdge(
472 473
        seriesModel, node, virtualRoot, symbolEl, sourceOldLayout,
        sourceLayout, targetLayout, group, seriesScope
474 475 476 477 478
    );

}

function drawEdge(
479 480
    seriesModel, node, virtualRoot, symbolEl, sourceOldLayout,
    sourceLayout, targetLayout, group, seriesScope
481
    ) {
482
        var edgeShape = seriesScope.edgeShape;
S
sushuang 已提交
483
        var edge = symbolEl.__edge;
484
        if (edgeShape === 'curve') {
485 486 487 488 489 490 491
            if (node.parentNode && node.parentNode !== virtualRoot) {
                if (!edge) {
                    edge = symbolEl.__edge = new graphic.BezierCurve({
                        shape: getEdgeShape(seriesScope, sourceOldLayout, sourceOldLayout),
                        style: zrUtil.defaults({opacity: 0, strokeNoScale: true}, seriesScope.lineStyle)
                    });
                }
492

493 494 495 496 497 498
                graphic.updateProps(edge, {
                    shape: getEdgeShape(seriesScope, sourceLayout, targetLayout),
                    style: {opacity: 1}
                }, seriesModel);
            }
        }
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
        else if (edgeShape === 'polyline') {
            if (seriesScope.layout === 'orthogonal') {
                if (node !== virtualRoot && node.children && (node.children.length !== 0) && (node.isExpand === true)) {
                    var children = node.children;
                    var childPoints = [];
                    for (var i = 0; i < children.length; i++) {
                        var childLayout = children[i].getLayout();
                        childPoints.push([childLayout.x, childLayout.y]);
                    }

                    if (!edge) {
                        edge = symbolEl.__edge = new TreeShape({
                            shape: {
                                parentPoint: [targetLayout.x, targetLayout.y],
                                childPoints: [[targetLayout.x, targetLayout.y]],
514 515
                                orient: seriesScope.orient,
                                splitLocation: seriesScope.edgeSplitLocation
516 517 518 519 520
                            },
                            style: zrUtil.defaults({opacity: 0, strokeNoScale: true}, seriesScope.lineStyle)
                        });
                    }
                    graphic.updateProps(edge, {
521 522
                        shape: {
                            parentPoint: [targetLayout.x, targetLayout.y],
523
                            childPoints: childPoints
524
                        },
525 526 527 528 529 530 531
                        style: {opacity: 1}
                    }, seriesModel);
                }
            }
            else {
                if (__DEV__) {
                    throw new Error('The polyline edgeShape can only be used in orthogonal layout');
532 533 534
                }
            }
        }
S
sushuang 已提交
535 536 537 538 539 540 541 542 543 544
        group.add(edge);
}

function removeNode(data, dataIndex, symbolEl, group, seriesModel, seriesScope) {
    var node = data.tree.getNodeByDataIndex(dataIndex);
    var virtualRoot = data.tree.root;
    var itemModel = node.getModel();
    var seriesScope = getTreeNodeStyle(node, itemModel, seriesScope);

    var source = node.parentNode === virtualRoot ? node : node.parentNode || node;
545
    var edgeShape = seriesScope.edgeShape;
S
sushuang 已提交
546 547 548
    var sourceLayout;
    while (sourceLayout = source.getLayout(), sourceLayout == null) {
        source = source.parentNode === virtualRoot ? source : source.parentNode || source;
D
deqingli 已提交
549
    }
D
deqingli 已提交
550

S
sushuang 已提交
551 552 553 554 555 556
    graphic.updateProps(symbolEl, {
        position: [sourceLayout.x + 1, sourceLayout.y + 1]
    }, seriesModel, function () {
        group.remove(symbolEl);
        data.setItemGraphicEl(dataIndex, null);
    });
D
deqingli 已提交
557

S
sushuang 已提交
558
    symbolEl.fadeOut(null, {keepLabel: true});
D
deqingli 已提交
559

560 561 562
    var sourceSymbolEl = data.getItemGraphicEl(source.dataIndex);
    var sourceEdge = sourceSymbolEl.__edge;
    var edge = symbolEl.__edge || (source.isExpand === false ? sourceEdge : undefined);
563
    var edgeShape = seriesScope.edgeShape;
564

S
sushuang 已提交
565
    if (edge) {
566
        if (edgeShape === 'curve') {
567 568 569 570 571 572 573 574 575
            graphic.updateProps(edge, {
                shape: getEdgeShape(seriesScope, sourceLayout, sourceLayout),
                style: {
                    opacity: 0
                }
            }, seriesModel, function () {
                group.remove(edge);
            });
        }
576
        else if (edgeShape === 'polyline' && seriesScope.layout === 'orthogonal') {
577 578 579
            graphic.updateProps(edge, {
                shape: {
                    parentPoint: [sourceLayout.x, sourceLayout.y],
580
                    childPoints: [[sourceLayout.x, sourceLayout.y]]
581 582 583 584 585 586 587 588 589
                },
                style: {
                    opacity: 0
                }
            }, seriesModel, function () {
                group.remove(edge);
            });
        }
    }
S
sushuang 已提交
590 591 592 593 594 595 596 597
}

function getEdgeShape(seriesScope, sourceLayout, targetLayout) {
    var cpx1;
    var cpy1;
    var cpx2;
    var cpy2;
    var orient = seriesScope.orient;
D
deqingli 已提交
598 599 600 601
    var x1;
    var x2;
    var y1;
    var y2;
S
sushuang 已提交
602 603

    if (seriesScope.layout === 'radial') {
D
deqingli 已提交
604 605 606 607
        x1 = sourceLayout.rawX;
        y1 = sourceLayout.rawY;
        x2 = targetLayout.rawX;
        y2 = targetLayout.rawY;
S
sushuang 已提交
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624

        var radialCoor1 = radialCoordinate(x1, y1);
        var radialCoor2 = radialCoordinate(x1, y1 + (y2 - y1) * seriesScope.curvature);
        var radialCoor3 = radialCoordinate(x2, y2 + (y1 - y2) * seriesScope.curvature);
        var radialCoor4 = radialCoordinate(x2, y2);

        return {
            x1: radialCoor1.x,
            y1: radialCoor1.y,
            x2: radialCoor4.x,
            y2: radialCoor4.y,
            cpx1: radialCoor2.x,
            cpy1: radialCoor2.y,
            cpx2: radialCoor3.x,
            cpy2: radialCoor3.y
        };
    }
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
    else {
        x1 = sourceLayout.x;
        y1 = sourceLayout.y;
        x2 = targetLayout.x;
        y2 = targetLayout.y;

        if (orient === 'LR' || orient === 'RL') {
            cpx1 = x1 + (x2 - x1) * seriesScope.curvature;
            cpy1 = y1;
            cpx2 = x2 + (x1 - x2) * seriesScope.curvature;
            cpy2 = y2;
        }
        if (orient === 'TB' || orient === 'BT') {
            cpx1 = x1;
            cpy1 = y1 + (y2 - y1) * seriesScope.curvature;
            cpx2 = x2;
            cpy2 = y2 + (y1 - y2) * seriesScope.curvature;
        }
D
deqingli 已提交
643
    }
D
deqingli 已提交
644 645 646 647 648 649 650 651 652 653 654 655

    return {
        x1: x1,
        y1: y1,
        x2: x2,
        y2: y2,
        cpx1: cpx1,
        cpy1: cpy1,
        cpx2: cpx2,
        cpy2: cpy2
    };

S
sushuang 已提交
656
}