Esempio n. 1
0
        init: function (option, parentModel, ecModel, extraOpt) {

            /**
             * @type {number}
             * @readOnly
             */
            this.seriesIndex = this.componentIndex;

            this.mergeDefaultAndTheme(option, ecModel);

            var data = this.getInitialData(option, ecModel);
            if (__DEV__) {
                zrUtil.assert(data, 'getInitialData returned invalid data.');
            }
            /**
             * @type {module:echarts/data/List|module:echarts/data/Tree|module:echarts/data/Graph}
             * @private
             */
            set(this, 'dataBeforeProcessed', data);

            // If we reverse the order (make data firstly, and then make
            // dataBeforeProcessed by cloneShallow), cloneShallow will
            // cause data.graph.data !== data when using
            // module:echarts/data/Graph or module:echarts/data/Tree.
            // See module:echarts/data/helper/linkList
            this.restoreData();
        },
Esempio n. 2
0
    // Caution:
    // In most case, either list or its shallow clones (see list.cloneShallow)
    // is active in echarts process. So considering heap memory consumption,
    // we do not clone tree or graph, but share them among list and its shallow clones.
    // But in some rare case, we have to keep old list (like do animation in chart). So
    // please take care that both the old list and the new list share the same tree/graph.

    /**
     * @param {Object} opt
     * @param {module:echarts/data/List} opt.mainData
     * @param {Object} [opt.struct] For example, instance of Graph or Tree.
     * @param {string} [opt.structAttr] designation: list[structAttr] = struct;
     * @param {Object} [opt.datas] {dataType: data},
     *                 like: {node: nodeList, edge: edgeList}.
     *                 Should contain mainData.
     * @param {Object} [opt.datasAttr] {dataType: attr},
     *                 designation: struct[datasAttr[dataType]] = list;
     */
    function linkList(opt) {
        var mainData = opt.mainData;
        var datas = opt.datas;

        if (!datas) {
            datas = {main: mainData};
            opt.datasAttr = {main: 'data'};
        }
        opt.datas = opt.mainData = null;

        linkAll(mainData, datas, opt);

        // Porxy data original methods.
        each(datas, function (data) {
            each(mainData.TRANSFERABLE_METHODS, function (methodName) {
                data.wrapMethod(methodName, zrUtil.curry(transferInjection, opt));
            });

        });

        // Beyond transfer, additional features should be added to `cloneShallow`.
        mainData.wrapMethod('cloneShallow', zrUtil.curry(cloneShallowInjection, opt));

        // Only mainData trigger change, because struct.update may trigger
        // another changable methods, which may bring about dead lock.
        each(mainData.CHANGABLE_METHODS, function (methodName) {
            mainData.wrapMethod(methodName, zrUtil.curry(changeInjection, opt));
        });

        // Make sure datas contains mainData.
        zrUtil.assert(datas[mainData.dataType] === mainData);
    }
Esempio n. 3
0
    function createEl(id, targetElParent, elOption, elMap) {
        var graphicType = elOption.type;

        if (__DEV__) {
            zrUtil.assert(graphicType, 'graphic type MUST be set');
        }

        var Clz = graphicUtil[graphicType.charAt(0).toUpperCase() + graphicType.slice(1)];

        if (__DEV__) {
            zrUtil.assert(Clz, 'graphic type can not be found');
        }

        var el = new Clz(elOption);
        targetElParent.add(el);
        elMap[id] = el;
        el.__ecGraphicId = id;
    }
Esempio n. 4
0
        updateCovers: function (brushOptionList) {
            if (__DEV__) {
                zrUtil.assert(this._mounted);
            }

            brushOptionList = zrUtil.map(brushOptionList, function (brushOption) {
                return zrUtil.merge(zrUtil.clone(DEFAULT_BRUSH_OPT), brushOption, true);
            });

            var tmpIdPrefix = '\0-brush-index-';
            var oldCovers = this._covers;
            var newCovers = this._covers = [];
            var controller = this;
            var creatingCover = this._creatingCover;

            (new DataDiffer(oldCovers, brushOptionList, oldGetKey, getKey))
                .add(addOrUpdate)
                .update(addOrUpdate)
                .remove(remove)
                .execute();

            return this;

            function getKey(brushOption, index) {
                return (brushOption.id != null ? brushOption.id : tmpIdPrefix + index)
                    + '-' + brushOption.brushType;
            }

            function oldGetKey(cover, index) {
                return getKey(cover.__brushOption, index);
            }

            function addOrUpdate(newIndex, oldIndex) {
                var newBrushOption = brushOptionList[newIndex];
                // Consider setOption in event listener of brushSelect,
                // where updating cover when creating should be forbiden.
                if (oldIndex != null && oldCovers[oldIndex] === creatingCover) {
                    newCovers[newIndex] = oldCovers[oldIndex];
                }
                else {
                    var cover = newCovers[newIndex] = oldIndex != null
                        ? (
                            oldCovers[oldIndex].__brushOption = newBrushOption,
                            oldCovers[oldIndex]
                        )
                        : endCreating(controller, createCover(controller, newBrushOption));
                    updateCoverAfterCreation(controller, cover);
                }
            }

            function remove(oldIndex) {
                if (oldCovers[oldIndex] !== creatingCover) {
                    controller.group.remove(oldCovers[oldIndex]);
                }
            }
        },
Esempio n. 5
0
        setOption: function (option, optionPreprocessorFuncs) {
            zrUtil.assert(
                !(OPTION_INNER_KEY in option),
                'please use chart.getOption()'
            );

            this._optionManager.setOption(option, optionPreprocessorFuncs);

            this.resetOption();
        },
Esempio n. 6
0
        enableBrush: function (brushOption) {
            if (__DEV__) {
                zrUtil.assert(this._mounted);
            }

            this._brushType && doDisableBrush(this);
            brushOption.brushType && doEnableBrush(this, brushOption);

            return this;
        },
Esempio n. 7
0
        each(mapResult, function (item, index) {
            var opt = item.option;

            zrUtil.assert(
                !opt || opt.id == null || !idMap[opt.id] || idMap[opt.id] === item,
                'id duplicates: ' + (opt && opt.id)
            );

            opt && opt.id != null && (idMap[opt.id] = item);
            !item.keyInfo && (item.keyInfo = {});
        });
Esempio n. 8
0
    var VisualMapping = function (option) {
        var mappingMethod = option.mappingMethod;
        var visualType = option.type;

        /**
         * @readOnly
         * @type {Object}
         */
        var thisOption = this.option = zrUtil.clone(option);

        /**
         * @readOnly
         * @type {string}
         */
        this.type = visualType;

        /**
         * @readOnly
         * @type {string}
         */
        this.mappingMethod = mappingMethod;

        /**
         * @private
         * @type {Function}
         */
        this._normalizeData = normalizers[mappingMethod];

        /**
         * @private
         * @type {Function}
         */
        this._getSpecifiedVisual = zrUtil.bind(
            specifiedVisualGetters[mappingMethod], this, visualType
        );

        zrUtil.extend(this, visualHandlers[visualType]);

        if (mappingMethod === 'piecewise') {
            normalizeVisualRange(thisOption);
            preprocessForPiecewise(thisOption);
        }
        else if (mappingMethod === 'category') {
            thisOption.categories
                ? preprocessForSpecifiedCategory(thisOption)
                // categories is ordinal when thisOption.categories not specified,
                // which need no more preprocess except normalize visual.
                : normalizeVisualRange(thisOption, true);
        }
        else { // mappingMethod === 'linear'
            zrUtil.assert(thisOption.dataExtent);
            normalizeVisualRange(thisOption);
        }
    };
Esempio n. 9
0
 function determineBrushType(brushType, panel) {
     if (brushType === 'auto') {
         if (__DEV__) {
             zrUtil.assert(
                 panel && panel.__defaultBrushType,
                 'MUST have defaultBrushType when brushType is "atuo"'
             );
         }
         return panel.__defaultBrushType;
     }
     return brushType;
 }
Esempio n. 10
0
    function axisConvert(axisName, to, coordInfo, coordRange) {
        var axis = coordInfo.coordSys.getAxis(axisName);

        if (__DEV__) {
            zrUtil.assert(axis, 'line brush is only available in cartesian (grid).');
        }

        return formatMinMax(zrUtil.map([0, 1], function (i) {
            return to
                ? axis.coordToData(axis.toLocalCoord(coordRange[i]))
                : axis.toGlobalCoord(axis.dataToCoord(coordRange[i]));
        }));
    }
Esempio n. 11
0
        setBrushRanges: function (brushRanges) {

            if (__DEV__) {
                zrUtil.assert(zrUtil.isArray(brushRanges));
                zrUtil.each(brushRanges, function (brushRange) {
                    zrUtil.assert(brushRange.brushType && brushRange.range, 'Illegal brushRanges');
                });
            }

            this.brushRanges = zrUtil.map(brushRanges, function (brushRange) {
                return this._mergeBrushOption(brushRange);
            }, this);
        },
Esempio n. 12
0
                each(mapResult, function (resultItem, index) {
                    var componentModel = resultItem.exist;
                    var newCptOption = resultItem.option;

                    zrUtil.assert(
                        isObject(newCptOption) || componentModel,
                        'Empty component definition'
                    );

                    // Consider where is no new option and should be merged using {},
                    // see removeEdgeAndAdd in topologicalTravel and
                    // ComponentModel.getAllClassMainTypes.
                    if (!newCptOption) {
                        componentModel.mergeOption({}, this);
                        componentModel.optionUpdated({}, false);
                    }
                    else {
                        var ComponentModelClass = ComponentModel.getClass(
                            mainType, resultItem.keyInfo.subType, true
                        );

                        if (componentModel && componentModel instanceof ComponentModelClass) {
                            componentModel.name = resultItem.keyInfo.name;
                            componentModel.mergeOption(newCptOption, this);
                            componentModel.optionUpdated(newCptOption, false);
                        }
                        else {
                            // PENDING Global as parent ?
                            var extraOpt = zrUtil.extend(
                                {
                                    dependentModels: dependentModels,
                                    componentIndex: index
                                },
                                resultItem.keyInfo
                            );
                            componentModel = new ComponentModelClass(
                                newCptOption, this, this, extraOpt
                            );
                            zrUtil.extend(componentModel, extraOpt);
                            componentModel.init(newCptOption, this, this, extraOpt);
                            // Call optionUpdated after init.
                            // newCptOption has been used as componentModel.option
                            // and may be merged with theme and default, so pass null
                            // to avoid confusion.
                            componentModel.optionUpdated(null, true);
                        }
                    }

                    componentsMap.get(mainType)[index] = componentModel;
                    option[mainType][index] = componentModel.option;
                }, this);
Esempio n. 13
0
        each(areas, function (area) {
            var targetInfo = this.findTargetInfo(area, ecModel);

            if (__DEV__) {
                zrUtil.assert(
                    !targetInfo || targetInfo === true || area.coordRange,
                    'coordRange must be specified when coord index specified.'
                );
                zrUtil.assert(
                    !targetInfo || targetInfo !== true || area.range,
                    'range must be specified in global brush.'
                );
            }

            area.range = area.range || [];

            // convert coordRange to global range and set panelId.
            if (targetInfo && targetInfo !== true) {
                area.panelId = targetInfo.panelId;
                // (1) area.range shoule always be calculate from coordRange but does
                // not keep its original value, for the sake of the dataZoom scenario,
                // where area.coordRange remains unchanged but area.range may be changed.
                // (2) Only support converting one coordRange to pixel range in brush
                // component. So do not consider `coordRanges`.
                // (3) About __rangeOffset, see comment above.
                var result = coordConvert[area.brushType](0, targetInfo.coordSys, area.coordRange);
                var rangeOffset = area.__rangeOffset;
                area.range = rangeOffset
                    ? diffProcessor[area.brushType](
                        result.values,
                        rangeOffset.offset,
                        getScales(result.xyMinMax, rangeOffset.xyMinMax)
                    )
                    : result.values;
            }
        }, this);
Esempio n. 14
0
        each(brushModel.brushRanges, function (brushRange) {
            var coordInfo = findCoordInfo(brushRange, brushModel.coordInfoList);

            if (__DEV__) {
                zrUtil.assert(
                    !coordInfo || coordInfo === true || brushRange.coordRange,
                    'coordRange must be specified when coord index specified.'
                );
                zrUtil.assert(
                    !coordInfo || coordInfo !== true || brushRange.range,
                    'range must be specified.'
                );
            }

            brushRange.range = brushRange.range || [];

            // convert coordRange to global range and set panelId.
            if (coordInfo && coordInfo !== true) {
                brushRange.range = coordConvert[brushRange.brushType](
                    0, coordInfo, brushRange.coordRange
                );
                brushRange.panelId = coordInfo.panelId;
            }
        });
Esempio n. 15
0
        each(mapResult, function (item, index) {
            var opt = item.option;

            zrUtil.assert(
                !opt || opt.id == null || !idMap[opt.id] || idMap[opt.id] === item,
                'id duplicates: ' + (opt && opt.id)
            );

            opt && opt.id != null && (idMap[opt.id] = item);

            // Complete subType
            if (isObject(opt)) {
                var subType = determineSubType(mainType, opt, item.exist);
                item.keyInfo = {mainType: mainType, subType: subType};
            }
        });
Esempio n. 16
0
    echartsProto.resize = function () {
        if (__DEV__) {
            zrUtil.assert(!this[IN_MAIN_PROCESS], '`resize` should not be called during main process.');
        }

        this[IN_MAIN_PROCESS] = true;

        this._zr.resize();

        var optionChanged = this._model && this._model.resetOption('media');
        updateMethods[optionChanged ? 'prepareAndUpdate' : 'update'].call(this);

        // Resize loading effect
        this._loadingFX && this._loadingFX.resize();

        this[IN_MAIN_PROCESS] = false;
    };
Esempio n. 17
0
                each(mapResult, function (resultItem, index) {
                    var componentModel = resultItem.exist;
                    var newCptOption = resultItem.option;

                    zrUtil.assert(
                        isObject(newCptOption) || componentModel,
                        'Empty component definition'
                    );

                    // Consider where is no new option and should be merged using {},
                    // see removeEdgeAndAdd in topologicalTravel and
                    // ComponentModel.getAllClassMainTypes.
                    if (!newCptOption) {
                        componentModel.mergeOption({}, this);
                        componentModel.optionUpdated(this);
                    }
                    else {
                        var ComponentModelClass = ComponentModel.getClass(
                            mainType, resultItem.keyInfo.subType, true
                        );

                        if (componentModel && componentModel instanceof ComponentModelClass) {
                            componentModel.mergeOption(newCptOption, this);
                            componentModel.optionUpdated(this);
                        }
                        else {
                            // PENDING Global as parent ?
                            componentModel = new ComponentModelClass(
                                newCptOption, this, this,
                                zrUtil.extend(
                                    {
                                        dependentModels: dependentModels,
                                        componentIndex: index
                                    },
                                    resultItem.keyInfo
                                )
                            );
                            // Call optionUpdated after init
                            componentModel.optionUpdated(this);
                        }
                    }

                    componentsMap[mainType][index] = componentModel;
                    option[mainType][index] = componentModel.option;
                }, this);
Esempio n. 18
0
    function createEl(elOption) {
        var graphicType = elOption.type;
        var el;

        if (graphicType === 'path') {
            var shape = elOption.shape;
            el = graphicUtil.makePath(
                shape.pathData,
                null,
                {
                    x: shape.x || 0,
                    y: shape.y || 0,
                    width: shape.width || 0,
                    height: shape.height || 0
                },
                'center'
            );
            el.__customPathData = elOption.pathData;
        }
        else if (graphicType === 'image') {
            el = new graphicUtil.Image({
            });
            el.__customImagePath = elOption.style.image;
        }
        else if (graphicType === 'text') {
            el = new graphicUtil.Text({
            });
            el.__customText = elOption.style.text;
        }
        else {
            var Clz = graphicUtil[graphicType.charAt(0).toUpperCase() + graphicType.slice(1)];

            if (__DEV__) {
                zrUtil.assert(Clz, 'graphic type "' + graphicType + '" can not be found.');
            }

            el = new Clz();
        }

        el.__customGraphicType = graphicType;
        el.name = elOption.name;

        return el;
    }
Esempio n. 19
0
            ecModel.eachComponent({mainType: componentName}, function (componentModel, index) {
                if (componentIndices !== 'all' && zrUtil.indexOf(componentIndices, index) < 0) {
                    return;
                }

                var grid;
                var coordSys;

                (componentName === 'xAxis' || componentName === 'yAxis')
                    ? (grid = componentModel.axis.grid)
                    : (coordSys = componentModel.coordinateSystem); // geo

                var coordInfo;

                // Check duplicate and find cartesian when tranval to yAxis.
                for (var i = 0, len = coordInfoList.length; i < len; i++) {
                    var cInfo = coordInfoList[i];
                    if (__DEV__) {
                        zrUtil.assert(
                            cInfo[componentName + 'Index'] != index,
                            'Coord should not be defined duplicately: ' + componentName + index
                        );
                    }
                    // CoordSys is always required for `rect brush` or `polygon brush`.
                    // If both xAxisIndex and yAxisIndex specified, fetch cartesian by them.
                    if (componentName === 'yAxis' && !cInfo.yAxis && cInfo.xAxis) {
                        var aCoordSys = grid.getCartesian(cInfo.xAxisIndex, index);
                        if (aCoordSys) { // The yAxis and xAxis are in the same cartesian.
                            coordSys = aCoordSys;
                            coordInfo = cInfo;
                            break;
                        }
                    }
                }

                !coordInfo && coordInfoList.push(coordInfo = {});

                coordInfo[componentName] = componentModel;
                coordInfo[componentName + 'Index'] = index;
                coordInfo.panelId = componentName + PANEL_ID_SPLIT + index;
                coordInfo.coordSys = coordSys
                    // If only xAxisIndex or only yAxisIndex specified, find its first cartesian.
                    || grid.getCartesian(coordInfo.xAxisIndex, coordInfo.yAxisIndex);
            });
Esempio n. 20
0
            zrUtil.each(elOptionsToUpdate, function (elOption) {
                var $action = elOption.$action;
                var id = elOption.id;
                var existEl = elMap[id];
                var parentId = elOption.parentId;
                var targetElParent = parentId != null ? elMap[parentId] : rootGroup;

                // In top/bottom mode, textVertical should not be used. And textBaseline
                // should not be 'alphabetic', which cause inaccurately locating.
                if (elOption.hv && elOption.hv[1] && elOption.type === 'text') {
                    elOption.style = zrUtil.defaults({textBaseline: 'middle'}, elOption.style);
                    elOption.style.textVerticalAlign = null;
                }

                // Remove unnecessary props to avoid potential problems.
                var elOptionCleaned = getCleanedElOption(elOption);

                // For simple, do not support parent change, otherwise reorder is needed.
                if (__DEV__) {
                    existEl && zrUtil.assert(
                        targetElParent === existEl.parent,
                        'Changing parent is not supported.'
                    );
                }

                if (!$action || $action === 'merge') {
                    existEl
                        ? existEl.attr(elOptionCleaned)
                        : createEl(id, targetElParent, elOptionCleaned, elMap);
                }
                else if ($action === 'replace') {
                    removeEl(existEl, elMap);
                    createEl(id, targetElParent, elOptionCleaned, elMap);
                }
                else if ($action === 'remove') {
                    removeEl(existEl, elMap);
                }

                if (elMap[id]) {
                    elMap[id].__ecGraphicWidth = elOption.width;
                    elMap[id].__ecGraphicHeight = elOption.height;
                }
            });
Esempio n. 21
0
        setBrushRanges: function (brushRanges) {
            if (__DEV__) {
                zrUtil.assert(zrUtil.isArray(brushRanges));
                zrUtil.each(brushRanges, function (brushRange) {
                    zrUtil.assert(brushRange.brushType, 'Illegal brushRanges');
                });
            }

            // If ranges is null/undefined, range state remain.
            // This helps user to dispatchAction({type: 'brush'}) with no brushRanges
            // set but just want to get the current brush select info from a `brush` event.
            if (!brushRanges) {
                return;
            }

            this.brushRanges = zrUtil.map(brushRanges, function (brushRange) {
                return this._mergeBrushOption(brushRange);
            }, this);
        },
Esempio n. 22
0
        setAreas: function (areas) {
            if (__DEV__) {
                zrUtil.assert(zrUtil.isArray(areas));
                zrUtil.each(areas, function (area) {
                    zrUtil.assert(area.brushType, 'Illegal areas');
                });
            }

            // If ranges is null/undefined, range state remain.
            // This helps user to dispatchAction({type: 'brush'}) with no areas
            // set but just want to get the current brush select info from a `brush` event.
            if (!areas) {
                return;
            }

            this.areas = zrUtil.map(areas, function (area) {
                return generateBrushOption(this.option, area);
            }, this);
        },
Esempio n. 23
0
    function axisConvert(axisNameIndex, to, coordSys, rangeOrCoordRange) {
        if (__DEV__) {
            zrUtil.assert(
                coordSys.type === 'cartesian2d',
                'lineX/lineY brush is available only in cartesian2d.'
            );
        }

        var axis = coordSys.getAxis(['x', 'y'][axisNameIndex]);
        var values = formatMinMax(zrUtil.map([0, 1], function (i) {
            return to
                ? axis.coordToData(axis.toLocalCoord(rangeOrCoordRange[i]))
                : axis.toGlobalCoord(axis.dataToCoord(rangeOrCoordRange[i]));
        }));
        var xyMinMax = [];
        xyMinMax[axisNameIndex] = values;
        xyMinMax[1 - axisNameIndex] = [NaN, NaN];

        return {values: values, xyMinMax: xyMinMax};
    }
Esempio n. 24
0
    echartsProto.setOption = function (option, notMerge, notRefreshImmediately) {
        if (__DEV__) {
            zrUtil.assert(!this[IN_MAIN_PROCESS], '`setOption` should not be called during main process.');
        }

        this[IN_MAIN_PROCESS] = true;

        if (!this._model || notMerge) {
            this._model = new GlobalModel(
                null, null, this._theme, new OptionManager(this._api)
            );
        }

        this._model.setOption(option, optionPreprocessorFuncs);

        updateMethods.prepareAndUpdate.call(this);

        !notRefreshImmediately && this._zr.refreshImmediately();

        this[IN_MAIN_PROCESS] = false;
    };
Esempio n. 25
0
            zrUtil.each(mappingResult, function (resultItem, index) {
                var newElOption = resultItem.option;

                if (__DEV__) {
                    zrUtil.assert(
                        zrUtil.isObject(newElOption) || resultItem.exist,
                        'Empty graphic option definition'
                    );
                }

                if (!newElOption) {
                    return;
                }

                elOptionsToUpdate.push(newElOption);

                setKeyInfoToNewElOption(resultItem, newElOption);

                mergeNewElOptionToExist(existList, index, newElOption);

                setLayoutInfoToExist(existList[index], newElOption);

            }, this);
Esempio n. 26
0
    function mergeNewElOptionToExist(existList, index, newElOption) {
        // Update existing options, for `getOption` feature.
        var newElOptCopy = zrUtil.extend({}, newElOption);
        var existElOption = existList[index];

        var $action = newElOption.$action || 'merge';
        if ($action === 'merge') {
            if (existElOption) {

                if (__DEV__) {
                    var newType = newElOption.type;
                    zrUtil.assert(
                        !newType || existElOption.type === newType,
                        'Please set $action: "replace" to change `type`'
                    );
                }

                // We can ensure that newElOptCopy and existElOption are not
                // the same object, so `merge` will not change newElOptCopy.
                zrUtil.merge(existElOption, newElOptCopy, true);
                // Rigid body, use ignoreSize.
                layoutUtil.mergeLayoutParam(existElOption, newElOptCopy, {ignoreSize: true});
                // Will be used in render.
                layoutUtil.copyLayoutParams(newElOption, existElOption);
            }
            else {
                existList[index] = newElOptCopy;
            }
        }
        else if ($action === 'replace') {
            existList[index] = newElOptCopy;
        }
        else if ($action === 'remove') {
            // null will be cleaned later.
            existElOption && (existList[index] = null);
        }
    }
Esempio n. 27
0
    function makeRenderItem(customSeries, data, ecModel, api) {
        var renderItem = customSeries.get('renderItem');
        var coordSys = customSeries.coordinateSystem;
        var prepareResult = {};

        if (coordSys) {
            if (__DEV__) {
                zrUtil.assert(renderItem, 'series.render is required.');
                zrUtil.assert(
                    coordSys.prepareCustoms || prepareCustoms[coordSys.type],
                    'This coordSys does not support custom series.'
                );
            }

            prepareResult = coordSys.prepareCustoms
                ? coordSys.prepareCustoms()
                : prepareCustoms[coordSys.type](coordSys);
        }

        var userAPI = zrUtil.defaults({
            getWidth: api.getWidth,
            getHeight: api.getHeight,
            getZr: api.getZr,
            getDevicePixelRatio: api.getDevicePixelRatio,
            value: value,
            style: style,
            styleEmphasis: styleEmphasis,
            visual: visual,
            barLayout: barLayout,
            currentSeriesIndices: currentSeriesIndices,
            font: font
        }, prepareResult.api || {});

        var userParams = {
            context: {},
            seriesId: customSeries.id,
            seriesName: customSeries.name,
            seriesIndex: customSeries.seriesIndex,
            coordSys: prepareResult.coordSys,
            dataInsideLength: data.count(),
            encode: wrapEncodeDef(customSeries.getData())
        };

        // Do not support call `api` asynchronously without dataIndexInside input.
        var currDataIndexInside;
        var currDirty = true;
        var currItemModel;
        var currLabelNormalModel;
        var currLabelEmphasisModel;
        var currLabelValueDim;
        var currVisualColor;

        return function (dataIndexInside) {
            currDataIndexInside = dataIndexInside;
            currDirty = true;
            return renderItem && renderItem(
                zrUtil.defaults({
                    dataIndexInside: dataIndexInside,
                    dataIndex: data.getRawIndex(dataIndexInside)
                }, userParams),
                userAPI
            ) || {};
        };

        // Do not update cache until api called.
        function updateCache(dataIndexInside) {
            dataIndexInside == null && (dataIndexInside = currDataIndexInside);
            if (currDirty) {
                currItemModel = data.getItemModel(dataIndexInside);
                currLabelNormalModel = currItemModel.getModel(LABEL_NORMAL);
                currLabelEmphasisModel = currItemModel.getModel(LABEL_EMPHASIS);
                currLabelValueDim = labelHelper.findLabelValueDim(data);
                currVisualColor = data.getItemVisual(dataIndexInside, 'color');

                currDirty = false;
            }
        }

        /**
         * @public
         * @param {number|string} dim
         * @param {number} [dataIndexInside=currDataIndexInside]
         * @return {number|string} value
         */
        function value(dim, dataIndexInside) {
            dataIndexInside == null && (dataIndexInside = currDataIndexInside);
            return data.get(data.getDimension(dim || 0), dataIndexInside);
        }

        /**
         * By default, `visual` is applied to style (to support visualMap).
         * `visual.color` is applied at `fill`. If user want apply visual.color on `stroke`,
         * it can be implemented as:
         * `api.style({stroke: api.visual('color'), fill: null})`;
         * @public
         * @param {Object} [extra]
         * @param {number} [dataIndexInside=currDataIndexInside]
         */
        function style(extra, dataIndexInside) {
            dataIndexInside == null && (dataIndexInside = currDataIndexInside);
            updateCache(dataIndexInside);

            var itemStyle = currItemModel.getModel(ITEM_STYLE_NORMAL_PATH).getItemStyle();

            currVisualColor != null && (itemStyle.fill = currVisualColor);
            var opacity = data.getItemVisual(dataIndexInside, 'opacity');
            opacity != null && (itemStyle.opacity = opacity);

            if (currLabelValueDim != null) {
                graphicUtil.setText(itemStyle, currLabelNormalModel, currVisualColor);
                itemStyle.text = currLabelNormalModel.getShallow('show')
                    ? zrUtil.retrieve2(
                        customSeries.getFormattedLabel(dataIndexInside, 'normal'),
                        data.get(currLabelValueDim, dataIndexInside)
                    )
                    : null;
            }

            extra && zrUtil.extend(itemStyle, extra);
            return itemStyle;
        }

        /**
         * @public
         * @param {Object} [extra]
         * @param {number} [dataIndexInside=currDataIndexInside]
         */
        function styleEmphasis(extra, dataIndexInside) {
            dataIndexInside == null && (dataIndexInside = currDataIndexInside);
            updateCache(dataIndexInside);

            var itemStyle = currItemModel.getModel(ITEM_STYLE_EMPHASIS_PATH).getItemStyle();

            if (currLabelValueDim != null) {
                graphicUtil.setText(itemStyle, currLabelEmphasisModel, false);
                itemStyle.text = currLabelEmphasisModel.getShallow('show')
                    ? customSeries.getFormattedLabel(dataIndexInside, 'emphasis')
                    : null;
            }

            extra && zrUtil.extend(itemStyle, extra);
            return itemStyle;
        }

        /**
         * @public
         * @param {string} visualType
         * @param {number} [dataIndexInside=currDataIndexInside]
         */
        function visual(visualType, dataIndexInside) {
            dataIndexInside == null && (dataIndexInside = currDataIndexInside);
            return data.getItemVisual(dataIndexInside, visualType);
        }

        /**
         * @public
         * @param {number} opt.count Positive interger.
         * @param {number} [opt.barWidth]
         * @param {number} [opt.barMaxWidth]
         * @param {number} [opt.barGap]
         * @param {number} [opt.barCategoryGap]
         * @return {Object} {width, offset, offsetCenter} is not support, return undefined.
         */
        function barLayout(opt) {
            if (coordSys.getBaseAxis) {
                var baseAxis = coordSys.getBaseAxis();
                return barGrid.getLayoutOnAxis(zrUtil.defaults({axis: baseAxis}, opt), api);
            }
        }

        /**
         * @public
         * @return {Array.<number>}
         */
        function currentSeriesIndices() {
            return ecModel.getCurrentSeriesIndices();
        }

        /**
         * @public
         * @param {Object} opt
         * @param {string} [opt.fontStyle]
         * @param {number} [opt.fontWeight]
         * @param {number} [opt.fontSize]
         * @param {string} [opt.fontFamily]
         * @return {string} font string
         */
        function font(opt) {
            return graphicUtil.getFont(opt, ecModel);
        }
    }
Esempio n. 28
0
    echartsProto.dispatchAction = function (payload, silent) {
        var actionWrap = actions[payload.type];
        if (!actionWrap) {
            return;
        }

        var actionInfo = actionWrap.actionInfo;
        var updateMethod = actionInfo.update || 'update';

        if (__DEV__) {
            zrUtil.assert(
                !this[IN_MAIN_PROCESS],
                '`dispatchAction` should not be called during main process.'
                + 'unless updateMathod is "none".'
            );
        }

        this[IN_MAIN_PROCESS] = true;

        var payloads = [payload];
        var batched = false;
        // Batch action
        if (payload.batch) {
            batched = true;
            payloads = zrUtil.map(payload.batch, function (item) {
                item = zrUtil.defaults(zrUtil.extend({}, item), payload);
                item.batch = null;
                return item;
            });
        }

        var eventObjBatch = [];
        var eventObj;
        var isHighlightOrDownplay = payload.type === 'highlight' || payload.type === 'downplay';
        for (var i = 0; i < payloads.length; i++) {
            var batchItem = payloads[i];
            // Action can specify the event by return it.
            eventObj = actionWrap.action(batchItem, this._model);
            // Emit event outside
            eventObj = eventObj || zrUtil.extend({}, batchItem);
            // Convert type to eventType
            eventObj.type = actionInfo.event || eventObj.type;
            eventObjBatch.push(eventObj);

            // Highlight and downplay are special.
            isHighlightOrDownplay && updateMethods[updateMethod].call(this, batchItem);
        }

        (updateMethod !== 'none' && !isHighlightOrDownplay)
            && updateMethods[updateMethod].call(this, payload);

        // Follow the rule of action batch
        if (batched) {
            eventObj = {
                type: actionInfo.event || payload.type,
                batch: eventObjBatch
            };
        }
        else {
            eventObj = eventObjBatch[0];
        }

        this[IN_MAIN_PROCESS] = false;

        !silent && this._messageCenter.trigger(eventObj.type, eventObj);
    };
Esempio n. 29
0
 zrUtil.each(areas, function (area) {
     zrUtil.assert(area.brushType, 'Illegal areas');
 });
Esempio n. 30
0
    /**
     * @alias module:echarts/component/helper/BrushController
     * @constructor
     * @mixin {module:zrender/mixin/Eventful}
     * @event module:echarts/component/helper/BrushController#brush
     *        params:
     *            areas: Array.<Array>, coord relates to container group,
     *                                    If no container specified, to global.
     *            opt {
     *                isEnd: boolean,
     *                removeOnClick: boolean
     *            }
     *
     * @param {module:zrender/zrender~ZRender} zr
     */
    function BrushController(zr) {

        if (__DEV__) {
            zrUtil.assert(zr);
        }

        Eventful.call(this);

        /**
         * @type {module:zrender/zrender~ZRender}
         * @private
         */
        this._zr = zr;

        /**
         * @type {module:zrender/container/Group}
         * @readOnly
         */
        this.group = new graphic.Group();

        /**
         * Only for drawing (after enabledBrush).
         *     'line', 'rect', 'polygon' or false
         *     If passing false/null/undefined, disable brush.
         *     If passing 'auto', determined by panel.defaultBrushType
         * @private
         * @type {string}
         */
        this._brushType;

        /**
         * Only for drawing (after enabledBrush).
         *
         * @private
         * @type {Object}
         */
        this._brushOption;

        /**
         * @private
         * @type {Object}
         */
        this._panels;

        /**
         * @private
         * @type {Array.<nubmer>}
         */
        this._track = [];

        /**
         * @private
         * @type {boolean}
         */
        this._dragging;

        /**
         * @private
         * @type {Array}
         */
        this._covers = [];

        /**
         * @private
         * @type {moudule:zrender/container/Group}
         */
        this._creatingCover;

        /**
         * true means global panel
         * @private
         * @type {module:zrender/container/Group|boolean}
         */
        this._creatingPanel;

        /**
         * @private
         * @type {boolean}
         */
        this._enableGlobalPan;

        /**
         * @private
         * @type {boolean}
         */
        if (__DEV__) {
            this._mounted;
        }

        /**
         * @private
         * @type {string}
         */
        this._uid = 'brushController_' + baseUID++;

        /**
         * @private
         * @type {Object}
         */
        this._handlers = {};
        each(mouseHandlers, function (handler, eventName) {
            this._handlers[eventName] = zrUtil.bind(handler, this);
        }, this);
    }