LineView.js 4.4 KB
Newer Older
L
lang 已提交
1 2 3 4
define(function(require) {

    'use strict';

L
lang 已提交
5
    var zrUtil = require('zrender/core/util');
L
lang 已提交
6
    var DataSymbol = require('../helper/DataSymbol');
L
lang 已提交
7

L
lang 已提交
8 9 10 11
    return require('../../echarts').extendChartView({

        type: 'line',

L
lang 已提交
12 13 14 15
        init: function () {
            this._dataSymbol = new DataSymbol();
            this.group.add(this._dataSymbol.group);
        },
L
lang 已提交
16

L
lang 已提交
17 18
        render: function (seriesModel, ecModel, api) {
            var group = this.group;
L
lang 已提交
19 20 21
            var data = seriesModel.getData();
            var lineStyleNormalModel = seriesModel.getModel('itemStyle.normal.lineStyle');

L
lang 已提交
22 23 24 25 26 27
            var points = data.map(function (dataItem) {
                var layout = dataItem.layout;
                if (layout) {
                    return [layout.x, layout.y];
                }
            });
L
lang 已提交
28 29 30
            var coordinateSystem = seriesModel.coordinateSystem;
            var isCoordinateSystemPolar = coordinateSystem.type === 'polar';

L
lang 已提交
31 32 33 34 35 36 37 38
            if (
                isCoordinateSystemPolar
                && points.length > 2
                && coordinateSystem.getAngleAxis().type === 'category'
            ) {
                // Close polyline
                points.push(Array.prototype.slice.call(points[0]));
            }
L
lang 已提交
39

L
lang 已提交
40
            // Initialization animation
L
lang 已提交
41
            if (!this._data) {
L
lang 已提交
42 43 44 45
                var polyline = new api.Polyline({
                    shape: {
                        points: points
                    },
L
tweak  
lang 已提交
46
                    style: zrUtil.extend(
L
lang 已提交
47 48 49
                        lineStyleNormalModel.getLineStyle(),
                        {
                            stroke: seriesModel.getVisual('color')
L
tweak  
lang 已提交
50
                        }
L
lang 已提交
51
                    )
L
lang 已提交
52
                });
L
lang 已提交
53

54 55 56 57 58 59 60 61
                var removeClipPath = zrUtil.bind(polyline.removeClipPath, polyline);

                var clipPath = isCoordinateSystemPolar
                    ? this._createPolarClipShape(coordinateSystem, api, removeClipPath)
                    : this._createGridClipShape(coordinateSystem, api, removeClipPath);

                polyline.setClipPath(clipPath);

L
lang 已提交
62
                group.add(polyline);
L
lang 已提交
63 64 65 66

                this._polyline = polyline;
            }
            else {
L
lang 已提交
67
                // FIXME Handle the situation of adding and removing data
L
lang 已提交
68 69 70 71 72 73 74
                this._polyline.animateTo({
                    shape: {
                        points: points
                    }
                }, 500, 'cubicOut');
                // this._polyline.shape.points = points;
                // this._polyline.dirty(true);
L
lang 已提交
75 76

                // Add back
L
lang 已提交
77
                group.add(this._polyline);
L
lang 已提交
78 79
            }

L
lang 已提交
80 81 82 83
            var dataSymbol = this._dataSymbol;
            dataSymbol.z = seriesModel.get('z') + 1;
            // Draw symbols
            dataSymbol.updateData(data);
L
tweak  
lang 已提交
84

L
lang 已提交
85
            this._data = data;
L
lang 已提交
86 87
        },

L
lang 已提交
88
        _createGridClipShape: function (cartesian, api, cb) {
L
lang 已提交
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
            var xAxis = cartesian.getAxis('x');
            var yAxis = cartesian.getAxis('y');
            var xExtent = xAxis.getExtent();
            var yExtent = yAxis.getExtent();

            var clipPath = new api.Rect({
                shape: {
                    x: xExtent[0],
                    y: yExtent[0],
                    width: 0,
                    height: yExtent[1] - yExtent[0]
                }
            });

            clipPath.animateTo({
                shape: {
                    x: xExtent[0],
                    y: yExtent[0],
                    width: xExtent[1] - xExtent[0],
                    height: yExtent[1] - yExtent[0]
                }
L
lang 已提交
110
            }, 1500, cb);
L
lang 已提交
111 112 113 114

            return clipPath;
        },

L
lang 已提交
115
        _createPolarClipShape: function (polar, api, cb) {
L
lang 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
            // var angleAxis = polar.getAngleAxis();
            var radiusAxis = polar.getRadiusAxis();

            var radiusExtent = radiusAxis.getExtent();

            var clipPath = new api.Sector({
                shape: {
                    cx: polar.cx,
                    cy: polar.cy,
                    r0: radiusExtent[0],
                    r: radiusExtent[1],
                    startAngle: 0,
                    endAngle: 0
                }
            });

            clipPath.animateTo({
                shape: {
                    endAngle: Math.PI * 2
                }
L
lang 已提交
136
            }, 1500, cb);
L
lang 已提交
137 138

            return clipPath;
L
lang 已提交
139 140 141 142 143
        },

        remove: function () {
            this.group.remove(this._polyline);
            this._dataSymbol.remove();
L
lang 已提交
144 145 146
        }
    });
});