markerHelper.js 3.0 KB
Newer Older
L
lang 已提交
1 2 3 4 5 6
define(function (require) {

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

    var markerTypeCalculatorWithExtent = function (percent, data, baseAxisDim, valueAxisDim) {
        var extent = data.getDataExtent(valueAxisDim);
L
lang 已提交
7
        var valueIndex = (valueAxisDim === 'angle' || valueAxisDim === 'x') ? 0 : 1;
L
lang 已提交
8 9 10 11 12 13 14 15 16 17
        var valueArr = [];
        var min = extent[0];
        var max = extent[1];
        var val = (max - min) * percent + min;
        var dataIndex = data.indexOfNearest(valueAxisDim, val);
        valueArr[1 - valueIndex] = data.get(baseAxisDim, dataIndex);
        valueArr[valueIndex] = data.get(valueAxisDim, dataIndex, true);
        return valueArr;
    };

L
tweak  
lang 已提交
18
    var curry = zrUtil.curry;
L
lang 已提交
19
    // TODO Specified percent
L
lang 已提交
20 21 22 23 24 25 26
    var markerTypeCalculator = {
        /**
         * @method
         * @param {module:echarts/data/List} data
         * @param {string} baseAxisDim
         * @param {string} valueAxisDim
         */
L
tweak  
lang 已提交
27
        min: curry(markerTypeCalculatorWithExtent, 0),
L
lang 已提交
28 29 30 31 32 33
        /**
         * @method
         * @param {module:echarts/data/List} data
         * @param {string} baseAxisDim
         * @param {string} valueAxisDim
         */
L
tweak  
lang 已提交
34
        max: curry(markerTypeCalculatorWithExtent, 1),
L
lang 已提交
35 36 37 38 39 40
        /**
         * @method
         * @param {module:echarts/data/List} data
         * @param {string} baseAxisDim
         * @param {string} valueAxisDim
         */
L
tweak  
lang 已提交
41
        average: curry(markerTypeCalculatorWithExtent, 0.5)
L
lang 已提交
42 43 44
    };

    var dataTransform = function (data, baseAxis, valueAxis, item) {
L
lang 已提交
45 46
        // 1. If not specify the position with pixel directly
        // 2. If value is not a data array. Which uses xAxis, yAxis to specify the value on each dimension
L
lang 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
        if (isNaN(item.x) || isNaN(item.y) && !zrUtil.isArray(item.value)) {
            // Clone the option
            // Transform the properties xAxis, yAxis, radiusAxis, angleAxis, geoCoord to value
            // Competitable with 2.x
            item = zrUtil.extend({}, item);

            // Special types, Compatible with 2.0
            if (item.type && markerTypeCalculator[item.type]
                && baseAxis && valueAxis) {
                var value = markerTypeCalculator[item.type](
                    data, baseAxis.dim, valueAxis.dim
                );
                value.push(+item.value);
                item.value = value;
            }
L
lang 已提交
62
            else {
L
lang 已提交
63 64
                // FIXME Only has one of xAxis and yAxis.
                item.value = [
L
lang 已提交
65 66
                    item.xAxis != null ? item.xAxis : item.radiusAxis,
                    item.yAxis != null ? item.yAxis : item.angleAxis,
L
lang 已提交
67 68 69 70 71 72 73 74
                    +item.value
                ];
            }
        }
        return item;
    };

    // Filter data which is out of coordinateSystem range
L
lang 已提交
75 76 77
    var dataFilter = function (coordSys, coordDataIdx, item) {
        var value = item.value;
        value = [value[coordDataIdx[0]], value[coordDataIdx[1]]];
L
lang 已提交
78 79 80 81 82 83 84 85
        return coordSys.containData(value);
    }

    return {
        dataTransform: dataTransform,
        dataFilter: dataFilter
    };
});