LineView.js 4.0 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 symbolCreator = require('../../util/symbol');
L
lang 已提交
7

L
lang 已提交
8 9 10 11 12 13 14 15 16
    return require('../../echarts').extendChartView({

        type: 'line',

        render: function (seriesModel, ecModel, api) {

            var data = seriesModel.getData();
            var lineStyleNormalModel = seriesModel.getModel('itemStyle.normal.lineStyle');

L
lang 已提交
17 18 19 20 21 22
            var points = data.map(function (dataItem) {
                var layout = dataItem.layout;
                if (layout) {
                    return [layout.x, layout.y];
                }
            });
L
lang 已提交
23 24 25
            var coordinateSystem = seriesModel.coordinateSystem;
            var isCoordinateSystemPolar = coordinateSystem.type === 'polar';

L
lang 已提交
26 27 28 29 30 31 32 33
            if (
                isCoordinateSystemPolar
                && points.length > 2
                && coordinateSystem.getAngleAxis().type === 'category'
            ) {
                // Close polyline
                points.push(Array.prototype.slice.call(points[0]));
            }
L
lang 已提交
34

L
lang 已提交
35
            // Initialization animation
L
lang 已提交
36
            if (!this._data) {
L
lang 已提交
37 38 39
                var clipPath = isCoordinateSystemPolar
                    ? this._createPolarClipShape(coordinateSystem, api)
                    : this._createGridClipShape(coordinateSystem, api);
L
lang 已提交
40 41 42 43 44 45 46

                this.group.setClipPath(clipPath);

                var polyline = new api.Polyline({
                    shape: {
                        points: points
                    },
L
lang 已提交
47 48 49 50 51 52 53
                    style: zrUtil.merge(
                        lineStyleNormalModel.getLineStyle(),
                        {
                            stroke: seriesModel.getVisual('color')
                        },
                        true, false
                    )
L
lang 已提交
54
                });
L
lang 已提交
55

L
lang 已提交
56
                this.group.add(polyline);
L
lang 已提交
57 58 59 60

                this._polyline = polyline;
            }
            else {
L
lang 已提交
61
                // FIXME Handle the situation of adding and removing data
P
pah100 已提交
62 63 64 65 66 67 68
                // this._polyline.animateShape()
                //     .when(500, {
                //         points: points
                //     })
                //     .start('cubicOut');
                this._polyline.shape.points = points;
                this._polyline.dirty(true);
L
lang 已提交
69 70 71

                // Add back
                this.group.add(this._polyline);
L
lang 已提交
72 73 74
            }

            this._data = data;
L
lang 已提交
75 76
        },

L
lang 已提交
77 78 79 80
        _drawSymbols: function (data) {

        },

L
lang 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
        _createGridClipShape: function (cartesian, api) {
            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]
                }
            }, 1500);

            return clipPath;
        },

        _createPolarClipShape: function (polar, api) {
            // 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
                }
            }, 1500);

            return clipPath;
L
lang 已提交
132 133 134
        }
    });
});