Cartesian2D.js 1.3 KB
Newer Older
L
lang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
define(function(require) {

    'use strict';

    var zrUtil = require('zrender/core/util');
    var Cartesian = require('./Cartesian');

    function Cartesian2D(name) {

        Cartesian.call(this, name);
    }

    Cartesian2D.prototype = {

        type: 'cartesian2d',

        /**
         * Convert series data to coorindates
         * @param {module:echarts/data/List} data
         * @return {Array}
         *  Return list of coordinates. For example:
         *  `[[10, 10], [20, 20], [30, 30]]`
         */
        dataToCoords: function (data) {
            var xAxis = this.getAxis('x');
            var yAxis = this.getAxis('y');

            var xIndex = xAxis.isHorizontal() ? 0 : 1;
L
lang 已提交
29

30 31
            return data.map(function (dataItem) {
                var coord = [];
L
lang 已提交
32 33
                coord[xIndex] = xAxis.dataToCoord(dataItem.getX(true));
                coord[1 - xIndex] = yAxis.dataToCoord(dataItem.getY(true));
34 35
                return coord;
            }, this);
L
lang 已提交
36 37 38 39 40 41 42 43
        },

        /**
         * Get other axis
         * @param {module:echarts/coord/cartesian/Axis2D} axis
         */
        getOtherAxis: function (axis) {
            return this.getAxis(axis.dim === 'x' ? 'y' : 'x');
L
lang 已提交
44 45 46 47 48 49 50
        }
    };

    zrUtil.inherits(Cartesian2D, Cartesian);

    return Cartesian2D;
});