blob: e10fee3b65be82ae2d60773becf378ec91265062 [file] [log] [blame]
{"version":3,"file":"echarts.js","sources":["../src/config.js","../node_modules/zrender/src/core/guid.js","../node_modules/zrender/src/core/env.js","../node_modules/zrender/src/core/util.js","../node_modules/zrender/src/core/vector.js","../node_modules/zrender/src/mixin/Draggable.js","../node_modules/zrender/src/mixin/Eventful.js","../node_modules/zrender/src/core/fourPointsTransform.js","../node_modules/zrender/src/core/dom.js","../node_modules/zrender/src/core/event.js","../node_modules/zrender/src/core/GestureMgr.js","../node_modules/zrender/src/Handler.js","../node_modules/zrender/src/core/matrix.js","../node_modules/zrender/src/mixin/Transformable.js","../node_modules/zrender/src/animation/easing.js","../node_modules/zrender/src/animation/Clip.js","../node_modules/zrender/src/core/LRU.js","../node_modules/zrender/src/tool/color.js","../node_modules/zrender/src/animation/Animator.js","../node_modules/zrender/src/config.js","../node_modules/zrender/src/core/log.js","../node_modules/zrender/src/mixin/Animatable.js","../node_modules/zrender/src/Element.js","../node_modules/zrender/src/core/BoundingRect.js","../node_modules/zrender/src/container/Group.js","../node_modules/zrender/src/core/timsort.js","../node_modules/zrender/src/Storage.js","../node_modules/zrender/src/graphic/helper/fixShadow.js","../node_modules/zrender/src/graphic/constant.js","../node_modules/zrender/src/graphic/Style.js","../node_modules/zrender/src/graphic/Pattern.js","../node_modules/zrender/src/Layer.js","../node_modules/zrender/src/animation/requestAnimationFrame.js","../node_modules/zrender/src/graphic/helper/image.js","../node_modules/zrender/src/contain/text.js","../node_modules/zrender/src/graphic/helper/roundRect.js","../node_modules/zrender/src/graphic/helper/text.js","../node_modules/zrender/src/graphic/mixin/RectText.js","../node_modules/zrender/src/graphic/Displayable.js","../node_modules/zrender/src/graphic/Image.js","../node_modules/zrender/src/Painter.js","../node_modules/zrender/src/animation/Animation.js","../node_modules/zrender/src/dom/HandlerProxy.js","../node_modules/zrender/src/zrender.js","../src/util/model.js","../src/util/clazz.js","../src/model/mixin/makeStyleMapper.js","../src/model/mixin/lineStyle.js","../src/model/mixin/areaStyle.js","../node_modules/zrender/src/core/curve.js","../node_modules/zrender/src/core/bbox.js","../node_modules/zrender/src/core/PathProxy.js","../node_modules/zrender/src/contain/line.js","../node_modules/zrender/src/contain/cubic.js","../node_modules/zrender/src/contain/quadratic.js","../node_modules/zrender/src/contain/util.js","../node_modules/zrender/src/contain/arc.js","../node_modules/zrender/src/contain/windingLine.js","../node_modules/zrender/src/contain/path.js","../node_modules/zrender/src/graphic/Path.js","../node_modules/zrender/src/tool/transformPath.js","../node_modules/zrender/src/tool/path.js","../node_modules/zrender/src/graphic/Text.js","../node_modules/zrender/src/graphic/shape/Circle.js","../node_modules/zrender/src/graphic/helper/fixClipWithShadow.js","../node_modules/zrender/src/graphic/shape/Sector.js","../node_modules/zrender/src/graphic/shape/Ring.js","../node_modules/zrender/src/graphic/helper/smoothSpline.js","../node_modules/zrender/src/graphic/helper/smoothBezier.js","../node_modules/zrender/src/graphic/helper/poly.js","../node_modules/zrender/src/graphic/shape/Polygon.js","../node_modules/zrender/src/graphic/shape/Polyline.js","../node_modules/zrender/src/graphic/helper/subPixelOptimize.js","../node_modules/zrender/src/graphic/shape/Rect.js","../node_modules/zrender/src/graphic/shape/Line.js","../node_modules/zrender/src/graphic/shape/BezierCurve.js","../node_modules/zrender/src/graphic/shape/Arc.js","../node_modules/zrender/src/graphic/CompoundPath.js","../node_modules/zrender/src/graphic/Gradient.js","../node_modules/zrender/src/graphic/LinearGradient.js","../node_modules/zrender/src/graphic/RadialGradient.js","../node_modules/zrender/src/graphic/IncrementalDisplayable.js","../src/util/graphic.js","../src/model/mixin/textStyle.js","../src/model/mixin/itemStyle.js","../src/model/Model.js","../src/util/component.js","../src/util/number.js","../src/util/format.js","../src/util/layout.js","../src/model/mixin/boxLayout.js","../src/model/Component.js","../src/model/globalDefault.js","../src/model/mixin/colorPalette.js","../src/data/helper/sourceType.js","../src/data/Source.js","../src/data/helper/sourceHelper.js","../src/model/Global.js","../src/ExtensionAPI.js","../src/CoordinateSystem.js","../src/model/OptionManager.js","../src/preprocessor/helper/compatStyle.js","../src/preprocessor/backwardCompat.js","../src/processor/dataStack.js","../src/data/helper/dataProvider.js","../src/model/mixin/dataFormat.js","../src/stream/task.js","../src/model/Series.js","../src/view/Component.js","../src/chart/helper/createRenderPlanner.js","../src/view/Chart.js","../src/util/throttle.js","../src/visual/seriesColor.js","../src/lang.js","../src/visual/aria.js","../src/loading/default.js","../src/stream/Scheduler.js","../src/theme/light.js","../src/theme/dark.js","../src/component/dataset.js","../node_modules/zrender/src/graphic/shape/Ellipse.js","../node_modules/zrender/src/tool/parseSVG.js","../src/coord/geo/mapDataStorage.js","../src/echarts.js","../src/data/DataDiffer.js","../src/data/helper/dimensionHelper.js","../src/data/DataDimensionInfo.js","../src/data/List.js","../src/data/helper/completeDimensions.js","../src/data/helper/createDimensions.js","../src/model/referHelper.js","../src/data/helper/dataStackHelper.js","../src/chart/helper/createListFromArray.js","../src/scale/Scale.js","../src/data/OrdinalMeta.js","../src/scale/Ordinal.js","../src/scale/helper.js","../src/scale/Interval.js","../src/layout/barGrid.js","../src/scale/Time.js","../src/scale/Log.js","../src/coord/axisHelper.js","../src/coord/axisModelCommonMixin.js","../src/util/symbol.js","../src/helper.js","../node_modules/zrender/src/contain/polygon.js","../src/coord/geo/Region.js","../src/coord/geo/parseGeoJson.js","../src/coord/axisTickLabelBuilder.js","../src/coord/Axis.js","../src/export.js","../src/chart/line/LineSeries.js","../src/chart/helper/labelHelper.js","../src/chart/helper/Symbol.js","../src/chart/helper/SymbolDraw.js","../src/chart/line/helper.js","../src/chart/line/lineAnimationDiff.js","../src/chart/line/poly.js","../src/chart/helper/createClipPathFromCoordSys.js","../src/chart/line/LineView.js","../src/visual/symbol.js","../src/layout/points.js","../src/processor/dataSample.js","../src/coord/cartesian/Cartesian.js","../src/coord/cartesian/Cartesian2D.js","../src/coord/cartesian/Axis2D.js","../src/coord/axisDefault.js","../src/coord/axisModelCreator.js","../src/coord/cartesian/AxisModel.js","../src/coord/cartesian/GridModel.js","../src/coord/cartesian/Grid.js","../src/component/axis/AxisBuilder.js","../src/component/axisPointer/modelHelper.js","../src/component/axis/AxisView.js","../src/coord/cartesian/cartesianAxisHelper.js","../src/component/axis/axisSplitHelper.js","../src/component/axis/CartesianAxisView.js","../src/component/axis.js","../src/component/gridSimple.js","../src/chart/line.js","../src/chart/bar/BaseBarSeries.js","../src/chart/bar/BarSeries.js","../src/chart/bar/helper.js","../src/chart/bar/barItemStyle.js","../src/util/shape/sausage.js","../src/chart/bar/BarView.js","../src/chart/bar.js","../src/chart/helper/createListSimply.js","../src/component/helper/selectableMixin.js","../src/visual/LegendVisualProvider.js","../src/chart/pie/PieSeries.js","../src/chart/pie/PieView.js","../src/action/createDataSelectAction.js","../src/visual/dataColor.js","../src/chart/pie/labelLayout.js","../src/chart/pie/pieLayout.js","../src/processor/dataFilter.js","../src/chart/pie.js","../src/chart/scatter/ScatterSeries.js","../src/chart/helper/LargeSymbolDraw.js","../src/chart/scatter/ScatterView.js","../src/chart/scatter.js","../src/coord/radar/IndicatorAxis.js","../src/coord/radar/Radar.js","../src/coord/radar/RadarModel.js","../src/component/radar/RadarView.js","../src/component/radar.js","../src/chart/radar/RadarSeries.js","../src/chart/radar/RadarView.js","../src/chart/radar/radarLayout.js","../src/chart/radar/backwardCompat.js","../src/chart/radar.js","../src/coord/geo/fix/nanhai.js","../src/coord/geo/fix/textCoord.js","../src/coord/geo/fix/geoCoord.js","../src/coord/geo/fix/diaoyuIsland.js","../src/coord/geo/geoJSONLoader.js","../src/coord/geo/geoSVGLoader.js","../src/coord/geo/geoSourceManager.js","../src/chart/map/MapSeries.js","../src/component/helper/interactionMutex.js","../src/component/helper/RoamController.js","../src/component/helper/roamHelper.js","../src/component/helper/cursorHelper.js","../src/component/helper/MapDraw.js","../src/chart/map/MapView.js","../src/action/roamHelper.js","../src/action/geoRoam.js","../src/coord/View.js","../src/coord/geo/Geo.js","../src/coord/geo/geoCreator.js","../src/chart/map/mapSymbolLayout.js","../src/chart/map/mapVisual.js","../src/chart/map/mapDataStatistic.js","../src/chart/map/backwardCompat.js","../src/chart/map.js","../src/data/helper/linkList.js","../src/data/Tree.js","../src/chart/tree/TreeSeries.js","../src/chart/tree/layoutHelper.js","../src/chart/tree/TreeView.js","../src/chart/tree/treeAction.js","../src/chart/tree/traversalHelper.js","../src/chart/tree/treeLayout.js","../src/chart/tree.js","../src/chart/helper/treeHelper.js","../src/chart/treemap/TreemapSeries.js","../src/chart/treemap/Breadcrumb.js","../src/util/animation.js","../src/chart/treemap/TreemapView.js","../src/chart/treemap/treemapAction.js","../src/visual/VisualMapping.js","../src/chart/treemap/treemapVisual.js","../src/chart/treemap/treemapLayout.js","../src/chart/treemap.js","../src/data/Graph.js","../src/chart/helper/createGraphFromNodeEdge.js","../src/chart/helper/multipleGraphEdgeHelper.js","../src/chart/graph/GraphSeries.js","../src/chart/helper/LinePath.js","../src/chart/helper/Line.js","../src/chart/helper/LineDraw.js","../src/chart/graph/graphHelper.js","../src/chart/graph/adjustEdge.js","../src/chart/graph/GraphView.js","../src/chart/helper/focusNodeAdjacencyAction.js","../src/chart/graph/graphAction.js","../src/chart/graph/categoryFilter.js","../src/chart/graph/categoryVisual.js","../src/chart/graph/edgeVisual.js","../src/chart/graph/simpleLayoutHelper.js","../src/chart/graph/simpleLayout.js","../src/chart/graph/circularLayoutHelper.js","../src/chart/graph/circularLayout.js","../src/chart/graph/forceHelper.js","../src/chart/graph/forceLayout.js","../src/chart/graph/createView.js","../src/chart/graph.js","../src/chart/gauge/GaugeSeries.js","../src/chart/gauge/PointerPath.js","../src/chart/gauge/GaugeView.js","../src/chart/gauge.js","../src/chart/funnel/FunnelSeries.js","../src/chart/funnel/FunnelView.js","../src/chart/funnel/funnelLayout.js","../src/chart/funnel.js","../src/coord/parallel/parallelPreprocessor.js","../src/coord/parallel/ParallelAxis.js","../src/component/helper/sliderMove.js","../src/coord/parallel/Parallel.js","../src/coord/parallel/parallelCreator.js","../src/coord/parallel/AxisModel.js","../src/coord/parallel/ParallelModel.js","../src/component/axis/parallelAxisAction.js","../src/component/helper/BrushController.js","../src/component/helper/brushHelper.js","../src/component/axis/ParallelAxisView.js","../src/component/parallelAxis.js","../src/component/parallel.js","../src/chart/parallel/ParallelSeries.js","../src/chart/parallel/ParallelView.js","../src/chart/parallel/parallelVisual.js","../src/chart/parallel.js","../src/chart/sankey/SankeySeries.js","../src/chart/sankey/SankeyView.js","../src/chart/sankey/sankeyAction.js","../src/chart/sankey/sankeyLayout.js","../src/chart/sankey/sankeyVisual.js","../src/chart/sankey.js","../src/chart/helper/whiskerBoxCommon.js","../src/chart/boxplot/BoxplotSeries.js","../src/chart/boxplot/BoxplotView.js","../src/chart/boxplot/boxplotVisual.js","../src/chart/boxplot/boxplotLayout.js","../src/chart/boxplot.js","../src/chart/candlestick/CandlestickSeries.js","../src/chart/candlestick/CandlestickView.js","../src/chart/candlestick/preprocessor.js","../src/chart/candlestick/candlestickVisual.js","../src/chart/candlestick/candlestickLayout.js","../src/chart/candlestick.js","../src/chart/effectScatter/EffectScatterSeries.js","../src/chart/helper/EffectSymbol.js","../src/chart/effectScatter/EffectScatterView.js","../src/chart/effectScatter.js","../src/chart/lines/LinesSeries.js","../src/chart/helper/EffectLine.js","../src/chart/helper/Polyline.js","../src/chart/helper/EffectPolyline.js","../src/chart/helper/LargeLineDraw.js","../src/chart/lines/linesLayout.js","../src/chart/lines/LinesView.js","../src/chart/lines/linesVisual.js","../src/chart/lines.js","../src/chart/heatmap/HeatmapSeries.js","../src/chart/heatmap/HeatmapLayer.js","../src/chart/heatmap/HeatmapView.js","../src/chart/heatmap.js","../src/chart/bar/PictorialBarSeries.js","../src/chart/bar/PictorialBarView.js","../src/chart/pictorialBar.js","../src/coord/single/SingleAxis.js","../src/coord/single/Single.js","../src/coord/single/singleCreator.js","../src/coord/single/singleAxisHelper.js","../src/component/axis/SingleAxisView.js","../src/coord/single/AxisModel.js","../src/component/axisPointer/findPointFromSeries.js","../src/component/axisPointer/axisTrigger.js","../src/component/axisPointer/AxisPointerModel.js","../src/component/axisPointer/globalListener.js","../src/component/axisPointer/AxisPointerView.js","../src/component/axisPointer/BaseAxisPointer.js","../src/component/axisPointer/viewHelper.js","../src/component/axisPointer/CartesianAxisPointer.js","../src/component/axisPointer.js","../src/component/axisPointer/SingleAxisPointer.js","../src/component/singleAxis.js","../src/chart/themeRiver/ThemeRiverSeries.js","../src/chart/themeRiver/ThemeRiverView.js","../src/chart/themeRiver/themeRiverLayout.js","../src/chart/themeRiver/themeRiverVisual.js","../src/chart/themeRiver.js","../src/chart/sunburst/SunburstSeries.js","../src/chart/sunburst/SunburstPiece.js","../src/chart/sunburst/SunburstView.js","../src/chart/sunburst/sunburstAction.js","../src/chart/sunburst/sunburstLayout.js","../src/chart/sunburst.js","../src/coord/cartesian/prepareCustom.js","../src/coord/geo/prepareCustom.js","../src/coord/single/prepareCustom.js","../src/coord/polar/prepareCustom.js","../src/coord/calendar/prepareCustom.js","../src/chart/custom.js","../src/component/grid.js","../src/layout/barPolar.js","../src/coord/polar/RadiusAxis.js","../src/coord/polar/AngleAxis.js","../src/coord/polar/Polar.js","../src/coord/polar/AxisModel.js","../src/coord/polar/PolarModel.js","../src/coord/polar/polarCreator.js","../src/component/axis/AngleAxisView.js","../src/component/angleAxis.js","../src/component/axis/RadiusAxisView.js","../src/component/radiusAxis.js","../src/component/axisPointer/PolarAxisPointer.js","../src/component/polar.js","../src/coord/geo/GeoModel.js","../src/component/geo/GeoView.js","../src/component/geo.js","../src/coord/calendar/Calendar.js","../src/coord/calendar/CalendarModel.js","../src/component/calendar/CalendarView.js","../src/component/calendar.js","../src/component/graphic.js","../src/component/toolbox/featureManager.js","../src/component/toolbox/ToolboxModel.js","../src/component/helper/listComponent.js","../src/component/toolbox/ToolboxView.js","../src/component/toolbox/feature/SaveAsImage.js","../src/component/toolbox/feature/MagicType.js","../src/component/toolbox/feature/DataView.js","../src/component/helper/BrushTargetManager.js","../src/component/dataZoom/history.js","../src/component/dataZoom/typeDefaulter.js","../src/component/dataZoom/helper.js","../src/component/dataZoom/AxisProxy.js","../src/component/dataZoom/DataZoomModel.js","../src/component/dataZoom/DataZoomView.js","../src/component/dataZoom/SelectZoomModel.js","../src/component/dataZoom/SelectZoomView.js","../src/component/dataZoom/dataZoomProcessor.js","../src/component/dataZoom/dataZoomAction.js","../src/component/dataZoomSelect.js","../src/component/toolbox/feature/DataZoom.js","../src/component/toolbox/feature/Restore.js","../src/component/toolbox.js","../src/component/tooltip/TooltipModel.js","../src/component/tooltip/TooltipContent.js","../src/component/tooltip/TooltipRichContent.js","../src/component/tooltip/TooltipView.js","../src/component/tooltip.js","../src/component/brush/preprocessor.js","../src/visual/visualSolution.js","../src/component/brush/selector.js","../src/component/brush/visualEncoding.js","../src/component/brush/BrushModel.js","../src/component/brush/BrushView.js","../src/component/brush/brushAction.js","../src/component/toolbox/feature/Brush.js","../src/component/brush.js","../src/component/title.js","../src/component/timeline/preprocessor.js","../src/component/timeline/typeDefaulter.js","../src/component/timeline/timelineAction.js","../src/component/timeline/TimelineModel.js","../src/component/timeline/SliderTimelineModel.js","../src/component/timeline/TimelineView.js","../src/component/timeline/TimelineAxis.js","../src/component/timeline/SliderTimelineView.js","../src/component/timeline.js","../src/component/marker/MarkerModel.js","../src/component/marker/MarkPointModel.js","../src/component/marker/markerHelper.js","../src/component/marker/MarkerView.js","../src/component/marker/MarkPointView.js","../src/component/markPoint.js","../src/component/marker/MarkLineModel.js","../src/component/marker/MarkLineView.js","../src/component/markLine.js","../src/component/marker/MarkAreaModel.js","../src/component/marker/MarkAreaView.js","../src/component/markArea.js","../src/component/legend/LegendModel.js","../src/component/legend/legendAction.js","../src/component/legend/LegendView.js","../src/component/legend/legendFilter.js","../src/component/legend.js","../src/component/legend/ScrollableLegendModel.js","../src/component/legend/ScrollableLegendView.js","../src/component/legend/scrollableLegendAction.js","../src/component/legendScroll.js","../src/component/dataZoom/SliderZoomModel.js","../src/component/dataZoom/SliderZoomView.js","../src/component/dataZoomSlider.js","../src/component/dataZoom/InsideZoomModel.js","../src/component/dataZoom/roams.js","../src/component/dataZoom/InsideZoomView.js","../src/component/dataZoomInside.js","../src/component/dataZoom.js","../src/component/visualMap/preprocessor.js","../src/component/visualMap/typeDefaulter.js","../src/component/visualMap/visualEncoding.js","../src/visual/visualDefault.js","../src/component/visualMap/VisualMapModel.js","../src/component/visualMap/ContinuousModel.js","../src/component/visualMap/VisualMapView.js","../src/component/visualMap/helper.js","../src/component/visualMap/ContinuousView.js","../src/component/visualMap/visualMapAction.js","../src/component/visualMapContinuous.js","../src/component/visualMap/PiecewiseModel.js","../src/component/visualMap/PiecewiseView.js","../src/component/visualMapPiecewise.js","../src/component/visualMap.js","../node_modules/zrender/src/vml/core.js","../node_modules/zrender/src/vml/graphic.js","../node_modules/zrender/src/vml/Painter.js","../node_modules/zrender/src/vml/vml.js","../node_modules/zrender/src/svg/core.js","../node_modules/zrender/src/svg/graphic.js","../node_modules/zrender/src/core/arrayDiff2.js","../node_modules/zrender/src/svg/helper/Definable.js","../node_modules/zrender/src/svg/helper/GradientManager.js","../node_modules/zrender/src/svg/helper/ClippathManager.js","../node_modules/zrender/src/svg/helper/ShadowManager.js","../node_modules/zrender/src/svg/Painter.js","../node_modules/zrender/src/svg/svg.js","../echarts.all.js"],"sourcesContent":["/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\n// (1) The code `if (__DEV__) ...` can be removed by build tool.\n// (2) If intend to use `__DEV__`, this module should be imported. Use a global\n// variable `__DEV__` may cause that miss the declaration (see #6535), or the\n// declaration is behind of the using position (for example in `Model.extent`,\n// And tools like rollup can not analysis the dependency if not import).\n\nvar dev;\n\n// In browser\nif (typeof window !== 'undefined') {\n dev = window.__DEV__;\n}\n// In node\nelse if (typeof global !== 'undefined') {\n dev = global.__DEV__;\n}\n\nif (typeof dev === 'undefined') {\n dev = true;\n}\n\nexport var __DEV__ = dev;\n","/**\n * zrender: 生成唯一id\n *\n * @author errorrik (errorrik@gmail.com)\n */\n\nvar idStart = 0x0907;\n\nexport default function () {\n return idStart++;\n}","/**\n * echarts设备环境识别\n *\n * @desc echarts基于Canvas,纯Javascript图表库,提供直观,生动,可交互,可个性化定制的数据统计图表。\n * @author firede[firede@firede.us]\n * @desc thanks zepto.\n */\n\n/* global wx */\n\nvar env = {};\n\nif (typeof wx === 'object' && typeof wx.getSystemInfoSync === 'function') {\n // In Weixin Application\n env = {\n browser: {},\n os: {},\n node: false,\n wxa: true, // Weixin Application\n canvasSupported: true,\n svgSupported: false,\n touchEventsSupported: true,\n domSupported: false\n };\n}\nelse if (typeof document === 'undefined' && typeof self !== 'undefined') {\n // In worker\n env = {\n browser: {},\n os: {},\n node: false,\n worker: true,\n canvasSupported: true,\n domSupported: false\n };\n}\nelse if (typeof navigator === 'undefined') {\n // In node\n env = {\n browser: {},\n os: {},\n node: true,\n worker: false,\n // Assume canvas is supported\n canvasSupported: true,\n svgSupported: true,\n domSupported: false\n };\n}\nelse {\n env = detect(navigator.userAgent);\n}\n\nexport default env;\n\n// Zepto.js\n// (c) 2010-2013 Thomas Fuchs\n// Zepto.js may be freely distributed under the MIT license.\n\nfunction detect(ua) {\n var os = {};\n var browser = {};\n // var webkit = ua.match(/Web[kK]it[\\/]{0,1}([\\d.]+)/);\n // var android = ua.match(/(Android);?[\\s\\/]+([\\d.]+)?/);\n // var ipad = ua.match(/(iPad).*OS\\s([\\d_]+)/);\n // var ipod = ua.match(/(iPod)(.*OS\\s([\\d_]+))?/);\n // var iphone = !ipad && ua.match(/(iPhone\\sOS)\\s([\\d_]+)/);\n // var webos = ua.match(/(webOS|hpwOS)[\\s\\/]([\\d.]+)/);\n // var touchpad = webos && ua.match(/TouchPad/);\n // var kindle = ua.match(/Kindle\\/([\\d.]+)/);\n // var silk = ua.match(/Silk\\/([\\d._]+)/);\n // var blackberry = ua.match(/(BlackBerry).*Version\\/([\\d.]+)/);\n // var bb10 = ua.match(/(BB10).*Version\\/([\\d.]+)/);\n // var rimtabletos = ua.match(/(RIM\\sTablet\\sOS)\\s([\\d.]+)/);\n // var playbook = ua.match(/PlayBook/);\n // var chrome = ua.match(/Chrome\\/([\\d.]+)/) || ua.match(/CriOS\\/([\\d.]+)/);\n var firefox = ua.match(/Firefox\\/([\\d.]+)/);\n // var safari = webkit && ua.match(/Mobile\\//) && !chrome;\n // var webview = ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/) && !chrome;\n var ie = ua.match(/MSIE\\s([\\d.]+)/)\n // IE 11 Trident/7.0; rv:11.0\n || ua.match(/Trident\\/.+?rv:(([\\d.]+))/);\n var edge = ua.match(/Edge\\/([\\d.]+)/); // IE 12 and 12+\n\n var weChat = (/micromessenger/i).test(ua);\n\n // Todo: clean this up with a better OS/browser seperation:\n // - discern (more) between multiple browsers on android\n // - decide if kindle fire in silk mode is android or not\n // - Firefox on Android doesn't specify the Android version\n // - possibly devide in os, device and browser hashes\n\n // if (browser.webkit = !!webkit) browser.version = webkit[1];\n\n // if (android) os.android = true, os.version = android[2];\n // if (iphone && !ipod) os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.');\n // if (ipad) os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.');\n // if (ipod) os.ios = os.ipod = true, os.version = ipod[3] ? ipod[3].replace(/_/g, '.') : null;\n // if (webos) os.webos = true, os.version = webos[2];\n // if (touchpad) os.touchpad = true;\n // if (blackberry) os.blackberry = true, os.version = blackberry[2];\n // if (bb10) os.bb10 = true, os.version = bb10[2];\n // if (rimtabletos) os.rimtabletos = true, os.version = rimtabletos[2];\n // if (playbook) browser.playbook = true;\n // if (kindle) os.kindle = true, os.version = kindle[1];\n // if (silk) browser.silk = true, browser.version = silk[1];\n // if (!silk && os.android && ua.match(/Kindle Fire/)) browser.silk = true;\n // if (chrome) browser.chrome = true, browser.version = chrome[1];\n if (firefox) {\n browser.firefox = true;\n browser.version = firefox[1];\n }\n // if (safari && (ua.match(/Safari/) || !!os.ios)) browser.safari = true;\n // if (webview) browser.webview = true;\n\n if (ie) {\n browser.ie = true;\n browser.version = ie[1];\n }\n\n if (edge) {\n browser.edge = true;\n browser.version = edge[1];\n }\n\n // It is difficult to detect WeChat in Win Phone precisely, because ua can\n // not be set on win phone. So we do not consider Win Phone.\n if (weChat) {\n browser.weChat = true;\n }\n\n // os.tablet = !!(ipad || playbook || (android && !ua.match(/Mobile/)) ||\n // (firefox && ua.match(/Tablet/)) || (ie && !ua.match(/Phone/) && ua.match(/Touch/)));\n // os.phone = !!(!os.tablet && !os.ipod && (android || iphone || webos ||\n // (chrome && ua.match(/Android/)) || (chrome && ua.match(/CriOS\\/([\\d.]+)/)) ||\n // (firefox && ua.match(/Mobile/)) || (ie && ua.match(/Touch/))));\n\n return {\n browser: browser,\n os: os,\n node: false,\n // 原生canvas支持,改极端点了\n // canvasSupported : !(browser.ie && parseFloat(browser.version) < 9)\n canvasSupported: !!document.createElement('canvas').getContext,\n svgSupported: typeof SVGRect !== 'undefined',\n // works on most browsers\n // IE10/11 does not support touch event, and MS Edge supports them but not by\n // default, so we dont check navigator.maxTouchPoints for them here.\n touchEventsSupported: 'ontouchstart' in window && !browser.ie && !browser.edge,\n // <http://caniuse.com/#search=pointer%20event>.\n pointerEventsSupported:\n // (1) Firefox supports pointer but not by default, only MS browsers are reliable on pointer\n // events currently. So we dont use that on other browsers unless tested sufficiently.\n // For example, in iOS 13 Mobile Chromium 78, if the touching behavior starts page\n // scroll, the `pointermove` event can not be fired any more. That will break some\n // features like \"pan horizontally to move something and pan vertically to page scroll\".\n // The horizontal pan probably be interrupted by the casually triggered page scroll.\n // (2) Although IE 10 supports pointer event, it use old style and is different from the\n // standard. So we exclude that. (IE 10 is hardly used on touch device)\n 'onpointerdown' in window\n && (browser.edge || (browser.ie && browser.version >= 11)),\n // passiveSupported: detectPassiveSupport()\n domSupported: typeof document !== 'undefined'\n };\n}\n\n// See https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md#feature-detection\n// function detectPassiveSupport() {\n// // Test via a getter in the options object to see if the passive property is accessed\n// var supportsPassive = false;\n// try {\n// var opts = Object.defineProperty({}, 'passive', {\n// get: function() {\n// supportsPassive = true;\n// }\n// });\n// window.addEventListener('testPassive', function() {}, opts);\n// } catch (e) {\n// }\n// return supportsPassive;\n// }\n","/**\n * @module zrender/core/util\n */\n\n// 用于处理merge时无法遍历Date等对象的问题\nvar BUILTIN_OBJECT = {\n '[object Function]': 1,\n '[object RegExp]': 1,\n '[object Date]': 1,\n '[object Error]': 1,\n '[object CanvasGradient]': 1,\n '[object CanvasPattern]': 1,\n // For node-canvas\n '[object Image]': 1,\n '[object Canvas]': 1\n};\n\nvar TYPED_ARRAY = {\n '[object Int8Array]': 1,\n '[object Uint8Array]': 1,\n '[object Uint8ClampedArray]': 1,\n '[object Int16Array]': 1,\n '[object Uint16Array]': 1,\n '[object Int32Array]': 1,\n '[object Uint32Array]': 1,\n '[object Float32Array]': 1,\n '[object Float64Array]': 1\n};\n\nvar objToString = Object.prototype.toString;\n\nvar arrayProto = Array.prototype;\nvar nativeForEach = arrayProto.forEach;\nvar nativeFilter = arrayProto.filter;\nvar nativeSlice = arrayProto.slice;\nvar nativeMap = arrayProto.map;\nvar nativeReduce = arrayProto.reduce;\n\n// Avoid assign to an exported variable, for transforming to cjs.\nvar methods = {};\n\nexport function $override(name, fn) {\n // Clear ctx instance for different environment\n if (name === 'createCanvas') {\n _ctx = null;\n }\n\n methods[name] = fn;\n}\n\n/**\n * Those data types can be cloned:\n * Plain object, Array, TypedArray, number, string, null, undefined.\n * Those data types will be assgined using the orginal data:\n * BUILTIN_OBJECT\n * Instance of user defined class will be cloned to a plain object, without\n * properties in prototype.\n * Other data types is not supported (not sure what will happen).\n *\n * Caution: do not support clone Date, for performance consideration.\n * (There might be a large number of date in `series.data`).\n * So date should not be modified in and out of echarts.\n *\n * @param {*} source\n * @return {*} new\n */\nexport function clone(source) {\n if (source == null || typeof source !== 'object') {\n return source;\n }\n\n var result = source;\n var typeStr = objToString.call(source);\n\n if (typeStr === '[object Array]') {\n if (!isPrimitive(source)) {\n result = [];\n for (var i = 0, len = source.length; i < len; i++) {\n result[i] = clone(source[i]);\n }\n }\n }\n else if (TYPED_ARRAY[typeStr]) {\n if (!isPrimitive(source)) {\n var Ctor = source.constructor;\n if (source.constructor.from) {\n result = Ctor.from(source);\n }\n else {\n result = new Ctor(source.length);\n for (var i = 0, len = source.length; i < len; i++) {\n result[i] = clone(source[i]);\n }\n }\n }\n }\n else if (!BUILTIN_OBJECT[typeStr] && !isPrimitive(source) && !isDom(source)) {\n result = {};\n for (var key in source) {\n if (source.hasOwnProperty(key)) {\n result[key] = clone(source[key]);\n }\n }\n }\n\n return result;\n}\n\n/**\n * @memberOf module:zrender/core/util\n * @param {*} target\n * @param {*} source\n * @param {boolean} [overwrite=false]\n */\nexport function merge(target, source, overwrite) {\n // We should escapse that source is string\n // and enter for ... in ...\n if (!isObject(source) || !isObject(target)) {\n return overwrite ? clone(source) : target;\n }\n\n for (var key in source) {\n if (source.hasOwnProperty(key)) {\n var targetProp = target[key];\n var sourceProp = source[key];\n\n if (isObject(sourceProp)\n && isObject(targetProp)\n && !isArray(sourceProp)\n && !isArray(targetProp)\n && !isDom(sourceProp)\n && !isDom(targetProp)\n && !isBuiltInObject(sourceProp)\n && !isBuiltInObject(targetProp)\n && !isPrimitive(sourceProp)\n && !isPrimitive(targetProp)\n ) {\n // 如果需要递归覆盖,就递归调用merge\n merge(targetProp, sourceProp, overwrite);\n }\n else if (overwrite || !(key in target)) {\n // 否则只处理overwrite为true,或者在目标对象中没有此属性的情况\n // NOTE,在 target[key] 不存在的时候也是直接覆盖\n target[key] = clone(source[key], true);\n }\n }\n }\n\n return target;\n}\n\n/**\n * @param {Array} targetAndSources The first item is target, and the rests are source.\n * @param {boolean} [overwrite=false]\n * @return {*} target\n */\nexport function mergeAll(targetAndSources, overwrite) {\n var result = targetAndSources[0];\n for (var i = 1, len = targetAndSources.length; i < len; i++) {\n result = merge(result, targetAndSources[i], overwrite);\n }\n return result;\n}\n\n/**\n * @param {*} target\n * @param {*} source\n * @memberOf module:zrender/core/util\n */\nexport function extend(target, source) {\n for (var key in source) {\n if (source.hasOwnProperty(key)) {\n target[key] = source[key];\n }\n }\n return target;\n}\n\n/**\n * @param {*} target\n * @param {*} source\n * @param {boolean} [overlay=false]\n * @memberOf module:zrender/core/util\n */\nexport function defaults(target, source, overlay) {\n for (var key in source) {\n if (source.hasOwnProperty(key)\n && (overlay ? source[key] != null : target[key] == null)\n ) {\n target[key] = source[key];\n }\n }\n return target;\n}\n\nexport var createCanvas = function () {\n return methods.createCanvas();\n};\n\nmethods.createCanvas = function () {\n return document.createElement('canvas');\n};\n\n// FIXME\nvar _ctx;\n\nexport function getContext() {\n if (!_ctx) {\n // Use util.createCanvas instead of createCanvas\n // because createCanvas may be overwritten in different environment\n _ctx = createCanvas().getContext('2d');\n }\n return _ctx;\n}\n\n/**\n * 查询数组中元素的index\n * @memberOf module:zrender/core/util\n */\nexport function indexOf(array, value) {\n if (array) {\n if (array.indexOf) {\n return array.indexOf(value);\n }\n for (var i = 0, len = array.length; i < len; i++) {\n if (array[i] === value) {\n return i;\n }\n }\n }\n return -1;\n}\n\n/**\n * 构造类继承关系\n *\n * @memberOf module:zrender/core/util\n * @param {Function} clazz 源类\n * @param {Function} baseClazz 基类\n */\nexport function inherits(clazz, baseClazz) {\n var clazzPrototype = clazz.prototype;\n function F() {}\n F.prototype = baseClazz.prototype;\n clazz.prototype = new F();\n\n for (var prop in clazzPrototype) {\n if (clazzPrototype.hasOwnProperty(prop)) {\n clazz.prototype[prop] = clazzPrototype[prop];\n }\n }\n clazz.prototype.constructor = clazz;\n clazz.superClass = baseClazz;\n}\n\n/**\n * @memberOf module:zrender/core/util\n * @param {Object|Function} target\n * @param {Object|Function} sorce\n * @param {boolean} overlay\n */\nexport function mixin(target, source, overlay) {\n target = 'prototype' in target ? target.prototype : target;\n source = 'prototype' in source ? source.prototype : source;\n\n defaults(target, source, overlay);\n}\n\n/**\n * Consider typed array.\n * @param {Array|TypedArray} data\n */\nexport function isArrayLike(data) {\n if (!data) {\n return;\n }\n if (typeof data === 'string') {\n return false;\n }\n return typeof data.length === 'number';\n}\n\n/**\n * 数组或对象遍历\n * @memberOf module:zrender/core/util\n * @param {Object|Array} obj\n * @param {Function} cb\n * @param {*} [context]\n */\nexport function each(obj, cb, context) {\n if (!(obj && cb)) {\n return;\n }\n if (obj.forEach && obj.forEach === nativeForEach) {\n obj.forEach(cb, context);\n }\n else if (obj.length === +obj.length) {\n for (var i = 0, len = obj.length; i < len; i++) {\n cb.call(context, obj[i], i, obj);\n }\n }\n else {\n for (var key in obj) {\n if (obj.hasOwnProperty(key)) {\n cb.call(context, obj[key], key, obj);\n }\n }\n }\n}\n\n/**\n * 数组映射\n * @memberOf module:zrender/core/util\n * @param {Array} obj\n * @param {Function} cb\n * @param {*} [context]\n * @return {Array}\n */\nexport function map(obj, cb, context) {\n if (!(obj && cb)) {\n return;\n }\n if (obj.map && obj.map === nativeMap) {\n return obj.map(cb, context);\n }\n else {\n var result = [];\n for (var i = 0, len = obj.length; i < len; i++) {\n result.push(cb.call(context, obj[i], i, obj));\n }\n return result;\n }\n}\n\n/**\n * @memberOf module:zrender/core/util\n * @param {Array} obj\n * @param {Function} cb\n * @param {Object} [memo]\n * @param {*} [context]\n * @return {Array}\n */\nexport function reduce(obj, cb, memo, context) {\n if (!(obj && cb)) {\n return;\n }\n if (obj.reduce && obj.reduce === nativeReduce) {\n return obj.reduce(cb, memo, context);\n }\n else {\n for (var i = 0, len = obj.length; i < len; i++) {\n memo = cb.call(context, memo, obj[i], i, obj);\n }\n return memo;\n }\n}\n\n/**\n * 数组过滤\n * @memberOf module:zrender/core/util\n * @param {Array} obj\n * @param {Function} cb\n * @param {*} [context]\n * @return {Array}\n */\nexport function filter(obj, cb, context) {\n if (!(obj && cb)) {\n return;\n }\n if (obj.filter && obj.filter === nativeFilter) {\n return obj.filter(cb, context);\n }\n else {\n var result = [];\n for (var i = 0, len = obj.length; i < len; i++) {\n if (cb.call(context, obj[i], i, obj)) {\n result.push(obj[i]);\n }\n }\n return result;\n }\n}\n\n/**\n * 数组项查找\n * @memberOf module:zrender/core/util\n * @param {Array} obj\n * @param {Function} cb\n * @param {*} [context]\n * @return {*}\n */\nexport function find(obj, cb, context) {\n if (!(obj && cb)) {\n return;\n }\n for (var i = 0, len = obj.length; i < len; i++) {\n if (cb.call(context, obj[i], i, obj)) {\n return obj[i];\n }\n }\n}\n\n/**\n * @memberOf module:zrender/core/util\n * @param {Function} func\n * @param {*} context\n * @return {Function}\n */\nexport function bind(func, context) {\n var args = nativeSlice.call(arguments, 2);\n return function () {\n return func.apply(context, args.concat(nativeSlice.call(arguments)));\n };\n}\n\n/**\n * @memberOf module:zrender/core/util\n * @param {Function} func\n * @return {Function}\n */\nexport function curry(func) {\n var args = nativeSlice.call(arguments, 1);\n return function () {\n return func.apply(this, args.concat(nativeSlice.call(arguments)));\n };\n}\n\n/**\n * @memberOf module:zrender/core/util\n * @param {*} value\n * @return {boolean}\n */\nexport function isArray(value) {\n return objToString.call(value) === '[object Array]';\n}\n\n/**\n * @memberOf module:zrender/core/util\n * @param {*} value\n * @return {boolean}\n */\nexport function isFunction(value) {\n return typeof value === 'function';\n}\n\n/**\n * @memberOf module:zrender/core/util\n * @param {*} value\n * @return {boolean}\n */\nexport function isString(value) {\n return objToString.call(value) === '[object String]';\n}\n\n/**\n * @memberOf module:zrender/core/util\n * @param {*} value\n * @return {boolean}\n */\nexport function isObject(value) {\n // Avoid a V8 JIT bug in Chrome 19-20.\n // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.\n var type = typeof value;\n return type === 'function' || (!!value && type === 'object');\n}\n\n/**\n * @memberOf module:zrender/core/util\n * @param {*} value\n * @return {boolean}\n */\nexport function isBuiltInObject(value) {\n return !!BUILTIN_OBJECT[objToString.call(value)];\n}\n\n/**\n * @memberOf module:zrender/core/util\n * @param {*} value\n * @return {boolean}\n */\nexport function isTypedArray(value) {\n return !!TYPED_ARRAY[objToString.call(value)];\n}\n\n/**\n * @memberOf module:zrender/core/util\n * @param {*} value\n * @return {boolean}\n */\nexport function isDom(value) {\n return typeof value === 'object'\n && typeof value.nodeType === 'number'\n && typeof value.ownerDocument === 'object';\n}\n\n/**\n * Whether is exactly NaN. Notice isNaN('a') returns true.\n * @param {*} value\n * @return {boolean}\n */\nexport function eqNaN(value) {\n /* eslint-disable-next-line no-self-compare */\n return value !== value;\n}\n\n/**\n * If value1 is not null, then return value1, otherwise judget rest of values.\n * Low performance.\n * @memberOf module:zrender/core/util\n * @return {*} Final value\n */\nexport function retrieve(values) {\n for (var i = 0, len = arguments.length; i < len; i++) {\n if (arguments[i] != null) {\n return arguments[i];\n }\n }\n}\n\nexport function retrieve2(value0, value1) {\n return value0 != null\n ? value0\n : value1;\n}\n\nexport function retrieve3(value0, value1, value2) {\n return value0 != null\n ? value0\n : value1 != null\n ? value1\n : value2;\n}\n\n/**\n * @memberOf module:zrender/core/util\n * @param {Array} arr\n * @param {number} startIndex\n * @param {number} endIndex\n * @return {Array}\n */\nexport function slice() {\n return Function.call.apply(nativeSlice, arguments);\n}\n\n/**\n * Normalize css liked array configuration\n * e.g.\n * 3 => [3, 3, 3, 3]\n * [4, 2] => [4, 2, 4, 2]\n * [4, 3, 2] => [4, 3, 2, 3]\n * @param {number|Array.<number>} val\n * @return {Array.<number>}\n */\nexport function normalizeCssArray(val) {\n if (typeof (val) === 'number') {\n return [val, val, val, val];\n }\n var len = val.length;\n if (len === 2) {\n // vertical | horizontal\n return [val[0], val[1], val[0], val[1]];\n }\n else if (len === 3) {\n // top | horizontal | bottom\n return [val[0], val[1], val[2], val[1]];\n }\n return val;\n}\n\n/**\n * @memberOf module:zrender/core/util\n * @param {boolean} condition\n * @param {string} message\n */\nexport function assert(condition, message) {\n if (!condition) {\n throw new Error(message);\n }\n}\n\n/**\n * @memberOf module:zrender/core/util\n * @param {string} str string to be trimed\n * @return {string} trimed string\n */\nexport function trim(str) {\n if (str == null) {\n return null;\n }\n else if (typeof str.trim === 'function') {\n return str.trim();\n }\n else {\n return str.replace(/^[\\s\\uFEFF\\xA0]+|[\\s\\uFEFF\\xA0]+$/g, '');\n }\n}\n\nvar primitiveKey = '__ec_primitive__';\n/**\n * Set an object as primitive to be ignored traversing children in clone or merge\n */\nexport function setAsPrimitive(obj) {\n obj[primitiveKey] = true;\n}\n\nexport function isPrimitive(obj) {\n return obj[primitiveKey];\n}\n\n/**\n * @constructor\n * @param {Object} obj Only apply `ownProperty`.\n */\nfunction HashMap(obj) {\n var isArr = isArray(obj);\n // Key should not be set on this, otherwise\n // methods get/set/... may be overrided.\n this.data = {};\n var thisMap = this;\n\n (obj instanceof HashMap)\n ? obj.each(visit)\n : (obj && each(obj, visit));\n\n function visit(value, key) {\n isArr ? thisMap.set(value, key) : thisMap.set(key, value);\n }\n}\n\nHashMap.prototype = {\n constructor: HashMap,\n // Do not provide `has` method to avoid defining what is `has`.\n // (We usually treat `null` and `undefined` as the same, different\n // from ES6 Map).\n get: function (key) {\n return this.data.hasOwnProperty(key) ? this.data[key] : null;\n },\n set: function (key, value) {\n // Comparing with invocation chaining, `return value` is more commonly\n // used in this case: `var someVal = map.set('a', genVal());`\n return (this.data[key] = value);\n },\n // Although util.each can be performed on this hashMap directly, user\n // should not use the exposed keys, who are prefixed.\n each: function (cb, context) {\n context !== void 0 && (cb = bind(cb, context));\n /* eslint-disable guard-for-in */\n for (var key in this.data) {\n this.data.hasOwnProperty(key) && cb(this.data[key], key);\n }\n /* eslint-enable guard-for-in */\n },\n // Do not use this method if performance sensitive.\n removeKey: function (key) {\n delete this.data[key];\n }\n};\n\nexport function createHashMap(obj) {\n return new HashMap(obj);\n}\n\nexport function concatArray(a, b) {\n var newArray = new a.constructor(a.length + b.length);\n for (var i = 0; i < a.length; i++) {\n newArray[i] = a[i];\n }\n var offset = a.length;\n for (i = 0; i < b.length; i++) {\n newArray[i + offset] = b[i];\n }\n return newArray;\n}\n\n\nexport function noop() {}\n","/* global Float32Array */\n\nvar ArrayCtor = typeof Float32Array === 'undefined'\n ? Array\n : Float32Array;\n\n/**\n * 创建一个向量\n * @param {number} [x=0]\n * @param {number} [y=0]\n * @return {Vector2}\n */\nexport function create(x, y) {\n var out = new ArrayCtor(2);\n if (x == null) {\n x = 0;\n }\n if (y == null) {\n y = 0;\n }\n out[0] = x;\n out[1] = y;\n return out;\n}\n\n/**\n * 复制向量数据\n * @param {Vector2} out\n * @param {Vector2} v\n * @return {Vector2}\n */\nexport function copy(out, v) {\n out[0] = v[0];\n out[1] = v[1];\n return out;\n}\n\n/**\n * 克隆一个向量\n * @param {Vector2} v\n * @return {Vector2}\n */\nexport function clone(v) {\n var out = new ArrayCtor(2);\n out[0] = v[0];\n out[1] = v[1];\n return out;\n}\n\n/**\n * 设置向量的两个项\n * @param {Vector2} out\n * @param {number} a\n * @param {number} b\n * @return {Vector2} 结果\n */\nexport function set(out, a, b) {\n out[0] = a;\n out[1] = b;\n return out;\n}\n\n/**\n * 向量相加\n * @param {Vector2} out\n * @param {Vector2} v1\n * @param {Vector2} v2\n */\nexport function add(out, v1, v2) {\n out[0] = v1[0] + v2[0];\n out[1] = v1[1] + v2[1];\n return out;\n}\n\n/**\n * 向量缩放后相加\n * @param {Vector2} out\n * @param {Vector2} v1\n * @param {Vector2} v2\n * @param {number} a\n */\nexport function scaleAndAdd(out, v1, v2, a) {\n out[0] = v1[0] + v2[0] * a;\n out[1] = v1[1] + v2[1] * a;\n return out;\n}\n\n/**\n * 向量相减\n * @param {Vector2} out\n * @param {Vector2} v1\n * @param {Vector2} v2\n */\nexport function sub(out, v1, v2) {\n out[0] = v1[0] - v2[0];\n out[1] = v1[1] - v2[1];\n return out;\n}\n\n/**\n * 向量长度\n * @param {Vector2} v\n * @return {number}\n */\nexport function len(v) {\n return Math.sqrt(lenSquare(v));\n}\nexport var length = len; // jshint ignore:line\n\n/**\n * 向量长度平方\n * @param {Vector2} v\n * @return {number}\n */\nexport function lenSquare(v) {\n return v[0] * v[0] + v[1] * v[1];\n}\nexport var lengthSquare = lenSquare;\n\n/**\n * 向量乘法\n * @param {Vector2} out\n * @param {Vector2} v1\n * @param {Vector2} v2\n */\nexport function mul(out, v1, v2) {\n out[0] = v1[0] * v2[0];\n out[1] = v1[1] * v2[1];\n return out;\n}\n\n/**\n * 向量除法\n * @param {Vector2} out\n * @param {Vector2} v1\n * @param {Vector2} v2\n */\nexport function div(out, v1, v2) {\n out[0] = v1[0] / v2[0];\n out[1] = v1[1] / v2[1];\n return out;\n}\n\n/**\n * 向量点乘\n * @param {Vector2} v1\n * @param {Vector2} v2\n * @return {number}\n */\nexport function dot(v1, v2) {\n return v1[0] * v2[0] + v1[1] * v2[1];\n}\n\n/**\n * 向量缩放\n * @param {Vector2} out\n * @param {Vector2} v\n * @param {number} s\n */\nexport function scale(out, v, s) {\n out[0] = v[0] * s;\n out[1] = v[1] * s;\n return out;\n}\n\n/**\n * 向量归一化\n * @param {Vector2} out\n * @param {Vector2} v\n */\nexport function normalize(out, v) {\n var d = len(v);\n if (d === 0) {\n out[0] = 0;\n out[1] = 0;\n }\n else {\n out[0] = v[0] / d;\n out[1] = v[1] / d;\n }\n return out;\n}\n\n/**\n * 计算向量间距离\n * @param {Vector2} v1\n * @param {Vector2} v2\n * @return {number}\n */\nexport function distance(v1, v2) {\n return Math.sqrt(\n (v1[0] - v2[0]) * (v1[0] - v2[0])\n + (v1[1] - v2[1]) * (v1[1] - v2[1])\n );\n}\nexport var dist = distance;\n\n/**\n * 向量距离平方\n * @param {Vector2} v1\n * @param {Vector2} v2\n * @return {number}\n */\nexport function distanceSquare(v1, v2) {\n return (v1[0] - v2[0]) * (v1[0] - v2[0])\n + (v1[1] - v2[1]) * (v1[1] - v2[1]);\n}\nexport var distSquare = distanceSquare;\n\n/**\n * 求负向量\n * @param {Vector2} out\n * @param {Vector2} v\n */\nexport function negate(out, v) {\n out[0] = -v[0];\n out[1] = -v[1];\n return out;\n}\n\n/**\n * 插值两个点\n * @param {Vector2} out\n * @param {Vector2} v1\n * @param {Vector2} v2\n * @param {number} t\n */\nexport function lerp(out, v1, v2, t) {\n out[0] = v1[0] + t * (v2[0] - v1[0]);\n out[1] = v1[1] + t * (v2[1] - v1[1]);\n return out;\n}\n\n/**\n * 矩阵左乘向量\n * @param {Vector2} out\n * @param {Vector2} v\n * @param {Vector2} m\n */\nexport function applyTransform(out, v, m) {\n var x = v[0];\n var y = v[1];\n out[0] = m[0] * x + m[2] * y + m[4];\n out[1] = m[1] * x + m[3] * y + m[5];\n return out;\n}\n\n/**\n * 求两个向量最小值\n * @param {Vector2} out\n * @param {Vector2} v1\n * @param {Vector2} v2\n */\nexport function min(out, v1, v2) {\n out[0] = Math.min(v1[0], v2[0]);\n out[1] = Math.min(v1[1], v2[1]);\n return out;\n}\n\n/**\n * 求两个向量最大值\n * @param {Vector2} out\n * @param {Vector2} v1\n * @param {Vector2} v2\n */\nexport function max(out, v1, v2) {\n out[0] = Math.max(v1[0], v2[0]);\n out[1] = Math.max(v1[1], v2[1]);\n return out;\n}\n","// TODO Draggable for group\n// FIXME Draggable on element which has parent rotation or scale\nfunction Draggable() {\n\n this.on('mousedown', this._dragStart, this);\n this.on('mousemove', this._drag, this);\n this.on('mouseup', this._dragEnd, this);\n // `mosuemove` and `mouseup` can be continue to fire when dragging.\n // See [Drag outside] in `Handler.js`. So we do not need to trigger\n // `_dragEnd` when globalout. That would brings better user experience.\n // this.on('globalout', this._dragEnd, this);\n\n // this._dropTarget = null;\n // this._draggingTarget = null;\n\n // this._x = 0;\n // this._y = 0;\n}\n\nDraggable.prototype = {\n\n constructor: Draggable,\n\n _dragStart: function (e) {\n var draggingTarget = e.target;\n // Find if there is draggable in the ancestor\n while (draggingTarget && !draggingTarget.draggable) {\n draggingTarget = draggingTarget.parent;\n }\n if (draggingTarget) {\n this._draggingTarget = draggingTarget;\n draggingTarget.dragging = true;\n this._x = e.offsetX;\n this._y = e.offsetY;\n\n this.dispatchToElement(param(draggingTarget, e), 'dragstart', e.event);\n }\n },\n\n _drag: function (e) {\n var draggingTarget = this._draggingTarget;\n if (draggingTarget) {\n\n var x = e.offsetX;\n var y = e.offsetY;\n\n var dx = x - this._x;\n var dy = y - this._y;\n this._x = x;\n this._y = y;\n\n draggingTarget.drift(dx, dy, e);\n this.dispatchToElement(param(draggingTarget, e), 'drag', e.event);\n\n var dropTarget = this.findHover(x, y, draggingTarget).target;\n var lastDropTarget = this._dropTarget;\n this._dropTarget = dropTarget;\n\n if (draggingTarget !== dropTarget) {\n if (lastDropTarget && dropTarget !== lastDropTarget) {\n this.dispatchToElement(param(lastDropTarget, e), 'dragleave', e.event);\n }\n if (dropTarget && dropTarget !== lastDropTarget) {\n this.dispatchToElement(param(dropTarget, e), 'dragenter', e.event);\n }\n }\n }\n },\n\n _dragEnd: function (e) {\n var draggingTarget = this._draggingTarget;\n\n if (draggingTarget) {\n draggingTarget.dragging = false;\n }\n\n this.dispatchToElement(param(draggingTarget, e), 'dragend', e.event);\n\n if (this._dropTarget) {\n this.dispatchToElement(param(this._dropTarget, e), 'drop', e.event);\n }\n\n this._draggingTarget = null;\n this._dropTarget = null;\n }\n\n};\n\nfunction param(target, e) {\n return {target: target, topTarget: e && e.topTarget};\n}\n\nexport default Draggable;","/**\n * Event Mixin\n * @module zrender/mixin/Eventful\n * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)\n * pissang (https://www.github.com/pissang)\n */\n\nvar arrySlice = Array.prototype.slice;\n\n/**\n * Event dispatcher.\n *\n * @alias module:zrender/mixin/Eventful\n * @constructor\n * @param {Object} [eventProcessor] The object eventProcessor is the scope when\n * `eventProcessor.xxx` called.\n * @param {Function} [eventProcessor.normalizeQuery]\n * param: {string|Object} Raw query.\n * return: {string|Object} Normalized query.\n * @param {Function} [eventProcessor.filter] Event will be dispatched only\n * if it returns `true`.\n * param: {string} eventType\n * param: {string|Object} query\n * return: {boolean}\n * @param {Function} [eventProcessor.afterTrigger] Called after all handlers called.\n * param: {string} eventType\n */\nvar Eventful = function (eventProcessor) {\n this._$handlers = {};\n this._$eventProcessor = eventProcessor;\n};\n\nEventful.prototype = {\n\n constructor: Eventful,\n\n /**\n * The handler can only be triggered once, then removed.\n *\n * @param {string} event The event name.\n * @param {string|Object} [query] Condition used on event filter.\n * @param {Function} handler The event handler.\n * @param {Object} context\n */\n one: function (event, query, handler, context) {\n return on(this, event, query, handler, context, true);\n },\n\n /**\n * Bind a handler.\n *\n * @param {string} event The event name.\n * @param {string|Object} [query] Condition used on event filter.\n * @param {Function} handler The event handler.\n * @param {Object} [context]\n */\n on: function (event, query, handler, context) {\n return on(this, event, query, handler, context, false);\n },\n\n /**\n * Whether any handler has bound.\n *\n * @param {string} event\n * @return {boolean}\n */\n isSilent: function (event) {\n var _h = this._$handlers;\n return !_h[event] || !_h[event].length;\n },\n\n /**\n * Unbind a event.\n *\n * @param {string} [event] The event name.\n * If no `event` input, \"off\" all listeners.\n * @param {Function} [handler] The event handler.\n * If no `handler` input, \"off\" all listeners of the `event`.\n */\n off: function (event, handler) {\n var _h = this._$handlers;\n\n if (!event) {\n this._$handlers = {};\n return this;\n }\n\n if (handler) {\n if (_h[event]) {\n var newList = [];\n for (var i = 0, l = _h[event].length; i < l; i++) {\n if (_h[event][i].h !== handler) {\n newList.push(_h[event][i]);\n }\n }\n _h[event] = newList;\n }\n\n if (_h[event] && _h[event].length === 0) {\n delete _h[event];\n }\n }\n else {\n delete _h[event];\n }\n\n return this;\n },\n\n /**\n * Dispatch a event.\n *\n * @param {string} type The event name.\n */\n trigger: function (type) {\n var _h = this._$handlers[type];\n var eventProcessor = this._$eventProcessor;\n\n if (_h) {\n var args = arguments;\n var argLen = args.length;\n\n if (argLen > 3) {\n args = arrySlice.call(args, 1);\n }\n\n var len = _h.length;\n for (var i = 0; i < len;) {\n var hItem = _h[i];\n if (eventProcessor\n && eventProcessor.filter\n && hItem.query != null\n && !eventProcessor.filter(type, hItem.query)\n ) {\n i++;\n continue;\n }\n\n // Optimize advise from backbone\n switch (argLen) {\n case 1:\n hItem.h.call(hItem.ctx);\n break;\n case 2:\n hItem.h.call(hItem.ctx, args[1]);\n break;\n case 3:\n hItem.h.call(hItem.ctx, args[1], args[2]);\n break;\n default:\n // have more than 2 given arguments\n hItem.h.apply(hItem.ctx, args);\n break;\n }\n\n if (hItem.one) {\n _h.splice(i, 1);\n len--;\n }\n else {\n i++;\n }\n }\n }\n\n eventProcessor && eventProcessor.afterTrigger\n && eventProcessor.afterTrigger(type);\n\n return this;\n },\n\n /**\n * Dispatch a event with context, which is specified at the last parameter.\n *\n * @param {string} type The event name.\n */\n triggerWithContext: function (type) {\n var _h = this._$handlers[type];\n var eventProcessor = this._$eventProcessor;\n\n if (_h) {\n var args = arguments;\n var argLen = args.length;\n\n if (argLen > 4) {\n args = arrySlice.call(args, 1, args.length - 1);\n }\n var ctx = args[args.length - 1];\n\n var len = _h.length;\n for (var i = 0; i < len;) {\n var hItem = _h[i];\n if (eventProcessor\n && eventProcessor.filter\n && hItem.query != null\n && !eventProcessor.filter(type, hItem.query)\n ) {\n i++;\n continue;\n }\n\n // Optimize advise from backbone\n switch (argLen) {\n case 1:\n hItem.h.call(ctx);\n break;\n case 2:\n hItem.h.call(ctx, args[1]);\n break;\n case 3:\n hItem.h.call(ctx, args[1], args[2]);\n break;\n default:\n // have more than 2 given arguments\n hItem.h.apply(ctx, args);\n break;\n }\n\n if (hItem.one) {\n _h.splice(i, 1);\n len--;\n }\n else {\n i++;\n }\n }\n }\n\n eventProcessor && eventProcessor.afterTrigger\n && eventProcessor.afterTrigger(type);\n\n return this;\n }\n};\n\n\nfunction normalizeQuery(host, query) {\n var eventProcessor = host._$eventProcessor;\n if (query != null && eventProcessor && eventProcessor.normalizeQuery) {\n query = eventProcessor.normalizeQuery(query);\n }\n return query;\n}\n\nfunction on(eventful, event, query, handler, context, isOnce) {\n var _h = eventful._$handlers;\n\n if (typeof query === 'function') {\n context = handler;\n handler = query;\n query = null;\n }\n\n if (!handler || !event) {\n return eventful;\n }\n\n query = normalizeQuery(eventful, query);\n\n if (!_h[event]) {\n _h[event] = [];\n }\n\n for (var i = 0; i < _h[event].length; i++) {\n if (_h[event][i].h === handler) {\n return eventful;\n }\n }\n\n var wrap = {\n h: handler,\n one: isOnce,\n query: query,\n ctx: context || eventful,\n // FIXME\n // Do not publish this feature util it is proved that it makes sense.\n callAtLast: handler.zrEventfulCallAtLast\n };\n\n var lastIndex = _h[event].length - 1;\n var lastWrap = _h[event][lastIndex];\n (lastWrap && lastWrap.callAtLast)\n ? _h[event].splice(lastIndex, 0, wrap)\n : _h[event].push(wrap);\n\n return eventful;\n}\n\n// ----------------------\n// The events in zrender\n// ----------------------\n\n/**\n * @event module:zrender/mixin/Eventful#onclick\n * @type {Function}\n * @default null\n */\n/**\n * @event module:zrender/mixin/Eventful#onmouseover\n * @type {Function}\n * @default null\n */\n/**\n * @event module:zrender/mixin/Eventful#onmouseout\n * @type {Function}\n * @default null\n */\n/**\n * @event module:zrender/mixin/Eventful#onmousemove\n * @type {Function}\n * @default null\n */\n/**\n * @event module:zrender/mixin/Eventful#onmousewheel\n * @type {Function}\n * @default null\n */\n/**\n * @event module:zrender/mixin/Eventful#onmousedown\n * @type {Function}\n * @default null\n */\n/**\n * @event module:zrender/mixin/Eventful#onmouseup\n * @type {Function}\n * @default null\n */\n/**\n * @event module:zrender/mixin/Eventful#ondrag\n * @type {Function}\n * @default null\n */\n/**\n * @event module:zrender/mixin/Eventful#ondragstart\n * @type {Function}\n * @default null\n */\n/**\n * @event module:zrender/mixin/Eventful#ondragend\n * @type {Function}\n * @default null\n */\n/**\n * @event module:zrender/mixin/Eventful#ondragenter\n * @type {Function}\n * @default null\n */\n/**\n * @event module:zrender/mixin/Eventful#ondragleave\n * @type {Function}\n * @default null\n */\n/**\n * @event module:zrender/mixin/Eventful#ondragover\n * @type {Function}\n * @default null\n */\n/**\n * @event module:zrender/mixin/Eventful#ondrop\n * @type {Function}\n * @default null\n */\n\nexport default Eventful;","/**\n * The algoritm is learnt from\n * https://franklinta.com/2014/09/08/computing-css-matrix3d-transforms/\n * And we made some optimization for matrix inversion.\n * Other similar approaches:\n * \"cv::getPerspectiveTransform\", \"Direct Linear Transformation\".\n */\n\nvar LN2 = Math.log(2);\n\nfunction determinant(rows, rank, rowStart, rowMask, colMask, detCache) {\n var cacheKey = rowMask + '-' + colMask;\n var fullRank = rows.length;\n\n if (detCache.hasOwnProperty(cacheKey)) {\n return detCache[cacheKey];\n }\n\n if (rank === 1) {\n // In this case the colMask must be like: `11101111`. We can find the place of `0`.\n var colStart = Math.round(Math.log(((1 << fullRank) - 1) & ~colMask) / LN2);\n return rows[rowStart][colStart];\n }\n\n var subRowMask = rowMask | (1 << rowStart);\n var subRowStart = rowStart + 1;\n while (rowMask & (1 << subRowStart)) {\n subRowStart++;\n }\n\n var sum = 0;\n for (var j = 0, colLocalIdx = 0; j < fullRank; j++) {\n var colTag = 1 << j;\n if (!(colTag & colMask)) {\n sum += (colLocalIdx % 2 ? -1 : 1) * rows[rowStart][j]\n // det(subMatrix(0, j))\n * determinant(rows, rank - 1, subRowStart, subRowMask, colMask | colTag, detCache);\n colLocalIdx++;\n }\n }\n\n detCache[cacheKey] = sum;\n\n return sum;\n}\n\n/**\n * Usage:\n * ```js\n * var transformer = buildTransformer(\n * [10, 44, 100, 44, 100, 300, 10, 300],\n * [50, 54, 130, 14, 140, 330, 14, 220]\n * );\n * var out = [];\n * transformer && transformer([11, 33], out);\n * ```\n *\n * Notice: `buildTransformer` may take more than 10ms in some Android device.\n *\n * @param {Array.<number>} src source four points, [x0, y0, x1, y1, x2, y2, x3, y3]\n * @param {Array.<number>} dest destination four points, [x0, y0, x1, y1, x2, y2, x3, y3]\n * @return {Function} transformer If fail, return null/undefined.\n */\nexport function buildTransformer(src, dest) {\n var mA = [\n [src[0], src[1], 1, 0, 0, 0, -dest[0] * src[0], -dest[0] * src[1]],\n [0, 0, 0, src[0], src[1], 1, -dest[1] * src[0], -dest[1] * src[1]],\n [src[2], src[3], 1, 0, 0, 0, -dest[2] * src[2], -dest[2] * src[3]],\n [0, 0, 0, src[2], src[3], 1, -dest[3] * src[2], -dest[3] * src[3]],\n [src[4], src[5], 1, 0, 0, 0, -dest[4] * src[4], -dest[4] * src[5]],\n [0, 0, 0, src[4], src[5], 1, -dest[5] * src[4], -dest[5] * src[5]],\n [src[6], src[7], 1, 0, 0, 0, -dest[6] * src[6], -dest[6] * src[7]],\n [0, 0, 0, src[6], src[7], 1, -dest[7] * src[6], -dest[7] * src[7]]\n ];\n\n var detCache = {};\n var det = determinant(mA, 8, 0, 0, 0, detCache);\n if (det === 0) {\n // can not make transformer when and only when\n // any three of the markers are collinear.\n return;\n }\n\n // `invert(mA) * dest`, that is, `adj(mA) / det * dest`.\n var vh = [];\n for (var i = 0; i < 8; i++) {\n for (var j = 0; j < 8; j++) {\n vh[j] == null && (vh[j] = 0);\n vh[j] += ((i + j) % 2 ? -1 : 1)\n // det(subMatrix(i, j))\n * determinant(mA, 7, i === 0 ? 1 : 0, 1 << i, 1 << j, detCache)\n / det * dest[i];\n }\n }\n\n return function (out, srcPointX, srcPointY) {\n var pk = srcPointX * vh[6] + srcPointY * vh[7] + 1;\n out[0] = (srcPointX * vh[0] + srcPointY * vh[1] + vh[2]) / pk;\n out[1] = (srcPointX * vh[3] + srcPointY * vh[4] + vh[5]) / pk;\n };\n}\n","\nimport env from './env';\nimport {buildTransformer} from './fourPointsTransform';\n\nvar EVENT_SAVED_PROP = '___zrEVENTSAVED';\nvar _calcOut = [];\n\n/**\n * Transform \"local coord\" from `elFrom` to `elTarget`.\n * \"local coord\": the coord based on the input `el`. The origin point is at\n * the position of \"left: 0; top: 0;\" in the `el`.\n *\n * Support when CSS transform is used.\n *\n * Having the `out` (that is, `[outX, outY]`), we can create an DOM element\n * and set the CSS style as \"left: outX; top: outY;\" and append it to `elTarge`\n * to locate the element.\n *\n * For example, this code below positions a child of `document.body` on the event\n * point, no matter whether `body` has `margin`/`paddin`/`transfrom`/... :\n * ```js\n * transformLocalCoord(out, container, document.body, event.offsetX, event.offsetY);\n * if (!eqNaN(out[0])) {\n * // Then locate the tip element on the event point.\n * var tipEl = document.createElement('div');\n * tipEl.style.cssText = 'position: absolute; left:' + out[0] + ';top:' + out[1] + ';';\n * document.body.appendChild(tipEl);\n * }\n * ```\n *\n * Notice: In some env this method is not supported. If called, `out` will be `[NaN, NaN]`.\n *\n * @param {Array.<number>} out [inX: number, inY: number] The output..\n * If can not transform, `out` will not be modified but return `false`.\n * @param {HTMLElement} elFrom The `[inX, inY]` is based on elFrom.\n * @param {HTMLElement} elTarget The `out` is based on elTarget.\n * @param {number} inX\n * @param {number} inY\n * @return {boolean} Whether transform successfully.\n */\nexport function transformLocalCoord(out, elFrom, elTarget, inX, inY) {\n return transformCoordWithViewport(_calcOut, elFrom, inX, inY, true)\n && transformCoordWithViewport(out, elTarget, _calcOut[0], _calcOut[1]);\n}\n\n/**\n * Transform between a \"viewport coord\" and a \"local coord\".\n * \"viewport coord\": the coord based on the left-top corner of the viewport\n * of the browser.\n * \"local coord\": the coord based on the input `el`. The origin point is at\n * the position of \"left: 0; top: 0;\" in the `el`.\n *\n * Support the case when CSS transform is used on el.\n *\n * @param {Array.<number>} out [inX: number, inY: number] The output. If `inverse: false`,\n * it represents \"local coord\", otherwise \"vireport coord\".\n * If can not transform, `out` will not be modified but return `false`.\n * @param {HTMLElement} el The \"local coord\" is based on the `el`, see comment above.\n * @param {number} inX If `inverse: false`,\n * it represents \"vireport coord\", otherwise \"local coord\".\n * @param {number} inY If `inverse: false`,\n * it represents \"vireport coord\", otherwise \"local coord\".\n * @param {boolean} [inverse=false]\n * `true`: from \"viewport coord\" to \"local coord\".\n * `false`: from \"local coord\" to \"viewport coord\".\n * @return {boolean} Whether transform successfully.\n */\nexport function transformCoordWithViewport(out, el, inX, inY, inverse) {\n if (el.getBoundingClientRect && env.domSupported && !isCanvasEl(el)) {\n var saved = el[EVENT_SAVED_PROP] || (el[EVENT_SAVED_PROP] = {});\n var markers = prepareCoordMarkers(el, saved);\n var transformer = preparePointerTransformer(markers, saved, inverse);\n if (transformer) {\n transformer(out, inX, inY);\n return true;\n }\n }\n return false;\n}\n\nfunction prepareCoordMarkers(el, saved) {\n var markers = saved.markers;\n if (markers) {\n return markers;\n }\n\n markers = saved.markers = [];\n var propLR = ['left', 'right'];\n var propTB = ['top', 'bottom'];\n\n for (var i = 0; i < 4; i++) {\n var marker = document.createElement('div');\n var stl = marker.style;\n var idxLR = i % 2;\n var idxTB = (i >> 1) % 2;\n stl.cssText = [\n 'position: absolute',\n 'visibility: hidden',\n 'padding: 0',\n 'margin: 0',\n 'border-width: 0',\n 'user-select: none',\n 'width:0',\n 'height:0',\n // 'width: 5px',\n // 'height: 5px',\n propLR[idxLR] + ':0',\n propTB[idxTB] + ':0',\n propLR[1 - idxLR] + ':auto',\n propTB[1 - idxTB] + ':auto',\n ''\n ].join('!important;');\n el.appendChild(marker);\n markers.push(marker);\n }\n\n return markers;\n}\n\nfunction preparePointerTransformer(markers, saved, inverse) {\n var transformerName = inverse ? 'invTrans' : 'trans';\n var transformer = saved[transformerName];\n var oldSrcCoords = saved.srcCoords;\n var oldCoordTheSame = true;\n var srcCoords = [];\n var destCoords = [];\n\n for (var i = 0; i < 4; i++) {\n var rect = markers[i].getBoundingClientRect();\n var ii = 2 * i;\n var x = rect.left;\n var y = rect.top;\n srcCoords.push(x, y);\n oldCoordTheSame = oldCoordTheSame && oldSrcCoords && x === oldSrcCoords[ii] && y === oldSrcCoords[ii + 1];\n destCoords.push(markers[i].offsetLeft, markers[i].offsetTop);\n }\n // Cache to avoid time consuming of `buildTransformer`.\n return (oldCoordTheSame && transformer)\n ? transformer\n : (\n saved.srcCoords = srcCoords,\n saved[transformerName] = inverse\n ? buildTransformer(destCoords, srcCoords)\n : buildTransformer(srcCoords, destCoords)\n );\n}\n\nexport function isCanvasEl(el) {\n return el.nodeName.toUpperCase() === 'CANVAS';\n}\n","/**\n * Utilities for mouse or touch events.\n */\n\nimport Eventful from '../mixin/Eventful';\nimport env from './env';\nimport {isCanvasEl, transformCoordWithViewport} from './dom';\n\nvar isDomLevel2 = (typeof window !== 'undefined') && !!window.addEventListener;\n\nvar MOUSE_EVENT_REG = /^(?:mouse|pointer|contextmenu|drag|drop)|click/;\nvar _calcOut = [];\n\n/**\n * Get the `zrX` and `zrY`, which are relative to the top-left of\n * the input `el`.\n * CSS transform (2D & 3D) is supported.\n *\n * The strategy to fetch the coords:\n * + If `calculate` is not set as `true`, users of this method should\n * ensure that `el` is the same or the same size & location as `e.target`.\n * Otherwise the result coords are probably not expected. Because we\n * firstly try to get coords from e.offsetX/e.offsetY.\n * + If `calculate` is set as `true`, the input `el` can be any element\n * and we force to calculate the coords based on `el`.\n * + The input `el` should be positionable (not position:static).\n *\n * The force `calculate` can be used in case like:\n * When mousemove event triggered on ec tooltip, `e.target` is not `el`(zr painter.dom).\n *\n * @param {HTMLElement} el DOM element.\n * @param {Event} e Mouse event or touch event.\n * @param {Object} out Get `out.zrX` and `out.zrY` as the result.\n * @param {boolean} [calculate=false] Whether to force calculate\n * the coordinates but not use ones provided by browser.\n */\nexport function clientToLocal(el, e, out, calculate) {\n out = out || {};\n\n // According to the W3C Working Draft, offsetX and offsetY should be relative\n // to the padding edge of the target element. The only browser using this convention\n // is IE. Webkit uses the border edge, Opera uses the content edge, and FireFox does\n // not support the properties.\n // (see http://www.jacklmoore.com/notes/mouse-position/)\n // In zr painter.dom, padding edge equals to border edge.\n\n if (calculate || !env.canvasSupported) {\n calculateZrXY(el, e, out);\n }\n // Caution: In FireFox, layerX/layerY Mouse position relative to the closest positioned\n // ancestor element, so we should make sure el is positioned (e.g., not position:static).\n // BTW1, Webkit don't return the same results as FF in non-simple cases (like add\n // zoom-factor, overflow / opacity layers, transforms ...)\n // BTW2, (ev.offsetY || ev.pageY - $(ev.target).offset().top) is not correct in preserve-3d.\n // <https://bugs.jquery.com/ticket/8523#comment:14>\n // BTW3, In ff, offsetX/offsetY is always 0.\n else if (env.browser.firefox && e.layerX != null && e.layerX !== e.offsetX) {\n out.zrX = e.layerX;\n out.zrY = e.layerY;\n }\n // For IE6+, chrome, safari, opera. (When will ff support offsetX?)\n else if (e.offsetX != null) {\n out.zrX = e.offsetX;\n out.zrY = e.offsetY;\n }\n // For some other device, e.g., IOS safari.\n else {\n calculateZrXY(el, e, out);\n }\n\n return out;\n}\n\nfunction calculateZrXY(el, e, out) {\n // BlackBerry 5, iOS 3 (original iPhone) don't have getBoundingRect.\n if (env.domSupported && el.getBoundingClientRect) {\n var ex = e.clientX;\n var ey = e.clientY;\n\n if (isCanvasEl(el)) {\n // Original approach, which do not support CSS transform.\n // marker can not be locationed in a canvas container\n // (getBoundingClientRect is always 0). We do not support\n // that input a pre-created canvas to zr while using css\n // transform in iOS.\n var box = el.getBoundingClientRect();\n out.zrX = ex - box.left;\n out.zrY = ey - box.top;\n return;\n }\n else {\n if (transformCoordWithViewport(_calcOut, el, ex, ey)) {\n out.zrX = _calcOut[0];\n out.zrY = _calcOut[1];\n return;\n }\n }\n }\n out.zrX = out.zrY = 0;\n}\n\n/**\n * Find native event compat for legency IE.\n * Should be called at the begining of a native event listener.\n *\n * @param {Event} [e] Mouse event or touch event or pointer event.\n * For lagency IE, we use `window.event` is used.\n * @return {Event} The native event.\n */\nexport function getNativeEvent(e) {\n return e || window.event;\n}\n\n/**\n * Normalize the coordinates of the input event.\n *\n * Get the `e.zrX` and `e.zrY`, which are relative to the top-left of\n * the input `el`.\n * Get `e.zrDelta` if using mouse wheel.\n * Get `e.which`, see the comment inside this function.\n *\n * Do not calculate repeatly if `zrX` and `zrY` already exist.\n *\n * Notice: see comments in `clientToLocal`. check the relationship\n * between the result coords and the parameters `el` and `calculate`.\n *\n * @param {HTMLElement} el DOM element.\n * @param {Event} [e] See `getNativeEvent`.\n * @param {boolean} [calculate=false] Whether to force calculate\n * the coordinates but not use ones provided by browser.\n * @return {UIEvent} The normalized native UIEvent.\n */\nexport function normalizeEvent(el, e, calculate) {\n\n e = getNativeEvent(e);\n\n if (e.zrX != null) {\n return e;\n }\n\n var eventType = e.type;\n var isTouch = eventType && eventType.indexOf('touch') >= 0;\n\n if (!isTouch) {\n clientToLocal(el, e, e, calculate);\n e.zrDelta = (e.wheelDelta) ? e.wheelDelta / 120 : -(e.detail || 0) / 3;\n }\n else {\n var touch = eventType !== 'touchend'\n ? e.targetTouches[0]\n : e.changedTouches[0];\n touch && clientToLocal(el, touch, e, calculate);\n }\n\n // Add which for click: 1 === left; 2 === middle; 3 === right; otherwise: 0;\n // See jQuery: https://github.com/jquery/jquery/blob/master/src/event.js\n // If e.which has been defined, it may be readonly,\n // see: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/which\n var button = e.button;\n if (e.which == null && button !== undefined && MOUSE_EVENT_REG.test(e.type)) {\n e.which = (button & 1 ? 1 : (button & 2 ? 3 : (button & 4 ? 2 : 0)));\n }\n // [Caution]: `e.which` from browser is not always reliable. For example,\n // when press left button and `mousemove (pointermove)` in Edge, the `e.which`\n // is 65536 and the `e.button` is -1. But the `mouseup (pointerup)` and\n // `mousedown (pointerdown)` is the same as Chrome does.\n\n return e;\n}\n\n/**\n * @param {HTMLElement} el\n * @param {string} name\n * @param {Function} handler\n * @param {Object|boolean} opt If boolean, means `opt.capture`\n * @param {boolean} [opt.capture=false]\n * @param {boolean} [opt.passive=false]\n */\nexport function addEventListener(el, name, handler, opt) {\n if (isDomLevel2) {\n // Reproduct the console warning:\n // [Violation] Added non-passive event listener to a scroll-blocking <some> event.\n // Consider marking event handler as 'passive' to make the page more responsive.\n // Just set console log level: verbose in chrome dev tool.\n // then the warning log will be printed when addEventListener called.\n // See https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md\n // We have not yet found a neat way to using passive. Because in zrender the dom event\n // listener delegate all of the upper events of element. Some of those events need\n // to prevent default. For example, the feature `preventDefaultMouseMove` of echarts.\n // Before passive can be adopted, these issues should be considered:\n // (1) Whether and how a zrender user specifies an event listener passive. And by default,\n // passive or not.\n // (2) How to tread that some zrender event listener is passive, and some is not. If\n // we use other way but not preventDefault of mousewheel and touchmove, browser\n // compatibility should be handled.\n\n // var opts = (env.passiveSupported && name === 'mousewheel')\n // ? {passive: true}\n // // By default, the third param of el.addEventListener is `capture: false`.\n // : void 0;\n // el.addEventListener(name, handler /* , opts */);\n el.addEventListener(name, handler, opt);\n }\n else {\n // For simplicity, do not implement `setCapture` for IE9-.\n el.attachEvent('on' + name, handler);\n }\n}\n\n/**\n * Parameter are the same as `addEventListener`.\n *\n * Notice that if a listener is registered twice, one with capture and one without,\n * remove each one separately. Removal of a capturing listener does not affect a\n * non-capturing version of the same listener, and vice versa.\n */\nexport function removeEventListener(el, name, handler, opt) {\n if (isDomLevel2) {\n el.removeEventListener(name, handler, opt);\n }\n else {\n el.detachEvent('on' + name, handler);\n }\n}\n\n/**\n * preventDefault and stopPropagation.\n * Notice: do not use this method in zrender. It can only be\n * used by upper applications if necessary.\n *\n * @param {Event} e A mouse or touch event.\n */\nexport var stop = isDomLevel2\n ? function (e) {\n e.preventDefault();\n e.stopPropagation();\n e.cancelBubble = true;\n }\n : function (e) {\n e.returnValue = false;\n e.cancelBubble = true;\n };\n\n/**\n * This method only works for mouseup and mousedown. The functionality is restricted\n * for fault tolerance, See the `e.which` compatibility above.\n *\n * @param {MouseEvent} e\n * @return {boolean}\n */\nexport function isMiddleOrRightButtonOnMouseUpDown(e) {\n return e.which === 2 || e.which === 3;\n}\n\n/**\n * To be removed.\n * @deprecated\n */\nexport function notLeftMouse(e) {\n // If e.which is undefined, considered as left mouse event.\n return e.which > 1;\n}\n\n\n// For backward compatibility\nexport {Eventful as Dispatcher};\n","/**\n * Only implements needed gestures for mobile.\n */\n\nimport * as eventUtil from './event';\n\nvar GestureMgr = function () {\n\n /**\n * @private\n * @type {Array.<Object>}\n */\n this._track = [];\n};\n\nGestureMgr.prototype = {\n\n constructor: GestureMgr,\n\n recognize: function (event, target, root) {\n this._doTrack(event, target, root);\n return this._recognize(event);\n },\n\n clear: function () {\n this._track.length = 0;\n return this;\n },\n\n _doTrack: function (event, target, root) {\n var touches = event.touches;\n\n if (!touches) {\n return;\n }\n\n var trackItem = {\n points: [],\n touches: [],\n target: target,\n event: event\n };\n\n for (var i = 0, len = touches.length; i < len; i++) {\n var touch = touches[i];\n var pos = eventUtil.clientToLocal(root, touch, {});\n trackItem.points.push([pos.zrX, pos.zrY]);\n trackItem.touches.push(touch);\n }\n\n this._track.push(trackItem);\n },\n\n _recognize: function (event) {\n for (var eventName in recognizers) {\n if (recognizers.hasOwnProperty(eventName)) {\n var gestureInfo = recognizers[eventName](this._track, event);\n if (gestureInfo) {\n return gestureInfo;\n }\n }\n }\n }\n};\n\nfunction dist(pointPair) {\n var dx = pointPair[1][0] - pointPair[0][0];\n var dy = pointPair[1][1] - pointPair[0][1];\n\n return Math.sqrt(dx * dx + dy * dy);\n}\n\nfunction center(pointPair) {\n return [\n (pointPair[0][0] + pointPair[1][0]) / 2,\n (pointPair[0][1] + pointPair[1][1]) / 2\n ];\n}\n\nvar recognizers = {\n\n pinch: function (track, event) {\n var trackLen = track.length;\n\n if (!trackLen) {\n return;\n }\n\n var pinchEnd = (track[trackLen - 1] || {}).points;\n var pinchPre = (track[trackLen - 2] || {}).points || pinchEnd;\n\n if (pinchPre\n && pinchPre.length > 1\n && pinchEnd\n && pinchEnd.length > 1\n ) {\n var pinchScale = dist(pinchEnd) / dist(pinchPre);\n !isFinite(pinchScale) && (pinchScale = 1);\n\n event.pinchScale = pinchScale;\n\n var pinchCenter = center(pinchEnd);\n event.pinchX = pinchCenter[0];\n event.pinchY = pinchCenter[1];\n\n return {\n type: 'pinch',\n target: track[0].target,\n event: event\n };\n }\n }\n\n // Only pinch currently.\n};\n\nexport default GestureMgr;","import * as util from './core/util';\nimport * as vec2 from './core/vector';\nimport Draggable from './mixin/Draggable';\nimport Eventful from './mixin/Eventful';\nimport * as eventTool from './core/event';\nimport GestureMgr from './core/GestureMgr';\n\n\n/**\n * [The interface between `Handler` and `HandlerProxy`]:\n *\n * The default `HandlerProxy` only support the common standard web environment\n * (e.g., standalone browser, headless browser, embed browser in mobild APP, ...).\n * But `HandlerProxy` can be replaced to support more non-standard environment\n * (e.g., mini app), or to support more feature that the default `HandlerProxy`\n * not provided (like echarts-gl did).\n * So the interface between `Handler` and `HandlerProxy` should be stable. Do not\n * make break changes util inevitable. The interface include the public methods\n * of `Handler` and the events listed in `handlerNames` below, by which `HandlerProxy`\n * drives `Handler`.\n */\n\n/**\n * [Drag outside]:\n *\n * That is, triggering `mousemove` and `mouseup` event when the pointer is out of the\n * zrender area when dragging. That is important for the improvement of the user experience\n * when dragging something near the boundary without being terminated unexpectedly.\n *\n * We originally consider to introduce new events like `pagemovemove` and `pagemouseup`\n * to resolve this issue. But some drawbacks of it is described in\n * https://github.com/ecomfe/zrender/pull/536#issuecomment-560286899\n *\n * Instead, we referenced the specifications:\n * https://www.w3.org/TR/touch-events/#the-touchmove-event\n * https://www.w3.org/TR/2014/WD-DOM-Level-3-Events-20140925/#event-type-mousemove\n * where the the mousemove/touchmove can be continue to fire if the user began a drag\n * operation and the pointer has left the boundary. (for the mouse event, browsers\n * only do it on `document` and when the pointer has left the boundary of the browser.)\n *\n * So the default `HandlerProxy` supports this feature similarly: if it is in the dragging\n * state (see `pointerCapture` in `HandlerProxy`), the `mousemove` and `mouseup` continue\n * to fire until release the pointer. That is implemented by listen to those event on\n * `document`.\n * If we implement some other `HandlerProxy` only for touch device, that would be easier.\n * The touch event support this feature by default.\n *\n * Note:\n * There might be some cases that the mouse event can not be\n * received on `document`. For example,\n * (A) `useCapture` is not supported and some user defined event listeners on the ancestor\n * of zr dom throw Error .\n * (B) `useCapture` is not supported Some user defined event listeners on the ancestor of\n * zr dom call `stopPropagation`.\n * In these cases, the `mousemove` event might be keep triggered event\n * if the mouse is released. We try to reduce the side-effect in those cases.\n * That is, do nothing (especially, `findHover`) in those cases. See `isOutsideBoundary`.\n *\n * Note:\n * If `HandlerProxy` listens to `document` with `useCapture`, `HandlerProxy` needs to\n * make sure `stopPropagation` and `preventDefault` doing nothing if and only if the event\n * target is not zrender dom. Becuase it is dangerous to enable users to call them in\n * `document` capture phase to prevent the propagation to any listener of the webpage.\n * But they are needed to work when the pointer inside the zrender dom.\n */\n\n\nvar SILENT = 'silent';\n\nfunction makeEventPacket(eveType, targetInfo, event) {\n return {\n type: eveType,\n event: event,\n // target can only be an element that is not silent.\n target: targetInfo.target,\n // topTarget can be a silent element.\n topTarget: targetInfo.topTarget,\n cancelBubble: false,\n offsetX: event.zrX,\n offsetY: event.zrY,\n gestureEvent: event.gestureEvent,\n pinchX: event.pinchX,\n pinchY: event.pinchY,\n pinchScale: event.pinchScale,\n wheelDelta: event.zrDelta,\n zrByTouch: event.zrByTouch,\n which: event.which,\n stop: stopEvent\n };\n}\n\nfunction stopEvent() {\n eventTool.stop(this.event);\n}\n\nfunction EmptyProxy() {}\nEmptyProxy.prototype.dispose = function () {};\n\n\nvar handlerNames = [\n 'click', 'dblclick', 'mousewheel', 'mouseout',\n 'mouseup', 'mousedown', 'mousemove', 'contextmenu'\n];\n\n/**\n * @alias module:zrender/Handler\n * @constructor\n * @extends module:zrender/mixin/Eventful\n * @param {module:zrender/Storage} storage Storage instance.\n * @param {module:zrender/Painter} painter Painter instance.\n * @param {module:zrender/dom/HandlerProxy} proxy HandlerProxy instance.\n * @param {HTMLElement} painterRoot painter.root (not painter.getViewportRoot()).\n */\nvar Handler = function (storage, painter, proxy, painterRoot) {\n Eventful.call(this);\n\n this.storage = storage;\n\n this.painter = painter;\n\n this.painterRoot = painterRoot;\n\n proxy = proxy || new EmptyProxy();\n\n /**\n * Proxy of event. can be Dom, WebGLSurface, etc.\n */\n this.proxy = null;\n\n /**\n * {target, topTarget, x, y}\n * @private\n * @type {Object}\n */\n this._hovered = {};\n\n /**\n * @private\n * @type {Date}\n */\n this._lastTouchMoment;\n\n /**\n * @private\n * @type {number}\n */\n this._lastX;\n\n /**\n * @private\n * @type {number}\n */\n this._lastY;\n\n /**\n * @private\n * @type {module:zrender/core/GestureMgr}\n */\n this._gestureMgr;\n\n Draggable.call(this);\n\n this.setHandlerProxy(proxy);\n};\n\nHandler.prototype = {\n\n constructor: Handler,\n\n setHandlerProxy: function (proxy) {\n if (this.proxy) {\n this.proxy.dispose();\n }\n\n if (proxy) {\n util.each(handlerNames, function (name) {\n proxy.on && proxy.on(name, this[name], this);\n }, this);\n // Attach handler\n proxy.handler = this;\n }\n this.proxy = proxy;\n },\n\n mousemove: function (event) {\n var x = event.zrX;\n var y = event.zrY;\n\n var isOutside = isOutsideBoundary(this, x, y);\n\n var lastHovered = this._hovered;\n var lastHoveredTarget = lastHovered.target;\n\n // If lastHoveredTarget is removed from zr (detected by '__zr') by some API call\n // (like 'setOption' or 'dispatchAction') in event handlers, we should find\n // lastHovered again here. Otherwise 'mouseout' can not be triggered normally.\n // See #6198.\n if (lastHoveredTarget && !lastHoveredTarget.__zr) {\n lastHovered = this.findHover(lastHovered.x, lastHovered.y);\n lastHoveredTarget = lastHovered.target;\n }\n\n var hovered = this._hovered = isOutside ? {x: x, y: y} : this.findHover(x, y);\n var hoveredTarget = hovered.target;\n\n var proxy = this.proxy;\n proxy.setCursor && proxy.setCursor(hoveredTarget ? hoveredTarget.cursor : 'default');\n\n // Mouse out on previous hovered element\n if (lastHoveredTarget && hoveredTarget !== lastHoveredTarget) {\n this.dispatchToElement(lastHovered, 'mouseout', event);\n }\n\n // Mouse moving on one element\n this.dispatchToElement(hovered, 'mousemove', event);\n\n // Mouse over on a new element\n if (hoveredTarget && hoveredTarget !== lastHoveredTarget) {\n this.dispatchToElement(hovered, 'mouseover', event);\n }\n },\n\n mouseout: function (event) {\n var eventControl = event.zrEventControl;\n var zrIsToLocalDOM = event.zrIsToLocalDOM;\n\n if (eventControl !== 'only_globalout') {\n this.dispatchToElement(this._hovered, 'mouseout', event);\n }\n\n if (eventControl !== 'no_globalout') {\n // FIXME: if the pointer moving from the extra doms to realy \"outside\",\n // the `globalout` should have been triggered. But currently not.\n !zrIsToLocalDOM && this.trigger('globalout', {type: 'globalout', event: event});\n }\n },\n\n /**\n * Resize\n */\n resize: function (event) {\n this._hovered = {};\n },\n\n /**\n * Dispatch event\n * @param {string} eventName\n * @param {event=} eventArgs\n */\n dispatch: function (eventName, eventArgs) {\n var handler = this[eventName];\n handler && handler.call(this, eventArgs);\n },\n\n /**\n * Dispose\n */\n dispose: function () {\n\n this.proxy.dispose();\n\n this.storage =\n this.proxy =\n this.painter = null;\n },\n\n /**\n * 设置默认的cursor style\n * @param {string} [cursorStyle='default'] 例如 crosshair\n */\n setCursorStyle: function (cursorStyle) {\n var proxy = this.proxy;\n proxy.setCursor && proxy.setCursor(cursorStyle);\n },\n\n /**\n * 事件分发代理\n *\n * @private\n * @param {Object} targetInfo {target, topTarget} 目标图形元素\n * @param {string} eventName 事件名称\n * @param {Object} event 事件对象\n */\n dispatchToElement: function (targetInfo, eventName, event) {\n targetInfo = targetInfo || {};\n var el = targetInfo.target;\n if (el && el.silent) {\n return;\n }\n var eventHandler = 'on' + eventName;\n var eventPacket = makeEventPacket(eventName, targetInfo, event);\n\n while (el) {\n el[eventHandler]\n && (eventPacket.cancelBubble = el[eventHandler].call(el, eventPacket));\n\n el.trigger(eventName, eventPacket);\n\n el = el.parent;\n\n if (eventPacket.cancelBubble) {\n break;\n }\n }\n\n if (!eventPacket.cancelBubble) {\n // 冒泡到顶级 zrender 对象\n this.trigger(eventName, eventPacket);\n // 分发事件到用户自定义层\n // 用户有可能在全局 click 事件中 dispose,所以需要判断下 painter 是否存在\n this.painter && this.painter.eachOtherLayer(function (layer) {\n if (typeof (layer[eventHandler]) === 'function') {\n layer[eventHandler].call(layer, eventPacket);\n }\n if (layer.trigger) {\n layer.trigger(eventName, eventPacket);\n }\n });\n }\n },\n\n /**\n * @private\n * @param {number} x\n * @param {number} y\n * @param {module:zrender/graphic/Displayable} exclude\n * @return {model:zrender/Element}\n * @method\n */\n findHover: function (x, y, exclude) {\n var list = this.storage.getDisplayList();\n var out = {x: x, y: y};\n\n for (var i = list.length - 1; i >= 0; i--) {\n var hoverCheckResult;\n if (list[i] !== exclude\n // getDisplayList may include ignored item in VML mode\n && !list[i].ignore\n && (hoverCheckResult = isHover(list[i], x, y))\n ) {\n !out.topTarget && (out.topTarget = list[i]);\n if (hoverCheckResult !== SILENT) {\n out.target = list[i];\n break;\n }\n }\n }\n\n return out;\n },\n\n processGesture: function (event, stage) {\n if (!this._gestureMgr) {\n this._gestureMgr = new GestureMgr();\n }\n var gestureMgr = this._gestureMgr;\n\n stage === 'start' && gestureMgr.clear();\n\n var gestureInfo = gestureMgr.recognize(\n event,\n this.findHover(event.zrX, event.zrY, null).target,\n this.proxy.dom\n );\n\n stage === 'end' && gestureMgr.clear();\n\n // Do not do any preventDefault here. Upper application do that if necessary.\n if (gestureInfo) {\n var type = gestureInfo.type;\n event.gestureEvent = type;\n\n this.dispatchToElement({target: gestureInfo.target}, type, gestureInfo.event);\n }\n }\n};\n\n// Common handlers\nutil.each(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {\n Handler.prototype[name] = function (event) {\n var x = event.zrX;\n var y = event.zrY;\n var isOutside = isOutsideBoundary(this, x, y);\n\n var hovered;\n var hoveredTarget;\n\n if (name !== 'mouseup' || !isOutside) {\n // Find hover again to avoid click event is dispatched manually. Or click is triggered without mouseover\n hovered = this.findHover(x, y);\n hoveredTarget = hovered.target;\n }\n\n if (name === 'mousedown') {\n this._downEl = hoveredTarget;\n this._downPoint = [event.zrX, event.zrY];\n // In case click triggered before mouseup\n this._upEl = hoveredTarget;\n }\n else if (name === 'mouseup') {\n this._upEl = hoveredTarget;\n }\n else if (name === 'click') {\n if (this._downEl !== this._upEl\n // Original click event is triggered on the whole canvas element,\n // including the case that `mousedown` - `mousemove` - `mouseup`,\n // which should be filtered, otherwise it will bring trouble to\n // pan and zoom.\n || !this._downPoint\n // Arbitrary value\n || vec2.dist(this._downPoint, [event.zrX, event.zrY]) > 4\n ) {\n return;\n }\n this._downPoint = null;\n }\n\n this.dispatchToElement(hovered, name, event);\n };\n});\n\nfunction isHover(displayable, x, y) {\n if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {\n var el = displayable;\n var isSilent;\n while (el) {\n // If clipped by ancestor.\n // FIXME: If clipPath has neither stroke nor fill,\n // el.clipPath.contain(x, y) will always return false.\n if (el.clipPath && !el.clipPath.contain(x, y)) {\n return false;\n }\n if (el.silent) {\n isSilent = true;\n }\n el = el.parent;\n }\n return isSilent ? SILENT : true;\n }\n\n return false;\n}\n\n/**\n * See [Drag outside].\n */\nfunction isOutsideBoundary(handlerInstance, x, y) {\n var painter = handlerInstance.painter;\n return x < 0 || x > painter.getWidth() || y < 0 || y > painter.getHeight();\n}\n\nutil.mixin(Handler, Eventful);\nutil.mixin(Handler, Draggable);\n\nexport default Handler;\n","/**\n * 3x2矩阵操作类\n * @exports zrender/tool/matrix\n */\n\n/* global Float32Array */\n\nvar ArrayCtor = typeof Float32Array === 'undefined'\n ? Array\n : Float32Array;\n\n/**\n * Create a identity matrix.\n * @return {Float32Array|Array.<number>}\n */\nexport function create() {\n var out = new ArrayCtor(6);\n identity(out);\n\n return out;\n}\n\n/**\n * 设置矩阵为单位矩阵\n * @param {Float32Array|Array.<number>} out\n */\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n\n/**\n * 复制矩阵\n * @param {Float32Array|Array.<number>} out\n * @param {Float32Array|Array.<number>} m\n */\nexport function copy(out, m) {\n out[0] = m[0];\n out[1] = m[1];\n out[2] = m[2];\n out[3] = m[3];\n out[4] = m[4];\n out[5] = m[5];\n return out;\n}\n\n/**\n * 矩阵相乘\n * @param {Float32Array|Array.<number>} out\n * @param {Float32Array|Array.<number>} m1\n * @param {Float32Array|Array.<number>} m2\n */\nexport function mul(out, m1, m2) {\n // Consider matrix.mul(m, m2, m);\n // where out is the same as m2.\n // So use temp variable to escape error.\n var out0 = m1[0] * m2[0] + m1[2] * m2[1];\n var out1 = m1[1] * m2[0] + m1[3] * m2[1];\n var out2 = m1[0] * m2[2] + m1[2] * m2[3];\n var out3 = m1[1] * m2[2] + m1[3] * m2[3];\n var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];\n var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];\n out[0] = out0;\n out[1] = out1;\n out[2] = out2;\n out[3] = out3;\n out[4] = out4;\n out[5] = out5;\n return out;\n}\n\n/**\n * 平移变换\n * @param {Float32Array|Array.<number>} out\n * @param {Float32Array|Array.<number>} a\n * @param {Float32Array|Array.<number>} v\n */\nexport function translate(out, a, v) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4] + v[0];\n out[5] = a[5] + v[1];\n return out;\n}\n\n/**\n * 旋转变换\n * @param {Float32Array|Array.<number>} out\n * @param {Float32Array|Array.<number>} a\n * @param {number} rad\n */\nexport function rotate(out, a, rad) {\n var aa = a[0];\n var ac = a[2];\n var atx = a[4];\n var ab = a[1];\n var ad = a[3];\n var aty = a[5];\n var st = Math.sin(rad);\n var ct = Math.cos(rad);\n\n out[0] = aa * ct + ab * st;\n out[1] = -aa * st + ab * ct;\n out[2] = ac * ct + ad * st;\n out[3] = -ac * st + ct * ad;\n out[4] = ct * atx + st * aty;\n out[5] = ct * aty - st * atx;\n return out;\n}\n\n/**\n * 缩放变换\n * @param {Float32Array|Array.<number>} out\n * @param {Float32Array|Array.<number>} a\n * @param {Float32Array|Array.<number>} v\n */\nexport function scale(out, a, v) {\n var vx = v[0];\n var vy = v[1];\n out[0] = a[0] * vx;\n out[1] = a[1] * vy;\n out[2] = a[2] * vx;\n out[3] = a[3] * vy;\n out[4] = a[4] * vx;\n out[5] = a[5] * vy;\n return out;\n}\n\n/**\n * 求逆矩阵\n * @param {Float32Array|Array.<number>} out\n * @param {Float32Array|Array.<number>} a\n */\nexport function invert(out, a) {\n\n var aa = a[0];\n var ac = a[2];\n var atx = a[4];\n var ab = a[1];\n var ad = a[3];\n var aty = a[5];\n\n var det = aa * ad - ab * ac;\n if (!det) {\n return null;\n }\n det = 1.0 / det;\n\n out[0] = ad * det;\n out[1] = -ab * det;\n out[2] = -ac * det;\n out[3] = aa * det;\n out[4] = (ac * aty - ad * atx) * det;\n out[5] = (ab * atx - aa * aty) * det;\n return out;\n}\n\n/**\n * Clone a new matrix.\n * @param {Float32Array|Array.<number>} a\n */\nexport function clone(a) {\n var b = create();\n copy(b, a);\n return b;\n}","/**\n * 提供变换扩展\n * @module zrender/mixin/Transformable\n * @author pissang (https://www.github.com/pissang)\n */\n\nimport * as matrix from '../core/matrix';\nimport * as vector from '../core/vector';\n\nvar mIdentity = matrix.identity;\n\nvar EPSILON = 5e-5;\n\nfunction isNotAroundZero(val) {\n return val > EPSILON || val < -EPSILON;\n}\n\n/**\n * @alias module:zrender/mixin/Transformable\n * @constructor\n */\nvar Transformable = function (opts) {\n opts = opts || {};\n // If there are no given position, rotation, scale\n if (!opts.position) {\n /**\n * 平移\n * @type {Array.<number>}\n * @default [0, 0]\n */\n this.position = [0, 0];\n }\n if (opts.rotation == null) {\n /**\n * 旋转\n * @type {Array.<number>}\n * @default 0\n */\n this.rotation = 0;\n }\n if (!opts.scale) {\n /**\n * 缩放\n * @type {Array.<number>}\n * @default [1, 1]\n */\n this.scale = [1, 1];\n }\n /**\n * 旋转和缩放的原点\n * @type {Array.<number>}\n * @default null\n */\n this.origin = this.origin || null;\n};\n\nvar transformableProto = Transformable.prototype;\ntransformableProto.transform = null;\n\n/**\n * 判断是否需要有坐标变换\n * 如果有坐标变换, 则从position, rotation, scale以及父节点的transform计算出自身的transform矩阵\n */\ntransformableProto.needLocalTransform = function () {\n return isNotAroundZero(this.rotation)\n || isNotAroundZero(this.position[0])\n || isNotAroundZero(this.position[1])\n || isNotAroundZero(this.scale[0] - 1)\n || isNotAroundZero(this.scale[1] - 1);\n};\n\nvar scaleTmp = [];\ntransformableProto.updateTransform = function () {\n var parent = this.parent;\n var parentHasTransform = parent && parent.transform;\n var needLocalTransform = this.needLocalTransform();\n\n var m = this.transform;\n if (!(needLocalTransform || parentHasTransform)) {\n m && mIdentity(m);\n return;\n }\n\n m = m || matrix.create();\n\n if (needLocalTransform) {\n this.getLocalTransform(m);\n }\n else {\n mIdentity(m);\n }\n\n // 应用父节点变换\n if (parentHasTransform) {\n if (needLocalTransform) {\n matrix.mul(m, parent.transform, m);\n }\n else {\n matrix.copy(m, parent.transform);\n }\n }\n // 保存这个变换矩阵\n this.transform = m;\n\n var globalScaleRatio = this.globalScaleRatio;\n if (globalScaleRatio != null && globalScaleRatio !== 1) {\n this.getGlobalScale(scaleTmp);\n var relX = scaleTmp[0] < 0 ? -1 : 1;\n var relY = scaleTmp[1] < 0 ? -1 : 1;\n var sx = ((scaleTmp[0] - relX) * globalScaleRatio + relX) / scaleTmp[0] || 0;\n var sy = ((scaleTmp[1] - relY) * globalScaleRatio + relY) / scaleTmp[1] || 0;\n\n m[0] *= sx;\n m[1] *= sx;\n m[2] *= sy;\n m[3] *= sy;\n }\n\n this.invTransform = this.invTransform || matrix.create();\n matrix.invert(this.invTransform, m);\n};\n\ntransformableProto.getLocalTransform = function (m) {\n return Transformable.getLocalTransform(this, m);\n};\n\n/**\n * 将自己的transform应用到context上\n * @param {CanvasRenderingContext2D} ctx\n */\ntransformableProto.setTransform = function (ctx) {\n var m = this.transform;\n var dpr = ctx.dpr || 1;\n if (m) {\n ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);\n }\n else {\n ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n }\n};\n\ntransformableProto.restoreTransform = function (ctx) {\n var dpr = ctx.dpr || 1;\n ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n};\n\nvar tmpTransform = [];\nvar originTransform = matrix.create();\n\ntransformableProto.setLocalTransform = function (m) {\n if (!m) {\n // TODO return or set identity?\n return;\n }\n var sx = m[0] * m[0] + m[1] * m[1];\n var sy = m[2] * m[2] + m[3] * m[3];\n var position = this.position;\n var scale = this.scale;\n if (isNotAroundZero(sx - 1)) {\n sx = Math.sqrt(sx);\n }\n if (isNotAroundZero(sy - 1)) {\n sy = Math.sqrt(sy);\n }\n if (m[0] < 0) {\n sx = -sx;\n }\n if (m[3] < 0) {\n sy = -sy;\n }\n\n position[0] = m[4];\n position[1] = m[5];\n scale[0] = sx;\n scale[1] = sy;\n this.rotation = Math.atan2(-m[1] / sy, m[0] / sx);\n};\n/**\n * 分解`transform`矩阵到`position`, `rotation`, `scale`\n */\ntransformableProto.decomposeTransform = function () {\n if (!this.transform) {\n return;\n }\n var parent = this.parent;\n var m = this.transform;\n if (parent && parent.transform) {\n // Get local transform and decompose them to position, scale, rotation\n matrix.mul(tmpTransform, parent.invTransform, m);\n m = tmpTransform;\n }\n var origin = this.origin;\n if (origin && (origin[0] || origin[1])) {\n originTransform[4] = origin[0];\n originTransform[5] = origin[1];\n matrix.mul(tmpTransform, m, originTransform);\n tmpTransform[4] -= origin[0];\n tmpTransform[5] -= origin[1];\n m = tmpTransform;\n }\n\n this.setLocalTransform(m);\n};\n\n/**\n * Get global scale\n * @return {Array.<number>}\n */\ntransformableProto.getGlobalScale = function (out) {\n var m = this.transform;\n out = out || [];\n if (!m) {\n out[0] = 1;\n out[1] = 1;\n return out;\n }\n out[0] = Math.sqrt(m[0] * m[0] + m[1] * m[1]);\n out[1] = Math.sqrt(m[2] * m[2] + m[3] * m[3]);\n if (m[0] < 0) {\n out[0] = -out[0];\n }\n if (m[3] < 0) {\n out[1] = -out[1];\n }\n return out;\n};\n/**\n * 变换坐标位置到 shape 的局部坐标空间\n * @method\n * @param {number} x\n * @param {number} y\n * @return {Array.<number>}\n */\ntransformableProto.transformCoordToLocal = function (x, y) {\n var v2 = [x, y];\n var invTransform = this.invTransform;\n if (invTransform) {\n vector.applyTransform(v2, v2, invTransform);\n }\n return v2;\n};\n\n/**\n * 变换局部坐标位置到全局坐标空间\n * @method\n * @param {number} x\n * @param {number} y\n * @return {Array.<number>}\n */\ntransformableProto.transformCoordToGlobal = function (x, y) {\n var v2 = [x, y];\n var transform = this.transform;\n if (transform) {\n vector.applyTransform(v2, v2, transform);\n }\n return v2;\n};\n\n/**\n * @static\n * @param {Object} target\n * @param {Array.<number>} target.origin\n * @param {number} target.rotation\n * @param {Array.<number>} target.position\n * @param {Array.<number>} [m]\n */\nTransformable.getLocalTransform = function (target, m) {\n m = m || [];\n mIdentity(m);\n\n var origin = target.origin;\n var scale = target.scale || [1, 1];\n var rotation = target.rotation || 0;\n var position = target.position || [0, 0];\n\n if (origin) {\n // Translate to origin\n m[4] -= origin[0];\n m[5] -= origin[1];\n }\n matrix.scale(m, m, scale);\n if (rotation) {\n matrix.rotate(m, m, rotation);\n }\n if (origin) {\n // Translate back from origin\n m[4] += origin[0];\n m[5] += origin[1];\n }\n\n m[4] += position[0];\n m[5] += position[1];\n\n return m;\n};\n\nexport default Transformable;","/**\n * 缓动代码来自 https://github.com/sole/tween.js/blob/master/src/Tween.js\n * @see http://sole.github.io/tween.js/examples/03_graphs.html\n * @exports zrender/animation/easing\n */\nvar easing = {\n /**\n * @param {number} k\n * @return {number}\n */\n linear: function (k) {\n return k;\n },\n\n /**\n * @param {number} k\n * @return {number}\n */\n quadraticIn: function (k) {\n return k * k;\n },\n /**\n * @param {number} k\n * @return {number}\n */\n quadraticOut: function (k) {\n return k * (2 - k);\n },\n /**\n * @param {number} k\n * @return {number}\n */\n quadraticInOut: function (k) {\n if ((k *= 2) < 1) {\n return 0.5 * k * k;\n }\n return -0.5 * (--k * (k - 2) - 1);\n },\n\n // 三次方的缓动(t^3)\n /**\n * @param {number} k\n * @return {number}\n */\n cubicIn: function (k) {\n return k * k * k;\n },\n /**\n * @param {number} k\n * @return {number}\n */\n cubicOut: function (k) {\n return --k * k * k + 1;\n },\n /**\n * @param {number} k\n * @return {number}\n */\n cubicInOut: function (k) {\n if ((k *= 2) < 1) {\n return 0.5 * k * k * k;\n }\n return 0.5 * ((k -= 2) * k * k + 2);\n },\n\n // 四次方的缓动(t^4)\n /**\n * @param {number} k\n * @return {number}\n */\n quarticIn: function (k) {\n return k * k * k * k;\n },\n /**\n * @param {number} k\n * @return {number}\n */\n quarticOut: function (k) {\n return 1 - (--k * k * k * k);\n },\n /**\n * @param {number} k\n * @return {number}\n */\n quarticInOut: function (k) {\n if ((k *= 2) < 1) {\n return 0.5 * k * k * k * k;\n }\n return -0.5 * ((k -= 2) * k * k * k - 2);\n },\n\n // 五次方的缓动(t^5)\n /**\n * @param {number} k\n * @return {number}\n */\n quinticIn: function (k) {\n return k * k * k * k * k;\n },\n /**\n * @param {number} k\n * @return {number}\n */\n quinticOut: function (k) {\n return --k * k * k * k * k + 1;\n },\n /**\n * @param {number} k\n * @return {number}\n */\n quinticInOut: function (k) {\n if ((k *= 2) < 1) {\n return 0.5 * k * k * k * k * k;\n }\n return 0.5 * ((k -= 2) * k * k * k * k + 2);\n },\n\n // 正弦曲线的缓动(sin(t))\n /**\n * @param {number} k\n * @return {number}\n */\n sinusoidalIn: function (k) {\n return 1 - Math.cos(k * Math.PI / 2);\n },\n /**\n * @param {number} k\n * @return {number}\n */\n sinusoidalOut: function (k) {\n return Math.sin(k * Math.PI / 2);\n },\n /**\n * @param {number} k\n * @return {number}\n */\n sinusoidalInOut: function (k) {\n return 0.5 * (1 - Math.cos(Math.PI * k));\n },\n\n // 指数曲线的缓动(2^t)\n /**\n * @param {number} k\n * @return {number}\n */\n exponentialIn: function (k) {\n return k === 0 ? 0 : Math.pow(1024, k - 1);\n },\n /**\n * @param {number} k\n * @return {number}\n */\n exponentialOut: function (k) {\n return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);\n },\n /**\n * @param {number} k\n * @return {number}\n */\n exponentialInOut: function (k) {\n if (k === 0) {\n return 0;\n }\n if (k === 1) {\n return 1;\n }\n if ((k *= 2) < 1) {\n return 0.5 * Math.pow(1024, k - 1);\n }\n return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);\n },\n\n // 圆形曲线的缓动(sqrt(1-t^2))\n /**\n * @param {number} k\n * @return {number}\n */\n circularIn: function (k) {\n return 1 - Math.sqrt(1 - k * k);\n },\n /**\n * @param {number} k\n * @return {number}\n */\n circularOut: function (k) {\n return Math.sqrt(1 - (--k * k));\n },\n /**\n * @param {number} k\n * @return {number}\n */\n circularInOut: function (k) {\n if ((k *= 2) < 1) {\n return -0.5 * (Math.sqrt(1 - k * k) - 1);\n }\n return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);\n },\n\n // 创建类似于弹簧在停止前来回振荡的动画\n /**\n * @param {number} k\n * @return {number}\n */\n elasticIn: function (k) {\n var s;\n var a = 0.1;\n var p = 0.4;\n if (k === 0) {\n return 0;\n }\n if (k === 1) {\n return 1;\n }\n if (!a || a < 1) {\n a = 1;\n s = p / 4;\n }\n else {\n s = p * Math.asin(1 / a) / (2 * Math.PI);\n }\n return -(a * Math.pow(2, 10 * (k -= 1))\n * Math.sin((k - s) * (2 * Math.PI) / p));\n },\n /**\n * @param {number} k\n * @return {number}\n */\n elasticOut: function (k) {\n var s;\n var a = 0.1;\n var p = 0.4;\n if (k === 0) {\n return 0;\n }\n if (k === 1) {\n return 1;\n }\n if (!a || a < 1) {\n a = 1;\n s = p / 4;\n }\n else {\n s = p * Math.asin(1 / a) / (2 * Math.PI);\n }\n return (a * Math.pow(2, -10 * k)\n * Math.sin((k - s) * (2 * Math.PI) / p) + 1);\n },\n /**\n * @param {number} k\n * @return {number}\n */\n elasticInOut: function (k) {\n var s;\n var a = 0.1;\n var p = 0.4;\n if (k === 0) {\n return 0;\n }\n if (k === 1) {\n return 1;\n }\n if (!a || a < 1) {\n a = 1;\n s = p / 4;\n }\n else {\n s = p * Math.asin(1 / a) / (2 * Math.PI);\n }\n if ((k *= 2) < 1) {\n return -0.5 * (a * Math.pow(2, 10 * (k -= 1))\n * Math.sin((k - s) * (2 * Math.PI) / p));\n }\n return a * Math.pow(2, -10 * (k -= 1))\n * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;\n\n },\n\n // 在某一动画开始沿指示的路径进行动画处理前稍稍收回该动画的移动\n /**\n * @param {number} k\n * @return {number}\n */\n backIn: function (k) {\n var s = 1.70158;\n return k * k * ((s + 1) * k - s);\n },\n /**\n * @param {number} k\n * @return {number}\n */\n backOut: function (k) {\n var s = 1.70158;\n return --k * k * ((s + 1) * k + s) + 1;\n },\n /**\n * @param {number} k\n * @return {number}\n */\n backInOut: function (k) {\n var s = 1.70158 * 1.525;\n if ((k *= 2) < 1) {\n return 0.5 * (k * k * ((s + 1) * k - s));\n }\n return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);\n },\n\n // 创建弹跳效果\n /**\n * @param {number} k\n * @return {number}\n */\n bounceIn: function (k) {\n return 1 - easing.bounceOut(1 - k);\n },\n /**\n * @param {number} k\n * @return {number}\n */\n bounceOut: function (k) {\n if (k < (1 / 2.75)) {\n return 7.5625 * k * k;\n }\n else if (k < (2 / 2.75)) {\n return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;\n }\n else if (k < (2.5 / 2.75)) {\n return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;\n }\n else {\n return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;\n }\n },\n /**\n * @param {number} k\n * @return {number}\n */\n bounceInOut: function (k) {\n if (k < 0.5) {\n return easing.bounceIn(k * 2) * 0.5;\n }\n return easing.bounceOut(k * 2 - 1) * 0.5 + 0.5;\n }\n};\n\nexport default easing;","/**\n * 动画主控制器\n * @config target 动画对象,可以是数组,如果是数组的话会批量分发onframe等事件\n * @config life(1000) 动画时长\n * @config delay(0) 动画延迟时间\n * @config loop(true)\n * @config gap(0) 循环的间隔时间\n * @config onframe\n * @config easing(optional)\n * @config ondestroy(optional)\n * @config onrestart(optional)\n *\n * TODO pause\n */\n\nimport easingFuncs from './easing';\n\nfunction Clip(options) {\n\n this._target = options.target;\n\n // 生命周期\n this._life = options.life || 1000;\n // 延时\n this._delay = options.delay || 0;\n // 开始时间\n // this._startTime = new Date().getTime() + this._delay;// 单位毫秒\n this._initialized = false;\n\n // 是否循环\n this.loop = options.loop == null ? false : options.loop;\n\n this.gap = options.gap || 0;\n\n this.easing = options.easing || 'Linear';\n\n this.onframe = options.onframe;\n this.ondestroy = options.ondestroy;\n this.onrestart = options.onrestart;\n\n this._pausedTime = 0;\n this._paused = false;\n}\n\nClip.prototype = {\n\n constructor: Clip,\n\n step: function (globalTime, deltaTime) {\n // Set startTime on first step, or _startTime may has milleseconds different between clips\n // PENDING\n if (!this._initialized) {\n this._startTime = globalTime + this._delay;\n this._initialized = true;\n }\n\n if (this._paused) {\n this._pausedTime += deltaTime;\n return;\n }\n\n var percent = (globalTime - this._startTime - this._pausedTime) / this._life;\n\n // 还没开始\n if (percent < 0) {\n return;\n }\n\n percent = Math.min(percent, 1);\n\n var easing = this.easing;\n var easingFunc = typeof easing === 'string' ? easingFuncs[easing] : easing;\n var schedule = typeof easingFunc === 'function'\n ? easingFunc(percent)\n : percent;\n\n this.fire('frame', schedule);\n\n // 结束\n if (percent === 1) {\n if (this.loop) {\n this.restart(globalTime);\n // 重新开始周期\n // 抛出而不是直接调用事件直到 stage.update 后再统一调用这些事件\n return 'restart';\n }\n\n // 动画完成将这个控制器标识为待删除\n // 在Animation.update中进行批量删除\n this._needsRemove = true;\n return 'destroy';\n }\n\n return null;\n },\n\n restart: function (globalTime) {\n var remainder = (globalTime - this._startTime - this._pausedTime) % this._life;\n this._startTime = globalTime - remainder + this.gap;\n this._pausedTime = 0;\n\n this._needsRemove = false;\n },\n\n fire: function (eventType, arg) {\n eventType = 'on' + eventType;\n if (this[eventType]) {\n this[eventType](this._target, arg);\n }\n },\n\n pause: function () {\n this._paused = true;\n },\n\n resume: function () {\n this._paused = false;\n }\n};\n\nexport default Clip;","// Simple LRU cache use doubly linked list\n// @module zrender/core/LRU\n\n/**\n * Simple double linked list. Compared with array, it has O(1) remove operation.\n * @constructor\n */\nvar LinkedList = function () {\n\n /**\n * @type {module:zrender/core/LRU~Entry}\n */\n this.head = null;\n\n /**\n * @type {module:zrender/core/LRU~Entry}\n */\n this.tail = null;\n\n this._len = 0;\n};\n\nvar linkedListProto = LinkedList.prototype;\n/**\n * Insert a new value at the tail\n * @param {} val\n * @return {module:zrender/core/LRU~Entry}\n */\nlinkedListProto.insert = function (val) {\n var entry = new Entry(val);\n this.insertEntry(entry);\n return entry;\n};\n\n/**\n * Insert an entry at the tail\n * @param {module:zrender/core/LRU~Entry} entry\n */\nlinkedListProto.insertEntry = function (entry) {\n if (!this.head) {\n this.head = this.tail = entry;\n }\n else {\n this.tail.next = entry;\n entry.prev = this.tail;\n entry.next = null;\n this.tail = entry;\n }\n this._len++;\n};\n\n/**\n * Remove entry.\n * @param {module:zrender/core/LRU~Entry} entry\n */\nlinkedListProto.remove = function (entry) {\n var prev = entry.prev;\n var next = entry.next;\n if (prev) {\n prev.next = next;\n }\n else {\n // Is head\n this.head = next;\n }\n if (next) {\n next.prev = prev;\n }\n else {\n // Is tail\n this.tail = prev;\n }\n entry.next = entry.prev = null;\n this._len--;\n};\n\n/**\n * @return {number}\n */\nlinkedListProto.len = function () {\n return this._len;\n};\n\n/**\n * Clear list\n */\nlinkedListProto.clear = function () {\n this.head = this.tail = null;\n this._len = 0;\n};\n\n/**\n * @constructor\n * @param {} val\n */\nvar Entry = function (val) {\n /**\n * @type {}\n */\n this.value = val;\n\n /**\n * @type {module:zrender/core/LRU~Entry}\n */\n this.next;\n\n /**\n * @type {module:zrender/core/LRU~Entry}\n */\n this.prev;\n};\n\n/**\n * LRU Cache\n * @constructor\n * @alias module:zrender/core/LRU\n */\nvar LRU = function (maxSize) {\n\n this._list = new LinkedList();\n\n this._map = {};\n\n this._maxSize = maxSize || 10;\n\n this._lastRemovedEntry = null;\n};\n\nvar LRUProto = LRU.prototype;\n\n/**\n * @param {string} key\n * @param {} value\n * @return {} Removed value\n */\nLRUProto.put = function (key, value) {\n var list = this._list;\n var map = this._map;\n var removed = null;\n if (map[key] == null) {\n var len = list.len();\n // Reuse last removed entry\n var entry = this._lastRemovedEntry;\n\n if (len >= this._maxSize && len > 0) {\n // Remove the least recently used\n var leastUsedEntry = list.head;\n list.remove(leastUsedEntry);\n delete map[leastUsedEntry.key];\n\n removed = leastUsedEntry.value;\n this._lastRemovedEntry = leastUsedEntry;\n }\n\n if (entry) {\n entry.value = value;\n }\n else {\n entry = new Entry(value);\n }\n entry.key = key;\n list.insertEntry(entry);\n map[key] = entry;\n }\n\n return removed;\n};\n\n/**\n * @param {string} key\n * @return {}\n */\nLRUProto.get = function (key) {\n var entry = this._map[key];\n var list = this._list;\n if (entry != null) {\n // Put the latest used entry in the tail\n if (entry !== list.tail) {\n list.remove(entry);\n list.insertEntry(entry);\n }\n\n return entry.value;\n }\n};\n\n/**\n * Clear the cache\n */\nLRUProto.clear = function () {\n this._list.clear();\n this._map = {};\n};\n\nexport default LRU;","import LRU from '../core/LRU';\n\nvar kCSSColorTable = {\n 'transparent': [0, 0, 0, 0], 'aliceblue': [240, 248, 255, 1],\n 'antiquewhite': [250, 235, 215, 1], 'aqua': [0, 255, 255, 1],\n 'aquamarine': [127, 255, 212, 1], 'azure': [240, 255, 255, 1],\n 'beige': [245, 245, 220, 1], 'bisque': [255, 228, 196, 1],\n 'black': [0, 0, 0, 1], 'blanchedalmond': [255, 235, 205, 1],\n 'blue': [0, 0, 255, 1], 'blueviolet': [138, 43, 226, 1],\n 'brown': [165, 42, 42, 1], 'burlywood': [222, 184, 135, 1],\n 'cadetblue': [95, 158, 160, 1], 'chartreuse': [127, 255, 0, 1],\n 'chocolate': [210, 105, 30, 1], 'coral': [255, 127, 80, 1],\n 'cornflowerblue': [100, 149, 237, 1], 'cornsilk': [255, 248, 220, 1],\n 'crimson': [220, 20, 60, 1], 'cyan': [0, 255, 255, 1],\n 'darkblue': [0, 0, 139, 1], 'darkcyan': [0, 139, 139, 1],\n 'darkgoldenrod': [184, 134, 11, 1], 'darkgray': [169, 169, 169, 1],\n 'darkgreen': [0, 100, 0, 1], 'darkgrey': [169, 169, 169, 1],\n 'darkkhaki': [189, 183, 107, 1], 'darkmagenta': [139, 0, 139, 1],\n 'darkolivegreen': [85, 107, 47, 1], 'darkorange': [255, 140, 0, 1],\n 'darkorchid': [153, 50, 204, 1], 'darkred': [139, 0, 0, 1],\n 'darksalmon': [233, 150, 122, 1], 'darkseagreen': [143, 188, 143, 1],\n 'darkslateblue': [72, 61, 139, 1], 'darkslategray': [47, 79, 79, 1],\n 'darkslategrey': [47, 79, 79, 1], 'darkturquoise': [0, 206, 209, 1],\n 'darkviolet': [148, 0, 211, 1], 'deeppink': [255, 20, 147, 1],\n 'deepskyblue': [0, 191, 255, 1], 'dimgray': [105, 105, 105, 1],\n 'dimgrey': [105, 105, 105, 1], 'dodgerblue': [30, 144, 255, 1],\n 'firebrick': [178, 34, 34, 1], 'floralwhite': [255, 250, 240, 1],\n 'forestgreen': [34, 139, 34, 1], 'fuchsia': [255, 0, 255, 1],\n 'gainsboro': [220, 220, 220, 1], 'ghostwhite': [248, 248, 255, 1],\n 'gold': [255, 215, 0, 1], 'goldenrod': [218, 165, 32, 1],\n 'gray': [128, 128, 128, 1], 'green': [0, 128, 0, 1],\n 'greenyellow': [173, 255, 47, 1], 'grey': [128, 128, 128, 1],\n 'honeydew': [240, 255, 240, 1], 'hotpink': [255, 105, 180, 1],\n 'indianred': [205, 92, 92, 1], 'indigo': [75, 0, 130, 1],\n 'ivory': [255, 255, 240, 1], 'khaki': [240, 230, 140, 1],\n 'lavender': [230, 230, 250, 1], 'lavenderblush': [255, 240, 245, 1],\n 'lawngreen': [124, 252, 0, 1], 'lemonchiffon': [255, 250, 205, 1],\n 'lightblue': [173, 216, 230, 1], 'lightcoral': [240, 128, 128, 1],\n 'lightcyan': [224, 255, 255, 1], 'lightgoldenrodyellow': [250, 250, 210, 1],\n 'lightgray': [211, 211, 211, 1], 'lightgreen': [144, 238, 144, 1],\n 'lightgrey': [211, 211, 211, 1], 'lightpink': [255, 182, 193, 1],\n 'lightsalmon': [255, 160, 122, 1], 'lightseagreen': [32, 178, 170, 1],\n 'lightskyblue': [135, 206, 250, 1], 'lightslategray': [119, 136, 153, 1],\n 'lightslategrey': [119, 136, 153, 1], 'lightsteelblue': [176, 196, 222, 1],\n 'lightyellow': [255, 255, 224, 1], 'lime': [0, 255, 0, 1],\n 'limegreen': [50, 205, 50, 1], 'linen': [250, 240, 230, 1],\n 'magenta': [255, 0, 255, 1], 'maroon': [128, 0, 0, 1],\n 'mediumaquamarine': [102, 205, 170, 1], 'mediumblue': [0, 0, 205, 1],\n 'mediumorchid': [186, 85, 211, 1], 'mediumpurple': [147, 112, 219, 1],\n 'mediumseagreen': [60, 179, 113, 1], 'mediumslateblue': [123, 104, 238, 1],\n 'mediumspringgreen': [0, 250, 154, 1], 'mediumturquoise': [72, 209, 204, 1],\n 'mediumvioletred': [199, 21, 133, 1], 'midnightblue': [25, 25, 112, 1],\n 'mintcream': [245, 255, 250, 1], 'mistyrose': [255, 228, 225, 1],\n 'moccasin': [255, 228, 181, 1], 'navajowhite': [255, 222, 173, 1],\n 'navy': [0, 0, 128, 1], 'oldlace': [253, 245, 230, 1],\n 'olive': [128, 128, 0, 1], 'olivedrab': [107, 142, 35, 1],\n 'orange': [255, 165, 0, 1], 'orangered': [255, 69, 0, 1],\n 'orchid': [218, 112, 214, 1], 'palegoldenrod': [238, 232, 170, 1],\n 'palegreen': [152, 251, 152, 1], 'paleturquoise': [175, 238, 238, 1],\n 'palevioletred': [219, 112, 147, 1], 'papayawhip': [255, 239, 213, 1],\n 'peachpuff': [255, 218, 185, 1], 'peru': [205, 133, 63, 1],\n 'pink': [255, 192, 203, 1], 'plum': [221, 160, 221, 1],\n 'powderblue': [176, 224, 230, 1], 'purple': [128, 0, 128, 1],\n 'red': [255, 0, 0, 1], 'rosybrown': [188, 143, 143, 1],\n 'royalblue': [65, 105, 225, 1], 'saddlebrown': [139, 69, 19, 1],\n 'salmon': [250, 128, 114, 1], 'sandybrown': [244, 164, 96, 1],\n 'seagreen': [46, 139, 87, 1], 'seashell': [255, 245, 238, 1],\n 'sienna': [160, 82, 45, 1], 'silver': [192, 192, 192, 1],\n 'skyblue': [135, 206, 235, 1], 'slateblue': [106, 90, 205, 1],\n 'slategray': [112, 128, 144, 1], 'slategrey': [112, 128, 144, 1],\n 'snow': [255, 250, 250, 1], 'springgreen': [0, 255, 127, 1],\n 'steelblue': [70, 130, 180, 1], 'tan': [210, 180, 140, 1],\n 'teal': [0, 128, 128, 1], 'thistle': [216, 191, 216, 1],\n 'tomato': [255, 99, 71, 1], 'turquoise': [64, 224, 208, 1],\n 'violet': [238, 130, 238, 1], 'wheat': [245, 222, 179, 1],\n 'white': [255, 255, 255, 1], 'whitesmoke': [245, 245, 245, 1],\n 'yellow': [255, 255, 0, 1], 'yellowgreen': [154, 205, 50, 1]\n};\n\nfunction clampCssByte(i) { // Clamp to integer 0 .. 255.\n i = Math.round(i); // Seems to be what Chrome does (vs truncation).\n return i < 0 ? 0 : i > 255 ? 255 : i;\n}\n\nfunction clampCssAngle(i) { // Clamp to integer 0 .. 360.\n i = Math.round(i); // Seems to be what Chrome does (vs truncation).\n return i < 0 ? 0 : i > 360 ? 360 : i;\n}\n\nfunction clampCssFloat(f) { // Clamp to float 0.0 .. 1.0.\n return f < 0 ? 0 : f > 1 ? 1 : f;\n}\n\nfunction parseCssInt(str) { // int or percentage.\n if (str.length && str.charAt(str.length - 1) === '%') {\n return clampCssByte(parseFloat(str) / 100 * 255);\n }\n return clampCssByte(parseInt(str, 10));\n}\n\nfunction parseCssFloat(str) { // float or percentage.\n if (str.length && str.charAt(str.length - 1) === '%') {\n return clampCssFloat(parseFloat(str) / 100);\n }\n return clampCssFloat(parseFloat(str));\n}\n\nfunction cssHueToRgb(m1, m2, h) {\n if (h < 0) {\n h += 1;\n }\n else if (h > 1) {\n h -= 1;\n }\n\n if (h * 6 < 1) {\n return m1 + (m2 - m1) * h * 6;\n }\n if (h * 2 < 1) {\n return m2;\n }\n if (h * 3 < 2) {\n return m1 + (m2 - m1) * (2 / 3 - h) * 6;\n }\n return m1;\n}\n\nfunction lerpNumber(a, b, p) {\n return a + (b - a) * p;\n}\n\nfunction setRgba(out, r, g, b, a) {\n out[0] = r;\n out[1] = g;\n out[2] = b;\n out[3] = a;\n return out;\n}\nfunction copyRgba(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n\nvar colorCache = new LRU(20);\nvar lastRemovedArr = null;\n\nfunction putToCache(colorStr, rgbaArr) {\n // Reuse removed array\n if (lastRemovedArr) {\n copyRgba(lastRemovedArr, rgbaArr);\n }\n lastRemovedArr = colorCache.put(colorStr, lastRemovedArr || (rgbaArr.slice()));\n}\n\n/**\n * @param {string} colorStr\n * @param {Array.<number>} out\n * @return {Array.<number>}\n * @memberOf module:zrender/util/color\n */\nexport function parse(colorStr, rgbaArr) {\n if (!colorStr) {\n return;\n }\n rgbaArr = rgbaArr || [];\n\n var cached = colorCache.get(colorStr);\n if (cached) {\n return copyRgba(rgbaArr, cached);\n }\n\n // colorStr may be not string\n colorStr = colorStr + '';\n // Remove all whitespace, not compliant, but should just be more accepting.\n var str = colorStr.replace(/ /g, '').toLowerCase();\n\n // Color keywords (and transparent) lookup.\n if (str in kCSSColorTable) {\n copyRgba(rgbaArr, kCSSColorTable[str]);\n putToCache(colorStr, rgbaArr);\n return rgbaArr;\n }\n\n // #abc and #abc123 syntax.\n if (str.charAt(0) === '#') {\n if (str.length === 4) {\n var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.\n if (!(iv >= 0 && iv <= 0xfff)) {\n setRgba(rgbaArr, 0, 0, 0, 1);\n return; // Covers NaN.\n }\n setRgba(rgbaArr,\n ((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8),\n (iv & 0xf0) | ((iv & 0xf0) >> 4),\n (iv & 0xf) | ((iv & 0xf) << 4),\n 1\n );\n putToCache(colorStr, rgbaArr);\n return rgbaArr;\n }\n else if (str.length === 7) {\n var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.\n if (!(iv >= 0 && iv <= 0xffffff)) {\n setRgba(rgbaArr, 0, 0, 0, 1);\n return; // Covers NaN.\n }\n setRgba(rgbaArr,\n (iv & 0xff0000) >> 16,\n (iv & 0xff00) >> 8,\n iv & 0xff,\n 1\n );\n putToCache(colorStr, rgbaArr);\n return rgbaArr;\n }\n\n return;\n }\n var op = str.indexOf('(');\n var ep = str.indexOf(')');\n if (op !== -1 && ep + 1 === str.length) {\n var fname = str.substr(0, op);\n var params = str.substr(op + 1, ep - (op + 1)).split(',');\n var alpha = 1; // To allow case fallthrough.\n switch (fname) {\n case 'rgba':\n if (params.length !== 4) {\n setRgba(rgbaArr, 0, 0, 0, 1);\n return;\n }\n alpha = parseCssFloat(params.pop()); // jshint ignore:line\n // Fall through.\n case 'rgb':\n if (params.length !== 3) {\n setRgba(rgbaArr, 0, 0, 0, 1);\n return;\n }\n setRgba(rgbaArr,\n parseCssInt(params[0]),\n parseCssInt(params[1]),\n parseCssInt(params[2]),\n alpha\n );\n putToCache(colorStr, rgbaArr);\n return rgbaArr;\n case 'hsla':\n if (params.length !== 4) {\n setRgba(rgbaArr, 0, 0, 0, 1);\n return;\n }\n params[3] = parseCssFloat(params[3]);\n hsla2rgba(params, rgbaArr);\n putToCache(colorStr, rgbaArr);\n return rgbaArr;\n case 'hsl':\n if (params.length !== 3) {\n setRgba(rgbaArr, 0, 0, 0, 1);\n return;\n }\n hsla2rgba(params, rgbaArr);\n putToCache(colorStr, rgbaArr);\n return rgbaArr;\n default:\n return;\n }\n }\n\n setRgba(rgbaArr, 0, 0, 0, 1);\n return;\n}\n\n/**\n * @param {Array.<number>} hsla\n * @param {Array.<number>} rgba\n * @return {Array.<number>} rgba\n */\nfunction hsla2rgba(hsla, rgba) {\n var h = (((parseFloat(hsla[0]) % 360) + 360) % 360) / 360; // 0 .. 1\n // NOTE(deanm): According to the CSS spec s/l should only be\n // percentages, but we don't bother and let float or percentage.\n var s = parseCssFloat(hsla[1]);\n var l = parseCssFloat(hsla[2]);\n var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;\n var m1 = l * 2 - m2;\n\n rgba = rgba || [];\n setRgba(rgba,\n clampCssByte(cssHueToRgb(m1, m2, h + 1 / 3) * 255),\n clampCssByte(cssHueToRgb(m1, m2, h) * 255),\n clampCssByte(cssHueToRgb(m1, m2, h - 1 / 3) * 255),\n 1\n );\n\n if (hsla.length === 4) {\n rgba[3] = hsla[3];\n }\n\n return rgba;\n}\n\n/**\n * @param {Array.<number>} rgba\n * @return {Array.<number>} hsla\n */\nfunction rgba2hsla(rgba) {\n if (!rgba) {\n return;\n }\n\n // RGB from 0 to 255\n var R = rgba[0] / 255;\n var G = rgba[1] / 255;\n var B = rgba[2] / 255;\n\n var vMin = Math.min(R, G, B); // Min. value of RGB\n var vMax = Math.max(R, G, B); // Max. value of RGB\n var delta = vMax - vMin; // Delta RGB value\n\n var L = (vMax + vMin) / 2;\n var H;\n var S;\n // HSL results from 0 to 1\n if (delta === 0) {\n H = 0;\n S = 0;\n }\n else {\n if (L < 0.5) {\n S = delta / (vMax + vMin);\n }\n else {\n S = delta / (2 - vMax - vMin);\n }\n\n var deltaR = (((vMax - R) / 6) + (delta / 2)) / delta;\n var deltaG = (((vMax - G) / 6) + (delta / 2)) / delta;\n var deltaB = (((vMax - B) / 6) + (delta / 2)) / delta;\n\n if (R === vMax) {\n H = deltaB - deltaG;\n }\n else if (G === vMax) {\n H = (1 / 3) + deltaR - deltaB;\n }\n else if (B === vMax) {\n H = (2 / 3) + deltaG - deltaR;\n }\n\n if (H < 0) {\n H += 1;\n }\n\n if (H > 1) {\n H -= 1;\n }\n }\n\n var hsla = [H * 360, S, L];\n\n if (rgba[3] != null) {\n hsla.push(rgba[3]);\n }\n\n return hsla;\n}\n\n/**\n * @param {string} color\n * @param {number} level\n * @return {string}\n * @memberOf module:zrender/util/color\n */\nexport function lift(color, level) {\n var colorArr = parse(color);\n if (colorArr) {\n for (var i = 0; i < 3; i++) {\n if (level < 0) {\n colorArr[i] = colorArr[i] * (1 - level) | 0;\n }\n else {\n colorArr[i] = ((255 - colorArr[i]) * level + colorArr[i]) | 0;\n }\n if (colorArr[i] > 255) {\n colorArr[i] = 255;\n }\n else if (color[i] < 0) {\n colorArr[i] = 0;\n }\n }\n return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');\n }\n}\n\n/**\n * @param {string} color\n * @return {string}\n * @memberOf module:zrender/util/color\n */\nexport function toHex(color) {\n var colorArr = parse(color);\n if (colorArr) {\n return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + (+colorArr[2])).toString(16).slice(1);\n }\n}\n\n/**\n * Map value to color. Faster than lerp methods because color is represented by rgba array.\n * @param {number} normalizedValue A float between 0 and 1.\n * @param {Array.<Array.<number>>} colors List of rgba color array\n * @param {Array.<number>} [out] Mapped gba color array\n * @return {Array.<number>} will be null/undefined if input illegal.\n */\nexport function fastLerp(normalizedValue, colors, out) {\n if (!(colors && colors.length)\n || !(normalizedValue >= 0 && normalizedValue <= 1)\n ) {\n return;\n }\n\n out = out || [];\n\n var value = normalizedValue * (colors.length - 1);\n var leftIndex = Math.floor(value);\n var rightIndex = Math.ceil(value);\n var leftColor = colors[leftIndex];\n var rightColor = colors[rightIndex];\n var dv = value - leftIndex;\n out[0] = clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv));\n out[1] = clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv));\n out[2] = clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv));\n out[3] = clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv));\n\n return out;\n}\n\n/**\n * @deprecated\n */\nexport var fastMapToColor = fastLerp;\n\n/**\n * @param {number} normalizedValue A float between 0 and 1.\n * @param {Array.<string>} colors Color list.\n * @param {boolean=} fullOutput Default false.\n * @return {(string|Object)} Result color. If fullOutput,\n * return {color: ..., leftIndex: ..., rightIndex: ..., value: ...},\n * @memberOf module:zrender/util/color\n */\nexport function lerp(normalizedValue, colors, fullOutput) {\n if (!(colors && colors.length)\n || !(normalizedValue >= 0 && normalizedValue <= 1)\n ) {\n return;\n }\n\n var value = normalizedValue * (colors.length - 1);\n var leftIndex = Math.floor(value);\n var rightIndex = Math.ceil(value);\n var leftColor = parse(colors[leftIndex]);\n var rightColor = parse(colors[rightIndex]);\n var dv = value - leftIndex;\n\n var color = stringify(\n [\n clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv)),\n clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv)),\n clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv)),\n clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv))\n ],\n 'rgba'\n );\n\n return fullOutput\n ? {\n color: color,\n leftIndex: leftIndex,\n rightIndex: rightIndex,\n value: value\n }\n : color;\n}\n\n/**\n * @deprecated\n */\nexport var mapToColor = lerp;\n\n/**\n * @param {string} color\n * @param {number=} h 0 ~ 360, ignore when null.\n * @param {number=} s 0 ~ 1, ignore when null.\n * @param {number=} l 0 ~ 1, ignore when null.\n * @return {string} Color string in rgba format.\n * @memberOf module:zrender/util/color\n */\nexport function modifyHSL(color, h, s, l) {\n color = parse(color);\n\n if (color) {\n color = rgba2hsla(color);\n h != null && (color[0] = clampCssAngle(h));\n s != null && (color[1] = parseCssFloat(s));\n l != null && (color[2] = parseCssFloat(l));\n\n return stringify(hsla2rgba(color), 'rgba');\n }\n}\n\n/**\n * @param {string} color\n * @param {number=} alpha 0 ~ 1\n * @return {string} Color string in rgba format.\n * @memberOf module:zrender/util/color\n */\nexport function modifyAlpha(color, alpha) {\n color = parse(color);\n\n if (color && alpha != null) {\n color[3] = clampCssFloat(alpha);\n return stringify(color, 'rgba');\n }\n}\n\n/**\n * @param {Array.<number>} arrColor like [12,33,44,0.4]\n * @param {string} type 'rgba', 'hsva', ...\n * @return {string} Result color. (If input illegal, return undefined).\n */\nexport function stringify(arrColor, type) {\n if (!arrColor || !arrColor.length) {\n return;\n }\n var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];\n if (type === 'rgba' || type === 'hsva' || type === 'hsla') {\n colorStr += ',' + arrColor[3];\n }\n return type + '(' + colorStr + ')';\n}\n","/**\n * @module echarts/animation/Animator\n */\n\nimport Clip from './Clip';\nimport * as color from '../tool/color';\nimport {isArrayLike} from '../core/util';\n\nvar arraySlice = Array.prototype.slice;\n\nfunction defaultGetter(target, key) {\n return target[key];\n}\n\nfunction defaultSetter(target, key, value) {\n target[key] = value;\n}\n\n/**\n * @param {number} p0\n * @param {number} p1\n * @param {number} percent\n * @return {number}\n */\nfunction interpolateNumber(p0, p1, percent) {\n return (p1 - p0) * percent + p0;\n}\n\n/**\n * @param {string} p0\n * @param {string} p1\n * @param {number} percent\n * @return {string}\n */\nfunction interpolateString(p0, p1, percent) {\n return percent > 0.5 ? p1 : p0;\n}\n\n/**\n * @param {Array} p0\n * @param {Array} p1\n * @param {number} percent\n * @param {Array} out\n * @param {number} arrDim\n */\nfunction interpolateArray(p0, p1, percent, out, arrDim) {\n var len = p0.length;\n if (arrDim === 1) {\n for (var i = 0; i < len; i++) {\n out[i] = interpolateNumber(p0[i], p1[i], percent);\n }\n }\n else {\n var len2 = len && p0[0].length;\n for (var i = 0; i < len; i++) {\n for (var j = 0; j < len2; j++) {\n out[i][j] = interpolateNumber(\n p0[i][j], p1[i][j], percent\n );\n }\n }\n }\n}\n\n// arr0 is source array, arr1 is target array.\n// Do some preprocess to avoid error happened when interpolating from arr0 to arr1\nfunction fillArr(arr0, arr1, arrDim) {\n var arr0Len = arr0.length;\n var arr1Len = arr1.length;\n if (arr0Len !== arr1Len) {\n // FIXME Not work for TypedArray\n var isPreviousLarger = arr0Len > arr1Len;\n if (isPreviousLarger) {\n // Cut the previous\n arr0.length = arr1Len;\n }\n else {\n // Fill the previous\n for (var i = arr0Len; i < arr1Len; i++) {\n arr0.push(\n arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i])\n );\n }\n }\n }\n // Handling NaN value\n var len2 = arr0[0] && arr0[0].length;\n for (var i = 0; i < arr0.length; i++) {\n if (arrDim === 1) {\n if (isNaN(arr0[i])) {\n arr0[i] = arr1[i];\n }\n }\n else {\n for (var j = 0; j < len2; j++) {\n if (isNaN(arr0[i][j])) {\n arr0[i][j] = arr1[i][j];\n }\n }\n }\n }\n}\n\n/**\n * @param {Array} arr0\n * @param {Array} arr1\n * @param {number} arrDim\n * @return {boolean}\n */\nfunction isArraySame(arr0, arr1, arrDim) {\n if (arr0 === arr1) {\n return true;\n }\n var len = arr0.length;\n if (len !== arr1.length) {\n return false;\n }\n if (arrDim === 1) {\n for (var i = 0; i < len; i++) {\n if (arr0[i] !== arr1[i]) {\n return false;\n }\n }\n }\n else {\n var len2 = arr0[0].length;\n for (var i = 0; i < len; i++) {\n for (var j = 0; j < len2; j++) {\n if (arr0[i][j] !== arr1[i][j]) {\n return false;\n }\n }\n }\n }\n return true;\n}\n\n/**\n * Catmull Rom interpolate array\n * @param {Array} p0\n * @param {Array} p1\n * @param {Array} p2\n * @param {Array} p3\n * @param {number} t\n * @param {number} t2\n * @param {number} t3\n * @param {Array} out\n * @param {number} arrDim\n */\nfunction catmullRomInterpolateArray(\n p0, p1, p2, p3, t, t2, t3, out, arrDim\n) {\n var len = p0.length;\n if (arrDim === 1) {\n for (var i = 0; i < len; i++) {\n out[i] = catmullRomInterpolate(\n p0[i], p1[i], p2[i], p3[i], t, t2, t3\n );\n }\n }\n else {\n var len2 = p0[0].length;\n for (var i = 0; i < len; i++) {\n for (var j = 0; j < len2; j++) {\n out[i][j] = catmullRomInterpolate(\n p0[i][j], p1[i][j], p2[i][j], p3[i][j],\n t, t2, t3\n );\n }\n }\n }\n}\n\n/**\n * Catmull Rom interpolate number\n * @param {number} p0\n * @param {number} p1\n * @param {number} p2\n * @param {number} p3\n * @param {number} t\n * @param {number} t2\n * @param {number} t3\n * @return {number}\n */\nfunction catmullRomInterpolate(p0, p1, p2, p3, t, t2, t3) {\n var v0 = (p2 - p0) * 0.5;\n var v1 = (p3 - p1) * 0.5;\n return (2 * (p1 - p2) + v0 + v1) * t3\n + (-3 * (p1 - p2) - 2 * v0 - v1) * t2\n + v0 * t + p1;\n}\n\nfunction cloneValue(value) {\n if (isArrayLike(value)) {\n var len = value.length;\n if (isArrayLike(value[0])) {\n var ret = [];\n for (var i = 0; i < len; i++) {\n ret.push(arraySlice.call(value[i]));\n }\n return ret;\n }\n\n return arraySlice.call(value);\n }\n\n return value;\n}\n\nfunction rgba2String(rgba) {\n rgba[0] = Math.floor(rgba[0]);\n rgba[1] = Math.floor(rgba[1]);\n rgba[2] = Math.floor(rgba[2]);\n\n return 'rgba(' + rgba.join(',') + ')';\n}\n\nfunction getArrayDim(keyframes) {\n var lastValue = keyframes[keyframes.length - 1].value;\n return isArrayLike(lastValue && lastValue[0]) ? 2 : 1;\n}\n\nfunction createTrackClip(animator, easing, oneTrackDone, keyframes, propName, forceAnimate) {\n var getter = animator._getter;\n var setter = animator._setter;\n var useSpline = easing === 'spline';\n\n var trackLen = keyframes.length;\n if (!trackLen) {\n return;\n }\n // Guess data type\n var firstVal = keyframes[0].value;\n var isValueArray = isArrayLike(firstVal);\n var isValueColor = false;\n var isValueString = false;\n\n // For vertices morphing\n var arrDim = isValueArray ? getArrayDim(keyframes) : 0;\n\n var trackMaxTime;\n // Sort keyframe as ascending\n keyframes.sort(function (a, b) {\n return a.time - b.time;\n });\n\n trackMaxTime = keyframes[trackLen - 1].time;\n // Percents of each keyframe\n var kfPercents = [];\n // Value of each keyframe\n var kfValues = [];\n var prevValue = keyframes[0].value;\n var isAllValueEqual = true;\n for (var i = 0; i < trackLen; i++) {\n kfPercents.push(keyframes[i].time / trackMaxTime);\n // Assume value is a color when it is a string\n var value = keyframes[i].value;\n\n // Check if value is equal, deep check if value is array\n if (!((isValueArray && isArraySame(value, prevValue, arrDim))\n || (!isValueArray && value === prevValue))) {\n isAllValueEqual = false;\n }\n prevValue = value;\n\n // Try converting a string to a color array\n if (typeof value === 'string') {\n var colorArray = color.parse(value);\n if (colorArray) {\n value = colorArray;\n isValueColor = true;\n }\n else {\n isValueString = true;\n }\n }\n kfValues.push(value);\n }\n if (!forceAnimate && isAllValueEqual) {\n return;\n }\n\n var lastValue = kfValues[trackLen - 1];\n // Polyfill array and NaN value\n for (var i = 0; i < trackLen - 1; i++) {\n if (isValueArray) {\n fillArr(kfValues[i], lastValue, arrDim);\n }\n else {\n if (isNaN(kfValues[i]) && !isNaN(lastValue) && !isValueString && !isValueColor) {\n kfValues[i] = lastValue;\n }\n }\n }\n isValueArray && fillArr(getter(animator._target, propName), lastValue, arrDim);\n\n // Cache the key of last frame to speed up when\n // animation playback is sequency\n var lastFrame = 0;\n var lastFramePercent = 0;\n var start;\n var w;\n var p0;\n var p1;\n var p2;\n var p3;\n\n if (isValueColor) {\n var rgba = [0, 0, 0, 0];\n }\n\n var onframe = function (target, percent) {\n // Find the range keyframes\n // kf1-----kf2---------current--------kf3\n // find kf2 and kf3 and do interpolation\n var frame;\n // In the easing function like elasticOut, percent may less than 0\n if (percent < 0) {\n frame = 0;\n }\n else if (percent < lastFramePercent) {\n // Start from next key\n // PENDING start from lastFrame ?\n start = Math.min(lastFrame + 1, trackLen - 1);\n for (frame = start; frame >= 0; frame--) {\n if (kfPercents[frame] <= percent) {\n break;\n }\n }\n // PENDING really need to do this ?\n frame = Math.min(frame, trackLen - 2);\n }\n else {\n for (frame = lastFrame; frame < trackLen; frame++) {\n if (kfPercents[frame] > percent) {\n break;\n }\n }\n frame = Math.min(frame - 1, trackLen - 2);\n }\n lastFrame = frame;\n lastFramePercent = percent;\n\n var range = (kfPercents[frame + 1] - kfPercents[frame]);\n if (range === 0) {\n return;\n }\n else {\n w = (percent - kfPercents[frame]) / range;\n }\n if (useSpline) {\n p1 = kfValues[frame];\n p0 = kfValues[frame === 0 ? frame : frame - 1];\n p2 = kfValues[frame > trackLen - 2 ? trackLen - 1 : frame + 1];\n p3 = kfValues[frame > trackLen - 3 ? trackLen - 1 : frame + 2];\n if (isValueArray) {\n catmullRomInterpolateArray(\n p0, p1, p2, p3, w, w * w, w * w * w,\n getter(target, propName),\n arrDim\n );\n }\n else {\n var value;\n if (isValueColor) {\n value = catmullRomInterpolateArray(\n p0, p1, p2, p3, w, w * w, w * w * w,\n rgba, 1\n );\n value = rgba2String(rgba);\n }\n else if (isValueString) {\n // String is step(0.5)\n return interpolateString(p1, p2, w);\n }\n else {\n value = catmullRomInterpolate(\n p0, p1, p2, p3, w, w * w, w * w * w\n );\n }\n setter(\n target,\n propName,\n value\n );\n }\n }\n else {\n if (isValueArray) {\n interpolateArray(\n kfValues[frame], kfValues[frame + 1], w,\n getter(target, propName),\n arrDim\n );\n }\n else {\n var value;\n if (isValueColor) {\n interpolateArray(\n kfValues[frame], kfValues[frame + 1], w,\n rgba, 1\n );\n value = rgba2String(rgba);\n }\n else if (isValueString) {\n // String is step(0.5)\n return interpolateString(kfValues[frame], kfValues[frame + 1], w);\n }\n else {\n value = interpolateNumber(kfValues[frame], kfValues[frame + 1], w);\n }\n setter(\n target,\n propName,\n value\n );\n }\n }\n };\n\n var clip = new Clip({\n target: animator._target,\n life: trackMaxTime,\n loop: animator._loop,\n delay: animator._delay,\n onframe: onframe,\n ondestroy: oneTrackDone\n });\n\n if (easing && easing !== 'spline') {\n clip.easing = easing;\n }\n\n return clip;\n}\n\n/**\n * @alias module:zrender/animation/Animator\n * @constructor\n * @param {Object} target\n * @param {boolean} loop\n * @param {Function} getter\n * @param {Function} setter\n */\nvar Animator = function (target, loop, getter, setter) {\n this._tracks = {};\n this._target = target;\n\n this._loop = loop || false;\n\n this._getter = getter || defaultGetter;\n this._setter = setter || defaultSetter;\n\n this._clipCount = 0;\n\n this._delay = 0;\n\n this._doneList = [];\n\n this._onframeList = [];\n\n this._clipList = [];\n};\n\nAnimator.prototype = {\n /**\n * Set Animation keyframe\n * @param {number} time 关键帧时间,单位是ms\n * @param {Object} props 关键帧的属性值,key-value表示\n * @return {module:zrender/animation/Animator}\n */\n when: function (time /* ms */, props) {\n var tracks = this._tracks;\n for (var propName in props) {\n if (!props.hasOwnProperty(propName)) {\n continue;\n }\n\n if (!tracks[propName]) {\n tracks[propName] = [];\n // Invalid value\n var value = this._getter(this._target, propName);\n if (value == null) {\n // zrLog('Invalid property ' + propName);\n continue;\n }\n // If time is 0\n // Then props is given initialize value\n // Else\n // Initialize value from current prop value\n if (time !== 0) {\n tracks[propName].push({\n time: 0,\n value: cloneValue(value)\n });\n }\n }\n tracks[propName].push({\n time: time,\n value: props[propName]\n });\n }\n return this;\n },\n /**\n * 添加动画每一帧的回调函数\n * @param {Function} callback\n * @return {module:zrender/animation/Animator}\n */\n during: function (callback) {\n this._onframeList.push(callback);\n return this;\n },\n\n pause: function () {\n for (var i = 0; i < this._clipList.length; i++) {\n this._clipList[i].pause();\n }\n this._paused = true;\n },\n\n resume: function () {\n for (var i = 0; i < this._clipList.length; i++) {\n this._clipList[i].resume();\n }\n this._paused = false;\n },\n\n isPaused: function () {\n return !!this._paused;\n },\n\n _doneCallback: function () {\n // Clear all tracks\n this._tracks = {};\n // Clear all clips\n this._clipList.length = 0;\n\n var doneList = this._doneList;\n var len = doneList.length;\n for (var i = 0; i < len; i++) {\n doneList[i].call(this);\n }\n },\n /**\n * Start the animation\n * @param {string|Function} [easing]\n * 动画缓动函数,详见{@link module:zrender/animation/easing}\n * @param {boolean} forceAnimate\n * @return {module:zrender/animation/Animator}\n */\n start: function (easing, forceAnimate) {\n\n var self = this;\n var clipCount = 0;\n\n var oneTrackDone = function () {\n clipCount--;\n if (!clipCount) {\n self._doneCallback();\n }\n };\n\n var lastClip;\n for (var propName in this._tracks) {\n if (!this._tracks.hasOwnProperty(propName)) {\n continue;\n }\n var clip = createTrackClip(\n this, easing, oneTrackDone,\n this._tracks[propName], propName, forceAnimate\n );\n if (clip) {\n this._clipList.push(clip);\n clipCount++;\n\n // If start after added to animation\n if (this.animation) {\n this.animation.addClip(clip);\n }\n\n lastClip = clip;\n }\n }\n\n // Add during callback on the last clip\n if (lastClip) {\n var oldOnFrame = lastClip.onframe;\n lastClip.onframe = function (target, percent) {\n oldOnFrame(target, percent);\n\n for (var i = 0; i < self._onframeList.length; i++) {\n self._onframeList[i](target, percent);\n }\n };\n }\n\n // This optimization will help the case that in the upper application\n // the view may be refreshed frequently, where animation will be\n // called repeatly but nothing changed.\n if (!clipCount) {\n this._doneCallback();\n }\n return this;\n },\n /**\n * Stop animation\n * @param {boolean} forwardToLast If move to last frame before stop\n */\n stop: function (forwardToLast) {\n var clipList = this._clipList;\n var animation = this.animation;\n for (var i = 0; i < clipList.length; i++) {\n var clip = clipList[i];\n if (forwardToLast) {\n // Move to last frame before stop\n clip.onframe(this._target, 1);\n }\n animation && animation.removeClip(clip);\n }\n clipList.length = 0;\n },\n /**\n * Set when animation delay starts\n * @param {number} time 单位ms\n * @return {module:zrender/animation/Animator}\n */\n delay: function (time) {\n this._delay = time;\n return this;\n },\n /**\n * Add callback for animation end\n * @param {Function} cb\n * @return {module:zrender/animation/Animator}\n */\n done: function (cb) {\n if (cb) {\n this._doneList.push(cb);\n }\n return this;\n },\n\n /**\n * @return {Array.<module:zrender/animation/Clip>}\n */\n getClips: function () {\n return this._clipList;\n }\n};\n\nexport default Animator;","var dpr = 1;\n\n// If in browser environment\nif (typeof window !== 'undefined') {\n dpr = Math.max(window.devicePixelRatio || 1, 1);\n}\n\n/**\n * config默认配置项\n * @exports zrender/config\n * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)\n */\n\n/**\n * Debug log mode:\n * 0: Do nothing, for release.\n * 1: console.error, for debug.\n */\nexport var debugMode = 0;\n\n// retina 屏幕优化\nexport var devicePixelRatio = dpr;\n","import {debugMode} from '../config';\n\nvar logError = function () {\n};\n\nif (debugMode === 1) {\n logError = console.error;\n}\n\nexport default logError;\n","import Animator from '../animation/Animator';\nimport logError from '../core/log';\nimport {\n isString,\n isFunction,\n isObject,\n isArrayLike,\n indexOf\n} from '../core/util';\n\n/**\n * @alias module:zrender/mixin/Animatable\n * @constructor\n */\nvar Animatable = function () {\n\n /**\n * @type {Array.<module:zrender/animation/Animator>}\n * @readOnly\n */\n this.animators = [];\n};\n\nAnimatable.prototype = {\n\n constructor: Animatable,\n\n /**\n * 动画\n *\n * @param {string} path The path to fetch value from object, like 'a.b.c'.\n * @param {boolean} [loop] Whether to loop animation.\n * @return {module:zrender/animation/Animator}\n * @example:\n * el.animate('style', false)\n * .when(1000, {x: 10} )\n * .done(function(){ // Animation done })\n * .start()\n */\n animate: function (path, loop) {\n var target;\n var animatingShape = false;\n var el = this;\n var zr = this.__zr;\n if (path) {\n var pathSplitted = path.split('.');\n var prop = el;\n // If animating shape\n animatingShape = pathSplitted[0] === 'shape';\n for (var i = 0, l = pathSplitted.length; i < l; i++) {\n if (!prop) {\n continue;\n }\n prop = prop[pathSplitted[i]];\n }\n if (prop) {\n target = prop;\n }\n }\n else {\n target = el;\n }\n\n if (!target) {\n logError(\n 'Property \"'\n + path\n + '\" is not existed in element '\n + el.id\n );\n return;\n }\n\n var animators = el.animators;\n\n var animator = new Animator(target, loop);\n\n animator.during(function (target) {\n el.dirty(animatingShape);\n })\n .done(function () {\n // FIXME Animator will not be removed if use `Animator#stop` to stop animation\n animators.splice(indexOf(animators, animator), 1);\n });\n\n animators.push(animator);\n\n // If animate after added to the zrender\n if (zr) {\n zr.animation.addAnimator(animator);\n }\n\n return animator;\n },\n\n /**\n * 停止动画\n * @param {boolean} forwardToLast If move to last frame before stop\n */\n stopAnimation: function (forwardToLast) {\n var animators = this.animators;\n var len = animators.length;\n for (var i = 0; i < len; i++) {\n animators[i].stop(forwardToLast);\n }\n animators.length = 0;\n\n return this;\n },\n\n /**\n * Caution: this method will stop previous animation.\n * So do not use this method to one element twice before\n * animation starts, unless you know what you are doing.\n * @param {Object} target\n * @param {number} [time=500] Time in ms\n * @param {string} [easing='linear']\n * @param {number} [delay=0]\n * @param {Function} [callback]\n * @param {Function} [forceAnimate] Prevent stop animation and callback\n * immediently when target values are the same as current values.\n *\n * @example\n * // Animate position\n * el.animateTo({\n * position: [10, 10]\n * }, function () { // done })\n *\n * // Animate shape, style and position in 100ms, delayed 100ms, with cubicOut easing\n * el.animateTo({\n * shape: {\n * width: 500\n * },\n * style: {\n * fill: 'red'\n * }\n * position: [10, 10]\n * }, 100, 100, 'cubicOut', function () { // done })\n */\n // TODO Return animation key\n animateTo: function (target, time, delay, easing, callback, forceAnimate) {\n animateTo(this, target, time, delay, easing, callback, forceAnimate);\n },\n\n /**\n * Animate from the target state to current state.\n * The params and the return value are the same as `this.animateTo`.\n */\n animateFrom: function (target, time, delay, easing, callback, forceAnimate) {\n animateTo(this, target, time, delay, easing, callback, forceAnimate, true);\n }\n};\n\nfunction animateTo(animatable, target, time, delay, easing, callback, forceAnimate, reverse) {\n // animateTo(target, time, easing, callback);\n if (isString(delay)) {\n callback = easing;\n easing = delay;\n delay = 0;\n }\n // animateTo(target, time, delay, callback);\n else if (isFunction(easing)) {\n callback = easing;\n easing = 'linear';\n delay = 0;\n }\n // animateTo(target, time, callback);\n else if (isFunction(delay)) {\n callback = delay;\n delay = 0;\n }\n // animateTo(target, callback)\n else if (isFunction(time)) {\n callback = time;\n time = 500;\n }\n // animateTo(target)\n else if (!time) {\n time = 500;\n }\n // Stop all previous animations\n animatable.stopAnimation();\n animateToShallow(animatable, '', animatable, target, time, delay, reverse);\n\n // Animators may be removed immediately after start\n // if there is nothing to animate\n var animators = animatable.animators.slice();\n var count = animators.length;\n function done() {\n count--;\n if (!count) {\n callback && callback();\n }\n }\n\n // No animators. This should be checked before animators[i].start(),\n // because 'done' may be executed immediately if no need to animate.\n if (!count) {\n callback && callback();\n }\n // Start after all animators created\n // Incase any animator is done immediately when all animation properties are not changed\n for (var i = 0; i < animators.length; i++) {\n animators[i]\n .done(done)\n .start(easing, forceAnimate);\n }\n}\n\n/**\n * @param {string} path=''\n * @param {Object} source=animatable\n * @param {Object} target\n * @param {number} [time=500]\n * @param {number} [delay=0]\n * @param {boolean} [reverse] If `true`, animate\n * from the `target` to current state.\n *\n * @example\n * // Animate position\n * el._animateToShallow({\n * position: [10, 10]\n * })\n *\n * // Animate shape, style and position in 100ms, delayed 100ms\n * el._animateToShallow({\n * shape: {\n * width: 500\n * },\n * style: {\n * fill: 'red'\n * }\n * position: [10, 10]\n * }, 100, 100)\n */\nfunction animateToShallow(animatable, path, source, target, time, delay, reverse) {\n var objShallow = {};\n var propertyCount = 0;\n for (var name in target) {\n if (!target.hasOwnProperty(name)) {\n continue;\n }\n\n if (source[name] != null) {\n if (isObject(target[name]) && !isArrayLike(target[name])) {\n animateToShallow(\n animatable,\n path ? path + '.' + name : name,\n source[name],\n target[name],\n time,\n delay,\n reverse\n );\n }\n else {\n if (reverse) {\n objShallow[name] = source[name];\n setAttrByPath(animatable, path, name, target[name]);\n }\n else {\n objShallow[name] = target[name];\n }\n propertyCount++;\n }\n }\n else if (target[name] != null && !reverse) {\n setAttrByPath(animatable, path, name, target[name]);\n }\n }\n\n if (propertyCount > 0) {\n animatable.animate(path, false)\n .when(time == null ? 500 : time, objShallow)\n .delay(delay || 0);\n }\n}\n\nfunction setAttrByPath(el, path, name, value) {\n // Attr directly if not has property\n // FIXME, if some property not needed for element ?\n if (!path) {\n el.attr(name, value);\n }\n else {\n // Only support set shape or style\n var props = {};\n props[path] = {};\n props[path][name] = value;\n el.attr(props);\n }\n}\n\nexport default Animatable;","import guid from './core/guid';\nimport Eventful from './mixin/Eventful';\nimport Transformable from './mixin/Transformable';\nimport Animatable from './mixin/Animatable';\nimport * as zrUtil from './core/util';\n\n/**\n * @alias module:zrender/Element\n * @constructor\n * @extends {module:zrender/mixin/Animatable}\n * @extends {module:zrender/mixin/Transformable}\n * @extends {module:zrender/mixin/Eventful}\n */\nvar Element = function (opts) { // jshint ignore:line\n\n Transformable.call(this, opts);\n Eventful.call(this, opts);\n Animatable.call(this, opts);\n\n /**\n * 画布元素ID\n * @type {string}\n */\n this.id = opts.id || guid();\n};\n\nElement.prototype = {\n\n /**\n * 元素类型\n * Element type\n * @type {string}\n */\n type: 'element',\n\n /**\n * 元素名字\n * Element name\n * @type {string}\n */\n name: '',\n\n /**\n * ZRender 实例对象,会在 element 添加到 zrender 实例中后自动赋值\n * ZRender instance will be assigned when element is associated with zrender\n * @name module:/zrender/Element#__zr\n * @type {module:zrender/ZRender}\n */\n __zr: null,\n\n /**\n * 图形是否忽略,为true时忽略图形的绘制以及事件触发\n * If ignore drawing and events of the element object\n * @name module:/zrender/Element#ignore\n * @type {boolean}\n * @default false\n */\n ignore: false,\n\n /**\n * 用于裁剪的路径(shape),所有 Group 内的路径在绘制时都会被这个路径裁剪\n * 该路径会继承被裁减对象的变换\n * @type {module:zrender/graphic/Path}\n * @see http://www.w3.org/TR/2dcontext/#clipping-region\n * @readOnly\n */\n clipPath: null,\n\n /**\n * 是否是 Group\n * @type {boolean}\n */\n isGroup: false,\n\n /**\n * Drift element\n * @param {number} dx dx on the global space\n * @param {number} dy dy on the global space\n */\n drift: function (dx, dy) {\n switch (this.draggable) {\n case 'horizontal':\n dy = 0;\n break;\n case 'vertical':\n dx = 0;\n break;\n }\n\n var m = this.transform;\n if (!m) {\n m = this.transform = [1, 0, 0, 1, 0, 0];\n }\n m[4] += dx;\n m[5] += dy;\n\n this.decomposeTransform();\n this.dirty(false);\n },\n\n /**\n * Hook before update\n */\n beforeUpdate: function () {},\n /**\n * Hook after update\n */\n afterUpdate: function () {},\n /**\n * Update each frame\n */\n update: function () {\n this.updateTransform();\n },\n\n /**\n * @param {Function} cb\n * @param {} context\n */\n traverse: function (cb, context) {},\n\n /**\n * @protected\n */\n attrKV: function (key, value) {\n if (key === 'position' || key === 'scale' || key === 'origin') {\n // Copy the array\n if (value) {\n var target = this[key];\n if (!target) {\n target = this[key] = [];\n }\n target[0] = value[0];\n target[1] = value[1];\n }\n }\n else {\n this[key] = value;\n }\n },\n\n /**\n * Hide the element\n */\n hide: function () {\n this.ignore = true;\n this.__zr && this.__zr.refresh();\n },\n\n /**\n * Show the element\n */\n show: function () {\n this.ignore = false;\n this.__zr && this.__zr.refresh();\n },\n\n /**\n * @param {string|Object} key\n * @param {*} value\n */\n attr: function (key, value) {\n if (typeof key === 'string') {\n this.attrKV(key, value);\n }\n else if (zrUtil.isObject(key)) {\n for (var name in key) {\n if (key.hasOwnProperty(name)) {\n this.attrKV(name, key[name]);\n }\n }\n }\n\n this.dirty(false);\n\n return this;\n },\n\n /**\n * @param {module:zrender/graphic/Path} clipPath\n */\n setClipPath: function (clipPath) {\n var zr = this.__zr;\n if (zr) {\n clipPath.addSelfToZr(zr);\n }\n\n // Remove previous clip path\n if (this.clipPath && this.clipPath !== clipPath) {\n this.removeClipPath();\n }\n\n this.clipPath = clipPath;\n clipPath.__zr = zr;\n clipPath.__clipTarget = this;\n\n this.dirty(false);\n },\n\n /**\n */\n removeClipPath: function () {\n var clipPath = this.clipPath;\n if (clipPath) {\n if (clipPath.__zr) {\n clipPath.removeSelfFromZr(clipPath.__zr);\n }\n\n clipPath.__zr = null;\n clipPath.__clipTarget = null;\n this.clipPath = null;\n\n this.dirty(false);\n }\n },\n\n /**\n * Add self from zrender instance.\n * Not recursively because it will be invoked when element added to storage.\n * @param {module:zrender/ZRender} zr\n */\n addSelfToZr: function (zr) {\n this.__zr = zr;\n // 添加动画\n var animators = this.animators;\n if (animators) {\n for (var i = 0; i < animators.length; i++) {\n zr.animation.addAnimator(animators[i]);\n }\n }\n\n if (this.clipPath) {\n this.clipPath.addSelfToZr(zr);\n }\n },\n\n /**\n * Remove self from zrender instance.\n * Not recursively because it will be invoked when element added to storage.\n * @param {module:zrender/ZRender} zr\n */\n removeSelfFromZr: function (zr) {\n this.__zr = null;\n // 移除动画\n var animators = this.animators;\n if (animators) {\n for (var i = 0; i < animators.length; i++) {\n zr.animation.removeAnimator(animators[i]);\n }\n }\n\n if (this.clipPath) {\n this.clipPath.removeSelfFromZr(zr);\n }\n }\n};\n\nzrUtil.mixin(Element, Animatable);\nzrUtil.mixin(Element, Transformable);\nzrUtil.mixin(Element, Eventful);\n\nexport default Element;","/**\n * @module echarts/core/BoundingRect\n */\n\nimport * as vec2 from './vector';\nimport * as matrix from './matrix';\n\nvar v2ApplyTransform = vec2.applyTransform;\nvar mathMin = Math.min;\nvar mathMax = Math.max;\n\n/**\n * @alias module:echarts/core/BoundingRect\n */\nfunction BoundingRect(x, y, width, height) {\n\n if (width < 0) {\n x = x + width;\n width = -width;\n }\n if (height < 0) {\n y = y + height;\n height = -height;\n }\n\n /**\n * @type {number}\n */\n this.x = x;\n /**\n * @type {number}\n */\n this.y = y;\n /**\n * @type {number}\n */\n this.width = width;\n /**\n * @type {number}\n */\n this.height = height;\n}\n\nBoundingRect.prototype = {\n\n constructor: BoundingRect,\n\n /**\n * @param {module:echarts/core/BoundingRect} other\n */\n union: function (other) {\n var x = mathMin(other.x, this.x);\n var y = mathMin(other.y, this.y);\n\n this.width = mathMax(\n other.x + other.width,\n this.x + this.width\n ) - x;\n this.height = mathMax(\n other.y + other.height,\n this.y + this.height\n ) - y;\n this.x = x;\n this.y = y;\n },\n\n /**\n * @param {Array.<number>} m\n * @methods\n */\n applyTransform: (function () {\n var lt = [];\n var rb = [];\n var lb = [];\n var rt = [];\n return function (m) {\n // In case usage like this\n // el.getBoundingRect().applyTransform(el.transform)\n // And element has no transform\n if (!m) {\n return;\n }\n lt[0] = lb[0] = this.x;\n lt[1] = rt[1] = this.y;\n rb[0] = rt[0] = this.x + this.width;\n rb[1] = lb[1] = this.y + this.height;\n\n v2ApplyTransform(lt, lt, m);\n v2ApplyTransform(rb, rb, m);\n v2ApplyTransform(lb, lb, m);\n v2ApplyTransform(rt, rt, m);\n\n this.x = mathMin(lt[0], rb[0], lb[0], rt[0]);\n this.y = mathMin(lt[1], rb[1], lb[1], rt[1]);\n var maxX = mathMax(lt[0], rb[0], lb[0], rt[0]);\n var maxY = mathMax(lt[1], rb[1], lb[1], rt[1]);\n this.width = maxX - this.x;\n this.height = maxY - this.y;\n };\n })(),\n\n /**\n * Calculate matrix of transforming from self to target rect\n * @param {module:zrender/core/BoundingRect} b\n * @return {Array.<number>}\n */\n calculateTransform: function (b) {\n var a = this;\n var sx = b.width / a.width;\n var sy = b.height / a.height;\n\n var m = matrix.create();\n\n // 矩阵右乘\n matrix.translate(m, m, [-a.x, -a.y]);\n matrix.scale(m, m, [sx, sy]);\n matrix.translate(m, m, [b.x, b.y]);\n\n return m;\n },\n\n /**\n * @param {(module:echarts/core/BoundingRect|Object)} b\n * @return {boolean}\n */\n intersect: function (b) {\n if (!b) {\n return false;\n }\n\n if (!(b instanceof BoundingRect)) {\n // Normalize negative width/height.\n b = BoundingRect.create(b);\n }\n\n var a = this;\n var ax0 = a.x;\n var ax1 = a.x + a.width;\n var ay0 = a.y;\n var ay1 = a.y + a.height;\n\n var bx0 = b.x;\n var bx1 = b.x + b.width;\n var by0 = b.y;\n var by1 = b.y + b.height;\n\n return !(ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);\n },\n\n contain: function (x, y) {\n var rect = this;\n return x >= rect.x\n && x <= (rect.x + rect.width)\n && y >= rect.y\n && y <= (rect.y + rect.height);\n },\n\n /**\n * @return {module:echarts/core/BoundingRect}\n */\n clone: function () {\n return new BoundingRect(this.x, this.y, this.width, this.height);\n },\n\n /**\n * Copy from another rect\n */\n copy: function (other) {\n this.x = other.x;\n this.y = other.y;\n this.width = other.width;\n this.height = other.height;\n },\n\n plain: function () {\n return {\n x: this.x,\n y: this.y,\n width: this.width,\n height: this.height\n };\n }\n};\n\n/**\n * @param {Object|module:zrender/core/BoundingRect} rect\n * @param {number} rect.x\n * @param {number} rect.y\n * @param {number} rect.width\n * @param {number} rect.height\n * @return {module:zrender/core/BoundingRect}\n */\nBoundingRect.create = function (rect) {\n return new BoundingRect(rect.x, rect.y, rect.width, rect.height);\n};\n\nexport default BoundingRect;","/**\n * Group是一个容器,可以插入子节点,Group的变换也会被应用到子节点上\n * @module zrender/graphic/Group\n * @example\n * var Group = require('zrender/container/Group');\n * var Circle = require('zrender/graphic/shape/Circle');\n * var g = new Group();\n * g.position[0] = 100;\n * g.position[1] = 100;\n * g.add(new Circle({\n * style: {\n * x: 100,\n * y: 100,\n * r: 20,\n * }\n * }));\n * zr.add(g);\n */\n\nimport * as zrUtil from '../core/util';\nimport Element from '../Element';\nimport BoundingRect from '../core/BoundingRect';\n\n/**\n * @alias module:zrender/graphic/Group\n * @constructor\n * @extends module:zrender/mixin/Transformable\n * @extends module:zrender/mixin/Eventful\n */\nvar Group = function (opts) {\n\n opts = opts || {};\n\n Element.call(this, opts);\n\n for (var key in opts) {\n if (opts.hasOwnProperty(key)) {\n this[key] = opts[key];\n }\n }\n\n this._children = [];\n\n this.__storage = null;\n\n this.__dirty = true;\n};\n\nGroup.prototype = {\n\n constructor: Group,\n\n isGroup: true,\n\n /**\n * @type {string}\n */\n type: 'group',\n\n /**\n * 所有子孙元素是否响应鼠标事件\n * @name module:/zrender/container/Group#silent\n * @type {boolean}\n * @default false\n */\n silent: false,\n\n /**\n * @return {Array.<module:zrender/Element>}\n */\n children: function () {\n return this._children.slice();\n },\n\n /**\n * 获取指定 index 的儿子节点\n * @param {number} idx\n * @return {module:zrender/Element}\n */\n childAt: function (idx) {\n return this._children[idx];\n },\n\n /**\n * 获取指定名字的儿子节点\n * @param {string} name\n * @return {module:zrender/Element}\n */\n childOfName: function (name) {\n var children = this._children;\n for (var i = 0; i < children.length; i++) {\n if (children[i].name === name) {\n return children[i];\n }\n }\n },\n\n /**\n * @return {number}\n */\n childCount: function () {\n return this._children.length;\n },\n\n /**\n * 添加子节点到最后\n * @param {module:zrender/Element} child\n */\n add: function (child) {\n if (child && child !== this && child.parent !== this) {\n\n this._children.push(child);\n\n this._doAdd(child);\n }\n\n return this;\n },\n\n /**\n * 添加子节点在 nextSibling 之前\n * @param {module:zrender/Element} child\n * @param {module:zrender/Element} nextSibling\n */\n addBefore: function (child, nextSibling) {\n if (child && child !== this && child.parent !== this\n && nextSibling && nextSibling.parent === this) {\n\n var children = this._children;\n var idx = children.indexOf(nextSibling);\n\n if (idx >= 0) {\n children.splice(idx, 0, child);\n this._doAdd(child);\n }\n }\n\n return this;\n },\n\n _doAdd: function (child) {\n if (child.parent) {\n child.parent.remove(child);\n }\n\n child.parent = this;\n\n var storage = this.__storage;\n var zr = this.__zr;\n if (storage && storage !== child.__storage) {\n\n storage.addToStorage(child);\n\n if (child instanceof Group) {\n child.addChildrenToStorage(storage);\n }\n }\n\n zr && zr.refresh();\n },\n\n /**\n * 移除子节点\n * @param {module:zrender/Element} child\n */\n remove: function (child) {\n var zr = this.__zr;\n var storage = this.__storage;\n var children = this._children;\n\n var idx = zrUtil.indexOf(children, child);\n if (idx < 0) {\n return this;\n }\n children.splice(idx, 1);\n\n child.parent = null;\n\n if (storage) {\n\n storage.delFromStorage(child);\n\n if (child instanceof Group) {\n child.delChildrenFromStorage(storage);\n }\n }\n\n zr && zr.refresh();\n\n return this;\n },\n\n /**\n * 移除所有子节点\n */\n removeAll: function () {\n var children = this._children;\n var storage = this.__storage;\n var child;\n var i;\n for (i = 0; i < children.length; i++) {\n child = children[i];\n if (storage) {\n storage.delFromStorage(child);\n if (child instanceof Group) {\n child.delChildrenFromStorage(storage);\n }\n }\n child.parent = null;\n }\n children.length = 0;\n\n return this;\n },\n\n /**\n * 遍历所有子节点\n * @param {Function} cb\n * @param {} context\n */\n eachChild: function (cb, context) {\n var children = this._children;\n for (var i = 0; i < children.length; i++) {\n var child = children[i];\n cb.call(context, child, i);\n }\n return this;\n },\n\n /**\n * 深度优先遍历所有子孙节点\n * @param {Function} cb\n * @param {} context\n */\n traverse: function (cb, context) {\n for (var i = 0; i < this._children.length; i++) {\n var child = this._children[i];\n cb.call(context, child);\n\n if (child.type === 'group') {\n child.traverse(cb, context);\n }\n }\n return this;\n },\n\n addChildrenToStorage: function (storage) {\n for (var i = 0; i < this._children.length; i++) {\n var child = this._children[i];\n storage.addToStorage(child);\n if (child instanceof Group) {\n child.addChildrenToStorage(storage);\n }\n }\n },\n\n delChildrenFromStorage: function (storage) {\n for (var i = 0; i < this._children.length; i++) {\n var child = this._children[i];\n storage.delFromStorage(child);\n if (child instanceof Group) {\n child.delChildrenFromStorage(storage);\n }\n }\n },\n\n dirty: function () {\n this.__dirty = true;\n this.__zr && this.__zr.refresh();\n return this;\n },\n\n /**\n * @return {module:zrender/core/BoundingRect}\n */\n getBoundingRect: function (includeChildren) {\n // TODO Caching\n var rect = null;\n var tmpRect = new BoundingRect(0, 0, 0, 0);\n var children = includeChildren || this._children;\n var tmpMat = [];\n\n for (var i = 0; i < children.length; i++) {\n var child = children[i];\n if (child.ignore || child.invisible) {\n continue;\n }\n\n var childRect = child.getBoundingRect();\n var transform = child.getLocalTransform(tmpMat);\n // TODO\n // The boundingRect cacluated by transforming original\n // rect may be bigger than the actual bundingRect when rotation\n // is used. (Consider a circle rotated aginst its center, where\n // the actual boundingRect should be the same as that not be\n // rotated.) But we can not find better approach to calculate\n // actual boundingRect yet, considering performance.\n if (transform) {\n tmpRect.copy(childRect);\n tmpRect.applyTransform(transform);\n rect = rect || tmpRect.clone();\n rect.union(tmpRect);\n }\n else {\n rect = rect || childRect.clone();\n rect.union(childRect);\n }\n }\n return rect || tmpRect;\n }\n};\n\nzrUtil.inherits(Group, Element);\n\nexport default Group;","// https://github.com/mziccard/node-timsort\nvar DEFAULT_MIN_MERGE = 32;\n\nvar DEFAULT_MIN_GALLOPING = 7;\n\nvar DEFAULT_TMP_STORAGE_LENGTH = 256;\n\nfunction minRunLength(n) {\n var r = 0;\n\n while (n >= DEFAULT_MIN_MERGE) {\n r |= n & 1;\n n >>= 1;\n }\n\n return n + r;\n}\n\nfunction makeAscendingRun(array, lo, hi, compare) {\n var runHi = lo + 1;\n\n if (runHi === hi) {\n return 1;\n }\n\n if (compare(array[runHi++], array[lo]) < 0) {\n while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {\n runHi++;\n }\n\n reverseRun(array, lo, runHi);\n }\n else {\n while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {\n runHi++;\n }\n }\n\n return runHi - lo;\n}\n\nfunction reverseRun(array, lo, hi) {\n hi--;\n\n while (lo < hi) {\n var t = array[lo];\n array[lo++] = array[hi];\n array[hi--] = t;\n }\n}\n\nfunction binaryInsertionSort(array, lo, hi, start, compare) {\n if (start === lo) {\n start++;\n }\n\n for (; start < hi; start++) {\n var pivot = array[start];\n\n var left = lo;\n var right = start;\n var mid;\n\n while (left < right) {\n mid = left + right >>> 1;\n\n if (compare(pivot, array[mid]) < 0) {\n right = mid;\n }\n else {\n left = mid + 1;\n }\n }\n\n var n = start - left;\n\n switch (n) {\n case 3:\n array[left + 3] = array[left + 2];\n\n case 2:\n array[left + 2] = array[left + 1];\n\n case 1:\n array[left + 1] = array[left];\n break;\n default:\n while (n > 0) {\n array[left + n] = array[left + n - 1];\n n--;\n }\n }\n\n array[left] = pivot;\n }\n}\n\nfunction gallopLeft(value, array, start, length, hint, compare) {\n var lastOffset = 0;\n var maxOffset = 0;\n var offset = 1;\n\n if (compare(value, array[start + hint]) > 0) {\n maxOffset = length - hint;\n\n while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {\n lastOffset = offset;\n offset = (offset << 1) + 1;\n\n if (offset <= 0) {\n offset = maxOffset;\n }\n }\n\n if (offset > maxOffset) {\n offset = maxOffset;\n }\n\n lastOffset += hint;\n offset += hint;\n }\n else {\n maxOffset = hint + 1;\n while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {\n lastOffset = offset;\n offset = (offset << 1) + 1;\n\n if (offset <= 0) {\n offset = maxOffset;\n }\n }\n if (offset > maxOffset) {\n offset = maxOffset;\n }\n\n var tmp = lastOffset;\n lastOffset = hint - offset;\n offset = hint - tmp;\n }\n\n lastOffset++;\n while (lastOffset < offset) {\n var m = lastOffset + (offset - lastOffset >>> 1);\n\n if (compare(value, array[start + m]) > 0) {\n lastOffset = m + 1;\n }\n else {\n offset = m;\n }\n }\n return offset;\n}\n\nfunction gallopRight(value, array, start, length, hint, compare) {\n var lastOffset = 0;\n var maxOffset = 0;\n var offset = 1;\n\n if (compare(value, array[start + hint]) < 0) {\n maxOffset = hint + 1;\n\n while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {\n lastOffset = offset;\n offset = (offset << 1) + 1;\n\n if (offset <= 0) {\n offset = maxOffset;\n }\n }\n\n if (offset > maxOffset) {\n offset = maxOffset;\n }\n\n var tmp = lastOffset;\n lastOffset = hint - offset;\n offset = hint - tmp;\n }\n else {\n maxOffset = length - hint;\n\n while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {\n lastOffset = offset;\n offset = (offset << 1) + 1;\n\n if (offset <= 0) {\n offset = maxOffset;\n }\n }\n\n if (offset > maxOffset) {\n offset = maxOffset;\n }\n\n lastOffset += hint;\n offset += hint;\n }\n\n lastOffset++;\n\n while (lastOffset < offset) {\n var m = lastOffset + (offset - lastOffset >>> 1);\n\n if (compare(value, array[start + m]) < 0) {\n offset = m;\n }\n else {\n lastOffset = m + 1;\n }\n }\n\n return offset;\n}\n\nfunction TimSort(array, compare) {\n var minGallop = DEFAULT_MIN_GALLOPING;\n var length = 0;\n var tmpStorageLength = DEFAULT_TMP_STORAGE_LENGTH;\n var stackLength = 0;\n var runStart;\n var runLength;\n var stackSize = 0;\n\n length = array.length;\n\n if (length < 2 * DEFAULT_TMP_STORAGE_LENGTH) {\n tmpStorageLength = length >>> 1;\n }\n\n var tmp = [];\n\n stackLength = length < 120 ? 5 : length < 1542 ? 10 : length < 119151 ? 19 : 40;\n\n runStart = [];\n runLength = [];\n\n function pushRun(_runStart, _runLength) {\n runStart[stackSize] = _runStart;\n runLength[stackSize] = _runLength;\n stackSize += 1;\n }\n\n function mergeRuns() {\n while (stackSize > 1) {\n var n = stackSize - 2;\n\n if (\n (n >= 1 && runLength[n - 1] <= runLength[n] + runLength[n + 1])\n || (n >= 2 && runLength[n - 2] <= runLength[n] + runLength[n - 1])\n ) {\n if (runLength[n - 1] < runLength[n + 1]) {\n n--;\n }\n }\n else if (runLength[n] > runLength[n + 1]) {\n break;\n }\n mergeAt(n);\n }\n }\n\n function forceMergeRuns() {\n while (stackSize > 1) {\n var n = stackSize - 2;\n\n if (n > 0 && runLength[n - 1] < runLength[n + 1]) {\n n--;\n }\n\n mergeAt(n);\n }\n }\n\n function mergeAt(i) {\n var start1 = runStart[i];\n var length1 = runLength[i];\n var start2 = runStart[i + 1];\n var length2 = runLength[i + 1];\n\n runLength[i] = length1 + length2;\n\n if (i === stackSize - 3) {\n runStart[i + 1] = runStart[i + 2];\n runLength[i + 1] = runLength[i + 2];\n }\n\n stackSize--;\n\n var k = gallopRight(array[start2], array, start1, length1, 0, compare);\n start1 += k;\n length1 -= k;\n\n if (length1 === 0) {\n return;\n }\n\n length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);\n\n if (length2 === 0) {\n return;\n }\n\n if (length1 <= length2) {\n mergeLow(start1, length1, start2, length2);\n }\n else {\n mergeHigh(start1, length1, start2, length2);\n }\n }\n\n function mergeLow(start1, length1, start2, length2) {\n var i = 0;\n\n for (i = 0; i < length1; i++) {\n tmp[i] = array[start1 + i];\n }\n\n var cursor1 = 0;\n var cursor2 = start2;\n var dest = start1;\n\n array[dest++] = array[cursor2++];\n\n if (--length2 === 0) {\n for (i = 0; i < length1; i++) {\n array[dest + i] = tmp[cursor1 + i];\n }\n return;\n }\n\n if (length1 === 1) {\n for (i = 0; i < length2; i++) {\n array[dest + i] = array[cursor2 + i];\n }\n array[dest + length2] = tmp[cursor1];\n return;\n }\n\n var _minGallop = minGallop;\n var count1;\n var count2;\n var exit;\n\n while (1) {\n count1 = 0;\n count2 = 0;\n exit = false;\n\n do {\n if (compare(array[cursor2], tmp[cursor1]) < 0) {\n array[dest++] = array[cursor2++];\n count2++;\n count1 = 0;\n\n if (--length2 === 0) {\n exit = true;\n break;\n }\n }\n else {\n array[dest++] = tmp[cursor1++];\n count1++;\n count2 = 0;\n if (--length1 === 1) {\n exit = true;\n break;\n }\n }\n } while ((count1 | count2) < _minGallop);\n\n if (exit) {\n break;\n }\n\n do {\n count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);\n\n if (count1 !== 0) {\n for (i = 0; i < count1; i++) {\n array[dest + i] = tmp[cursor1 + i];\n }\n\n dest += count1;\n cursor1 += count1;\n length1 -= count1;\n if (length1 <= 1) {\n exit = true;\n break;\n }\n }\n\n array[dest++] = array[cursor2++];\n\n if (--length2 === 0) {\n exit = true;\n break;\n }\n\n count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);\n\n if (count2 !== 0) {\n for (i = 0; i < count2; i++) {\n array[dest + i] = array[cursor2 + i];\n }\n\n dest += count2;\n cursor2 += count2;\n length2 -= count2;\n\n if (length2 === 0) {\n exit = true;\n break;\n }\n }\n array[dest++] = tmp[cursor1++];\n\n if (--length1 === 1) {\n exit = true;\n break;\n }\n\n _minGallop--;\n } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);\n\n if (exit) {\n break;\n }\n\n if (_minGallop < 0) {\n _minGallop = 0;\n }\n\n _minGallop += 2;\n }\n\n minGallop = _minGallop;\n\n minGallop < 1 && (minGallop = 1);\n\n if (length1 === 1) {\n for (i = 0; i < length2; i++) {\n array[dest + i] = array[cursor2 + i];\n }\n array[dest + length2] = tmp[cursor1];\n }\n else if (length1 === 0) {\n throw new Error();\n // throw new Error('mergeLow preconditions were not respected');\n }\n else {\n for (i = 0; i < length1; i++) {\n array[dest + i] = tmp[cursor1 + i];\n }\n }\n }\n\n function mergeHigh(start1, length1, start2, length2) {\n var i = 0;\n\n for (i = 0; i < length2; i++) {\n tmp[i] = array[start2 + i];\n }\n\n var cursor1 = start1 + length1 - 1;\n var cursor2 = length2 - 1;\n var dest = start2 + length2 - 1;\n var customCursor = 0;\n var customDest = 0;\n\n array[dest--] = array[cursor1--];\n\n if (--length1 === 0) {\n customCursor = dest - (length2 - 1);\n\n for (i = 0; i < length2; i++) {\n array[customCursor + i] = tmp[i];\n }\n\n return;\n }\n\n if (length2 === 1) {\n dest -= length1;\n cursor1 -= length1;\n customDest = dest + 1;\n customCursor = cursor1 + 1;\n\n for (i = length1 - 1; i >= 0; i--) {\n array[customDest + i] = array[customCursor + i];\n }\n\n array[dest] = tmp[cursor2];\n return;\n }\n\n var _minGallop = minGallop;\n\n while (true) {\n var count1 = 0;\n var count2 = 0;\n var exit = false;\n\n do {\n if (compare(tmp[cursor2], array[cursor1]) < 0) {\n array[dest--] = array[cursor1--];\n count1++;\n count2 = 0;\n if (--length1 === 0) {\n exit = true;\n break;\n }\n }\n else {\n array[dest--] = tmp[cursor2--];\n count2++;\n count1 = 0;\n if (--length2 === 1) {\n exit = true;\n break;\n }\n }\n } while ((count1 | count2) < _minGallop);\n\n if (exit) {\n break;\n }\n\n do {\n count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);\n\n if (count1 !== 0) {\n dest -= count1;\n cursor1 -= count1;\n length1 -= count1;\n customDest = dest + 1;\n customCursor = cursor1 + 1;\n\n for (i = count1 - 1; i >= 0; i--) {\n array[customDest + i] = array[customCursor + i];\n }\n\n if (length1 === 0) {\n exit = true;\n break;\n }\n }\n\n array[dest--] = tmp[cursor2--];\n\n if (--length2 === 1) {\n exit = true;\n break;\n }\n\n count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);\n\n if (count2 !== 0) {\n dest -= count2;\n cursor2 -= count2;\n length2 -= count2;\n customDest = dest + 1;\n customCursor = cursor2 + 1;\n\n for (i = 0; i < count2; i++) {\n array[customDest + i] = tmp[customCursor + i];\n }\n\n if (length2 <= 1) {\n exit = true;\n break;\n }\n }\n\n array[dest--] = array[cursor1--];\n\n if (--length1 === 0) {\n exit = true;\n break;\n }\n\n _minGallop--;\n } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);\n\n if (exit) {\n break;\n }\n\n if (_minGallop < 0) {\n _minGallop = 0;\n }\n\n _minGallop += 2;\n }\n\n minGallop = _minGallop;\n\n if (minGallop < 1) {\n minGallop = 1;\n }\n\n if (length2 === 1) {\n dest -= length1;\n cursor1 -= length1;\n customDest = dest + 1;\n customCursor = cursor1 + 1;\n\n for (i = length1 - 1; i >= 0; i--) {\n array[customDest + i] = array[customCursor + i];\n }\n\n array[dest] = tmp[cursor2];\n }\n else if (length2 === 0) {\n throw new Error();\n // throw new Error('mergeHigh preconditions were not respected');\n }\n else {\n customCursor = dest - (length2 - 1);\n for (i = 0; i < length2; i++) {\n array[customCursor + i] = tmp[i];\n }\n }\n }\n\n this.mergeRuns = mergeRuns;\n this.forceMergeRuns = forceMergeRuns;\n this.pushRun = pushRun;\n}\n\nexport default function sort(array, compare, lo, hi) {\n if (!lo) {\n lo = 0;\n }\n if (!hi) {\n hi = array.length;\n }\n\n var remaining = hi - lo;\n\n if (remaining < 2) {\n return;\n }\n\n var runLength = 0;\n\n if (remaining < DEFAULT_MIN_MERGE) {\n runLength = makeAscendingRun(array, lo, hi, compare);\n binaryInsertionSort(array, lo, hi, lo + runLength, compare);\n return;\n }\n\n var ts = new TimSort(array, compare);\n\n var minRun = minRunLength(remaining);\n\n do {\n runLength = makeAscendingRun(array, lo, hi, compare);\n if (runLength < minRun) {\n var force = remaining;\n if (force > minRun) {\n force = minRun;\n }\n\n binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);\n runLength = force;\n }\n\n ts.pushRun(lo, runLength);\n ts.mergeRuns();\n\n remaining -= runLength;\n lo += runLength;\n } while (remaining !== 0);\n\n ts.forceMergeRuns();\n}\n","import * as util from './core/util';\nimport env from './core/env';\nimport Group from './container/Group';\n\n// Use timsort because in most case elements are partially sorted\n// https://jsfiddle.net/pissang/jr4x7mdm/8/\nimport timsort from './core/timsort';\n\nfunction shapeCompareFunc(a, b) {\n if (a.zlevel === b.zlevel) {\n if (a.z === b.z) {\n // if (a.z2 === b.z2) {\n // // FIXME Slow has renderidx compare\n // // http://stackoverflow.com/questions/20883421/sorting-in-javascript-should-every-compare-function-have-a-return-0-statement\n // // https://github.com/v8/v8/blob/47cce544a31ed5577ffe2963f67acb4144ee0232/src/js/array.js#L1012\n // return a.__renderidx - b.__renderidx;\n // }\n return a.z2 - b.z2;\n }\n return a.z - b.z;\n }\n return a.zlevel - b.zlevel;\n}\n/**\n * 内容仓库 (M)\n * @alias module:zrender/Storage\n * @constructor\n */\nvar Storage = function () { // jshint ignore:line\n this._roots = [];\n\n this._displayList = [];\n\n this._displayListLen = 0;\n};\n\nStorage.prototype = {\n\n constructor: Storage,\n\n /**\n * @param {Function} cb\n *\n */\n traverse: function (cb, context) {\n for (var i = 0; i < this._roots.length; i++) {\n this._roots[i].traverse(cb, context);\n }\n },\n\n /**\n * 返回所有图形的绘制队列\n * @param {boolean} [update=false] 是否在返回前更新该数组\n * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组, 在 update 为 true 的时候有效\n *\n * 详见{@link module:zrender/graphic/Displayable.prototype.updateDisplayList}\n * @return {Array.<module:zrender/graphic/Displayable>}\n */\n getDisplayList: function (update, includeIgnore) {\n includeIgnore = includeIgnore || false;\n if (update) {\n this.updateDisplayList(includeIgnore);\n }\n return this._displayList;\n },\n\n /**\n * 更新图形的绘制队列。\n * 每次绘制前都会调用,该方法会先深度优先遍历整个树,更新所有Group和Shape的变换并且把所有可见的Shape保存到数组中,\n * 最后根据绘制的优先级(zlevel > z > 插入顺序)排序得到绘制队列\n * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组\n */\n updateDisplayList: function (includeIgnore) {\n this._displayListLen = 0;\n\n var roots = this._roots;\n var displayList = this._displayList;\n for (var i = 0, len = roots.length; i < len; i++) {\n this._updateAndAddDisplayable(roots[i], null, includeIgnore);\n }\n\n displayList.length = this._displayListLen;\n\n env.canvasSupported && timsort(displayList, shapeCompareFunc);\n },\n\n _updateAndAddDisplayable: function (el, clipPaths, includeIgnore) {\n\n if (el.ignore && !includeIgnore) {\n return;\n }\n\n el.beforeUpdate();\n\n if (el.__dirty) {\n\n el.update();\n\n }\n\n el.afterUpdate();\n\n var userSetClipPath = el.clipPath;\n if (userSetClipPath) {\n\n // FIXME 效率影响\n if (clipPaths) {\n clipPaths = clipPaths.slice();\n }\n else {\n clipPaths = [];\n }\n\n var currentClipPath = userSetClipPath;\n var parentClipPath = el;\n // Recursively add clip path\n while (currentClipPath) {\n // clipPath 的变换是基于使用这个 clipPath 的元素\n currentClipPath.parent = parentClipPath;\n currentClipPath.updateTransform();\n\n clipPaths.push(currentClipPath);\n\n parentClipPath = currentClipPath;\n currentClipPath = currentClipPath.clipPath;\n }\n }\n\n if (el.isGroup) {\n var children = el._children;\n\n for (var i = 0; i < children.length; i++) {\n var child = children[i];\n\n // Force to mark as dirty if group is dirty\n // FIXME __dirtyPath ?\n if (el.__dirty) {\n child.__dirty = true;\n }\n\n this._updateAndAddDisplayable(child, clipPaths, includeIgnore);\n }\n\n // Mark group clean here\n el.__dirty = false;\n\n }\n else {\n el.__clipPaths = clipPaths;\n\n this._displayList[this._displayListLen++] = el;\n }\n },\n\n /**\n * 添加图形(Shape)或者组(Group)到根节点\n * @param {module:zrender/Element} el\n */\n addRoot: function (el) {\n if (el.__storage === this) {\n return;\n }\n\n if (el instanceof Group) {\n el.addChildrenToStorage(this);\n }\n\n this.addToStorage(el);\n this._roots.push(el);\n },\n\n /**\n * 删除指定的图形(Shape)或者组(Group)\n * @param {string|Array.<string>} [el] 如果为空清空整个Storage\n */\n delRoot: function (el) {\n if (el == null) {\n // 不指定el清空\n for (var i = 0; i < this._roots.length; i++) {\n var root = this._roots[i];\n if (root instanceof Group) {\n root.delChildrenFromStorage(this);\n }\n }\n\n this._roots = [];\n this._displayList = [];\n this._displayListLen = 0;\n\n return;\n }\n\n if (el instanceof Array) {\n for (var i = 0, l = el.length; i < l; i++) {\n this.delRoot(el[i]);\n }\n return;\n }\n\n\n var idx = util.indexOf(this._roots, el);\n if (idx >= 0) {\n this.delFromStorage(el);\n this._roots.splice(idx, 1);\n if (el instanceof Group) {\n el.delChildrenFromStorage(this);\n }\n }\n },\n\n addToStorage: function (el) {\n if (el) {\n el.__storage = this;\n el.dirty(false);\n }\n return this;\n },\n\n delFromStorage: function (el) {\n if (el) {\n el.__storage = null;\n }\n\n return this;\n },\n\n /**\n * 清空并且释放Storage\n */\n dispose: function () {\n this._renderList =\n this._roots = null;\n },\n\n displayableSortFunc: shapeCompareFunc\n};\n\nexport default Storage;","\nvar SHADOW_PROPS = {\n 'shadowBlur': 1,\n 'shadowOffsetX': 1,\n 'shadowOffsetY': 1,\n 'textShadowBlur': 1,\n 'textShadowOffsetX': 1,\n 'textShadowOffsetY': 1,\n 'textBoxShadowBlur': 1,\n 'textBoxShadowOffsetX': 1,\n 'textBoxShadowOffsetY': 1\n};\n\nexport default function (ctx, propName, value) {\n if (SHADOW_PROPS.hasOwnProperty(propName)) {\n return value *= ctx.dpr;\n }\n return value;\n}\n","\nexport var ContextCachedBy = {\n NONE: 0,\n STYLE_BIND: 1,\n PLAIN_TEXT: 2\n};\n\n// Avoid confused with 0/false.\nexport var WILL_BE_RESTORED = 9;\n","\nimport fixShadow from './helper/fixShadow';\nimport {ContextCachedBy} from './constant';\n\nvar STYLE_COMMON_PROPS = [\n ['shadowBlur', 0], ['shadowOffsetX', 0], ['shadowOffsetY', 0], ['shadowColor', '#000'],\n ['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]\n];\n\n// var SHADOW_PROPS = STYLE_COMMON_PROPS.slice(0, 4);\n// var LINE_PROPS = STYLE_COMMON_PROPS.slice(4);\n\nvar Style = function (opts) {\n this.extendFrom(opts, false);\n};\n\nfunction createLinearGradient(ctx, obj, rect) {\n var x = obj.x == null ? 0 : obj.x;\n var x2 = obj.x2 == null ? 1 : obj.x2;\n var y = obj.y == null ? 0 : obj.y;\n var y2 = obj.y2 == null ? 0 : obj.y2;\n\n if (!obj.global) {\n x = x * rect.width + rect.x;\n x2 = x2 * rect.width + rect.x;\n y = y * rect.height + rect.y;\n y2 = y2 * rect.height + rect.y;\n }\n\n // Fix NaN when rect is Infinity\n x = isNaN(x) ? 0 : x;\n x2 = isNaN(x2) ? 1 : x2;\n y = isNaN(y) ? 0 : y;\n y2 = isNaN(y2) ? 0 : y2;\n\n var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);\n\n return canvasGradient;\n}\n\nfunction createRadialGradient(ctx, obj, rect) {\n var width = rect.width;\n var height = rect.height;\n var min = Math.min(width, height);\n\n var x = obj.x == null ? 0.5 : obj.x;\n var y = obj.y == null ? 0.5 : obj.y;\n var r = obj.r == null ? 0.5 : obj.r;\n if (!obj.global) {\n x = x * width + rect.x;\n y = y * height + rect.y;\n r = r * min;\n }\n\n var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);\n\n return canvasGradient;\n}\n\n\nStyle.prototype = {\n\n constructor: Style,\n\n /**\n * @type {string}\n */\n fill: '#000',\n\n /**\n * @type {string}\n */\n stroke: null,\n\n /**\n * @type {number}\n */\n opacity: 1,\n\n /**\n * @type {number}\n */\n fillOpacity: null,\n\n /**\n * @type {number}\n */\n strokeOpacity: null,\n\n /**\n * `true` is not supported.\n * `false`/`null`/`undefined` are the same.\n * `false` is used to remove lineDash in some\n * case that `null`/`undefined` can not be set.\n * (e.g., emphasis.lineStyle in echarts)\n * @type {Array.<number>|boolean}\n */\n lineDash: null,\n\n /**\n * @type {number}\n */\n lineDashOffset: 0,\n\n /**\n * @type {number}\n */\n shadowBlur: 0,\n\n /**\n * @type {number}\n */\n shadowOffsetX: 0,\n\n /**\n * @type {number}\n */\n shadowOffsetY: 0,\n\n /**\n * @type {number}\n */\n lineWidth: 1,\n\n /**\n * If stroke ignore scale\n * @type {Boolean}\n */\n strokeNoScale: false,\n\n // Bounding rect text configuration\n // Not affected by element transform\n /**\n * @type {string}\n */\n text: null,\n\n /**\n * If `fontSize` or `fontFamily` exists, `font` will be reset by\n * `fontSize`, `fontStyle`, `fontWeight`, `fontFamily`.\n * So do not visit it directly in upper application (like echarts),\n * but use `contain/text#makeFont` instead.\n * @type {string}\n */\n font: null,\n\n /**\n * The same as font. Use font please.\n * @deprecated\n * @type {string}\n */\n textFont: null,\n\n /**\n * It helps merging respectively, rather than parsing an entire font string.\n * @type {string}\n */\n fontStyle: null,\n\n /**\n * It helps merging respectively, rather than parsing an entire font string.\n * @type {string}\n */\n fontWeight: null,\n\n /**\n * It helps merging respectively, rather than parsing an entire font string.\n * Should be 12 but not '12px'.\n * @type {number}\n */\n fontSize: null,\n\n /**\n * It helps merging respectively, rather than parsing an entire font string.\n * @type {string}\n */\n fontFamily: null,\n\n /**\n * Reserved for special functinality, like 'hr'.\n * @type {string}\n */\n textTag: null,\n\n /**\n * @type {string}\n */\n textFill: '#000',\n\n /**\n * @type {string}\n */\n textStroke: null,\n\n /**\n * @type {number}\n */\n textWidth: null,\n\n /**\n * Only for textBackground.\n * @type {number}\n */\n textHeight: null,\n\n /**\n * textStroke may be set as some color as a default\n * value in upper applicaion, where the default value\n * of textStrokeWidth should be 0 to make sure that\n * user can choose to do not use text stroke.\n * @type {number}\n */\n textStrokeWidth: 0,\n\n /**\n * @type {number}\n */\n textLineHeight: null,\n\n /**\n * 'inside', 'left', 'right', 'top', 'bottom'\n * [x, y]\n * Based on x, y of rect.\n * @type {string|Array.<number>}\n * @default 'inside'\n */\n textPosition: 'inside',\n\n /**\n * If not specified, use the boundingRect of a `displayable`.\n * @type {Object}\n */\n textRect: null,\n\n /**\n * [x, y]\n * @type {Array.<number>}\n */\n textOffset: null,\n\n /**\n * @type {string}\n */\n textAlign: null,\n\n /**\n * @type {string}\n */\n textVerticalAlign: null,\n\n /**\n * @type {number}\n */\n textDistance: 5,\n\n /**\n * @type {string}\n */\n textShadowColor: 'transparent',\n\n /**\n * @type {number}\n */\n textShadowBlur: 0,\n\n /**\n * @type {number}\n */\n textShadowOffsetX: 0,\n\n /**\n * @type {number}\n */\n textShadowOffsetY: 0,\n\n /**\n * @type {string}\n */\n textBoxShadowColor: 'transparent',\n\n /**\n * @type {number}\n */\n textBoxShadowBlur: 0,\n\n /**\n * @type {number}\n */\n textBoxShadowOffsetX: 0,\n\n /**\n * @type {number}\n */\n textBoxShadowOffsetY: 0,\n\n /**\n * Whether transform text.\n * Only available in Path and Image element,\n * where the text is called as `RectText`.\n * @type {boolean}\n */\n transformText: false,\n\n /**\n * Text rotate around position of Path or Image.\n * The origin of the rotation can be specified by `textOrigin`.\n * Only available in Path and Image element,\n * where the text is called as `RectText`.\n */\n textRotation: 0,\n\n /**\n * Text origin of text rotation.\n * Useful in the case like label rotation of circular symbol.\n * Only available in Path and Image element, where the text is called\n * as `RectText` and the element is called as \"host element\".\n * The value can be:\n * + If specified as a coordinate like `[10, 40]`, it is the `[x, y]`\n * base on the left-top corner of the rect of its host element.\n * + If specified as a string `center`, it is the center of the rect of\n * its host element.\n * + By default, this origin is the `textPosition`.\n * @type {string|Array.<number>}\n */\n textOrigin: null,\n\n /**\n * @type {string}\n */\n textBackgroundColor: null,\n\n /**\n * @type {string}\n */\n textBorderColor: null,\n\n /**\n * @type {number}\n */\n textBorderWidth: 0,\n\n /**\n * @type {number}\n */\n textBorderRadius: 0,\n\n /**\n * Can be `2` or `[2, 4]` or `[2, 3, 4, 5]`\n * @type {number|Array.<number>}\n */\n textPadding: null,\n\n /**\n * Text styles for rich text.\n * @type {Object}\n */\n rich: null,\n\n /**\n * {outerWidth, outerHeight, ellipsis, placeholder}\n * @type {Object}\n */\n truncate: null,\n\n /**\n * https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation\n * @type {string}\n */\n blend: null,\n\n /**\n * @param {CanvasRenderingContext2D} ctx\n */\n bind: function (ctx, el, prevEl) {\n var style = this;\n var prevStyle = prevEl && prevEl.style;\n // If no prevStyle, it means first draw.\n // Only apply cache if the last time cachced by this function.\n var notCheckCache = !prevStyle || ctx.__attrCachedBy !== ContextCachedBy.STYLE_BIND;\n\n ctx.__attrCachedBy = ContextCachedBy.STYLE_BIND;\n\n for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {\n var prop = STYLE_COMMON_PROPS[i];\n var styleName = prop[0];\n\n if (notCheckCache || style[styleName] !== prevStyle[styleName]) {\n // FIXME Invalid property value will cause style leak from previous element.\n ctx[styleName] =\n fixShadow(ctx, styleName, style[styleName] || prop[1]);\n }\n }\n\n if ((notCheckCache || style.fill !== prevStyle.fill)) {\n ctx.fillStyle = style.fill;\n }\n if ((notCheckCache || style.stroke !== prevStyle.stroke)) {\n ctx.strokeStyle = style.stroke;\n }\n if ((notCheckCache || style.opacity !== prevStyle.opacity)) {\n ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;\n }\n\n if ((notCheckCache || style.blend !== prevStyle.blend)) {\n ctx.globalCompositeOperation = style.blend || 'source-over';\n }\n if (this.hasStroke()) {\n var lineWidth = style.lineWidth;\n ctx.lineWidth = lineWidth / (\n (this.strokeNoScale && el && el.getLineScale) ? el.getLineScale() : 1\n );\n }\n },\n\n hasFill: function () {\n var fill = this.fill;\n return fill != null && fill !== 'none';\n },\n\n hasStroke: function () {\n var stroke = this.stroke;\n return stroke != null && stroke !== 'none' && this.lineWidth > 0;\n },\n\n /**\n * Extend from other style\n * @param {zrender/graphic/Style} otherStyle\n * @param {boolean} overwrite true: overwrirte any way.\n * false: overwrite only when !target.hasOwnProperty\n * others: overwrite when property is not null/undefined.\n */\n extendFrom: function (otherStyle, overwrite) {\n if (otherStyle) {\n for (var name in otherStyle) {\n if (otherStyle.hasOwnProperty(name)\n && (overwrite === true\n || (\n overwrite === false\n ? !this.hasOwnProperty(name)\n : otherStyle[name] != null\n )\n )\n ) {\n this[name] = otherStyle[name];\n }\n }\n }\n },\n\n /**\n * Batch setting style with a given object\n * @param {Object|string} obj\n * @param {*} [obj]\n */\n set: function (obj, value) {\n if (typeof obj === 'string') {\n this[obj] = value;\n }\n else {\n this.extendFrom(obj, true);\n }\n },\n\n /**\n * Clone\n * @return {zrender/graphic/Style} [description]\n */\n clone: function () {\n var newStyle = new this.constructor();\n newStyle.extendFrom(this, true);\n return newStyle;\n },\n\n getGradient: function (ctx, obj, rect) {\n var method = obj.type === 'radial' ? createRadialGradient : createLinearGradient;\n var canvasGradient = method(ctx, obj, rect);\n var colorStops = obj.colorStops;\n for (var i = 0; i < colorStops.length; i++) {\n canvasGradient.addColorStop(\n colorStops[i].offset, colorStops[i].color\n );\n }\n return canvasGradient;\n }\n\n};\n\nvar styleProto = Style.prototype;\nfor (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {\n var prop = STYLE_COMMON_PROPS[i];\n if (!(prop[0] in styleProto)) {\n styleProto[prop[0]] = prop[1];\n }\n}\n\n// Provide for others\nStyle.getGradient = styleProto.getGradient;\n\nexport default Style;","\nvar Pattern = function (image, repeat) {\n // Should do nothing more in this constructor. Because gradient can be\n // declard by `color: {image: ...}`, where this constructor will not be called.\n\n this.image = image;\n this.repeat = repeat;\n\n // Can be cloned\n this.type = 'pattern';\n};\n\nPattern.prototype.getCanvasPattern = function (ctx) {\n return ctx.createPattern(this.image, this.repeat || 'repeat');\n};\n\nexport default Pattern;","/**\n * @module zrender/Layer\n * @author pissang(https://www.github.com/pissang)\n */\n\nimport * as util from './core/util';\nimport {devicePixelRatio} from './config';\nimport Style from './graphic/Style';\nimport Pattern from './graphic/Pattern';\n\nfunction returnFalse() {\n return false;\n}\n\n/**\n * 创建dom\n *\n * @inner\n * @param {string} id dom id 待用\n * @param {Painter} painter painter instance\n * @param {number} number\n */\nfunction createDom(id, painter, dpr) {\n var newDom = util.createCanvas();\n var width = painter.getWidth();\n var height = painter.getHeight();\n\n var newDomStyle = newDom.style;\n if (newDomStyle) { // In node or some other non-browser environment\n newDomStyle.position = 'absolute';\n newDomStyle.left = 0;\n newDomStyle.top = 0;\n newDomStyle.width = width + 'px';\n newDomStyle.height = height + 'px';\n\n newDom.setAttribute('data-zr-dom-id', id);\n }\n\n newDom.width = width * dpr;\n newDom.height = height * dpr;\n\n return newDom;\n}\n\n/**\n * @alias module:zrender/Layer\n * @constructor\n * @extends module:zrender/mixin/Transformable\n * @param {string} id\n * @param {module:zrender/Painter} painter\n * @param {number} [dpr]\n */\nvar Layer = function (id, painter, dpr) {\n var dom;\n dpr = dpr || devicePixelRatio;\n if (typeof id === 'string') {\n dom = createDom(id, painter, dpr);\n }\n // Not using isDom because in node it will return false\n else if (util.isObject(id)) {\n dom = id;\n id = dom.id;\n }\n this.id = id;\n this.dom = dom;\n\n var domStyle = dom.style;\n if (domStyle) { // Not in node\n dom.onselectstart = returnFalse; // 避免页面选中的尴尬\n domStyle['-webkit-user-select'] = 'none';\n domStyle['user-select'] = 'none';\n domStyle['-webkit-touch-callout'] = 'none';\n domStyle['-webkit-tap-highlight-color'] = 'rgba(0,0,0,0)';\n domStyle['padding'] = 0; // eslint-disable-line dot-notation\n domStyle['margin'] = 0; // eslint-disable-line dot-notation\n domStyle['border-width'] = 0;\n }\n\n this.domBack = null;\n this.ctxBack = null;\n\n this.painter = painter;\n\n this.config = null;\n\n // Configs\n /**\n * 每次清空画布的颜色\n * @type {string}\n * @default 0\n */\n this.clearColor = 0;\n /**\n * 是否开启动态模糊\n * @type {boolean}\n * @default false\n */\n this.motionBlur = false;\n /**\n * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显\n * @type {number}\n * @default 0.7\n */\n this.lastFrameAlpha = 0.7;\n\n /**\n * Layer dpr\n * @type {number}\n */\n this.dpr = dpr;\n};\n\nLayer.prototype = {\n\n constructor: Layer,\n\n __dirty: true,\n\n __used: false,\n\n __drawIndex: 0,\n __startIndex: 0,\n __endIndex: 0,\n\n incremental: false,\n\n getElementCount: function () {\n return this.__endIndex - this.__startIndex;\n },\n\n initContext: function () {\n this.ctx = this.dom.getContext('2d');\n this.ctx.dpr = this.dpr;\n },\n\n createBackBuffer: function () {\n var dpr = this.dpr;\n\n this.domBack = createDom('back-' + this.id, this.painter, dpr);\n this.ctxBack = this.domBack.getContext('2d');\n\n if (dpr !== 1) {\n this.ctxBack.scale(dpr, dpr);\n }\n },\n\n /**\n * @param {number} width\n * @param {number} height\n */\n resize: function (width, height) {\n var dpr = this.dpr;\n\n var dom = this.dom;\n var domStyle = dom.style;\n var domBack = this.domBack;\n\n if (domStyle) {\n domStyle.width = width + 'px';\n domStyle.height = height + 'px';\n }\n\n dom.width = width * dpr;\n dom.height = height * dpr;\n\n if (domBack) {\n domBack.width = width * dpr;\n domBack.height = height * dpr;\n\n if (dpr !== 1) {\n this.ctxBack.scale(dpr, dpr);\n }\n }\n },\n\n /**\n * 清空该层画布\n * @param {boolean} [clearAll]=false Clear all with out motion blur\n * @param {Color} [clearColor]\n */\n clear: function (clearAll, clearColor) {\n var dom = this.dom;\n var ctx = this.ctx;\n var width = dom.width;\n var height = dom.height;\n\n var clearColor = clearColor || this.clearColor;\n var haveMotionBLur = this.motionBlur && !clearAll;\n var lastFrameAlpha = this.lastFrameAlpha;\n\n var dpr = this.dpr;\n\n if (haveMotionBLur) {\n if (!this.domBack) {\n this.createBackBuffer();\n }\n\n this.ctxBack.globalCompositeOperation = 'copy';\n this.ctxBack.drawImage(\n dom, 0, 0,\n width / dpr,\n height / dpr\n );\n }\n\n ctx.clearRect(0, 0, width, height);\n if (clearColor && clearColor !== 'transparent') {\n var clearColorGradientOrPattern;\n // Gradient\n if (clearColor.colorStops) {\n // Cache canvas gradient\n clearColorGradientOrPattern = clearColor.__canvasGradient || Style.getGradient(ctx, clearColor, {\n x: 0,\n y: 0,\n width: width,\n height: height\n });\n\n clearColor.__canvasGradient = clearColorGradientOrPattern;\n }\n // Pattern\n else if (clearColor.image) {\n clearColorGradientOrPattern = Pattern.prototype.getCanvasPattern.call(clearColor, ctx);\n }\n ctx.save();\n ctx.fillStyle = clearColorGradientOrPattern || clearColor;\n ctx.fillRect(0, 0, width, height);\n ctx.restore();\n }\n\n if (haveMotionBLur) {\n var domBack = this.domBack;\n ctx.save();\n ctx.globalAlpha = lastFrameAlpha;\n ctx.drawImage(domBack, 0, 0, width, height);\n ctx.restore();\n }\n }\n};\n\nexport default Layer;","\nexport default (\n typeof window !== 'undefined'\n && (\n (window.requestAnimationFrame && window.requestAnimationFrame.bind(window))\n // https://github.com/ecomfe/zrender/issues/189#issuecomment-224919809\n || (window.msRequestAnimationFrame && window.msRequestAnimationFrame.bind(window))\n || window.mozRequestAnimationFrame\n || window.webkitRequestAnimationFrame\n )\n) || function (func) {\n setTimeout(func, 16);\n};","\nimport LRU from '../../core/LRU';\n\nvar globalImageCache = new LRU(50);\n\n/**\n * @param {string|HTMLImageElement|HTMLCanvasElement|Canvas} newImageOrSrc\n * @return {HTMLImageElement|HTMLCanvasElement|Canvas} image\n */\nexport function findExistImage(newImageOrSrc) {\n if (typeof newImageOrSrc === 'string') {\n var cachedImgObj = globalImageCache.get(newImageOrSrc);\n return cachedImgObj && cachedImgObj.image;\n }\n else {\n return newImageOrSrc;\n }\n}\n\n/**\n * Caution: User should cache loaded images, but not just count on LRU.\n * Consider if required images more than LRU size, will dead loop occur?\n *\n * @param {string|HTMLImageElement|HTMLCanvasElement|Canvas} newImageOrSrc\n * @param {HTMLImageElement|HTMLCanvasElement|Canvas} image Existent image.\n * @param {module:zrender/Element} [hostEl] For calling `dirty`.\n * @param {Function} [cb] params: (image, cbPayload)\n * @param {Object} [cbPayload] Payload on cb calling.\n * @return {HTMLImageElement|HTMLCanvasElement|Canvas} image\n */\nexport function createOrUpdateImage(newImageOrSrc, image, hostEl, cb, cbPayload) {\n if (!newImageOrSrc) {\n return image;\n }\n else if (typeof newImageOrSrc === 'string') {\n\n // Image should not be loaded repeatly.\n if ((image && image.__zrImageSrc === newImageOrSrc) || !hostEl) {\n return image;\n }\n\n // Only when there is no existent image or existent image src\n // is different, this method is responsible for load.\n var cachedImgObj = globalImageCache.get(newImageOrSrc);\n\n var pendingWrap = {hostEl: hostEl, cb: cb, cbPayload: cbPayload};\n\n if (cachedImgObj) {\n image = cachedImgObj.image;\n !isImageReady(image) && cachedImgObj.pending.push(pendingWrap);\n }\n else {\n image = new Image();\n image.onload = image.onerror = imageOnLoad;\n\n globalImageCache.put(\n newImageOrSrc,\n image.__cachedImgObj = {\n image: image,\n pending: [pendingWrap]\n }\n );\n\n image.src = image.__zrImageSrc = newImageOrSrc;\n }\n\n return image;\n }\n // newImageOrSrc is an HTMLImageElement or HTMLCanvasElement or Canvas\n else {\n return newImageOrSrc;\n }\n}\n\nfunction imageOnLoad() {\n var cachedImgObj = this.__cachedImgObj;\n this.onload = this.onerror = this.__cachedImgObj = null;\n\n for (var i = 0; i < cachedImgObj.pending.length; i++) {\n var pendingWrap = cachedImgObj.pending[i];\n var cb = pendingWrap.cb;\n cb && cb(this, pendingWrap.cbPayload);\n pendingWrap.hostEl.dirty();\n }\n cachedImgObj.pending.length = 0;\n}\n\nexport function isImageReady(image) {\n return image && image.width && image.height;\n}\n\n","import BoundingRect from '../core/BoundingRect';\nimport * as imageHelper from '../graphic/helper/image';\nimport {\n getContext,\n extend,\n retrieve2,\n retrieve3,\n trim\n} from '../core/util';\n\nvar textWidthCache = {};\nvar textWidthCacheCounter = 0;\n\nvar TEXT_CACHE_MAX = 5000;\nvar STYLE_REG = /\\{([a-zA-Z0-9_]+)\\|([^}]*)\\}/g;\n\nexport var DEFAULT_FONT = '12px sans-serif';\n\n// Avoid assign to an exported variable, for transforming to cjs.\nvar methods = {};\n\nexport function $override(name, fn) {\n methods[name] = fn;\n}\n\n/**\n * @public\n * @param {string} text\n * @param {string} font\n * @return {number} width\n */\nexport function getWidth(text, font) {\n font = font || DEFAULT_FONT;\n var key = text + ':' + font;\n if (textWidthCache[key]) {\n return textWidthCache[key];\n }\n\n var textLines = (text + '').split('\\n');\n var width = 0;\n\n for (var i = 0, l = textLines.length; i < l; i++) {\n // textContain.measureText may be overrided in SVG or VML\n width = Math.max(measureText(textLines[i], font).width, width);\n }\n\n if (textWidthCacheCounter > TEXT_CACHE_MAX) {\n textWidthCacheCounter = 0;\n textWidthCache = {};\n }\n textWidthCacheCounter++;\n textWidthCache[key] = width;\n\n return width;\n}\n\n/**\n * @public\n * @param {string} text\n * @param {string} font\n * @param {string} [textAlign='left']\n * @param {string} [textVerticalAlign='top']\n * @param {Array.<number>} [textPadding]\n * @param {Object} [rich]\n * @param {Object} [truncate]\n * @return {Object} {x, y, width, height, lineHeight}\n */\nexport function getBoundingRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate) {\n return rich\n ? getRichTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate)\n : getPlainTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, truncate);\n}\n\nfunction getPlainTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, truncate) {\n var contentBlock = parsePlainText(text, font, textPadding, textLineHeight, truncate);\n var outerWidth = getWidth(text, font);\n if (textPadding) {\n outerWidth += textPadding[1] + textPadding[3];\n }\n var outerHeight = contentBlock.outerHeight;\n\n var x = adjustTextX(0, outerWidth, textAlign);\n var y = adjustTextY(0, outerHeight, textVerticalAlign);\n\n var rect = new BoundingRect(x, y, outerWidth, outerHeight);\n rect.lineHeight = contentBlock.lineHeight;\n\n return rect;\n}\n\nfunction getRichTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate) {\n var contentBlock = parseRichText(text, {\n rich: rich,\n truncate: truncate,\n font: font,\n textAlign: textAlign,\n textPadding: textPadding,\n textLineHeight: textLineHeight\n });\n var outerWidth = contentBlock.outerWidth;\n var outerHeight = contentBlock.outerHeight;\n\n var x = adjustTextX(0, outerWidth, textAlign);\n var y = adjustTextY(0, outerHeight, textVerticalAlign);\n\n return new BoundingRect(x, y, outerWidth, outerHeight);\n}\n\n/**\n * @public\n * @param {number} x\n * @param {number} width\n * @param {string} [textAlign='left']\n * @return {number} Adjusted x.\n */\nexport function adjustTextX(x, width, textAlign) {\n // FIXME Right to left language\n if (textAlign === 'right') {\n x -= width;\n }\n else if (textAlign === 'center') {\n x -= width / 2;\n }\n return x;\n}\n\n/**\n * @public\n * @param {number} y\n * @param {number} height\n * @param {string} [textVerticalAlign='top']\n * @return {number} Adjusted y.\n */\nexport function adjustTextY(y, height, textVerticalAlign) {\n if (textVerticalAlign === 'middle') {\n y -= height / 2;\n }\n else if (textVerticalAlign === 'bottom') {\n y -= height;\n }\n return y;\n}\n\n/**\n * Follow same interface to `Displayable.prototype.calculateTextPosition`.\n * @public\n * @param {Obejct} [out] Prepared out object. If not input, auto created in the method.\n * @param {module:zrender/graphic/Style} style where `textPosition` and `textDistance` are visited.\n * @param {Object} rect {x, y, width, height} Rect of the host elment, according to which the text positioned.\n * @return {Object} The input `out`. Set: {x, y, textAlign, textVerticalAlign}\n */\nexport function calculateTextPosition(out, style, rect) {\n var textPosition = style.textPosition;\n var distance = style.textDistance;\n\n var x = rect.x;\n var y = rect.y;\n distance = distance || 0;\n\n var height = rect.height;\n var width = rect.width;\n var halfHeight = height / 2;\n\n var textAlign = 'left';\n var textVerticalAlign = 'top';\n\n switch (textPosition) {\n case 'left':\n x -= distance;\n y += halfHeight;\n textAlign = 'right';\n textVerticalAlign = 'middle';\n break;\n case 'right':\n x += distance + width;\n y += halfHeight;\n textVerticalAlign = 'middle';\n break;\n case 'top':\n x += width / 2;\n y -= distance;\n textAlign = 'center';\n textVerticalAlign = 'bottom';\n break;\n case 'bottom':\n x += width / 2;\n y += height + distance;\n textAlign = 'center';\n break;\n case 'inside':\n x += width / 2;\n y += halfHeight;\n textAlign = 'center';\n textVerticalAlign = 'middle';\n break;\n case 'insideLeft':\n x += distance;\n y += halfHeight;\n textVerticalAlign = 'middle';\n break;\n case 'insideRight':\n x += width - distance;\n y += halfHeight;\n textAlign = 'right';\n textVerticalAlign = 'middle';\n break;\n case 'insideTop':\n x += width / 2;\n y += distance;\n textAlign = 'center';\n break;\n case 'insideBottom':\n x += width / 2;\n y += height - distance;\n textAlign = 'center';\n textVerticalAlign = 'bottom';\n break;\n case 'insideTopLeft':\n x += distance;\n y += distance;\n break;\n case 'insideTopRight':\n x += width - distance;\n y += distance;\n textAlign = 'right';\n break;\n case 'insideBottomLeft':\n x += distance;\n y += height - distance;\n textVerticalAlign = 'bottom';\n break;\n case 'insideBottomRight':\n x += width - distance;\n y += height - distance;\n textAlign = 'right';\n textVerticalAlign = 'bottom';\n break;\n }\n\n out = out || {};\n out.x = x;\n out.y = y;\n out.textAlign = textAlign;\n out.textVerticalAlign = textVerticalAlign;\n\n return out;\n}\n\n/**\n * To be removed. But still do not remove in case that some one has imported it.\n * @deprecated\n * @public\n * @param {stirng} textPosition\n * @param {Object} rect {x, y, width, height}\n * @param {number} distance\n * @return {Object} {x, y, textAlign, textVerticalAlign}\n */\nexport function adjustTextPositionOnRect(textPosition, rect, distance) {\n var dummyStyle = {textPosition: textPosition, textDistance: distance};\n return calculateTextPosition({}, dummyStyle, rect);\n}\n\n/**\n * Show ellipsis if overflow.\n *\n * @public\n * @param {string} text\n * @param {string} containerWidth\n * @param {string} font\n * @param {number} [ellipsis='...']\n * @param {Object} [options]\n * @param {number} [options.maxIterations=3]\n * @param {number} [options.minChar=0] If truncate result are less\n * then minChar, ellipsis will not show, which is\n * better for user hint in some cases.\n * @param {number} [options.placeholder=''] When all truncated, use the placeholder.\n * @return {string}\n */\nexport function truncateText(text, containerWidth, font, ellipsis, options) {\n if (!containerWidth) {\n return '';\n }\n\n var textLines = (text + '').split('\\n');\n options = prepareTruncateOptions(containerWidth, font, ellipsis, options);\n\n // FIXME\n // It is not appropriate that every line has '...' when truncate multiple lines.\n for (var i = 0, len = textLines.length; i < len; i++) {\n textLines[i] = truncateSingleLine(textLines[i], options);\n }\n\n return textLines.join('\\n');\n}\n\nfunction prepareTruncateOptions(containerWidth, font, ellipsis, options) {\n options = extend({}, options);\n\n options.font = font;\n var ellipsis = retrieve2(ellipsis, '...');\n options.maxIterations = retrieve2(options.maxIterations, 2);\n var minChar = options.minChar = retrieve2(options.minChar, 0);\n // FIXME\n // Other languages?\n options.cnCharWidth = getWidth('国', font);\n // FIXME\n // Consider proportional font?\n var ascCharWidth = options.ascCharWidth = getWidth('a', font);\n options.placeholder = retrieve2(options.placeholder, '');\n\n // Example 1: minChar: 3, text: 'asdfzxcv', truncate result: 'asdf', but not: 'a...'.\n // Example 2: minChar: 3, text: '维度', truncate result: '维', but not: '...'.\n var contentWidth = containerWidth = Math.max(0, containerWidth - 1); // Reserve some gap.\n for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {\n contentWidth -= ascCharWidth;\n }\n\n var ellipsisWidth = getWidth(ellipsis, font);\n if (ellipsisWidth > contentWidth) {\n ellipsis = '';\n ellipsisWidth = 0;\n }\n\n contentWidth = containerWidth - ellipsisWidth;\n\n options.ellipsis = ellipsis;\n options.ellipsisWidth = ellipsisWidth;\n options.contentWidth = contentWidth;\n options.containerWidth = containerWidth;\n\n return options;\n}\n\nfunction truncateSingleLine(textLine, options) {\n var containerWidth = options.containerWidth;\n var font = options.font;\n var contentWidth = options.contentWidth;\n\n if (!containerWidth) {\n return '';\n }\n\n var lineWidth = getWidth(textLine, font);\n\n if (lineWidth <= containerWidth) {\n return textLine;\n }\n\n for (var j = 0; ; j++) {\n if (lineWidth <= contentWidth || j >= options.maxIterations) {\n textLine += options.ellipsis;\n break;\n }\n\n var subLength = j === 0\n ? estimateLength(textLine, contentWidth, options.ascCharWidth, options.cnCharWidth)\n : lineWidth > 0\n ? Math.floor(textLine.length * contentWidth / lineWidth)\n : 0;\n\n textLine = textLine.substr(0, subLength);\n lineWidth = getWidth(textLine, font);\n }\n\n if (textLine === '') {\n textLine = options.placeholder;\n }\n\n return textLine;\n}\n\nfunction estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {\n var width = 0;\n var i = 0;\n for (var len = text.length; i < len && width < contentWidth; i++) {\n var charCode = text.charCodeAt(i);\n width += (0 <= charCode && charCode <= 127) ? ascCharWidth : cnCharWidth;\n }\n return i;\n}\n\n/**\n * @public\n * @param {string} font\n * @return {number} line height\n */\nexport function getLineHeight(font) {\n // FIXME A rough approach.\n return getWidth('国', font);\n}\n\n/**\n * @public\n * @param {string} text\n * @param {string} font\n * @return {Object} width\n */\nexport function measureText(text, font) {\n return methods.measureText(text, font);\n}\n\n// Avoid assign to an exported variable, for transforming to cjs.\nmethods.measureText = function (text, font) {\n var ctx = getContext();\n ctx.font = font || DEFAULT_FONT;\n return ctx.measureText(text);\n};\n\n/**\n * @public\n * @param {string} text\n * @param {string} font\n * @param {Object} [truncate]\n * @return {Object} block: {lineHeight, lines, height, outerHeight, canCacheByTextString}\n * Notice: for performance, do not calculate outerWidth util needed.\n * `canCacheByTextString` means the result `lines` is only determined by the input `text`.\n * Thus we can simply comparing the `input` text to determin whether the result changed,\n * without travel the result `lines`.\n */\nexport function parsePlainText(text, font, padding, textLineHeight, truncate) {\n text != null && (text += '');\n\n var lineHeight = retrieve2(textLineHeight, getLineHeight(font));\n var lines = text ? text.split('\\n') : [];\n var height = lines.length * lineHeight;\n var outerHeight = height;\n var canCacheByTextString = true;\n\n if (padding) {\n outerHeight += padding[0] + padding[2];\n }\n\n if (text && truncate) {\n canCacheByTextString = false;\n var truncOuterHeight = truncate.outerHeight;\n var truncOuterWidth = truncate.outerWidth;\n if (truncOuterHeight != null && outerHeight > truncOuterHeight) {\n text = '';\n lines = [];\n }\n else if (truncOuterWidth != null) {\n var options = prepareTruncateOptions(\n truncOuterWidth - (padding ? padding[1] + padding[3] : 0),\n font,\n truncate.ellipsis,\n {minChar: truncate.minChar, placeholder: truncate.placeholder}\n );\n\n // FIXME\n // It is not appropriate that every line has '...' when truncate multiple lines.\n for (var i = 0, len = lines.length; i < len; i++) {\n lines[i] = truncateSingleLine(lines[i], options);\n }\n }\n }\n\n return {\n lines: lines,\n height: height,\n outerHeight: outerHeight,\n lineHeight: lineHeight,\n canCacheByTextString: canCacheByTextString\n };\n}\n\n/**\n * For example: 'some text {a|some text}other text{b|some text}xxx{c|}xxx'\n * Also consider 'bbbb{a|xxx\\nzzz}xxxx\\naaaa'.\n *\n * @public\n * @param {string} text\n * @param {Object} style\n * @return {Object} block\n * {\n * width,\n * height,\n * lines: [{\n * lineHeight,\n * width,\n * tokens: [[{\n * styleName,\n * text,\n * width, // include textPadding\n * height, // include textPadding\n * textWidth, // pure text width\n * textHeight, // pure text height\n * lineHeihgt,\n * font,\n * textAlign,\n * textVerticalAlign\n * }], [...], ...]\n * }, ...]\n * }\n * If styleName is undefined, it is plain text.\n */\nexport function parseRichText(text, style) {\n var contentBlock = {lines: [], width: 0, height: 0};\n\n text != null && (text += '');\n if (!text) {\n return contentBlock;\n }\n\n var lastIndex = STYLE_REG.lastIndex = 0;\n var result;\n while ((result = STYLE_REG.exec(text)) != null) {\n var matchedIndex = result.index;\n if (matchedIndex > lastIndex) {\n pushTokens(contentBlock, text.substring(lastIndex, matchedIndex));\n }\n pushTokens(contentBlock, result[2], result[1]);\n lastIndex = STYLE_REG.lastIndex;\n }\n\n if (lastIndex < text.length) {\n pushTokens(contentBlock, text.substring(lastIndex, text.length));\n }\n\n var lines = contentBlock.lines;\n var contentHeight = 0;\n var contentWidth = 0;\n // For `textWidth: 100%`\n var pendingList = [];\n\n var stlPadding = style.textPadding;\n\n var truncate = style.truncate;\n var truncateWidth = truncate && truncate.outerWidth;\n var truncateHeight = truncate && truncate.outerHeight;\n if (stlPadding) {\n truncateWidth != null && (truncateWidth -= stlPadding[1] + stlPadding[3]);\n truncateHeight != null && (truncateHeight -= stlPadding[0] + stlPadding[2]);\n }\n\n // Calculate layout info of tokens.\n for (var i = 0; i < lines.length; i++) {\n var line = lines[i];\n var lineHeight = 0;\n var lineWidth = 0;\n\n for (var j = 0; j < line.tokens.length; j++) {\n var token = line.tokens[j];\n var tokenStyle = token.styleName && style.rich[token.styleName] || {};\n // textPadding should not inherit from style.\n var textPadding = token.textPadding = tokenStyle.textPadding;\n\n // textFont has been asigned to font by `normalizeStyle`.\n var font = token.font = tokenStyle.font || style.font;\n\n // textHeight can be used when textVerticalAlign is specified in token.\n var tokenHeight = token.textHeight = retrieve2(\n // textHeight should not be inherited, consider it can be specified\n // as box height of the block.\n tokenStyle.textHeight, getLineHeight(font)\n );\n textPadding && (tokenHeight += textPadding[0] + textPadding[2]);\n token.height = tokenHeight;\n token.lineHeight = retrieve3(\n tokenStyle.textLineHeight, style.textLineHeight, tokenHeight\n );\n\n token.textAlign = tokenStyle && tokenStyle.textAlign || style.textAlign;\n token.textVerticalAlign = tokenStyle && tokenStyle.textVerticalAlign || 'middle';\n\n if (truncateHeight != null && contentHeight + token.lineHeight > truncateHeight) {\n return {lines: [], width: 0, height: 0};\n }\n\n token.textWidth = getWidth(token.text, font);\n var tokenWidth = tokenStyle.textWidth;\n var tokenWidthNotSpecified = tokenWidth == null || tokenWidth === 'auto';\n\n // Percent width, can be `100%`, can be used in drawing separate\n // line when box width is needed to be auto.\n if (typeof tokenWidth === 'string' && tokenWidth.charAt(tokenWidth.length - 1) === '%') {\n token.percentWidth = tokenWidth;\n pendingList.push(token);\n tokenWidth = 0;\n // Do not truncate in this case, because there is no user case\n // and it is too complicated.\n }\n else {\n if (tokenWidthNotSpecified) {\n tokenWidth = token.textWidth;\n\n // FIXME: If image is not loaded and textWidth is not specified, calling\n // `getBoundingRect()` will not get correct result.\n var textBackgroundColor = tokenStyle.textBackgroundColor;\n var bgImg = textBackgroundColor && textBackgroundColor.image;\n\n // Use cases:\n // (1) If image is not loaded, it will be loaded at render phase and call\n // `dirty()` and `textBackgroundColor.image` will be replaced with the loaded\n // image, and then the right size will be calculated here at the next tick.\n // See `graphic/helper/text.js`.\n // (2) If image loaded, and `textBackgroundColor.image` is image src string,\n // use `imageHelper.findExistImage` to find cached image.\n // `imageHelper.findExistImage` will always be called here before\n // `imageHelper.createOrUpdateImage` in `graphic/helper/text.js#renderRichText`\n // which ensures that image will not be rendered before correct size calcualted.\n if (bgImg) {\n bgImg = imageHelper.findExistImage(bgImg);\n if (imageHelper.isImageReady(bgImg)) {\n tokenWidth = Math.max(tokenWidth, bgImg.width * tokenHeight / bgImg.height);\n }\n }\n }\n\n var paddingW = textPadding ? textPadding[1] + textPadding[3] : 0;\n tokenWidth += paddingW;\n\n var remianTruncWidth = truncateWidth != null ? truncateWidth - lineWidth : null;\n\n if (remianTruncWidth != null && remianTruncWidth < tokenWidth) {\n if (!tokenWidthNotSpecified || remianTruncWidth < paddingW) {\n token.text = '';\n token.textWidth = tokenWidth = 0;\n }\n else {\n token.text = truncateText(\n token.text, remianTruncWidth - paddingW, font, truncate.ellipsis,\n {minChar: truncate.minChar}\n );\n token.textWidth = getWidth(token.text, font);\n tokenWidth = token.textWidth + paddingW;\n }\n }\n }\n\n lineWidth += (token.width = tokenWidth);\n tokenStyle && (lineHeight = Math.max(lineHeight, token.lineHeight));\n }\n\n line.width = lineWidth;\n line.lineHeight = lineHeight;\n contentHeight += lineHeight;\n contentWidth = Math.max(contentWidth, lineWidth);\n }\n\n contentBlock.outerWidth = contentBlock.width = retrieve2(style.textWidth, contentWidth);\n contentBlock.outerHeight = contentBlock.height = retrieve2(style.textHeight, contentHeight);\n\n if (stlPadding) {\n contentBlock.outerWidth += stlPadding[1] + stlPadding[3];\n contentBlock.outerHeight += stlPadding[0] + stlPadding[2];\n }\n\n for (var i = 0; i < pendingList.length; i++) {\n var token = pendingList[i];\n var percentWidth = token.percentWidth;\n // Should not base on outerWidth, because token can not be placed out of padding.\n token.width = parseInt(percentWidth, 10) / 100 * contentWidth;\n }\n\n return contentBlock;\n}\n\nfunction pushTokens(block, str, styleName) {\n var isEmptyStr = str === '';\n var strs = str.split('\\n');\n var lines = block.lines;\n\n for (var i = 0; i < strs.length; i++) {\n var text = strs[i];\n var token = {\n styleName: styleName,\n text: text,\n isLineHolder: !text && !isEmptyStr\n };\n\n // The first token should be appended to the last line.\n if (!i) {\n var tokens = (lines[lines.length - 1] || (lines[0] = {tokens: []})).tokens;\n\n // Consider cases:\n // (1) ''.split('\\n') => ['', '\\n', ''], the '' at the first item\n // (which is a placeholder) should be replaced by new token.\n // (2) A image backage, where token likes {a|}.\n // (3) A redundant '' will affect textAlign in line.\n // (4) tokens with the same tplName should not be merged, because\n // they should be displayed in different box (with border and padding).\n var tokensLen = tokens.length;\n (tokensLen === 1 && tokens[0].isLineHolder)\n ? (tokens[0] = token)\n // Consider text is '', only insert when it is the \"lineHolder\" or\n // \"emptyStr\". Otherwise a redundant '' will affect textAlign in line.\n : ((text || !tokensLen || isEmptyStr) && tokens.push(token));\n }\n // Other tokens always start a new line.\n else {\n // If there is '', insert it as a placeholder.\n lines.push({tokens: [token]});\n }\n }\n}\n\nexport function makeFont(style) {\n // FIXME in node-canvas fontWeight is before fontStyle\n // Use `fontSize` `fontFamily` to check whether font properties are defined.\n var font = (style.fontSize || style.fontFamily) && [\n style.fontStyle,\n style.fontWeight,\n (style.fontSize || 12) + 'px',\n // If font properties are defined, `fontFamily` should not be ignored.\n style.fontFamily || 'sans-serif'\n ].join(' ');\n return font && trim(font) || style.textFont || style.font;\n}\n","\n/**\n * @param {Object} ctx\n * @param {Object} shape\n * @param {number} shape.x\n * @param {number} shape.y\n * @param {number} shape.width\n * @param {number} shape.height\n * @param {number} shape.r\n */\nexport function buildPath(ctx, shape) {\n var x = shape.x;\n var y = shape.y;\n var width = shape.width;\n var height = shape.height;\n var r = shape.r;\n var r1;\n var r2;\n var r3;\n var r4;\n\n // Convert width and height to positive for better borderRadius\n if (width < 0) {\n x = x + width;\n width = -width;\n }\n if (height < 0) {\n y = y + height;\n height = -height;\n }\n\n if (typeof r === 'number') {\n r1 = r2 = r3 = r4 = r;\n }\n else if (r instanceof Array) {\n if (r.length === 1) {\n r1 = r2 = r3 = r4 = r[0];\n }\n else if (r.length === 2) {\n r1 = r3 = r[0];\n r2 = r4 = r[1];\n }\n else if (r.length === 3) {\n r1 = r[0];\n r2 = r4 = r[1];\n r3 = r[2];\n }\n else {\n r1 = r[0];\n r2 = r[1];\n r3 = r[2];\n r4 = r[3];\n }\n }\n else {\n r1 = r2 = r3 = r4 = 0;\n }\n\n var total;\n if (r1 + r2 > width) {\n total = r1 + r2;\n r1 *= width / total;\n r2 *= width / total;\n }\n if (r3 + r4 > width) {\n total = r3 + r4;\n r3 *= width / total;\n r4 *= width / total;\n }\n if (r2 + r3 > height) {\n total = r2 + r3;\n r2 *= height / total;\n r3 *= height / total;\n }\n if (r1 + r4 > height) {\n total = r1 + r4;\n r1 *= height / total;\n r4 *= height / total;\n }\n ctx.moveTo(x + r1, y);\n ctx.lineTo(x + width - r2, y);\n r2 !== 0 && ctx.arc(x + width - r2, y + r2, r2, -Math.PI / 2, 0);\n ctx.lineTo(x + width, y + height - r3);\n r3 !== 0 && ctx.arc(x + width - r3, y + height - r3, r3, 0, Math.PI / 2);\n ctx.lineTo(x + r4, y + height);\n r4 !== 0 && ctx.arc(x + r4, y + height - r4, r4, Math.PI / 2, Math.PI);\n ctx.lineTo(x, y + r1);\n r1 !== 0 && ctx.arc(x + r1, y + r1, r1, Math.PI, Math.PI * 1.5);\n}\n","\nimport {\n retrieve2,\n retrieve3,\n each,\n normalizeCssArray,\n isString,\n isObject\n} from '../../core/util';\nimport * as textContain from '../../contain/text';\nimport * as roundRectHelper from './roundRect';\nimport * as imageHelper from './image';\nimport fixShadow from './fixShadow';\nimport {ContextCachedBy, WILL_BE_RESTORED} from '../constant';\n\nvar DEFAULT_FONT = textContain.DEFAULT_FONT;\n\n// TODO: Have not support 'start', 'end' yet.\nvar VALID_TEXT_ALIGN = {left: 1, right: 1, center: 1};\nvar VALID_TEXT_VERTICAL_ALIGN = {top: 1, bottom: 1, middle: 1};\n// Different from `STYLE_COMMON_PROPS` of `graphic/Style`,\n// the default value of shadowColor is `'transparent'`.\nvar SHADOW_STYLE_COMMON_PROPS = [\n ['textShadowBlur', 'shadowBlur', 0],\n ['textShadowOffsetX', 'shadowOffsetX', 0],\n ['textShadowOffsetY', 'shadowOffsetY', 0],\n ['textShadowColor', 'shadowColor', 'transparent']\n];\nvar _tmpTextPositionResult = {};\nvar _tmpBoxPositionResult = {};\n\n/**\n * @param {module:zrender/graphic/Style} style\n * @return {module:zrender/graphic/Style} The input style.\n */\nexport function normalizeTextStyle(style) {\n normalizeStyle(style);\n each(style.rich, normalizeStyle);\n return style;\n}\n\nfunction normalizeStyle(style) {\n if (style) {\n\n style.font = textContain.makeFont(style);\n\n var textAlign = style.textAlign;\n textAlign === 'middle' && (textAlign = 'center');\n style.textAlign = (\n textAlign == null || VALID_TEXT_ALIGN[textAlign]\n ) ? textAlign : 'left';\n\n // Compatible with textBaseline.\n var textVerticalAlign = style.textVerticalAlign || style.textBaseline;\n textVerticalAlign === 'center' && (textVerticalAlign = 'middle');\n style.textVerticalAlign = (\n textVerticalAlign == null || VALID_TEXT_VERTICAL_ALIGN[textVerticalAlign]\n ) ? textVerticalAlign : 'top';\n\n var textPadding = style.textPadding;\n if (textPadding) {\n style.textPadding = normalizeCssArray(style.textPadding);\n }\n }\n}\n\n/**\n * @param {CanvasRenderingContext2D} ctx\n * @param {string} text\n * @param {module:zrender/graphic/Style} style\n * @param {Object|boolean} [rect] {x, y, width, height}\n * If set false, rect text is not used.\n * @param {Element|module:zrender/graphic/helper/constant.WILL_BE_RESTORED} [prevEl] For ctx prop cache.\n */\nexport function renderText(hostEl, ctx, text, style, rect, prevEl) {\n style.rich\n ? renderRichText(hostEl, ctx, text, style, rect, prevEl)\n : renderPlainText(hostEl, ctx, text, style, rect, prevEl);\n}\n\n// Avoid setting to ctx according to prevEl if possible for\n// performance in scenarios of large amount text.\nfunction renderPlainText(hostEl, ctx, text, style, rect, prevEl) {\n 'use strict';\n\n var needDrawBg = needDrawBackground(style);\n\n var prevStyle;\n var checkCache = false;\n var cachedByMe = ctx.__attrCachedBy === ContextCachedBy.PLAIN_TEXT;\n\n // Only take and check cache for `Text` el, but not RectText.\n if (prevEl !== WILL_BE_RESTORED) {\n if (prevEl) {\n prevStyle = prevEl.style;\n checkCache = !needDrawBg && cachedByMe && prevStyle;\n }\n\n // Prevent from using cache in `Style::bind`, because of the case:\n // ctx property is modified by other properties than `Style::bind`\n // used, and Style::bind is called next.\n ctx.__attrCachedBy = needDrawBg ? ContextCachedBy.NONE : ContextCachedBy.PLAIN_TEXT;\n }\n // Since this will be restored, prevent from using these props to check cache in the next\n // entering of this method. But do not need to clear other cache like `Style::bind`.\n else if (cachedByMe) {\n ctx.__attrCachedBy = ContextCachedBy.NONE;\n }\n\n var styleFont = style.font || DEFAULT_FONT;\n // PENDING\n // Only `Text` el set `font` and keep it (`RectText` will restore). So theoretically\n // we can make font cache on ctx, which can cache for text el that are discontinuous.\n // But layer save/restore needed to be considered.\n // if (styleFont !== ctx.__fontCache) {\n // ctx.font = styleFont;\n // if (prevEl !== WILL_BE_RESTORED) {\n // ctx.__fontCache = styleFont;\n // }\n // }\n if (!checkCache || styleFont !== (prevStyle.font || DEFAULT_FONT)) {\n ctx.font = styleFont;\n }\n\n // Use the final font from context-2d, because the final\n // font might not be the style.font when it is illegal.\n // But get `ctx.font` might be time consuming.\n var computedFont = hostEl.__computedFont;\n if (hostEl.__styleFont !== styleFont) {\n hostEl.__styleFont = styleFont;\n computedFont = hostEl.__computedFont = ctx.font;\n }\n\n var textPadding = style.textPadding;\n var textLineHeight = style.textLineHeight;\n\n var contentBlock = hostEl.__textCotentBlock;\n if (!contentBlock || hostEl.__dirtyText) {\n contentBlock = hostEl.__textCotentBlock = textContain.parsePlainText(\n text, computedFont, textPadding, textLineHeight, style.truncate\n );\n }\n\n var outerHeight = contentBlock.outerHeight;\n\n var textLines = contentBlock.lines;\n var lineHeight = contentBlock.lineHeight;\n\n var boxPos = getBoxPosition(_tmpBoxPositionResult, hostEl, style, rect);\n var baseX = boxPos.baseX;\n var baseY = boxPos.baseY;\n var textAlign = boxPos.textAlign || 'left';\n var textVerticalAlign = boxPos.textVerticalAlign;\n\n // Origin of textRotation should be the base point of text drawing.\n applyTextRotation(ctx, style, rect, baseX, baseY);\n\n var boxY = textContain.adjustTextY(baseY, outerHeight, textVerticalAlign);\n var textX = baseX;\n var textY = boxY;\n\n if (needDrawBg || textPadding) {\n // Consider performance, do not call getTextWidth util necessary.\n var textWidth = textContain.getWidth(text, computedFont);\n var outerWidth = textWidth;\n textPadding && (outerWidth += textPadding[1] + textPadding[3]);\n var boxX = textContain.adjustTextX(baseX, outerWidth, textAlign);\n\n needDrawBg && drawBackground(hostEl, ctx, style, boxX, boxY, outerWidth, outerHeight);\n\n if (textPadding) {\n textX = getTextXForPadding(baseX, textAlign, textPadding);\n textY += textPadding[0];\n }\n }\n\n // Always set textAlign and textBase line, because it is difficute to calculate\n // textAlign from prevEl, and we dont sure whether textAlign will be reset if\n // font set happened.\n ctx.textAlign = textAlign;\n // Force baseline to be \"middle\". Otherwise, if using \"top\", the\n // text will offset downward a little bit in font \"Microsoft YaHei\".\n ctx.textBaseline = 'middle';\n // Set text opacity\n ctx.globalAlpha = style.opacity || 1;\n\n // Always set shadowBlur and shadowOffset to avoid leak from displayable.\n for (var i = 0; i < SHADOW_STYLE_COMMON_PROPS.length; i++) {\n var propItem = SHADOW_STYLE_COMMON_PROPS[i];\n var styleProp = propItem[0];\n var ctxProp = propItem[1];\n var val = style[styleProp];\n if (!checkCache || val !== prevStyle[styleProp]) {\n ctx[ctxProp] = fixShadow(ctx, ctxProp, val || propItem[2]);\n }\n }\n\n // `textBaseline` is set as 'middle'.\n textY += lineHeight / 2;\n\n var textStrokeWidth = style.textStrokeWidth;\n var textStrokeWidthPrev = checkCache ? prevStyle.textStrokeWidth : null;\n var strokeWidthChanged = !checkCache || textStrokeWidth !== textStrokeWidthPrev;\n var strokeChanged = !checkCache || strokeWidthChanged || style.textStroke !== prevStyle.textStroke;\n var textStroke = getStroke(style.textStroke, textStrokeWidth);\n var textFill = getFill(style.textFill);\n\n if (textStroke) {\n if (strokeWidthChanged) {\n ctx.lineWidth = textStrokeWidth;\n }\n if (strokeChanged) {\n ctx.strokeStyle = textStroke;\n }\n }\n if (textFill) {\n if (!checkCache || style.textFill !== prevStyle.textFill) {\n ctx.fillStyle = textFill;\n }\n }\n\n // Optimize simply, in most cases only one line exists.\n if (textLines.length === 1) {\n // Fill after stroke so the outline will not cover the main part.\n textStroke && ctx.strokeText(textLines[0], textX, textY);\n textFill && ctx.fillText(textLines[0], textX, textY);\n }\n else {\n for (var i = 0; i < textLines.length; i++) {\n // Fill after stroke so the outline will not cover the main part.\n textStroke && ctx.strokeText(textLines[i], textX, textY);\n textFill && ctx.fillText(textLines[i], textX, textY);\n textY += lineHeight;\n }\n }\n}\n\nfunction renderRichText(hostEl, ctx, text, style, rect, prevEl) {\n // Do not do cache for rich text because of the complexity.\n // But `RectText` this will be restored, do not need to clear other cache like `Style::bind`.\n if (prevEl !== WILL_BE_RESTORED) {\n ctx.__attrCachedBy = ContextCachedBy.NONE;\n }\n\n var contentBlock = hostEl.__textCotentBlock;\n\n if (!contentBlock || hostEl.__dirtyText) {\n contentBlock = hostEl.__textCotentBlock = textContain.parseRichText(text, style);\n }\n\n drawRichText(hostEl, ctx, contentBlock, style, rect);\n}\n\nfunction drawRichText(hostEl, ctx, contentBlock, style, rect) {\n var contentWidth = contentBlock.width;\n var outerWidth = contentBlock.outerWidth;\n var outerHeight = contentBlock.outerHeight;\n var textPadding = style.textPadding;\n\n var boxPos = getBoxPosition(_tmpBoxPositionResult, hostEl, style, rect);\n var baseX = boxPos.baseX;\n var baseY = boxPos.baseY;\n var textAlign = boxPos.textAlign;\n var textVerticalAlign = boxPos.textVerticalAlign;\n\n // Origin of textRotation should be the base point of text drawing.\n applyTextRotation(ctx, style, rect, baseX, baseY);\n\n var boxX = textContain.adjustTextX(baseX, outerWidth, textAlign);\n var boxY = textContain.adjustTextY(baseY, outerHeight, textVerticalAlign);\n var xLeft = boxX;\n var lineTop = boxY;\n if (textPadding) {\n xLeft += textPadding[3];\n lineTop += textPadding[0];\n }\n var xRight = xLeft + contentWidth;\n\n needDrawBackground(style) && drawBackground(\n hostEl, ctx, style, boxX, boxY, outerWidth, outerHeight\n );\n\n for (var i = 0; i < contentBlock.lines.length; i++) {\n var line = contentBlock.lines[i];\n var tokens = line.tokens;\n var tokenCount = tokens.length;\n var lineHeight = line.lineHeight;\n var usedWidth = line.width;\n\n var leftIndex = 0;\n var lineXLeft = xLeft;\n var lineXRight = xRight;\n var rightIndex = tokenCount - 1;\n var token;\n\n while (\n leftIndex < tokenCount\n && (token = tokens[leftIndex], !token.textAlign || token.textAlign === 'left')\n ) {\n placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXLeft, 'left');\n usedWidth -= token.width;\n lineXLeft += token.width;\n leftIndex++;\n }\n\n while (\n rightIndex >= 0\n && (token = tokens[rightIndex], token.textAlign === 'right')\n ) {\n placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXRight, 'right');\n usedWidth -= token.width;\n lineXRight -= token.width;\n rightIndex--;\n }\n\n // The other tokens are placed as textAlign 'center' if there is enough space.\n lineXLeft += (contentWidth - (lineXLeft - xLeft) - (xRight - lineXRight) - usedWidth) / 2;\n while (leftIndex <= rightIndex) {\n token = tokens[leftIndex];\n // Consider width specified by user, use 'center' rather than 'left'.\n placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXLeft + token.width / 2, 'center');\n lineXLeft += token.width;\n leftIndex++;\n }\n\n lineTop += lineHeight;\n }\n}\n\nfunction applyTextRotation(ctx, style, rect, x, y) {\n // textRotation only apply in RectText.\n if (rect && style.textRotation) {\n var origin = style.textOrigin;\n if (origin === 'center') {\n x = rect.width / 2 + rect.x;\n y = rect.height / 2 + rect.y;\n }\n else if (origin) {\n x = origin[0] + rect.x;\n y = origin[1] + rect.y;\n }\n\n ctx.translate(x, y);\n // Positive: anticlockwise\n ctx.rotate(-style.textRotation);\n ctx.translate(-x, -y);\n }\n}\n\nfunction placeToken(hostEl, ctx, token, style, lineHeight, lineTop, x, textAlign) {\n var tokenStyle = style.rich[token.styleName] || {};\n tokenStyle.text = token.text;\n\n // 'ctx.textBaseline' is always set as 'middle', for sake of\n // the bias of \"Microsoft YaHei\".\n var textVerticalAlign = token.textVerticalAlign;\n var y = lineTop + lineHeight / 2;\n if (textVerticalAlign === 'top') {\n y = lineTop + token.height / 2;\n }\n else if (textVerticalAlign === 'bottom') {\n y = lineTop + lineHeight - token.height / 2;\n }\n\n !token.isLineHolder && needDrawBackground(tokenStyle) && drawBackground(\n hostEl,\n ctx,\n tokenStyle,\n textAlign === 'right'\n ? x - token.width\n : textAlign === 'center'\n ? x - token.width / 2\n : x,\n y - token.height / 2,\n token.width,\n token.height\n );\n\n var textPadding = token.textPadding;\n if (textPadding) {\n x = getTextXForPadding(x, textAlign, textPadding);\n y -= token.height / 2 - textPadding[2] - token.textHeight / 2;\n }\n\n setCtx(ctx, 'shadowBlur', retrieve3(tokenStyle.textShadowBlur, style.textShadowBlur, 0));\n setCtx(ctx, 'shadowColor', tokenStyle.textShadowColor || style.textShadowColor || 'transparent');\n setCtx(ctx, 'shadowOffsetX', retrieve3(tokenStyle.textShadowOffsetX, style.textShadowOffsetX, 0));\n setCtx(ctx, 'shadowOffsetY', retrieve3(tokenStyle.textShadowOffsetY, style.textShadowOffsetY, 0));\n\n setCtx(ctx, 'textAlign', textAlign);\n // Force baseline to be \"middle\". Otherwise, if using \"top\", the\n // text will offset downward a little bit in font \"Microsoft YaHei\".\n setCtx(ctx, 'textBaseline', 'middle');\n\n setCtx(ctx, 'font', token.font || DEFAULT_FONT);\n\n var textStroke = getStroke(tokenStyle.textStroke || style.textStroke, textStrokeWidth);\n var textFill = getFill(tokenStyle.textFill || style.textFill);\n var textStrokeWidth = retrieve2(tokenStyle.textStrokeWidth, style.textStrokeWidth);\n\n // Fill after stroke so the outline will not cover the main part.\n if (textStroke) {\n setCtx(ctx, 'lineWidth', textStrokeWidth);\n setCtx(ctx, 'strokeStyle', textStroke);\n ctx.strokeText(token.text, x, y);\n }\n if (textFill) {\n setCtx(ctx, 'fillStyle', textFill);\n ctx.fillText(token.text, x, y);\n }\n}\n\nfunction needDrawBackground(style) {\n return !!(\n style.textBackgroundColor\n || (style.textBorderWidth && style.textBorderColor)\n );\n}\n\n// style: {textBackgroundColor, textBorderWidth, textBorderColor, textBorderRadius, text}\n// shape: {x, y, width, height}\nfunction drawBackground(hostEl, ctx, style, x, y, width, height) {\n var textBackgroundColor = style.textBackgroundColor;\n var textBorderWidth = style.textBorderWidth;\n var textBorderColor = style.textBorderColor;\n var isPlainBg = isString(textBackgroundColor);\n\n setCtx(ctx, 'shadowBlur', style.textBoxShadowBlur || 0);\n setCtx(ctx, 'shadowColor', style.textBoxShadowColor || 'transparent');\n setCtx(ctx, 'shadowOffsetX', style.textBoxShadowOffsetX || 0);\n setCtx(ctx, 'shadowOffsetY', style.textBoxShadowOffsetY || 0);\n\n if (isPlainBg || (textBorderWidth && textBorderColor)) {\n ctx.beginPath();\n var textBorderRadius = style.textBorderRadius;\n if (!textBorderRadius) {\n ctx.rect(x, y, width, height);\n }\n else {\n roundRectHelper.buildPath(ctx, {\n x: x, y: y, width: width, height: height, r: textBorderRadius\n });\n }\n ctx.closePath();\n }\n\n if (isPlainBg) {\n setCtx(ctx, 'fillStyle', textBackgroundColor);\n\n if (style.fillOpacity != null) {\n var originalGlobalAlpha = ctx.globalAlpha;\n ctx.globalAlpha = style.fillOpacity * style.opacity;\n ctx.fill();\n ctx.globalAlpha = originalGlobalAlpha;\n }\n else {\n ctx.fill();\n }\n }\n else if (isObject(textBackgroundColor)) {\n var image = textBackgroundColor.image;\n\n image = imageHelper.createOrUpdateImage(\n image, null, hostEl, onBgImageLoaded, textBackgroundColor\n );\n if (image && imageHelper.isImageReady(image)) {\n ctx.drawImage(image, x, y, width, height);\n }\n }\n\n if (textBorderWidth && textBorderColor) {\n setCtx(ctx, 'lineWidth', textBorderWidth);\n setCtx(ctx, 'strokeStyle', textBorderColor);\n\n if (style.strokeOpacity != null) {\n var originalGlobalAlpha = ctx.globalAlpha;\n ctx.globalAlpha = style.strokeOpacity * style.opacity;\n ctx.stroke();\n ctx.globalAlpha = originalGlobalAlpha;\n }\n else {\n ctx.stroke();\n }\n }\n}\n\nfunction onBgImageLoaded(image, textBackgroundColor) {\n // Replace image, so that `contain/text.js#parseRichText`\n // will get correct result in next tick.\n textBackgroundColor.image = image;\n}\n\nexport function getBoxPosition(out, hostEl, style, rect) {\n var baseX = style.x || 0;\n var baseY = style.y || 0;\n var textAlign = style.textAlign;\n var textVerticalAlign = style.textVerticalAlign;\n\n // Text position represented by coord\n if (rect) {\n var textPosition = style.textPosition;\n if (textPosition instanceof Array) {\n // Percent\n baseX = rect.x + parsePercent(textPosition[0], rect.width);\n baseY = rect.y + parsePercent(textPosition[1], rect.height);\n }\n else {\n var res = (hostEl && hostEl.calculateTextPosition)\n ? hostEl.calculateTextPosition(_tmpTextPositionResult, style, rect)\n : textContain.calculateTextPosition(_tmpTextPositionResult, style, rect);\n baseX = res.x;\n baseY = res.y;\n // Default align and baseline when has textPosition\n textAlign = textAlign || res.textAlign;\n textVerticalAlign = textVerticalAlign || res.textVerticalAlign;\n }\n\n // textOffset is only support in RectText, otherwise\n // we have to adjust boundingRect for textOffset.\n var textOffset = style.textOffset;\n if (textOffset) {\n baseX += textOffset[0];\n baseY += textOffset[1];\n }\n }\n\n out = out || {};\n out.baseX = baseX;\n out.baseY = baseY;\n out.textAlign = textAlign;\n out.textVerticalAlign = textVerticalAlign;\n\n return out;\n}\n\n\nfunction setCtx(ctx, prop, value) {\n ctx[prop] = fixShadow(ctx, prop, value);\n return ctx[prop];\n}\n\n/**\n * @param {string} [stroke] If specified, do not check style.textStroke.\n * @param {string} [lineWidth] If specified, do not check style.textStroke.\n * @param {number} style\n */\nexport function getStroke(stroke, lineWidth) {\n return (stroke == null || lineWidth <= 0 || stroke === 'transparent' || stroke === 'none')\n ? null\n // TODO pattern and gradient?\n : (stroke.image || stroke.colorStops)\n ? '#000'\n : stroke;\n}\n\nexport function getFill(fill) {\n return (fill == null || fill === 'none')\n ? null\n // TODO pattern and gradient?\n : (fill.image || fill.colorStops)\n ? '#000'\n : fill;\n}\n\nexport function parsePercent(value, maxValue) {\n if (typeof value === 'string') {\n if (value.lastIndexOf('%') >= 0) {\n return parseFloat(value) / 100 * maxValue;\n }\n return parseFloat(value);\n }\n return value;\n}\n\nfunction getTextXForPadding(x, textAlign, textPadding) {\n return textAlign === 'right'\n ? (x - textPadding[1])\n : textAlign === 'center'\n ? (x + textPadding[3] / 2 - textPadding[1] / 2)\n : (x + textPadding[3]);\n}\n\n/**\n * @param {string} text\n * @param {module:zrender/Style} style\n * @return {boolean}\n */\nexport function needDrawText(text, style) {\n return text != null\n && (text\n || style.textBackgroundColor\n || (style.textBorderWidth && style.textBorderColor)\n || style.textPadding\n );\n}\n","/**\n * Mixin for drawing text in a element bounding rect\n * @module zrender/mixin/RectText\n */\n\nimport * as textHelper from '../helper/text';\nimport BoundingRect from '../../core/BoundingRect';\nimport {WILL_BE_RESTORED} from '../constant';\n\nvar tmpRect = new BoundingRect();\n\nvar RectText = function () {};\n\nRectText.prototype = {\n\n constructor: RectText,\n\n /**\n * Draw text in a rect with specified position.\n * @param {CanvasRenderingContext2D} ctx\n * @param {Object} rect Displayable rect\n */\n drawRectText: function (ctx, rect) {\n var style = this.style;\n\n rect = style.textRect || rect;\n\n // Optimize, avoid normalize every time.\n this.__dirty && textHelper.normalizeTextStyle(style, true);\n\n var text = style.text;\n\n // Convert to string\n text != null && (text += '');\n\n if (!textHelper.needDrawText(text, style)) {\n return;\n }\n\n // FIXME\n // Do not provide prevEl to `textHelper.renderText` for ctx prop cache,\n // but use `ctx.save()` and `ctx.restore()`. Because the cache for rect\n // text propably break the cache for its host elements.\n ctx.save();\n\n // Transform rect to view space\n var transform = this.transform;\n if (!style.transformText) {\n if (transform) {\n tmpRect.copy(rect);\n tmpRect.applyTransform(transform);\n rect = tmpRect;\n }\n }\n else {\n this.setTransform(ctx);\n }\n\n // transformText and textRotation can not be used at the same time.\n textHelper.renderText(this, ctx, text, style, rect, WILL_BE_RESTORED);\n\n ctx.restore();\n }\n};\n\nexport default RectText;","/**\n * Base class of all displayable graphic objects\n * @module zrender/graphic/Displayable\n */\n\n\nimport * as zrUtil from '../core/util';\nimport Style from './Style';\nimport Element from '../Element';\nimport RectText from './mixin/RectText';\n\n/**\n * @alias module:zrender/graphic/Displayable\n * @extends module:zrender/Element\n * @extends module:zrender/graphic/mixin/RectText\n */\nfunction Displayable(opts) {\n\n opts = opts || {};\n\n Element.call(this, opts);\n\n // Extend properties\n for (var name in opts) {\n if (\n opts.hasOwnProperty(name)\n && name !== 'style'\n ) {\n this[name] = opts[name];\n }\n }\n\n /**\n * @type {module:zrender/graphic/Style}\n */\n this.style = new Style(opts.style, this);\n\n this._rect = null;\n // Shapes for cascade clipping.\n // Can only be `null`/`undefined` or an non-empty array, MUST NOT be an empty array.\n // because it is easy to only using null to check whether clipPaths changed.\n this.__clipPaths = null;\n\n // FIXME Stateful must be mixined after style is setted\n // Stateful.call(this, opts);\n}\n\nDisplayable.prototype = {\n\n constructor: Displayable,\n\n type: 'displayable',\n\n /**\n * Dirty flag. From which painter will determine if this displayable object needs brush.\n * @name module:zrender/graphic/Displayable#__dirty\n * @type {boolean}\n */\n __dirty: true,\n\n /**\n * Whether the displayable object is visible. when it is true, the displayable object\n * is not drawn, but the mouse event can still trigger the object.\n * @name module:/zrender/graphic/Displayable#invisible\n * @type {boolean}\n * @default false\n */\n invisible: false,\n\n /**\n * @name module:/zrender/graphic/Displayable#z\n * @type {number}\n * @default 0\n */\n z: 0,\n\n /**\n * @name module:/zrender/graphic/Displayable#z\n * @type {number}\n * @default 0\n */\n z2: 0,\n\n /**\n * The z level determines the displayable object can be drawn in which layer canvas.\n * @name module:/zrender/graphic/Displayable#zlevel\n * @type {number}\n * @default 0\n */\n zlevel: 0,\n\n /**\n * Whether it can be dragged.\n * @name module:/zrender/graphic/Displayable#draggable\n * @type {boolean}\n * @default false\n */\n draggable: false,\n\n /**\n * Whether is it dragging.\n * @name module:/zrender/graphic/Displayable#draggable\n * @type {boolean}\n * @default false\n */\n dragging: false,\n\n /**\n * Whether to respond to mouse events.\n * @name module:/zrender/graphic/Displayable#silent\n * @type {boolean}\n * @default false\n */\n silent: false,\n\n /**\n * If enable culling\n * @type {boolean}\n * @default false\n */\n culling: false,\n\n /**\n * Mouse cursor when hovered\n * @name module:/zrender/graphic/Displayable#cursor\n * @type {string}\n */\n cursor: 'pointer',\n\n /**\n * If hover area is bounding rect\n * @name module:/zrender/graphic/Displayable#rectHover\n * @type {string}\n */\n rectHover: false,\n\n /**\n * Render the element progressively when the value >= 0,\n * usefull for large data.\n * @type {boolean}\n */\n progressive: false,\n\n /**\n * @type {boolean}\n */\n incremental: false,\n /**\n * Scale ratio for global scale.\n * @type {boolean}\n */\n globalScaleRatio: 1,\n\n beforeBrush: function (ctx) {},\n\n afterBrush: function (ctx) {},\n\n /**\n * Graphic drawing method.\n * @param {CanvasRenderingContext2D} ctx\n */\n // Interface\n brush: function (ctx, prevEl) {},\n\n /**\n * Get the minimum bounding box.\n * @return {module:zrender/core/BoundingRect}\n */\n // Interface\n getBoundingRect: function () {},\n\n /**\n * If displayable element contain coord x, y\n * @param {number} x\n * @param {number} y\n * @return {boolean}\n */\n contain: function (x, y) {\n return this.rectContain(x, y);\n },\n\n /**\n * @param {Function} cb\n * @param {} context\n */\n traverse: function (cb, context) {\n cb.call(context, this);\n },\n\n /**\n * If bounding rect of element contain coord x, y\n * @param {number} x\n * @param {number} y\n * @return {boolean}\n */\n rectContain: function (x, y) {\n var coord = this.transformCoordToLocal(x, y);\n var rect = this.getBoundingRect();\n return rect.contain(coord[0], coord[1]);\n },\n\n /**\n * Mark displayable element dirty and refresh next frame\n */\n dirty: function () {\n this.__dirty = this.__dirtyText = true;\n\n this._rect = null;\n\n this.__zr && this.__zr.refresh();\n },\n\n /**\n * If displayable object binded any event\n * @return {boolean}\n */\n // TODO, events bound by bind\n // isSilent: function () {\n // return !(\n // this.hoverable || this.draggable\n // || this.onmousemove || this.onmouseover || this.onmouseout\n // || this.onmousedown || this.onmouseup || this.onclick\n // || this.ondragenter || this.ondragover || this.ondragleave\n // || this.ondrop\n // );\n // },\n /**\n * Alias for animate('style')\n * @param {boolean} loop\n */\n animateStyle: function (loop) {\n return this.animate('style', loop);\n },\n\n attrKV: function (key, value) {\n if (key !== 'style') {\n Element.prototype.attrKV.call(this, key, value);\n }\n else {\n this.style.set(value);\n }\n },\n\n /**\n * @param {Object|string} key\n * @param {*} value\n */\n setStyle: function (key, value) {\n this.style.set(key, value);\n this.dirty(false);\n return this;\n },\n\n /**\n * Use given style object\n * @param {Object} obj\n */\n useStyle: function (obj) {\n this.style = new Style(obj, this);\n this.dirty(false);\n return this;\n },\n\n /**\n * The string value of `textPosition` needs to be calculated to a real postion.\n * For example, `'inside'` is calculated to `[rect.width/2, rect.height/2]`\n * by default. See `contain/text.js#calculateTextPosition` for more details.\n * But some coutom shapes like \"pin\", \"flag\" have center that is not exactly\n * `[width/2, height/2]`. So we provide this hook to customize the calculation\n * for those shapes. It will be called if the `style.textPosition` is a string.\n * @param {Obejct} [out] Prepared out object. If not provided, this method should\n * be responsible for creating one.\n * @param {module:zrender/graphic/Style} style\n * @param {Object} rect {x, y, width, height}\n * @return {Obejct} out The same as the input out.\n * {\n * x: number. mandatory.\n * y: number. mandatory.\n * textAlign: string. optional. use style.textAlign by default.\n * textVerticalAlign: string. optional. use style.textVerticalAlign by default.\n * }\n */\n calculateTextPosition: null\n};\n\nzrUtil.inherits(Displayable, Element);\n\nzrUtil.mixin(Displayable, RectText);\n// zrUtil.mixin(Displayable, Stateful);\n\nexport default Displayable;","import Displayable from './Displayable';\nimport BoundingRect from '../core/BoundingRect';\nimport * as zrUtil from '../core/util';\nimport * as imageHelper from './helper/image';\n\n/**\n * @alias zrender/graphic/Image\n * @extends module:zrender/graphic/Displayable\n * @constructor\n * @param {Object} opts\n */\nfunction ZImage(opts) {\n Displayable.call(this, opts);\n}\n\nZImage.prototype = {\n\n constructor: ZImage,\n\n type: 'image',\n\n brush: function (ctx, prevEl) {\n var style = this.style;\n var src = style.image;\n\n // Must bind each time\n style.bind(ctx, this, prevEl);\n\n var image = this._image = imageHelper.createOrUpdateImage(\n src,\n this._image,\n this,\n this.onload\n );\n\n if (!image || !imageHelper.isImageReady(image)) {\n return;\n }\n\n // 图片已经加载完成\n // if (image.nodeName.toUpperCase() == 'IMG') {\n // if (!image.complete) {\n // return;\n // }\n // }\n // Else is canvas\n\n var x = style.x || 0;\n var y = style.y || 0;\n var width = style.width;\n var height = style.height;\n var aspect = image.width / image.height;\n if (width == null && height != null) {\n // Keep image/height ratio\n width = height * aspect;\n }\n else if (height == null && width != null) {\n height = width / aspect;\n }\n else if (width == null && height == null) {\n width = image.width;\n height = image.height;\n }\n\n // 设置transform\n this.setTransform(ctx);\n\n if (style.sWidth && style.sHeight) {\n var sx = style.sx || 0;\n var sy = style.sy || 0;\n ctx.drawImage(\n image,\n sx, sy, style.sWidth, style.sHeight,\n x, y, width, height\n );\n }\n else if (style.sx && style.sy) {\n var sx = style.sx;\n var sy = style.sy;\n var sWidth = width - sx;\n var sHeight = height - sy;\n ctx.drawImage(\n image,\n sx, sy, sWidth, sHeight,\n x, y, width, height\n );\n }\n else {\n ctx.drawImage(image, x, y, width, height);\n }\n\n // Draw rect text\n if (style.text != null) {\n // Only restore transform when needs draw text.\n this.restoreTransform(ctx);\n this.drawRectText(ctx, this.getBoundingRect());\n }\n },\n\n getBoundingRect: function () {\n var style = this.style;\n if (!this._rect) {\n this._rect = new BoundingRect(\n style.x || 0, style.y || 0, style.width || 0, style.height || 0\n );\n }\n return this._rect;\n }\n};\n\nzrUtil.inherits(ZImage, Displayable);\n\nexport default ZImage;","import {devicePixelRatio} from './config';\nimport * as util from './core/util';\nimport logError from './core/log';\nimport BoundingRect from './core/BoundingRect';\nimport timsort from './core/timsort';\nimport Layer from './Layer';\nimport requestAnimationFrame from './animation/requestAnimationFrame';\nimport Image from './graphic/Image';\nimport env from './core/env';\n\nvar HOVER_LAYER_ZLEVEL = 1e5;\nvar CANVAS_ZLEVEL = 314159;\n\nvar EL_AFTER_INCREMENTAL_INC = 0.01;\nvar INCREMENTAL_INC = 0.001;\n\nfunction parseInt10(val) {\n return parseInt(val, 10);\n}\n\nfunction isLayerValid(layer) {\n if (!layer) {\n return false;\n }\n\n if (layer.__builtin__) {\n return true;\n }\n\n if (typeof (layer.resize) !== 'function'\n || typeof (layer.refresh) !== 'function'\n ) {\n return false;\n }\n\n return true;\n}\n\nvar tmpRect = new BoundingRect(0, 0, 0, 0);\nvar viewRect = new BoundingRect(0, 0, 0, 0);\nfunction isDisplayableCulled(el, width, height) {\n tmpRect.copy(el.getBoundingRect());\n if (el.transform) {\n tmpRect.applyTransform(el.transform);\n }\n viewRect.width = width;\n viewRect.height = height;\n return !tmpRect.intersect(viewRect);\n}\n\nfunction isClipPathChanged(clipPaths, prevClipPaths) {\n // displayable.__clipPaths can only be `null`/`undefined` or an non-empty array.\n if (clipPaths === prevClipPaths) {\n return false;\n }\n if (!clipPaths || !prevClipPaths || (clipPaths.length !== prevClipPaths.length)) {\n return true;\n }\n for (var i = 0; i < clipPaths.length; i++) {\n if (clipPaths[i] !== prevClipPaths[i]) {\n return true;\n }\n }\n return false;\n}\n\nfunction doClip(clipPaths, ctx) {\n for (var i = 0; i < clipPaths.length; i++) {\n var clipPath = clipPaths[i];\n\n clipPath.setTransform(ctx);\n ctx.beginPath();\n clipPath.buildPath(ctx, clipPath.shape);\n ctx.clip();\n // Transform back\n clipPath.restoreTransform(ctx);\n }\n}\n\nfunction createRoot(width, height) {\n var domRoot = document.createElement('div');\n\n // domRoot.onselectstart = returnFalse; // Avoid page selected\n domRoot.style.cssText = [\n 'position:relative',\n // IOS13 safari probably has a compositing bug (z order of the canvas and the consequent\n // dom does not act as expected) when some of the parent dom has\n // `-webkit-overflow-scrolling: touch;` and the webpage is longer than one screen and\n // the canvas is not at the top part of the page.\n // Check `https://bugs.webkit.org/show_bug.cgi?id=203681` for more details. We remove\n // this `overflow:hidden` to avoid the bug.\n // 'overflow:hidden',\n 'width:' + width + 'px',\n 'height:' + height + 'px',\n 'padding:0',\n 'margin:0',\n 'border-width:0'\n ].join(';') + ';';\n\n return domRoot;\n}\n\n\n/**\n * @alias module:zrender/Painter\n * @constructor\n * @param {HTMLElement} root 绘图容器\n * @param {module:zrender/Storage} storage\n * @param {Object} opts\n */\nvar Painter = function (root, storage, opts) {\n\n this.type = 'canvas';\n\n // In node environment using node-canvas\n var singleCanvas = !root.nodeName // In node ?\n || root.nodeName.toUpperCase() === 'CANVAS';\n\n this._opts = opts = util.extend({}, opts || {});\n\n /**\n * @type {number}\n */\n this.dpr = opts.devicePixelRatio || devicePixelRatio;\n /**\n * @type {boolean}\n * @private\n */\n this._singleCanvas = singleCanvas;\n /**\n * 绘图容器\n * @type {HTMLElement}\n */\n this.root = root;\n\n var rootStyle = root.style;\n\n if (rootStyle) {\n rootStyle['-webkit-tap-highlight-color'] = 'transparent';\n rootStyle['-webkit-user-select'] =\n rootStyle['user-select'] =\n rootStyle['-webkit-touch-callout'] = 'none';\n\n root.innerHTML = '';\n }\n\n /**\n * @type {module:zrender/Storage}\n */\n this.storage = storage;\n\n /**\n * @type {Array.<number>}\n * @private\n */\n var zlevelList = this._zlevelList = [];\n\n /**\n * @type {Object.<string, module:zrender/Layer>}\n * @private\n */\n var layers = this._layers = {};\n\n /**\n * @type {Object.<string, Object>}\n * @private\n */\n this._layerConfig = {};\n\n /**\n * zrender will do compositing when root is a canvas and have multiple zlevels.\n */\n this._needsManuallyCompositing = false;\n\n if (!singleCanvas) {\n this._width = this._getSize(0);\n this._height = this._getSize(1);\n\n var domRoot = this._domRoot = createRoot(\n this._width, this._height\n );\n root.appendChild(domRoot);\n }\n else {\n var width = root.width;\n var height = root.height;\n\n if (opts.width != null) {\n width = opts.width;\n }\n if (opts.height != null) {\n height = opts.height;\n }\n this.dpr = opts.devicePixelRatio || 1;\n\n // Use canvas width and height directly\n root.width = width * this.dpr;\n root.height = height * this.dpr;\n\n this._width = width;\n this._height = height;\n\n // Create layer if only one given canvas\n // Device can be specified to create a high dpi image.\n var mainLayer = new Layer(root, this, this.dpr);\n mainLayer.__builtin__ = true;\n mainLayer.initContext();\n // FIXME Use canvas width and height\n // mainLayer.resize(width, height);\n layers[CANVAS_ZLEVEL] = mainLayer;\n mainLayer.zlevel = CANVAS_ZLEVEL;\n // Not use common zlevel.\n zlevelList.push(CANVAS_ZLEVEL);\n\n this._domRoot = root;\n }\n\n /**\n * @type {module:zrender/Layer}\n * @private\n */\n this._hoverlayer = null;\n\n this._hoverElements = [];\n};\n\nPainter.prototype = {\n\n constructor: Painter,\n\n getType: function () {\n return 'canvas';\n },\n\n /**\n * If painter use a single canvas\n * @return {boolean}\n */\n isSingleCanvas: function () {\n return this._singleCanvas;\n },\n /**\n * @return {HTMLDivElement}\n */\n getViewportRoot: function () {\n return this._domRoot;\n },\n\n getViewportRootOffset: function () {\n var viewportRoot = this.getViewportRoot();\n if (viewportRoot) {\n return {\n offsetLeft: viewportRoot.offsetLeft || 0,\n offsetTop: viewportRoot.offsetTop || 0\n };\n }\n },\n\n /**\n * 刷新\n * @param {boolean} [paintAll=false] 强制绘制所有displayable\n */\n refresh: function (paintAll) {\n\n var list = this.storage.getDisplayList(true);\n\n var zlevelList = this._zlevelList;\n\n this._redrawId = Math.random();\n\n this._paintList(list, paintAll, this._redrawId);\n\n // Paint custum layers\n for (var i = 0; i < zlevelList.length; i++) {\n var z = zlevelList[i];\n var layer = this._layers[z];\n if (!layer.__builtin__ && layer.refresh) {\n var clearColor = i === 0 ? this._backgroundColor : null;\n layer.refresh(clearColor);\n }\n }\n\n this.refreshHover();\n\n return this;\n },\n\n addHover: function (el, hoverStyle) {\n if (el.__hoverMir) {\n return;\n }\n var elMirror = new el.constructor({\n style: el.style,\n shape: el.shape,\n z: el.z,\n z2: el.z2,\n silent: el.silent\n });\n elMirror.__from = el;\n el.__hoverMir = elMirror;\n hoverStyle && elMirror.setStyle(hoverStyle);\n this._hoverElements.push(elMirror);\n\n return elMirror;\n },\n\n removeHover: function (el) {\n var elMirror = el.__hoverMir;\n var hoverElements = this._hoverElements;\n var idx = util.indexOf(hoverElements, elMirror);\n if (idx >= 0) {\n hoverElements.splice(idx, 1);\n }\n el.__hoverMir = null;\n },\n\n clearHover: function (el) {\n var hoverElements = this._hoverElements;\n for (var i = 0; i < hoverElements.length; i++) {\n var from = hoverElements[i].__from;\n if (from) {\n from.__hoverMir = null;\n }\n }\n hoverElements.length = 0;\n },\n\n refreshHover: function () {\n var hoverElements = this._hoverElements;\n var len = hoverElements.length;\n var hoverLayer = this._hoverlayer;\n hoverLayer && hoverLayer.clear();\n\n if (!len) {\n return;\n }\n timsort(hoverElements, this.storage.displayableSortFunc);\n\n // Use a extream large zlevel\n // FIXME?\n if (!hoverLayer) {\n hoverLayer = this._hoverlayer = this.getLayer(HOVER_LAYER_ZLEVEL);\n }\n\n var scope = {};\n hoverLayer.ctx.save();\n for (var i = 0; i < len;) {\n var el = hoverElements[i];\n var originalEl = el.__from;\n // Original el is removed\n // PENDING\n if (!(originalEl && originalEl.__zr)) {\n hoverElements.splice(i, 1);\n originalEl.__hoverMir = null;\n len--;\n continue;\n }\n i++;\n\n // Use transform\n // FIXME style and shape ?\n if (!originalEl.invisible) {\n el.transform = originalEl.transform;\n el.invTransform = originalEl.invTransform;\n el.__clipPaths = originalEl.__clipPaths;\n // el.\n this._doPaintEl(el, hoverLayer, true, scope);\n }\n }\n\n hoverLayer.ctx.restore();\n },\n\n getHoverLayer: function () {\n return this.getLayer(HOVER_LAYER_ZLEVEL);\n },\n\n _paintList: function (list, paintAll, redrawId) {\n if (this._redrawId !== redrawId) {\n return;\n }\n\n paintAll = paintAll || false;\n\n this._updateLayerStatus(list);\n\n var finished = this._doPaintList(list, paintAll);\n\n if (this._needsManuallyCompositing) {\n this._compositeManually();\n }\n\n if (!finished) {\n var self = this;\n requestAnimationFrame(function () {\n self._paintList(list, paintAll, redrawId);\n });\n }\n },\n\n _compositeManually: function () {\n var ctx = this.getLayer(CANVAS_ZLEVEL).ctx;\n var width = this._domRoot.width;\n var height = this._domRoot.height;\n ctx.clearRect(0, 0, width, height);\n // PENDING, If only builtin layer?\n this.eachBuiltinLayer(function (layer) {\n if (layer.virtual) {\n ctx.drawImage(layer.dom, 0, 0, width, height);\n }\n });\n },\n\n _doPaintList: function (list, paintAll) {\n var layerList = [];\n for (var zi = 0; zi < this._zlevelList.length; zi++) {\n var zlevel = this._zlevelList[zi];\n var layer = this._layers[zlevel];\n if (layer.__builtin__\n && layer !== this._hoverlayer\n && (layer.__dirty || paintAll)\n ) {\n layerList.push(layer);\n }\n }\n\n var finished = true;\n\n for (var k = 0; k < layerList.length; k++) {\n var layer = layerList[k];\n var ctx = layer.ctx;\n var scope = {};\n ctx.save();\n\n var start = paintAll ? layer.__startIndex : layer.__drawIndex;\n\n var useTimer = !paintAll && layer.incremental && Date.now;\n var startTime = useTimer && Date.now();\n\n var clearColor = layer.zlevel === this._zlevelList[0]\n ? this._backgroundColor : null;\n // All elements in this layer are cleared.\n if (layer.__startIndex === layer.__endIndex) {\n layer.clear(false, clearColor);\n }\n else if (start === layer.__startIndex) {\n var firstEl = list[start];\n if (!firstEl.incremental || !firstEl.notClear || paintAll) {\n layer.clear(false, clearColor);\n }\n }\n if (start === -1) {\n console.error('For some unknown reason. drawIndex is -1');\n start = layer.__startIndex;\n }\n for (var i = start; i < layer.__endIndex; i++) {\n var el = list[i];\n this._doPaintEl(el, layer, paintAll, scope);\n el.__dirty = el.__dirtyText = false;\n\n if (useTimer) {\n // Date.now can be executed in 13,025,305 ops/second.\n var dTime = Date.now() - startTime;\n // Give 15 millisecond to draw.\n // The rest elements will be drawn in the next frame.\n if (dTime > 15) {\n break;\n }\n }\n }\n\n layer.__drawIndex = i;\n\n if (layer.__drawIndex < layer.__endIndex) {\n finished = false;\n }\n\n if (scope.prevElClipPaths) {\n // Needs restore the state. If last drawn element is in the clipping area.\n ctx.restore();\n }\n\n ctx.restore();\n }\n\n if (env.wxa) {\n // Flush for weixin application\n util.each(this._layers, function (layer) {\n if (layer && layer.ctx && layer.ctx.draw) {\n layer.ctx.draw();\n }\n });\n }\n\n return finished;\n },\n\n _doPaintEl: function (el, currentLayer, forcePaint, scope) {\n var ctx = currentLayer.ctx;\n var m = el.transform;\n if (\n (currentLayer.__dirty || forcePaint)\n // Ignore invisible element\n && !el.invisible\n // Ignore transparent element\n && el.style.opacity !== 0\n // Ignore scale 0 element, in some environment like node-canvas\n // Draw a scale 0 element can cause all following draw wrong\n // And setTransform with scale 0 will cause set back transform failed.\n && !(m && !m[0] && !m[3])\n // Ignore culled element\n && !(el.culling && isDisplayableCulled(el, this._width, this._height))\n ) {\n\n var clipPaths = el.__clipPaths;\n var prevElClipPaths = scope.prevElClipPaths;\n\n // Optimize when clipping on group with several elements\n if (!prevElClipPaths || isClipPathChanged(clipPaths, prevElClipPaths)) {\n // If has previous clipping state, restore from it\n if (prevElClipPaths) {\n ctx.restore();\n scope.prevElClipPaths = null;\n // Reset prevEl since context has been restored\n scope.prevEl = null;\n }\n // New clipping state\n if (clipPaths) {\n ctx.save();\n doClip(clipPaths, ctx);\n scope.prevElClipPaths = clipPaths;\n }\n }\n el.beforeBrush && el.beforeBrush(ctx);\n\n el.brush(ctx, scope.prevEl || null);\n scope.prevEl = el;\n\n el.afterBrush && el.afterBrush(ctx);\n }\n },\n\n /**\n * 获取 zlevel 所在层,如果不存在则会创建一个新的层\n * @param {number} zlevel\n * @param {boolean} virtual Virtual layer will not be inserted into dom.\n * @return {module:zrender/Layer}\n */\n getLayer: function (zlevel, virtual) {\n if (this._singleCanvas && !this._needsManuallyCompositing) {\n zlevel = CANVAS_ZLEVEL;\n }\n var layer = this._layers[zlevel];\n if (!layer) {\n // Create a new layer\n layer = new Layer('zr_' + zlevel, this, this.dpr);\n layer.zlevel = zlevel;\n layer.__builtin__ = true;\n\n if (this._layerConfig[zlevel]) {\n util.merge(layer, this._layerConfig[zlevel], true);\n }\n // TODO Remove EL_AFTER_INCREMENTAL_INC magic number\n else if (this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC]) {\n util.merge(layer, this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC], true);\n }\n\n if (virtual) {\n layer.virtual = virtual;\n }\n\n this.insertLayer(zlevel, layer);\n\n // Context is created after dom inserted to document\n // Or excanvas will get 0px clientWidth and clientHeight\n layer.initContext();\n }\n\n return layer;\n },\n\n insertLayer: function (zlevel, layer) {\n\n var layersMap = this._layers;\n var zlevelList = this._zlevelList;\n var len = zlevelList.length;\n var prevLayer = null;\n var i = -1;\n var domRoot = this._domRoot;\n\n if (layersMap[zlevel]) {\n logError('ZLevel ' + zlevel + ' has been used already');\n return;\n }\n // Check if is a valid layer\n if (!isLayerValid(layer)) {\n logError('Layer of zlevel ' + zlevel + ' is not valid');\n return;\n }\n\n if (len > 0 && zlevel > zlevelList[0]) {\n for (i = 0; i < len - 1; i++) {\n if (\n zlevelList[i] < zlevel\n && zlevelList[i + 1] > zlevel\n ) {\n break;\n }\n }\n prevLayer = layersMap[zlevelList[i]];\n }\n zlevelList.splice(i + 1, 0, zlevel);\n\n layersMap[zlevel] = layer;\n\n // Vitual layer will not directly show on the screen.\n // (It can be a WebGL layer and assigned to a ZImage element)\n // But it still under management of zrender.\n if (!layer.virtual) {\n if (prevLayer) {\n var prevDom = prevLayer.dom;\n if (prevDom.nextSibling) {\n domRoot.insertBefore(\n layer.dom,\n prevDom.nextSibling\n );\n }\n else {\n domRoot.appendChild(layer.dom);\n }\n }\n else {\n if (domRoot.firstChild) {\n domRoot.insertBefore(layer.dom, domRoot.firstChild);\n }\n else {\n domRoot.appendChild(layer.dom);\n }\n }\n }\n },\n\n // Iterate each layer\n eachLayer: function (cb, context) {\n var zlevelList = this._zlevelList;\n var z;\n var i;\n for (i = 0; i < zlevelList.length; i++) {\n z = zlevelList[i];\n cb.call(context, this._layers[z], z);\n }\n },\n\n // Iterate each buildin layer\n eachBuiltinLayer: function (cb, context) {\n var zlevelList = this._zlevelList;\n var layer;\n var z;\n var i;\n for (i = 0; i < zlevelList.length; i++) {\n z = zlevelList[i];\n layer = this._layers[z];\n if (layer.__builtin__) {\n cb.call(context, layer, z);\n }\n }\n },\n\n // Iterate each other layer except buildin layer\n eachOtherLayer: function (cb, context) {\n var zlevelList = this._zlevelList;\n var layer;\n var z;\n var i;\n for (i = 0; i < zlevelList.length; i++) {\n z = zlevelList[i];\n layer = this._layers[z];\n if (!layer.__builtin__) {\n cb.call(context, layer, z);\n }\n }\n },\n\n /**\n * 获取所有已创建的层\n * @param {Array.<module:zrender/Layer>} [prevLayer]\n */\n getLayers: function () {\n return this._layers;\n },\n\n _updateLayerStatus: function (list) {\n\n this.eachBuiltinLayer(function (layer, z) {\n layer.__dirty = layer.__used = false;\n });\n\n function updatePrevLayer(idx) {\n if (prevLayer) {\n if (prevLayer.__endIndex !== idx) {\n prevLayer.__dirty = true;\n }\n prevLayer.__endIndex = idx;\n }\n }\n\n if (this._singleCanvas) {\n for (var i = 1; i < list.length; i++) {\n var el = list[i];\n if (el.zlevel !== list[i - 1].zlevel || el.incremental) {\n this._needsManuallyCompositing = true;\n break;\n }\n }\n }\n\n var prevLayer = null;\n var incrementalLayerCount = 0;\n var prevZlevel;\n for (var i = 0; i < list.length; i++) {\n var el = list[i];\n var zlevel = el.zlevel;\n var layer;\n\n if (prevZlevel !== zlevel) {\n prevZlevel = zlevel;\n incrementalLayerCount = 0;\n }\n\n // TODO Not use magic number on zlevel.\n\n // Each layer with increment element can be separated to 3 layers.\n // (Other Element drawn after incremental element)\n // -----------------zlevel + EL_AFTER_INCREMENTAL_INC--------------------\n // (Incremental element)\n // ----------------------zlevel + INCREMENTAL_INC------------------------\n // (Element drawn before incremental element)\n // --------------------------------zlevel--------------------------------\n if (el.incremental) {\n layer = this.getLayer(zlevel + INCREMENTAL_INC, this._needsManuallyCompositing);\n layer.incremental = true;\n incrementalLayerCount = 1;\n }\n else {\n layer = this.getLayer(\n zlevel + (incrementalLayerCount > 0 ? EL_AFTER_INCREMENTAL_INC : 0),\n this._needsManuallyCompositing\n );\n }\n\n if (!layer.__builtin__) {\n logError('ZLevel ' + zlevel + ' has been used by unkown layer ' + layer.id);\n }\n\n if (layer !== prevLayer) {\n layer.__used = true;\n if (layer.__startIndex !== i) {\n layer.__dirty = true;\n }\n layer.__startIndex = i;\n if (!layer.incremental) {\n layer.__drawIndex = i;\n }\n else {\n // Mark layer draw index needs to update.\n layer.__drawIndex = -1;\n }\n updatePrevLayer(i);\n prevLayer = layer;\n }\n if (el.__dirty) {\n layer.__dirty = true;\n if (layer.incremental && layer.__drawIndex < 0) {\n // Start draw from the first dirty element.\n layer.__drawIndex = i;\n }\n }\n }\n\n updatePrevLayer(i);\n\n this.eachBuiltinLayer(function (layer, z) {\n // Used in last frame but not in this frame. Needs clear\n if (!layer.__used && layer.getElementCount() > 0) {\n layer.__dirty = true;\n layer.__startIndex = layer.__endIndex = layer.__drawIndex = 0;\n }\n // For incremental layer. In case start index changed and no elements are dirty.\n if (layer.__dirty && layer.__drawIndex < 0) {\n layer.__drawIndex = layer.__startIndex;\n }\n });\n },\n\n /**\n * 清除hover层外所有内容\n */\n clear: function () {\n this.eachBuiltinLayer(this._clearLayer);\n return this;\n },\n\n _clearLayer: function (layer) {\n layer.clear();\n },\n\n setBackgroundColor: function (backgroundColor) {\n this._backgroundColor = backgroundColor;\n },\n\n /**\n * 修改指定zlevel的绘制参数\n *\n * @param {string} zlevel\n * @param {Object} config 配置对象\n * @param {string} [config.clearColor=0] 每次清空画布的颜色\n * @param {string} [config.motionBlur=false] 是否开启动态模糊\n * @param {number} [config.lastFrameAlpha=0.7]\n * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显\n */\n configLayer: function (zlevel, config) {\n if (config) {\n var layerConfig = this._layerConfig;\n if (!layerConfig[zlevel]) {\n layerConfig[zlevel] = config;\n }\n else {\n util.merge(layerConfig[zlevel], config, true);\n }\n\n for (var i = 0; i < this._zlevelList.length; i++) {\n var _zlevel = this._zlevelList[i];\n // TODO Remove EL_AFTER_INCREMENTAL_INC magic number\n if (_zlevel === zlevel || _zlevel === zlevel + EL_AFTER_INCREMENTAL_INC) {\n var layer = this._layers[_zlevel];\n util.merge(layer, layerConfig[zlevel], true);\n }\n }\n }\n },\n\n /**\n * 删除指定层\n * @param {number} zlevel 层所在的zlevel\n */\n delLayer: function (zlevel) {\n var layers = this._layers;\n var zlevelList = this._zlevelList;\n var layer = layers[zlevel];\n if (!layer) {\n return;\n }\n layer.dom.parentNode.removeChild(layer.dom);\n delete layers[zlevel];\n\n zlevelList.splice(util.indexOf(zlevelList, zlevel), 1);\n },\n\n /**\n * 区域大小变化后重绘\n */\n resize: function (width, height) {\n if (!this._domRoot.style) { // Maybe in node or worker\n if (width == null || height == null) {\n return;\n }\n this._width = width;\n this._height = height;\n\n this.getLayer(CANVAS_ZLEVEL).resize(width, height);\n }\n else {\n var domRoot = this._domRoot;\n // FIXME Why ?\n domRoot.style.display = 'none';\n\n // Save input w/h\n var opts = this._opts;\n width != null && (opts.width = width);\n height != null && (opts.height = height);\n\n width = this._getSize(0);\n height = this._getSize(1);\n\n domRoot.style.display = '';\n\n // 优化没有实际改变的resize\n if (this._width !== width || height !== this._height) {\n domRoot.style.width = width + 'px';\n domRoot.style.height = height + 'px';\n\n for (var id in this._layers) {\n if (this._layers.hasOwnProperty(id)) {\n this._layers[id].resize(width, height);\n }\n }\n util.each(this._progressiveLayers, function (layer) {\n layer.resize(width, height);\n });\n\n this.refresh(true);\n }\n\n this._width = width;\n this._height = height;\n\n }\n return this;\n },\n\n /**\n * 清除单独的一个层\n * @param {number} zlevel\n */\n clearLayer: function (zlevel) {\n var layer = this._layers[zlevel];\n if (layer) {\n layer.clear();\n }\n },\n\n /**\n * 释放\n */\n dispose: function () {\n this.root.innerHTML = '';\n\n this.root =\n this.storage =\n\n this._domRoot =\n this._layers = null;\n },\n\n /**\n * Get canvas which has all thing rendered\n * @param {Object} opts\n * @param {string} [opts.backgroundColor]\n * @param {number} [opts.pixelRatio]\n */\n getRenderedCanvas: function (opts) {\n opts = opts || {};\n if (this._singleCanvas && !this._compositeManually) {\n return this._layers[CANVAS_ZLEVEL].dom;\n }\n\n var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);\n imageLayer.initContext();\n imageLayer.clear(false, opts.backgroundColor || this._backgroundColor);\n\n if (opts.pixelRatio <= this.dpr) {\n this.refresh();\n\n var width = imageLayer.dom.width;\n var height = imageLayer.dom.height;\n var ctx = imageLayer.ctx;\n this.eachLayer(function (layer) {\n if (layer.__builtin__) {\n ctx.drawImage(layer.dom, 0, 0, width, height);\n }\n else if (layer.renderToCanvas) {\n imageLayer.ctx.save();\n layer.renderToCanvas(imageLayer.ctx);\n imageLayer.ctx.restore();\n }\n });\n }\n else {\n // PENDING, echarts-gl and incremental rendering.\n var scope = {};\n var displayList = this.storage.getDisplayList(true);\n for (var i = 0; i < displayList.length; i++) {\n var el = displayList[i];\n this._doPaintEl(el, imageLayer, true, scope);\n }\n }\n\n return imageLayer.dom;\n },\n /**\n * 获取绘图区域宽度\n */\n getWidth: function () {\n return this._width;\n },\n\n /**\n * 获取绘图区域高度\n */\n getHeight: function () {\n return this._height;\n },\n\n _getSize: function (whIdx) {\n var opts = this._opts;\n var wh = ['width', 'height'][whIdx];\n var cwh = ['clientWidth', 'clientHeight'][whIdx];\n var plt = ['paddingLeft', 'paddingTop'][whIdx];\n var prb = ['paddingRight', 'paddingBottom'][whIdx];\n\n if (opts[wh] != null && opts[wh] !== 'auto') {\n return parseFloat(opts[wh]);\n }\n\n var root = this.root;\n // IE8 does not support getComputedStyle, but it use VML.\n var stl = document.defaultView.getComputedStyle(root);\n\n return (\n (root[cwh] || parseInt10(stl[wh]) || parseInt10(root.style[wh]))\n - (parseInt10(stl[plt]) || 0)\n - (parseInt10(stl[prb]) || 0)\n ) | 0;\n },\n\n pathToImage: function (path, dpr) {\n dpr = dpr || this.dpr;\n\n var canvas = document.createElement('canvas');\n var ctx = canvas.getContext('2d');\n var rect = path.getBoundingRect();\n var style = path.style;\n var shadowBlurSize = style.shadowBlur * dpr;\n var shadowOffsetX = style.shadowOffsetX * dpr;\n var shadowOffsetY = style.shadowOffsetY * dpr;\n var lineWidth = style.hasStroke() ? style.lineWidth : 0;\n\n var leftMargin = Math.max(lineWidth / 2, -shadowOffsetX + shadowBlurSize);\n var rightMargin = Math.max(lineWidth / 2, shadowOffsetX + shadowBlurSize);\n var topMargin = Math.max(lineWidth / 2, -shadowOffsetY + shadowBlurSize);\n var bottomMargin = Math.max(lineWidth / 2, shadowOffsetY + shadowBlurSize);\n var width = rect.width + leftMargin + rightMargin;\n var height = rect.height + topMargin + bottomMargin;\n\n canvas.width = width * dpr;\n canvas.height = height * dpr;\n\n ctx.scale(dpr, dpr);\n ctx.clearRect(0, 0, width, height);\n ctx.dpr = dpr;\n\n var pathTransform = {\n position: path.position,\n rotation: path.rotation,\n scale: path.scale\n };\n path.position = [leftMargin - rect.x, topMargin - rect.y];\n path.rotation = 0;\n path.scale = [1, 1];\n path.updateTransform();\n if (path) {\n path.brush(ctx);\n }\n\n var ImageShape = Image;\n var imgShape = new ImageShape({\n style: {\n x: 0,\n y: 0,\n image: canvas\n }\n });\n\n if (pathTransform.position != null) {\n imgShape.position = path.position = pathTransform.position;\n }\n\n if (pathTransform.rotation != null) {\n imgShape.rotation = path.rotation = pathTransform.rotation;\n }\n\n if (pathTransform.scale != null) {\n imgShape.scale = path.scale = pathTransform.scale;\n }\n\n return imgShape;\n }\n};\n\nexport default Painter;","/**\n * Animation main class, dispatch and manage all animation controllers\n *\n * @module zrender/animation/Animation\n * @author pissang(https://github.com/pissang)\n */\n// TODO Additive animation\n// http://iosoteric.com/additive-animations-animatewithduration-in-ios-8/\n// https://developer.apple.com/videos/wwdc2014/#236\n\nimport * as util from '../core/util';\nimport {Dispatcher} from '../core/event';\nimport requestAnimationFrame from './requestAnimationFrame';\nimport Animator from './Animator';\n\n/**\n * @typedef {Object} IZRenderStage\n * @property {Function} update\n */\n\n/**\n * @alias module:zrender/animation/Animation\n * @constructor\n * @param {Object} [options]\n * @param {Function} [options.onframe]\n * @param {IZRenderStage} [options.stage]\n * @example\n * var animation = new Animation();\n * var obj = {\n * x: 100,\n * y: 100\n * };\n * animation.animate(node.position)\n * .when(1000, {\n * x: 500,\n * y: 500\n * })\n * .when(2000, {\n * x: 100,\n * y: 100\n * })\n * .start('spline');\n */\nvar Animation = function (options) {\n\n options = options || {};\n\n this.stage = options.stage || {};\n\n this.onframe = options.onframe || function () {};\n\n // private properties\n this._clips = [];\n\n this._running = false;\n\n this._time;\n\n this._pausedTime;\n\n this._pauseStart;\n\n this._paused = false;\n\n Dispatcher.call(this);\n};\n\nAnimation.prototype = {\n\n constructor: Animation,\n /**\n * Add clip\n * @param {module:zrender/animation/Clip} clip\n */\n addClip: function (clip) {\n this._clips.push(clip);\n },\n /**\n * Add animator\n * @param {module:zrender/animation/Animator} animator\n */\n addAnimator: function (animator) {\n animator.animation = this;\n var clips = animator.getClips();\n for (var i = 0; i < clips.length; i++) {\n this.addClip(clips[i]);\n }\n },\n /**\n * Delete animation clip\n * @param {module:zrender/animation/Clip} clip\n */\n removeClip: function (clip) {\n var idx = util.indexOf(this._clips, clip);\n if (idx >= 0) {\n this._clips.splice(idx, 1);\n }\n },\n\n /**\n * Delete animation clip\n * @param {module:zrender/animation/Animator} animator\n */\n removeAnimator: function (animator) {\n var clips = animator.getClips();\n for (var i = 0; i < clips.length; i++) {\n this.removeClip(clips[i]);\n }\n animator.animation = null;\n },\n\n _update: function () {\n var time = new Date().getTime() - this._pausedTime;\n var delta = time - this._time;\n var clips = this._clips;\n var len = clips.length;\n\n var deferredEvents = [];\n var deferredClips = [];\n for (var i = 0; i < len; i++) {\n var clip = clips[i];\n var e = clip.step(time, delta);\n // Throw out the events need to be called after\n // stage.update, like destroy\n if (e) {\n deferredEvents.push(e);\n deferredClips.push(clip);\n }\n }\n\n // Remove the finished clip\n for (var i = 0; i < len;) {\n if (clips[i]._needsRemove) {\n clips[i] = clips[len - 1];\n clips.pop();\n len--;\n }\n else {\n i++;\n }\n }\n\n len = deferredEvents.length;\n for (var i = 0; i < len; i++) {\n deferredClips[i].fire(deferredEvents[i]);\n }\n\n this._time = time;\n\n this.onframe(delta);\n\n // 'frame' should be triggered before stage, because upper application\n // depends on the sequence (e.g., echarts-stream and finish\n // event judge)\n this.trigger('frame', delta);\n\n if (this.stage.update) {\n this.stage.update();\n }\n },\n\n _startLoop: function () {\n var self = this;\n\n this._running = true;\n\n function step() {\n if (self._running) {\n\n requestAnimationFrame(step);\n\n !self._paused && self._update();\n }\n }\n\n requestAnimationFrame(step);\n },\n\n /**\n * Start animation.\n */\n start: function () {\n\n this._time = new Date().getTime();\n this._pausedTime = 0;\n\n this._startLoop();\n },\n\n /**\n * Stop animation.\n */\n stop: function () {\n this._running = false;\n },\n\n /**\n * Pause animation.\n */\n pause: function () {\n if (!this._paused) {\n this._pauseStart = new Date().getTime();\n this._paused = true;\n }\n },\n\n /**\n * Resume animation.\n */\n resume: function () {\n if (this._paused) {\n this._pausedTime += (new Date().getTime()) - this._pauseStart;\n this._paused = false;\n }\n },\n\n /**\n * Clear animation.\n */\n clear: function () {\n this._clips = [];\n },\n\n /**\n * Whether animation finished.\n */\n isFinished: function () {\n return !this._clips.length;\n },\n\n /**\n * Creat animator for a target, whose props can be animated.\n *\n * @param {Object} target\n * @param {Object} options\n * @param {boolean} [options.loop=false] Whether loop animation.\n * @param {Function} [options.getter=null] Get value from target.\n * @param {Function} [options.setter=null] Set value to target.\n * @return {module:zrender/animation/Animation~Animator}\n */\n // TODO Gap\n animate: function (target, options) {\n options = options || {};\n\n var animator = new Animator(\n target,\n options.loop,\n options.getter,\n options.setter\n );\n\n this.addAnimator(animator);\n\n return animator;\n }\n};\n\nutil.mixin(Animation, Dispatcher);\n\nexport default Animation;","\n/* global document */\n\nimport {\n addEventListener,\n removeEventListener,\n normalizeEvent,\n getNativeEvent\n} from '../core/event';\nimport * as zrUtil from '../core/util';\nimport Eventful from '../mixin/Eventful';\nimport env from '../core/env';\n\nvar TOUCH_CLICK_DELAY = 300;\n\nvar globalEventSupported = env.domSupported;\n\n\nvar localNativeListenerNames = (function () {\n var mouseHandlerNames = [\n 'click', 'dblclick', 'mousewheel', 'mouseout',\n 'mouseup', 'mousedown', 'mousemove', 'contextmenu'\n ];\n var touchHandlerNames = [\n 'touchstart', 'touchend', 'touchmove'\n ];\n var pointerEventNameMap = {\n pointerdown: 1, pointerup: 1, pointermove: 1, pointerout: 1\n };\n var pointerHandlerNames = zrUtil.map(mouseHandlerNames, function (name) {\n var nm = name.replace('mouse', 'pointer');\n return pointerEventNameMap.hasOwnProperty(nm) ? nm : name;\n });\n\n return {\n mouse: mouseHandlerNames,\n touch: touchHandlerNames,\n pointer: pointerHandlerNames\n };\n})();\n\nvar globalNativeListenerNames = {\n mouse: ['mousemove', 'mouseup'],\n pointer: ['pointermove', 'pointerup']\n};\n\n\nfunction eventNameFix(name) {\n return (name === 'mousewheel' && env.browser.firefox) ? 'DOMMouseScroll' : name;\n}\n\nfunction isPointerFromTouch(event) {\n var pointerType = event.pointerType;\n return pointerType === 'pen' || pointerType === 'touch';\n}\n\n// function useMSGuesture(handlerProxy, event) {\n// return isPointerFromTouch(event) && !!handlerProxy._msGesture;\n// }\n\n// function onMSGestureChange(proxy, event) {\n// if (event.translationX || event.translationY) {\n// // mousemove is carried by MSGesture to reduce the sensitivity.\n// proxy.handler.dispatchToElement(event.target, 'mousemove', event);\n// }\n// if (event.scale !== 1) {\n// event.pinchX = event.offsetX;\n// event.pinchY = event.offsetY;\n// event.pinchScale = event.scale;\n// proxy.handler.dispatchToElement(event.target, 'pinch', event);\n// }\n// }\n\n/**\n * Prevent mouse event from being dispatched after Touch Events action\n * @see <https://github.com/deltakosh/handjs/blob/master/src/hand.base.js>\n * 1. Mobile browsers dispatch mouse events 300ms after touchend.\n * 2. Chrome for Android dispatch mousedown for long-touch about 650ms\n * Result: Blocking Mouse Events for 700ms.\n *\n * @param {DOMHandlerScope} scope\n */\nfunction setTouchTimer(scope) {\n scope.touching = true;\n if (scope.touchTimer != null) {\n clearTimeout(scope.touchTimer);\n scope.touchTimer = null;\n }\n scope.touchTimer = setTimeout(function () {\n scope.touching = false;\n scope.touchTimer = null;\n }, 700);\n}\n\n// Mark touch, which is useful in distinguish touch and\n// mouse event in upper applicatoin.\nfunction markTouch(event) {\n event && (event.zrByTouch = true);\n}\n\n\n// function markTriggeredFromLocal(event) {\n// event && (event.__zrIsFromLocal = true);\n// }\n\n// function isTriggeredFromLocal(instance, event) {\n// return !!(event && event.__zrIsFromLocal);\n// }\n\nfunction normalizeGlobalEvent(instance, event) {\n // offsetX, offsetY still need to be calculated. They are necessary in the event\n // handlers of the upper applications. Set `true` to force calculate them.\n return normalizeEvent(instance.dom, new FakeGlobalEvent(instance, event), true);\n}\n\n/**\n * Detect whether the given el is in `painterRoot`.\n */\nfunction isLocalEl(instance, el) {\n var elTmp = el;\n var isLocal = false;\n while (elTmp && elTmp.nodeType !== 9\n && !(\n isLocal = elTmp.domBelongToZr\n || (elTmp !== el && elTmp === instance.painterRoot)\n )\n ) {\n elTmp = elTmp.parentNode;\n }\n return isLocal;\n}\n\n/**\n * Make a fake event but not change the original event,\n * becuase the global event probably be used by other\n * listeners not belonging to zrender.\n * @class\n */\nfunction FakeGlobalEvent(instance, event) {\n this.type = event.type;\n this.target = this.currentTarget = instance.dom;\n this.pointerType = event.pointerType;\n // Necessray for the force calculation of zrX, zrY\n this.clientX = event.clientX;\n this.clientY = event.clientY;\n // Because we do not mount global listeners to touch events,\n // we do not copy `targetTouches` and `changedTouches` here.\n}\nvar fakeGlobalEventProto = FakeGlobalEvent.prototype;\n// we make the default methods on the event do nothing,\n// otherwise it is dangerous. See more details in\n// [Drag outside] in `Handler.js`.\nfakeGlobalEventProto.stopPropagation =\n fakeGlobalEventProto.stopImmediatePropagation =\n fakeGlobalEventProto.preventDefault = zrUtil.noop;\n\n\n/**\n * Local DOM Handlers\n * @this {HandlerProxy}\n */\nvar localDOMHandlers = {\n\n mousedown: function (event) {\n event = normalizeEvent(this.dom, event);\n\n this._mayPointerCapture = [event.zrX, event.zrY];\n\n this.trigger('mousedown', event);\n },\n\n mousemove: function (event) {\n event = normalizeEvent(this.dom, event);\n\n var downPoint = this._mayPointerCapture;\n if (downPoint && (event.zrX !== downPoint[0] || event.zrY !== downPoint[1])) {\n togglePointerCapture(this, true);\n }\n\n this.trigger('mousemove', event);\n },\n\n mouseup: function (event) {\n event = normalizeEvent(this.dom, event);\n\n togglePointerCapture(this, false);\n\n this.trigger('mouseup', event);\n },\n\n mouseout: function (event) {\n event = normalizeEvent(this.dom, event);\n\n // Similarly to the browser did on `document` and touch event,\n // `globalout` will be delayed to final pointer cature release.\n if (this._pointerCapturing) {\n event.zrEventControl = 'no_globalout';\n }\n\n // There might be some doms created by upper layer application\n // at the same level of painter.getViewportRoot() (e.g., tooltip\n // dom created by echarts), where 'globalout' event should not\n // be triggered when mouse enters these doms. (But 'mouseout'\n // should be triggered at the original hovered element as usual).\n var element = event.toElement || event.relatedTarget;\n event.zrIsToLocalDOM = isLocalEl(this, element);\n\n this.trigger('mouseout', event);\n },\n\n touchstart: function (event) {\n // Default mouse behaviour should not be disabled here.\n // For example, page may needs to be slided.\n event = normalizeEvent(this.dom, event);\n\n markTouch(event);\n\n this._lastTouchMoment = new Date();\n\n this.handler.processGesture(event, 'start');\n\n // For consistent event listener for both touch device and mouse device,\n // we simulate \"mouseover-->mousedown\" in touch device. So we trigger\n // `mousemove` here (to trigger `mouseover` inside), and then trigger\n // `mousedown`.\n localDOMHandlers.mousemove.call(this, event);\n localDOMHandlers.mousedown.call(this, event);\n },\n\n touchmove: function (event) {\n event = normalizeEvent(this.dom, event);\n\n markTouch(event);\n\n this.handler.processGesture(event, 'change');\n\n // Mouse move should always be triggered no matter whether\n // there is gestrue event, because mouse move and pinch may\n // be used at the same time.\n localDOMHandlers.mousemove.call(this, event);\n },\n\n touchend: function (event) {\n event = normalizeEvent(this.dom, event);\n\n markTouch(event);\n\n this.handler.processGesture(event, 'end');\n\n localDOMHandlers.mouseup.call(this, event);\n\n // Do not trigger `mouseout` here, in spite of `mousemove`(`mouseover`) is\n // triggered in `touchstart`. This seems to be illogical, but by this mechanism,\n // we can conveniently implement \"hover style\" in both PC and touch device just\n // by listening to `mouseover` to add \"hover style\" and listening to `mouseout`\n // to remove \"hover style\" on an element, without any additional code for\n // compatibility. (`mouseout` will not be triggered in `touchend`, so \"hover\n // style\" will remain for user view)\n\n // click event should always be triggered no matter whether\n // there is gestrue event. System click can not be prevented.\n if (+new Date() - this._lastTouchMoment < TOUCH_CLICK_DELAY) {\n localDOMHandlers.click.call(this, event);\n }\n },\n\n pointerdown: function (event) {\n localDOMHandlers.mousedown.call(this, event);\n\n // if (useMSGuesture(this, event)) {\n // this._msGesture.addPointer(event.pointerId);\n // }\n },\n\n pointermove: function (event) {\n // FIXME\n // pointermove is so sensitive that it always triggered when\n // tap(click) on touch screen, which affect some judgement in\n // upper application. So, we dont support mousemove on MS touch\n // device yet.\n if (!isPointerFromTouch(event)) {\n localDOMHandlers.mousemove.call(this, event);\n }\n },\n\n pointerup: function (event) {\n localDOMHandlers.mouseup.call(this, event);\n },\n\n pointerout: function (event) {\n // pointerout will be triggered when tap on touch screen\n // (IE11+/Edge on MS Surface) after click event triggered,\n // which is inconsistent with the mousout behavior we defined\n // in touchend. So we unify them.\n // (check localDOMHandlers.touchend for detailed explanation)\n if (!isPointerFromTouch(event)) {\n localDOMHandlers.mouseout.call(this, event);\n }\n }\n\n};\n\n/**\n * Othere DOM UI Event handlers for zr dom.\n * @this {HandlerProxy}\n */\nzrUtil.each(['click', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {\n localDOMHandlers[name] = function (event) {\n event = normalizeEvent(this.dom, event);\n this.trigger(name, event);\n };\n});\n\n\n/**\n * DOM UI Event handlers for global page.\n *\n * [Caution]:\n * those handlers should both support in capture phase and bubble phase!\n *\n * @this {HandlerProxy}\n */\nvar globalDOMHandlers = {\n\n pointermove: function (event) {\n // FIXME\n // pointermove is so sensitive that it always triggered when\n // tap(click) on touch screen, which affect some judgement in\n // upper application. So, we dont support mousemove on MS touch\n // device yet.\n if (!isPointerFromTouch(event)) {\n globalDOMHandlers.mousemove.call(this, event);\n }\n },\n\n pointerup: function (event) {\n globalDOMHandlers.mouseup.call(this, event);\n },\n\n mousemove: function (event) {\n this.trigger('mousemove', event);\n },\n\n mouseup: function (event) {\n var pointerCaptureReleasing = this._pointerCapturing;\n\n togglePointerCapture(this, false);\n\n this.trigger('mouseup', event);\n\n if (pointerCaptureReleasing) {\n event.zrEventControl = 'only_globalout';\n this.trigger('mouseout', event);\n }\n }\n\n};\n\n\n/**\n * @param {HandlerProxy} instance\n * @param {DOMHandlerScope} scope\n */\nfunction mountLocalDOMEventListeners(instance, scope) {\n var domHandlers = scope.domHandlers;\n\n if (env.pointerEventsSupported) { // Only IE11+/Edge\n // 1. On devices that both enable touch and mouse (e.g., MS Surface and lenovo X240),\n // IE11+/Edge do not trigger touch event, but trigger pointer event and mouse event\n // at the same time.\n // 2. On MS Surface, it probablely only trigger mousedown but no mouseup when tap on\n // screen, which do not occurs in pointer event.\n // So we use pointer event to both detect touch gesture and mouse behavior.\n zrUtil.each(localNativeListenerNames.pointer, function (nativeEventName) {\n mountSingleDOMEventListener(scope, nativeEventName, function (event) {\n // markTriggeredFromLocal(event);\n domHandlers[nativeEventName].call(instance, event);\n });\n });\n\n // FIXME\n // Note: MS Gesture require CSS touch-action set. But touch-action is not reliable,\n // which does not prevent defuault behavior occasionally (which may cause view port\n // zoomed in but use can not zoom it back). And event.preventDefault() does not work.\n // So we have to not to use MSGesture and not to support touchmove and pinch on MS\n // touch screen. And we only support click behavior on MS touch screen now.\n\n // MS Gesture Event is only supported on IE11+/Edge and on Windows 8+.\n // We dont support touch on IE on win7.\n // See <https://msdn.microsoft.com/en-us/library/dn433243(v=vs.85).aspx>\n // if (typeof MSGesture === 'function') {\n // (this._msGesture = new MSGesture()).target = dom; // jshint ignore:line\n // dom.addEventListener('MSGestureChange', onMSGestureChange);\n // }\n }\n else {\n if (env.touchEventsSupported) {\n zrUtil.each(localNativeListenerNames.touch, function (nativeEventName) {\n mountSingleDOMEventListener(scope, nativeEventName, function (event) {\n // markTriggeredFromLocal(event);\n domHandlers[nativeEventName].call(instance, event);\n setTouchTimer(scope);\n });\n });\n // Handler of 'mouseout' event is needed in touch mode, which will be mounted below.\n // addEventListener(root, 'mouseout', this._mouseoutHandler);\n }\n\n // 1. Considering some devices that both enable touch and mouse event (like on MS Surface\n // and lenovo X240, @see #2350), we make mouse event be always listened, otherwise\n // mouse event can not be handle in those devices.\n // 2. On MS Surface, Chrome will trigger both touch event and mouse event. How to prevent\n // mouseevent after touch event triggered, see `setTouchTimer`.\n zrUtil.each(localNativeListenerNames.mouse, function (nativeEventName) {\n mountSingleDOMEventListener(scope, nativeEventName, function (event) {\n event = getNativeEvent(event);\n if (!scope.touching) {\n // markTriggeredFromLocal(event);\n domHandlers[nativeEventName].call(instance, event);\n }\n });\n });\n }\n}\n\n/**\n * @param {HandlerProxy} instance\n * @param {DOMHandlerScope} scope\n */\nfunction mountGlobalDOMEventListeners(instance, scope) {\n // Only IE11+/Edge. See the comment in `mountLocalDOMEventListeners`.\n if (env.pointerEventsSupported) {\n zrUtil.each(globalNativeListenerNames.pointer, mount);\n }\n // Touch event has implemented \"drag outside\" so we do not mount global listener for touch event.\n // (see https://www.w3.org/TR/touch-events/#the-touchmove-event)\n // We do not consider \"both-support-touch-and-mouse device\" for this feature (see the comment of\n // `mountLocalDOMEventListeners`) to avoid bugs util some requirements come.\n else if (!env.touchEventsSupported) {\n zrUtil.each(globalNativeListenerNames.mouse, mount);\n }\n\n function mount(nativeEventName) {\n function nativeEventListener(event) {\n event = getNativeEvent(event);\n // See the reason in [Drag outside] in `Handler.js`\n // This checking supports both `useCapture` or not.\n // PENDING: if there is performance issue in some devices,\n // we probably can not use `useCapture` and change a easier\n // to judes whether local (mark).\n if (!isLocalEl(instance, event.target)) {\n event = normalizeGlobalEvent(instance, event);\n scope.domHandlers[nativeEventName].call(instance, event);\n }\n }\n mountSingleDOMEventListener(\n scope, nativeEventName, nativeEventListener,\n {capture: true} // See [Drag Outside] in `Handler.js`\n );\n }\n}\n\nfunction mountSingleDOMEventListener(scope, nativeEventName, listener, opt) {\n scope.mounted[nativeEventName] = listener;\n scope.listenerOpts[nativeEventName] = opt;\n addEventListener(scope.domTarget, eventNameFix(nativeEventName), listener, opt);\n}\n\nfunction unmountDOMEventListeners(scope) {\n var mounted = scope.mounted;\n for (var nativeEventName in mounted) {\n if (mounted.hasOwnProperty(nativeEventName)) {\n removeEventListener(\n scope.domTarget, eventNameFix(nativeEventName), mounted[nativeEventName],\n scope.listenerOpts[nativeEventName]\n );\n }\n }\n scope.mounted = {};\n}\n\n/**\n * See [Drag Outside] in `Handler.js`.\n * @implement\n * @param {boolean} isPointerCapturing Should never be `null`/`undefined`.\n * `true`: start to capture pointer if it is not capturing.\n * `false`: end the capture if it is capturing.\n */\nfunction togglePointerCapture(instance, isPointerCapturing) {\n instance._mayPointerCapture = null;\n\n if (globalEventSupported && (instance._pointerCapturing ^ isPointerCapturing)) {\n instance._pointerCapturing = isPointerCapturing;\n\n var globalHandlerScope = instance._globalHandlerScope;\n isPointerCapturing\n ? mountGlobalDOMEventListeners(instance, globalHandlerScope)\n : unmountDOMEventListeners(globalHandlerScope);\n }\n}\n\n/**\n * @inner\n * @class\n */\nfunction DOMHandlerScope(domTarget, domHandlers) {\n this.domTarget = domTarget;\n this.domHandlers = domHandlers;\n\n // Key: eventName, value: mounted handler funcitons.\n // Used for unmount.\n this.mounted = {};\n this.listenerOpts = {};\n\n this.touchTimer = null;\n this.touching = false;\n}\n\n/**\n * @public\n * @class\n */\nfunction HandlerDomProxy(dom, painterRoot) {\n Eventful.call(this);\n\n this.dom = dom;\n this.painterRoot = painterRoot;\n\n this._localHandlerScope = new DOMHandlerScope(dom, localDOMHandlers);\n\n if (globalEventSupported) {\n this._globalHandlerScope = new DOMHandlerScope(document, globalDOMHandlers);\n }\n\n /**\n * @type {boolean}\n */\n this._pointerCapturing = false;\n /**\n * @type {Array.<number>} [x, y] or null.\n */\n this._mayPointerCapture = null;\n\n mountLocalDOMEventListeners(this, this._localHandlerScope);\n}\n\nvar handlerDomProxyProto = HandlerDomProxy.prototype;\n\nhandlerDomProxyProto.dispose = function () {\n unmountDOMEventListeners(this._localHandlerScope);\n if (globalEventSupported) {\n unmountDOMEventListeners(this._globalHandlerScope);\n }\n};\n\nhandlerDomProxyProto.setCursor = function (cursorStyle) {\n this.dom.style && (this.dom.style.cursor = cursorStyle || 'default');\n};\n\n\nzrUtil.mixin(HandlerDomProxy, Eventful);\n\nexport default HandlerDomProxy;\n","/*!\n* ZRender, a high performance 2d drawing library.\n*\n* Copyright (c) 2013, Baidu Inc.\n* All rights reserved.\n*\n* LICENSE\n* https://github.com/ecomfe/zrender/blob/master/LICENSE.txt\n*/\n\nimport guid from './core/guid';\nimport env from './core/env';\nimport * as zrUtil from './core/util';\nimport Handler from './Handler';\nimport Storage from './Storage';\nimport Painter from './Painter';\nimport Animation from './animation/Animation';\nimport HandlerProxy from './dom/HandlerProxy';\n\nvar useVML = !env.canvasSupported;\n\nvar painterCtors = {\n canvas: Painter\n};\n\nvar instances = {}; // ZRender实例map索引\n\n/**\n * @type {string}\n */\nexport var version = '4.3.2';\n\n/**\n * Initializing a zrender instance\n * @param {HTMLElement} dom\n * @param {Object} [opts]\n * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'\n * @param {number} [opts.devicePixelRatio]\n * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)\n * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)\n * @return {module:zrender/ZRender}\n */\nexport function init(dom, opts) {\n var zr = new ZRender(guid(), dom, opts);\n instances[zr.id] = zr;\n return zr;\n}\n\n/**\n * Dispose zrender instance\n * @param {module:zrender/ZRender} zr\n */\nexport function dispose(zr) {\n if (zr) {\n zr.dispose();\n }\n else {\n for (var key in instances) {\n if (instances.hasOwnProperty(key)) {\n instances[key].dispose();\n }\n }\n instances = {};\n }\n\n return this;\n}\n\n/**\n * Get zrender instance by id\n * @param {string} id zrender instance id\n * @return {module:zrender/ZRender}\n */\nexport function getInstance(id) {\n return instances[id];\n}\n\nexport function registerPainter(name, Ctor) {\n painterCtors[name] = Ctor;\n}\n\nfunction delInstance(id) {\n delete instances[id];\n}\n\n/**\n * @module zrender/ZRender\n */\n/**\n * @constructor\n * @alias module:zrender/ZRender\n * @param {string} id\n * @param {HTMLElement} dom\n * @param {Object} opts\n * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'\n * @param {number} [opts.devicePixelRatio]\n * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)\n * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)\n */\nvar ZRender = function (id, dom, opts) {\n\n opts = opts || {};\n\n /**\n * @type {HTMLDomElement}\n */\n this.dom = dom;\n\n /**\n * @type {string}\n */\n this.id = id;\n\n var self = this;\n var storage = new Storage();\n\n var rendererType = opts.renderer;\n // TODO WebGL\n if (useVML) {\n if (!painterCtors.vml) {\n throw new Error('You need to require \\'zrender/vml/vml\\' to support IE8');\n }\n rendererType = 'vml';\n }\n else if (!rendererType || !painterCtors[rendererType]) {\n rendererType = 'canvas';\n }\n var painter = new painterCtors[rendererType](dom, storage, opts, id);\n\n this.storage = storage;\n this.painter = painter;\n\n var handerProxy = (!env.node && !env.worker) ? new HandlerProxy(painter.getViewportRoot(), painter.root) : null;\n this.handler = new Handler(storage, painter, handerProxy, painter.root);\n\n /**\n * @type {module:zrender/animation/Animation}\n */\n this.animation = new Animation({\n stage: {\n update: zrUtil.bind(this.flush, this)\n }\n });\n this.animation.start();\n\n /**\n * @type {boolean}\n * @private\n */\n this._needsRefresh;\n\n // 修改 storage.delFromStorage, 每次删除元素之前删除动画\n // FIXME 有点ugly\n var oldDelFromStorage = storage.delFromStorage;\n var oldAddToStorage = storage.addToStorage;\n\n storage.delFromStorage = function (el) {\n oldDelFromStorage.call(storage, el);\n\n el && el.removeSelfFromZr(self);\n };\n\n storage.addToStorage = function (el) {\n oldAddToStorage.call(storage, el);\n\n el.addSelfToZr(self);\n };\n};\n\nZRender.prototype = {\n\n constructor: ZRender,\n /**\n * 获取实例唯一标识\n * @return {string}\n */\n getId: function () {\n return this.id;\n },\n\n /**\n * 添加元素\n * @param {module:zrender/Element} el\n */\n add: function (el) {\n this.storage.addRoot(el);\n this._needsRefresh = true;\n },\n\n /**\n * 删除元素\n * @param {module:zrender/Element} el\n */\n remove: function (el) {\n this.storage.delRoot(el);\n this._needsRefresh = true;\n },\n\n /**\n * Change configuration of layer\n * @param {string} zLevel\n * @param {Object} config\n * @param {string} [config.clearColor=0] Clear color\n * @param {string} [config.motionBlur=false] If enable motion blur\n * @param {number} [config.lastFrameAlpha=0.7] Motion blur factor. Larger value cause longer trailer\n */\n configLayer: function (zLevel, config) {\n if (this.painter.configLayer) {\n this.painter.configLayer(zLevel, config);\n }\n this._needsRefresh = true;\n },\n\n /**\n * Set background color\n * @param {string} backgroundColor\n */\n setBackgroundColor: function (backgroundColor) {\n if (this.painter.setBackgroundColor) {\n this.painter.setBackgroundColor(backgroundColor);\n }\n this._needsRefresh = true;\n },\n\n /**\n * Repaint the canvas immediately\n */\n refreshImmediately: function () {\n // var start = new Date();\n\n // Clear needsRefresh ahead to avoid something wrong happens in refresh\n // Or it will cause zrender refreshes again and again.\n this._needsRefresh = this._needsRefreshHover = false;\n this.painter.refresh();\n // Avoid trigger zr.refresh in Element#beforeUpdate hook\n this._needsRefresh = this._needsRefreshHover = false;\n\n // var end = new Date();\n // var log = document.getElementById('log');\n // if (log) {\n // log.innerHTML = log.innerHTML + '<br>' + (end - start);\n // }\n },\n\n /**\n * Mark and repaint the canvas in the next frame of browser\n */\n refresh: function () {\n this._needsRefresh = true;\n },\n\n /**\n * Perform all refresh\n */\n flush: function () {\n var triggerRendered;\n\n if (this._needsRefresh) {\n triggerRendered = true;\n this.refreshImmediately();\n }\n if (this._needsRefreshHover) {\n triggerRendered = true;\n this.refreshHoverImmediately();\n }\n\n triggerRendered && this.trigger('rendered');\n },\n\n /**\n * Add element to hover layer\n * @param {module:zrender/Element} el\n * @param {Object} style\n */\n addHover: function (el, style) {\n if (this.painter.addHover) {\n var elMirror = this.painter.addHover(el, style);\n this.refreshHover();\n return elMirror;\n }\n },\n\n /**\n * Add element from hover layer\n * @param {module:zrender/Element} el\n */\n removeHover: function (el) {\n if (this.painter.removeHover) {\n this.painter.removeHover(el);\n this.refreshHover();\n }\n },\n\n /**\n * Clear all hover elements in hover layer\n * @param {module:zrender/Element} el\n */\n clearHover: function () {\n if (this.painter.clearHover) {\n this.painter.clearHover();\n this.refreshHover();\n }\n },\n\n /**\n * Refresh hover in next frame\n */\n refreshHover: function () {\n this._needsRefreshHover = true;\n },\n\n /**\n * Refresh hover immediately\n */\n refreshHoverImmediately: function () {\n this._needsRefreshHover = false;\n this.painter.refreshHover && this.painter.refreshHover();\n },\n\n /**\n * Resize the canvas.\n * Should be invoked when container size is changed\n * @param {Object} [opts]\n * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)\n * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)\n */\n resize: function (opts) {\n opts = opts || {};\n this.painter.resize(opts.width, opts.height);\n this.handler.resize();\n },\n\n /**\n * Stop and clear all animation immediately\n */\n clearAnimation: function () {\n this.animation.clear();\n },\n\n /**\n * Get container width\n */\n getWidth: function () {\n return this.painter.getWidth();\n },\n\n /**\n * Get container height\n */\n getHeight: function () {\n return this.painter.getHeight();\n },\n\n /**\n * Export the canvas as Base64 URL\n * @param {string} type\n * @param {string} [backgroundColor='#fff']\n * @return {string} Base64 URL\n */\n // toDataURL: function(type, backgroundColor) {\n // return this.painter.getRenderedCanvas({\n // backgroundColor: backgroundColor\n // }).toDataURL(type);\n // },\n\n /**\n * Converting a path to image.\n * It has much better performance of drawing image rather than drawing a vector path.\n * @param {module:zrender/graphic/Path} e\n * @param {number} width\n * @param {number} height\n */\n pathToImage: function (e, dpr) {\n return this.painter.pathToImage(e, dpr);\n },\n\n /**\n * Set default cursor\n * @param {string} [cursorStyle='default'] 例如 crosshair\n */\n setCursorStyle: function (cursorStyle) {\n this.handler.setCursorStyle(cursorStyle);\n },\n\n /**\n * Find hovered element\n * @param {number} x\n * @param {number} y\n * @return {Object} {target, topTarget}\n */\n findHover: function (x, y) {\n return this.handler.findHover(x, y);\n },\n\n /**\n * Bind event\n *\n * @param {string} eventName Event name\n * @param {Function} eventHandler Handler function\n * @param {Object} [context] Context object\n */\n on: function (eventName, eventHandler, context) {\n this.handler.on(eventName, eventHandler, context);\n },\n\n /**\n * Unbind event\n * @param {string} eventName Event name\n * @param {Function} [eventHandler] Handler function\n */\n off: function (eventName, eventHandler) {\n this.handler.off(eventName, eventHandler);\n },\n\n /**\n * Trigger event manually\n *\n * @param {string} eventName Event name\n * @param {event=} event Event object\n */\n trigger: function (eventName, event) {\n this.handler.trigger(eventName, event);\n },\n\n\n /**\n * Clear all objects and the canvas.\n */\n clear: function () {\n this.storage.delRoot();\n this.painter.clear();\n },\n\n /**\n * Dispose self.\n */\n dispose: function () {\n this.animation.stop();\n\n this.clear();\n this.storage.dispose();\n this.painter.dispose();\n this.handler.dispose();\n\n this.animation =\n this.storage =\n this.painter =\n this.handler = null;\n\n delInstance(this.id);\n }\n};\n\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport * as zrUtil from 'zrender/src/core/util';\nimport env from 'zrender/src/core/env';\n\nvar each = zrUtil.each;\nvar isObject = zrUtil.isObject;\nvar isArray = zrUtil.isArray;\n\n/**\n * Make the name displayable. But we should\n * make sure it is not duplicated with user\n * specified name, so use '\\0';\n */\nvar DUMMY_COMPONENT_NAME_PREFIX = 'series\\0';\n\n/**\n * If value is not array, then translate it to array.\n * @param {*} value\n * @return {Array} [value] or value\n */\nexport function normalizeToArray(value) {\n return value instanceof Array\n ? value\n : value == null\n ? []\n : [value];\n}\n\n/**\n * Sync default option between normal and emphasis like `position` and `show`\n * In case some one will write code like\n * label: {\n * show: false,\n * position: 'outside',\n * fontSize: 18\n * },\n * emphasis: {\n * label: { show: true }\n * }\n * @param {Object} opt\n * @param {string} key\n * @param {Array.<string>} subOpts\n */\nexport function defaultEmphasis(opt, key, subOpts) {\n // Caution: performance sensitive.\n if (opt) {\n opt[key] = opt[key] || {};\n opt.emphasis = opt.emphasis || {};\n opt.emphasis[key] = opt.emphasis[key] || {};\n\n // Default emphasis option from normal\n for (var i = 0, len = subOpts.length; i < len; i++) {\n var subOptName = subOpts[i];\n if (!opt.emphasis[key].hasOwnProperty(subOptName)\n && opt[key].hasOwnProperty(subOptName)\n ) {\n opt.emphasis[key][subOptName] = opt[key][subOptName];\n }\n }\n }\n}\n\nexport var TEXT_STYLE_OPTIONS = [\n 'fontStyle', 'fontWeight', 'fontSize', 'fontFamily',\n 'rich', 'tag', 'color', 'textBorderColor', 'textBorderWidth',\n 'width', 'height', 'lineHeight', 'align', 'verticalAlign', 'baseline',\n 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY',\n 'textShadowColor', 'textShadowBlur', 'textShadowOffsetX', 'textShadowOffsetY',\n 'backgroundColor', 'borderColor', 'borderWidth', 'borderRadius', 'padding'\n];\n\n// modelUtil.LABEL_OPTIONS = modelUtil.TEXT_STYLE_OPTIONS.concat([\n// 'position', 'offset', 'rotate', 'origin', 'show', 'distance', 'formatter',\n// 'fontStyle', 'fontWeight', 'fontSize', 'fontFamily',\n// // FIXME: deprecated, check and remove it.\n// 'textStyle'\n// ]);\n\n/**\n * The method do not ensure performance.\n * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]\n * This helper method retieves value from data.\n * @param {string|number|Date|Array|Object} dataItem\n * @return {number|string|Date|Array.<number|string|Date>}\n */\nexport function getDataItemValue(dataItem) {\n return (isObject(dataItem) && !isArray(dataItem) && !(dataItem instanceof Date))\n ? dataItem.value : dataItem;\n}\n\n/**\n * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]\n * This helper method determine if dataItem has extra option besides value\n * @param {string|number|Date|Array|Object} dataItem\n */\nexport function isDataItemOption(dataItem) {\n return isObject(dataItem)\n && !(dataItem instanceof Array);\n // // markLine data can be array\n // && !(dataItem[0] && isObject(dataItem[0]) && !(dataItem[0] instanceof Array));\n}\n\n/**\n * Mapping to exists for merge.\n *\n * @public\n * @param {Array.<Object>|Array.<module:echarts/model/Component>} exists\n * @param {Object|Array.<Object>} newCptOptions\n * @return {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],\n * index of which is the same as exists.\n */\nexport function mappingToExists(exists, newCptOptions) {\n // Mapping by the order by original option (but not order of\n // new option) in merge mode. Because we should ensure\n // some specified index (like xAxisIndex) is consistent with\n // original option, which is easy to understand, espatially in\n // media query. And in most case, merge option is used to\n // update partial option but not be expected to change order.\n newCptOptions = (newCptOptions || []).slice();\n\n var result = zrUtil.map(exists || [], function (obj, index) {\n return {exist: obj};\n });\n\n // Mapping by id or name if specified.\n each(newCptOptions, function (cptOption, index) {\n if (!isObject(cptOption)) {\n return;\n }\n\n // id has highest priority.\n for (var i = 0; i < result.length; i++) {\n if (!result[i].option // Consider name: two map to one.\n && cptOption.id != null\n && result[i].exist.id === cptOption.id + ''\n ) {\n result[i].option = cptOption;\n newCptOptions[index] = null;\n return;\n }\n }\n\n for (var i = 0; i < result.length; i++) {\n var exist = result[i].exist;\n if (!result[i].option // Consider name: two map to one.\n // Can not match when both ids exist but different.\n && (exist.id == null || cptOption.id == null)\n && cptOption.name != null\n && !isIdInner(cptOption)\n && !isIdInner(exist)\n && exist.name === cptOption.name + ''\n ) {\n result[i].option = cptOption;\n newCptOptions[index] = null;\n return;\n }\n }\n });\n\n // Otherwise mapping by index.\n each(newCptOptions, function (cptOption, index) {\n if (!isObject(cptOption)) {\n return;\n }\n\n var i = 0;\n for (; i < result.length; i++) {\n var exist = result[i].exist;\n if (!result[i].option\n // Existing model that already has id should be able to\n // mapped to (because after mapping performed model may\n // be assigned with a id, whish should not affect next\n // mapping), except those has inner id.\n && !isIdInner(exist)\n // Caution:\n // Do not overwrite id. But name can be overwritten,\n // because axis use name as 'show label text'.\n // 'exist' always has id and name and we dont\n // need to check it.\n && cptOption.id == null\n ) {\n result[i].option = cptOption;\n break;\n }\n }\n\n if (i >= result.length) {\n result.push({option: cptOption});\n }\n });\n\n return result;\n}\n\n/**\n * Make id and name for mapping result (result of mappingToExists)\n * into `keyInfo` field.\n *\n * @public\n * @param {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],\n * which order is the same as exists.\n * @return {Array.<Object>} The input.\n */\nexport function makeIdAndName(mapResult) {\n // We use this id to hash component models and view instances\n // in echarts. id can be specified by user, or auto generated.\n\n // The id generation rule ensures new view instance are able\n // to mapped to old instance when setOption are called in\n // no-merge mode. So we generate model id by name and plus\n // type in view id.\n\n // name can be duplicated among components, which is convenient\n // to specify multi components (like series) by one name.\n\n // Ensure that each id is distinct.\n var idMap = zrUtil.createHashMap();\n\n each(mapResult, function (item, index) {\n var existCpt = item.exist;\n existCpt && idMap.set(existCpt.id, item);\n });\n\n each(mapResult, function (item, index) {\n var opt = item.option;\n\n zrUtil.assert(\n !opt || opt.id == null || !idMap.get(opt.id) || idMap.get(opt.id) === item,\n 'id duplicates: ' + (opt && opt.id)\n );\n\n opt && opt.id != null && idMap.set(opt.id, item);\n !item.keyInfo && (item.keyInfo = {});\n });\n\n // Make name and id.\n each(mapResult, function (item, index) {\n var existCpt = item.exist;\n var opt = item.option;\n var keyInfo = item.keyInfo;\n\n if (!isObject(opt)) {\n return;\n }\n\n // name can be overwitten. Consider case: axis.name = '20km'.\n // But id generated by name will not be changed, which affect\n // only in that case: setOption with 'not merge mode' and view\n // instance will be recreated, which can be accepted.\n keyInfo.name = opt.name != null\n ? opt.name + ''\n : existCpt\n ? existCpt.name\n // Avoid diffferent series has the same name,\n // because name may be used like in color pallet.\n : DUMMY_COMPONENT_NAME_PREFIX + index;\n\n if (existCpt) {\n keyInfo.id = existCpt.id;\n }\n else if (opt.id != null) {\n keyInfo.id = opt.id + '';\n }\n else {\n // Consider this situatoin:\n // optionA: [{name: 'a'}, {name: 'a'}, {..}]\n // optionB [{..}, {name: 'a'}, {name: 'a'}]\n // Series with the same name between optionA and optionB\n // should be mapped.\n var idNum = 0;\n do {\n keyInfo.id = '\\0' + keyInfo.name + '\\0' + idNum++;\n }\n while (idMap.get(keyInfo.id));\n }\n\n idMap.set(keyInfo.id, item);\n });\n}\n\nexport function isNameSpecified(componentModel) {\n var name = componentModel.name;\n // Is specified when `indexOf` get -1 or > 0.\n return !!(name && name.indexOf(DUMMY_COMPONENT_NAME_PREFIX));\n}\n\n/**\n * @public\n * @param {Object} cptOption\n * @return {boolean}\n */\nexport function isIdInner(cptOption) {\n return isObject(cptOption)\n && cptOption.id\n && (cptOption.id + '').indexOf('\\0_ec_\\0') === 0;\n}\n\n/**\n * A helper for removing duplicate items between batchA and batchB,\n * and in themselves, and categorize by series.\n *\n * @param {Array.<Object>} batchA Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]\n * @param {Array.<Object>} batchB Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]\n * @return {Array.<Array.<Object>, Array.<Object>>} result: [resultBatchA, resultBatchB]\n */\nexport function compressBatches(batchA, batchB) {\n var mapA = {};\n var mapB = {};\n\n makeMap(batchA || [], mapA);\n makeMap(batchB || [], mapB, mapA);\n\n return [mapToArray(mapA), mapToArray(mapB)];\n\n function makeMap(sourceBatch, map, otherMap) {\n for (var i = 0, len = sourceBatch.length; i < len; i++) {\n var seriesId = sourceBatch[i].seriesId;\n var dataIndices = normalizeToArray(sourceBatch[i].dataIndex);\n var otherDataIndices = otherMap && otherMap[seriesId];\n\n for (var j = 0, lenj = dataIndices.length; j < lenj; j++) {\n var dataIndex = dataIndices[j];\n\n if (otherDataIndices && otherDataIndices[dataIndex]) {\n otherDataIndices[dataIndex] = null;\n }\n else {\n (map[seriesId] || (map[seriesId] = {}))[dataIndex] = 1;\n }\n }\n }\n }\n\n function mapToArray(map, isData) {\n var result = [];\n for (var i in map) {\n if (map.hasOwnProperty(i) && map[i] != null) {\n if (isData) {\n result.push(+i);\n }\n else {\n var dataIndices = mapToArray(map[i], true);\n dataIndices.length && result.push({seriesId: i, dataIndex: dataIndices});\n }\n }\n }\n return result;\n }\n}\n\n/**\n * @param {module:echarts/data/List} data\n * @param {Object} payload Contains dataIndex (means rawIndex) / dataIndexInside / name\n * each of which can be Array or primary type.\n * @return {number|Array.<number>} dataIndex If not found, return undefined/null.\n */\nexport function queryDataIndex(data, payload) {\n if (payload.dataIndexInside != null) {\n return payload.dataIndexInside;\n }\n else if (payload.dataIndex != null) {\n return zrUtil.isArray(payload.dataIndex)\n ? zrUtil.map(payload.dataIndex, function (value) {\n return data.indexOfRawIndex(value);\n })\n : data.indexOfRawIndex(payload.dataIndex);\n }\n else if (payload.name != null) {\n return zrUtil.isArray(payload.name)\n ? zrUtil.map(payload.name, function (value) {\n return data.indexOfName(value);\n })\n : data.indexOfName(payload.name);\n }\n}\n\n/**\n * Enable property storage to any host object.\n * Notice: Serialization is not supported.\n *\n * For example:\n * var inner = zrUitl.makeInner();\n *\n * function some1(hostObj) {\n * inner(hostObj).someProperty = 1212;\n * ...\n * }\n * function some2() {\n * var fields = inner(this);\n * fields.someProperty1 = 1212;\n * fields.someProperty2 = 'xx';\n * ...\n * }\n *\n * @return {Function}\n */\nexport function makeInner() {\n // Consider different scope by es module import.\n var key = '__\\0ec_inner_' + innerUniqueIndex++ + '_' + Math.random().toFixed(5);\n return function (hostObj) {\n return hostObj[key] || (hostObj[key] = {});\n };\n}\nvar innerUniqueIndex = 0;\n\n/**\n * @param {module:echarts/model/Global} ecModel\n * @param {string|Object} finder\n * If string, e.g., 'geo', means {geoIndex: 0}.\n * If Object, could contain some of these properties below:\n * {\n * seriesIndex, seriesId, seriesName,\n * geoIndex, geoId, geoName,\n * bmapIndex, bmapId, bmapName,\n * xAxisIndex, xAxisId, xAxisName,\n * yAxisIndex, yAxisId, yAxisName,\n * gridIndex, gridId, gridName,\n * ... (can be extended)\n * }\n * Each properties can be number|string|Array.<number>|Array.<string>\n * For example, a finder could be\n * {\n * seriesIndex: 3,\n * geoId: ['aa', 'cc'],\n * gridName: ['xx', 'rr']\n * }\n * xxxIndex can be set as 'all' (means all xxx) or 'none' (means not specify)\n * If nothing or null/undefined specified, return nothing.\n * @param {Object} [opt]\n * @param {string} [opt.defaultMainType]\n * @param {Array.<string>} [opt.includeMainTypes]\n * @return {Object} result like:\n * {\n * seriesModels: [seriesModel1, seriesModel2],\n * seriesModel: seriesModel1, // The first model\n * geoModels: [geoModel1, geoModel2],\n * geoModel: geoModel1, // The first model\n * ...\n * }\n */\nexport function parseFinder(ecModel, finder, opt) {\n if (zrUtil.isString(finder)) {\n var obj = {};\n obj[finder + 'Index'] = 0;\n finder = obj;\n }\n\n var defaultMainType = opt && opt.defaultMainType;\n if (defaultMainType\n && !has(finder, defaultMainType + 'Index')\n && !has(finder, defaultMainType + 'Id')\n && !has(finder, defaultMainType + 'Name')\n ) {\n finder[defaultMainType + 'Index'] = 0;\n }\n\n var result = {};\n\n each(finder, function (value, key) {\n var value = finder[key];\n\n // Exclude 'dataIndex' and other illgal keys.\n if (key === 'dataIndex' || key === 'dataIndexInside') {\n result[key] = value;\n return;\n }\n\n var parsedKey = key.match(/^(\\w+)(Index|Id|Name)$/) || [];\n var mainType = parsedKey[1];\n var queryType = (parsedKey[2] || '').toLowerCase();\n\n if (!mainType\n || !queryType\n || value == null\n || (queryType === 'index' && value === 'none')\n || (opt && opt.includeMainTypes && zrUtil.indexOf(opt.includeMainTypes, mainType) < 0)\n ) {\n return;\n }\n\n var queryParam = {mainType: mainType};\n if (queryType !== 'index' || value !== 'all') {\n queryParam[queryType] = value;\n }\n\n var models = ecModel.queryComponents(queryParam);\n result[mainType + 'Models'] = models;\n result[mainType + 'Model'] = models[0];\n });\n\n return result;\n}\n\nfunction has(obj, prop) {\n return obj && obj.hasOwnProperty(prop);\n}\n\nexport function setAttribute(dom, key, value) {\n dom.setAttribute\n ? dom.setAttribute(key, value)\n : (dom[key] = value);\n}\n\nexport function getAttribute(dom, key) {\n return dom.getAttribute\n ? dom.getAttribute(key)\n : dom[key];\n}\n\nexport function getTooltipRenderMode(renderModeOption) {\n if (renderModeOption === 'auto') {\n // Using html when `document` exists, use richText otherwise\n return env.domSupported ? 'html' : 'richText';\n }\n else {\n return renderModeOption || 'html';\n }\n}\n\n/**\n * Group a list by key.\n *\n * @param {Array} array\n * @param {Function} getKey\n * param {*} Array item\n * return {string} key\n * @return {Object} Result\n * {Array}: keys,\n * {module:zrender/core/util/HashMap} buckets: {key -> Array}\n */\nexport function groupData(array, getKey) {\n var buckets = zrUtil.createHashMap();\n var keys = [];\n\n zrUtil.each(array, function (item) {\n var key = getKey(item);\n (buckets.get(key)\n || (keys.push(key), buckets.set(key, []))\n ).push(item);\n });\n\n return {keys: keys, buckets: buckets};\n}\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport {__DEV__} from '../config';\nimport * as zrUtil from 'zrender/src/core/util';\n\nvar TYPE_DELIMITER = '.';\nvar IS_CONTAINER = '___EC__COMPONENT__CONTAINER___';\n\n/**\n * Notice, parseClassType('') should returns {main: '', sub: ''}\n * @public\n */\nexport function parseClassType(componentType) {\n var ret = {main: '', sub: ''};\n if (componentType) {\n componentType = componentType.split(TYPE_DELIMITER);\n ret.main = componentType[0] || '';\n ret.sub = componentType[1] || '';\n }\n return ret;\n}\n\n/**\n * @public\n */\nfunction checkClassType(componentType) {\n zrUtil.assert(\n /^[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)?$/.test(componentType),\n 'componentType \"' + componentType + '\" illegal'\n );\n}\n\n/**\n * @public\n */\nexport function enableClassExtend(RootClass, mandatoryMethods) {\n\n RootClass.$constructor = RootClass;\n RootClass.extend = function (proto) {\n\n if (__DEV__) {\n zrUtil.each(mandatoryMethods, function (method) {\n if (!proto[method]) {\n console.warn(\n 'Method `' + method + '` should be implemented'\n + (proto.type ? ' in ' + proto.type : '') + '.'\n );\n }\n });\n }\n\n var superClass = this;\n var ExtendedClass = function () {\n if (!proto.$constructor) {\n superClass.apply(this, arguments);\n }\n else {\n proto.$constructor.apply(this, arguments);\n }\n };\n\n zrUtil.extend(ExtendedClass.prototype, proto);\n\n ExtendedClass.extend = this.extend;\n ExtendedClass.superCall = superCall;\n ExtendedClass.superApply = superApply;\n zrUtil.inherits(ExtendedClass, this);\n ExtendedClass.superClass = superClass;\n\n return ExtendedClass;\n };\n}\n\nvar classBase = 0;\n\n/**\n * Can not use instanceof, consider different scope by\n * cross domain or es module import in ec extensions.\n * Mount a method \"isInstance()\" to Clz.\n */\nexport function enableClassCheck(Clz) {\n var classAttr = ['__\\0is_clz', classBase++, Math.random().toFixed(3)].join('_');\n Clz.prototype[classAttr] = true;\n\n if (__DEV__) {\n zrUtil.assert(!Clz.isInstance, 'The method \"is\" can not be defined.');\n }\n\n Clz.isInstance = function (obj) {\n return !!(obj && obj[classAttr]);\n };\n}\n\n// superCall should have class info, which can not be fetch from 'this'.\n// Consider this case:\n// class A has method f,\n// class B inherits class A, overrides method f, f call superApply('f'),\n// class C inherits class B, do not overrides method f,\n// then when method of class C is called, dead loop occured.\nfunction superCall(context, methodName) {\n var args = zrUtil.slice(arguments, 2);\n return this.superClass.prototype[methodName].apply(context, args);\n}\n\nfunction superApply(context, methodName, args) {\n return this.superClass.prototype[methodName].apply(context, args);\n}\n\n/**\n * @param {Object} entity\n * @param {Object} options\n * @param {boolean} [options.registerWhenExtend]\n * @public\n */\nexport function enableClassManagement(entity, options) {\n options = options || {};\n\n /**\n * Component model classes\n * key: componentType,\n * value:\n * componentClass, when componentType is 'xxx'\n * or Object.<subKey, componentClass>, when componentType is 'xxx.yy'\n * @type {Object}\n */\n var storage = {};\n\n entity.registerClass = function (Clazz, componentType) {\n if (componentType) {\n checkClassType(componentType);\n componentType = parseClassType(componentType);\n\n if (!componentType.sub) {\n if (__DEV__) {\n if (storage[componentType.main]) {\n console.warn(componentType.main + ' exists.');\n }\n }\n storage[componentType.main] = Clazz;\n }\n else if (componentType.sub !== IS_CONTAINER) {\n var container = makeContainer(componentType);\n container[componentType.sub] = Clazz;\n }\n }\n return Clazz;\n };\n\n entity.getClass = function (componentMainType, subType, throwWhenNotFound) {\n var Clazz = storage[componentMainType];\n\n if (Clazz && Clazz[IS_CONTAINER]) {\n Clazz = subType ? Clazz[subType] : null;\n }\n\n if (throwWhenNotFound && !Clazz) {\n throw new Error(\n !subType\n ? componentMainType + '.' + 'type should be specified.'\n : 'Component ' + componentMainType + '.' + (subType || '') + ' not exists. Load it first.'\n );\n }\n\n return Clazz;\n };\n\n entity.getClassesByMainType = function (componentType) {\n componentType = parseClassType(componentType);\n\n var result = [];\n var obj = storage[componentType.main];\n\n if (obj && obj[IS_CONTAINER]) {\n zrUtil.each(obj, function (o, type) {\n type !== IS_CONTAINER && result.push(o);\n });\n }\n else {\n result.push(obj);\n }\n\n return result;\n };\n\n entity.hasClass = function (componentType) {\n // Just consider componentType.main.\n componentType = parseClassType(componentType);\n return !!storage[componentType.main];\n };\n\n /**\n * @return {Array.<string>} Like ['aa', 'bb'], but can not be ['aa.xx']\n */\n entity.getAllClassMainTypes = function () {\n var types = [];\n zrUtil.each(storage, function (obj, type) {\n types.push(type);\n });\n return types;\n };\n\n /**\n * If a main type is container and has sub types\n * @param {string} mainType\n * @return {boolean}\n */\n entity.hasSubTypes = function (componentType) {\n componentType = parseClassType(componentType);\n var obj = storage[componentType.main];\n return obj && obj[IS_CONTAINER];\n };\n\n entity.parseClassType = parseClassType;\n\n function makeContainer(componentType) {\n var container = storage[componentType.main];\n if (!container || !container[IS_CONTAINER]) {\n container = storage[componentType.main] = {};\n container[IS_CONTAINER] = true;\n }\n return container;\n }\n\n if (options.registerWhenExtend) {\n var originalExtend = entity.extend;\n if (originalExtend) {\n entity.extend = function (proto) {\n var ExtendedClass = originalExtend.call(this, proto);\n return entity.registerClass(ExtendedClass, proto.type);\n };\n }\n }\n\n return entity;\n}\n\n/**\n * @param {string|Array.<string>} properties\n */\nexport function setReadOnly(obj, properties) {\n // FIXME It seems broken in IE8 simulation of IE11\n // if (!zrUtil.isArray(properties)) {\n // properties = properties != null ? [properties] : [];\n // }\n // zrUtil.each(properties, function (prop) {\n // var value = obj[prop];\n\n // Object.defineProperty\n // && Object.defineProperty(obj, prop, {\n // value: value, writable: false\n // });\n // zrUtil.isArray(obj[prop])\n // && Object.freeze\n // && Object.freeze(obj[prop]);\n // });\n}\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\n// TODO Parse shadow style\n// TODO Only shallow path support\nimport * as zrUtil from 'zrender/src/core/util';\n\nexport default function (properties) {\n // Normalize\n for (var i = 0; i < properties.length; i++) {\n if (!properties[i][1]) {\n properties[i][1] = properties[i][0];\n }\n }\n return function (model, excludes, includes) {\n var style = {};\n for (var i = 0; i < properties.length; i++) {\n var propName = properties[i][1];\n if ((excludes && zrUtil.indexOf(excludes, propName) >= 0)\n || (includes && zrUtil.indexOf(includes, propName) < 0)\n ) {\n continue;\n }\n var val = model.getShallow(propName);\n if (val != null) {\n style[properties[i][0]] = val;\n }\n }\n return style;\n };\n}","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport makeStyleMapper from './makeStyleMapper';\n\nvar getLineStyle = makeStyleMapper(\n [\n ['lineWidth', 'width'],\n ['stroke', 'color'],\n ['opacity'],\n ['shadowBlur'],\n ['shadowOffsetX'],\n ['shadowOffsetY'],\n ['shadowColor']\n ]\n);\n\nexport default {\n getLineStyle: function (excludes) {\n var style = getLineStyle(this, excludes);\n // Always set lineDash whether dashed, otherwise we can not\n // erase the previous style when assigning to el.style.\n style.lineDash = this.getLineDash(style.lineWidth);\n return style;\n },\n\n getLineDash: function (lineWidth) {\n if (lineWidth == null) {\n lineWidth = 1;\n }\n var lineType = this.get('type');\n var dotSize = Math.max(lineWidth, 2);\n var dashSize = lineWidth * 4;\n return (lineType === 'solid' || lineType == null)\n // Use `false` but not `null` for the solid line here, because `null` might be\n // ignored when assigning to `el.style`. e.g., when setting `lineStyle.type` as\n // `'dashed'` and `emphasis.lineStyle.type` as `'solid'` in graph series, the\n // `lineDash` gotten form the latter one is not able to erase that from the former\n // one if using `null` here according to the emhpsis strategy in `util/graphic.js`.\n ? false\n : lineType === 'dashed'\n ? [dashSize, dashSize]\n : [dotSize, dotSize];\n }\n};","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport makeStyleMapper from './makeStyleMapper';\n\nvar getAreaStyle = makeStyleMapper(\n [\n ['fill', 'color'],\n ['shadowBlur'],\n ['shadowOffsetX'],\n ['shadowOffsetY'],\n ['opacity'],\n ['shadowColor']\n ]\n);\n\nexport default {\n getAreaStyle: function (excludes, includes) {\n return getAreaStyle(this, excludes, includes);\n }\n};","/**\n * 曲线辅助模块\n * @module zrender/core/curve\n * @author pissang(https://www.github.com/pissang)\n */\n\nimport {\n create as v2Create,\n distSquare as v2DistSquare\n} from './vector';\n\nvar mathPow = Math.pow;\nvar mathSqrt = Math.sqrt;\n\nvar EPSILON = 1e-8;\nvar EPSILON_NUMERIC = 1e-4;\n\nvar THREE_SQRT = mathSqrt(3);\nvar ONE_THIRD = 1 / 3;\n\n// 临时变量\nvar _v0 = v2Create();\nvar _v1 = v2Create();\nvar _v2 = v2Create();\n\nfunction isAroundZero(val) {\n return val > -EPSILON && val < EPSILON;\n}\nfunction isNotAroundZero(val) {\n return val > EPSILON || val < -EPSILON;\n}\n/**\n * 计算三次贝塞尔值\n * @memberOf module:zrender/core/curve\n * @param {number} p0\n * @param {number} p1\n * @param {number} p2\n * @param {number} p3\n * @param {number} t\n * @return {number}\n */\nexport function cubicAt(p0, p1, p2, p3, t) {\n var onet = 1 - t;\n return onet * onet * (onet * p0 + 3 * t * p1)\n + t * t * (t * p3 + 3 * onet * p2);\n}\n\n/**\n * 计算三次贝塞尔导数值\n * @memberOf module:zrender/core/curve\n * @param {number} p0\n * @param {number} p1\n * @param {number} p2\n * @param {number} p3\n * @param {number} t\n * @return {number}\n */\nexport function cubicDerivativeAt(p0, p1, p2, p3, t) {\n var onet = 1 - t;\n return 3 * (\n ((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet\n + (p3 - p2) * t * t\n );\n}\n\n/**\n * 计算三次贝塞尔方程根,使用盛金公式\n * @memberOf module:zrender/core/curve\n * @param {number} p0\n * @param {number} p1\n * @param {number} p2\n * @param {number} p3\n * @param {number} val\n * @param {Array.<number>} roots\n * @return {number} 有效根数目\n */\nexport function cubicRootAt(p0, p1, p2, p3, val, roots) {\n // Evaluate roots of cubic functions\n var a = p3 + 3 * (p1 - p2) - p0;\n var b = 3 * (p2 - p1 * 2 + p0);\n var c = 3 * (p1 - p0);\n var d = p0 - val;\n\n var A = b * b - 3 * a * c;\n var B = b * c - 9 * a * d;\n var C = c * c - 3 * b * d;\n\n var n = 0;\n\n if (isAroundZero(A) && isAroundZero(B)) {\n if (isAroundZero(b)) {\n roots[0] = 0;\n }\n else {\n var t1 = -c / b; //t1, t2, t3, b is not zero\n if (t1 >= 0 && t1 <= 1) {\n roots[n++] = t1;\n }\n }\n }\n else {\n var disc = B * B - 4 * A * C;\n\n if (isAroundZero(disc)) {\n var K = B / A;\n var t1 = -b / a + K; // t1, a is not zero\n var t2 = -K / 2; // t2, t3\n if (t1 >= 0 && t1 <= 1) {\n roots[n++] = t1;\n }\n if (t2 >= 0 && t2 <= 1) {\n roots[n++] = t2;\n }\n }\n else if (disc > 0) {\n var discSqrt = mathSqrt(disc);\n var Y1 = A * b + 1.5 * a * (-B + discSqrt);\n var Y2 = A * b + 1.5 * a * (-B - discSqrt);\n if (Y1 < 0) {\n Y1 = -mathPow(-Y1, ONE_THIRD);\n }\n else {\n Y1 = mathPow(Y1, ONE_THIRD);\n }\n if (Y2 < 0) {\n Y2 = -mathPow(-Y2, ONE_THIRD);\n }\n else {\n Y2 = mathPow(Y2, ONE_THIRD);\n }\n var t1 = (-b - (Y1 + Y2)) / (3 * a);\n if (t1 >= 0 && t1 <= 1) {\n roots[n++] = t1;\n }\n }\n else {\n var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt(A * A * A));\n var theta = Math.acos(T) / 3;\n var ASqrt = mathSqrt(A);\n var tmp = Math.cos(theta);\n\n var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);\n var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);\n var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);\n if (t1 >= 0 && t1 <= 1) {\n roots[n++] = t1;\n }\n if (t2 >= 0 && t2 <= 1) {\n roots[n++] = t2;\n }\n if (t3 >= 0 && t3 <= 1) {\n roots[n++] = t3;\n }\n }\n }\n return n;\n}\n\n/**\n * 计算三次贝塞尔方程极限值的位置\n * @memberOf module:zrender/core/curve\n * @param {number} p0\n * @param {number} p1\n * @param {number} p2\n * @param {number} p3\n * @param {Array.<number>} extrema\n * @return {number} 有效数目\n */\nexport function cubicExtrema(p0, p1, p2, p3, extrema) {\n var b = 6 * p2 - 12 * p1 + 6 * p0;\n var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;\n var c = 3 * p1 - 3 * p0;\n\n var n = 0;\n if (isAroundZero(a)) {\n if (isNotAroundZero(b)) {\n var t1 = -c / b;\n if (t1 >= 0 && t1 <= 1) {\n extrema[n++] = t1;\n }\n }\n }\n else {\n var disc = b * b - 4 * a * c;\n if (isAroundZero(disc)) {\n extrema[0] = -b / (2 * a);\n }\n else if (disc > 0) {\n var discSqrt = mathSqrt(disc);\n var t1 = (-b + discSqrt) / (2 * a);\n var t2 = (-b - discSqrt) / (2 * a);\n if (t1 >= 0 && t1 <= 1) {\n extrema[n++] = t1;\n }\n if (t2 >= 0 && t2 <= 1) {\n extrema[n++] = t2;\n }\n }\n }\n return n;\n}\n\n/**\n * 细分三次贝塞尔曲线\n * @memberOf module:zrender/core/curve\n * @param {number} p0\n * @param {number} p1\n * @param {number} p2\n * @param {number} p3\n * @param {number} t\n * @param {Array.<number>} out\n */\nexport function cubicSubdivide(p0, p1, p2, p3, t, out) {\n var p01 = (p1 - p0) * t + p0;\n var p12 = (p2 - p1) * t + p1;\n var p23 = (p3 - p2) * t + p2;\n\n var p012 = (p12 - p01) * t + p01;\n var p123 = (p23 - p12) * t + p12;\n\n var p0123 = (p123 - p012) * t + p012;\n // Seg0\n out[0] = p0;\n out[1] = p01;\n out[2] = p012;\n out[3] = p0123;\n // Seg1\n out[4] = p0123;\n out[5] = p123;\n out[6] = p23;\n out[7] = p3;\n}\n\n/**\n * 投射点到三次贝塞尔曲线上,返回投射距离。\n * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。\n * @param {number} x0\n * @param {number} y0\n * @param {number} x1\n * @param {number} y1\n * @param {number} x2\n * @param {number} y2\n * @param {number} x3\n * @param {number} y3\n * @param {number} x\n * @param {number} y\n * @param {Array.<number>} [out] 投射点\n * @return {number}\n */\nexport function cubicProjectPoint(\n x0, y0, x1, y1, x2, y2, x3, y3,\n x, y, out\n) {\n // http://pomax.github.io/bezierinfo/#projections\n var t;\n var interval = 0.005;\n var d = Infinity;\n var prev;\n var next;\n var d1;\n var d2;\n\n _v0[0] = x;\n _v0[1] = y;\n\n // 先粗略估计一下可能的最小距离的 t 值\n // PENDING\n for (var _t = 0; _t < 1; _t += 0.05) {\n _v1[0] = cubicAt(x0, x1, x2, x3, _t);\n _v1[1] = cubicAt(y0, y1, y2, y3, _t);\n d1 = v2DistSquare(_v0, _v1);\n if (d1 < d) {\n t = _t;\n d = d1;\n }\n }\n d = Infinity;\n\n // At most 32 iteration\n for (var i = 0; i < 32; i++) {\n if (interval < EPSILON_NUMERIC) {\n break;\n }\n prev = t - interval;\n next = t + interval;\n // t - interval\n _v1[0] = cubicAt(x0, x1, x2, x3, prev);\n _v1[1] = cubicAt(y0, y1, y2, y3, prev);\n\n d1 = v2DistSquare(_v1, _v0);\n\n if (prev >= 0 && d1 < d) {\n t = prev;\n d = d1;\n }\n else {\n // t + interval\n _v2[0] = cubicAt(x0, x1, x2, x3, next);\n _v2[1] = cubicAt(y0, y1, y2, y3, next);\n d2 = v2DistSquare(_v2, _v0);\n\n if (next <= 1 && d2 < d) {\n t = next;\n d = d2;\n }\n else {\n interval *= 0.5;\n }\n }\n }\n // t\n if (out) {\n out[0] = cubicAt(x0, x1, x2, x3, t);\n out[1] = cubicAt(y0, y1, y2, y3, t);\n }\n // console.log(interval, i);\n return mathSqrt(d);\n}\n\n/**\n * 计算二次方贝塞尔值\n * @param {number} p0\n * @param {number} p1\n * @param {number} p2\n * @param {number} t\n * @return {number}\n */\nexport function quadraticAt(p0, p1, p2, t) {\n var onet = 1 - t;\n return onet * (onet * p0 + 2 * t * p1) + t * t * p2;\n}\n\n/**\n * 计算二次方贝塞尔导数值\n * @param {number} p0\n * @param {number} p1\n * @param {number} p2\n * @param {number} t\n * @return {number}\n */\nexport function quadraticDerivativeAt(p0, p1, p2, t) {\n return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));\n}\n\n/**\n * 计算二次方贝塞尔方程根\n * @param {number} p0\n * @param {number} p1\n * @param {number} p2\n * @param {number} t\n * @param {Array.<number>} roots\n * @return {number} 有效根数目\n */\nexport function quadraticRootAt(p0, p1, p2, val, roots) {\n var a = p0 - 2 * p1 + p2;\n var b = 2 * (p1 - p0);\n var c = p0 - val;\n\n var n = 0;\n if (isAroundZero(a)) {\n if (isNotAroundZero(b)) {\n var t1 = -c / b;\n if (t1 >= 0 && t1 <= 1) {\n roots[n++] = t1;\n }\n }\n }\n else {\n var disc = b * b - 4 * a * c;\n if (isAroundZero(disc)) {\n var t1 = -b / (2 * a);\n if (t1 >= 0 && t1 <= 1) {\n roots[n++] = t1;\n }\n }\n else if (disc > 0) {\n var discSqrt = mathSqrt(disc);\n var t1 = (-b + discSqrt) / (2 * a);\n var t2 = (-b - discSqrt) / (2 * a);\n if (t1 >= 0 && t1 <= 1) {\n roots[n++] = t1;\n }\n if (t2 >= 0 && t2 <= 1) {\n roots[n++] = t2;\n }\n }\n }\n return n;\n}\n\n/**\n * 计算二次贝塞尔方程极限值\n * @memberOf module:zrender/core/curve\n * @param {number} p0\n * @param {number} p1\n * @param {number} p2\n * @return {number}\n */\nexport function quadraticExtremum(p0, p1, p2) {\n var divider = p0 + p2 - 2 * p1;\n if (divider === 0) {\n // p1 is center of p0 and p2\n return 0.5;\n }\n else {\n return (p0 - p1) / divider;\n }\n}\n\n/**\n * 细分二次贝塞尔曲线\n * @memberOf module:zrender/core/curve\n * @param {number} p0\n * @param {number} p1\n * @param {number} p2\n * @param {number} t\n * @param {Array.<number>} out\n */\nexport function quadraticSubdivide(p0, p1, p2, t, out) {\n var p01 = (p1 - p0) * t + p0;\n var p12 = (p2 - p1) * t + p1;\n var p012 = (p12 - p01) * t + p01;\n\n // Seg0\n out[0] = p0;\n out[1] = p01;\n out[2] = p012;\n\n // Seg1\n out[3] = p012;\n out[4] = p12;\n out[5] = p2;\n}\n\n/**\n * 投射点到二次贝塞尔曲线上,返回投射距离。\n * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。\n * @param {number} x0\n * @param {number} y0\n * @param {number} x1\n * @param {number} y1\n * @param {number} x2\n * @param {number} y2\n * @param {number} x\n * @param {number} y\n * @param {Array.<number>} out 投射点\n * @return {number}\n */\nexport function quadraticProjectPoint(\n x0, y0, x1, y1, x2, y2,\n x, y, out\n) {\n // http://pomax.github.io/bezierinfo/#projections\n var t;\n var interval = 0.005;\n var d = Infinity;\n\n _v0[0] = x;\n _v0[1] = y;\n\n // 先粗略估计一下可能的最小距离的 t 值\n // PENDING\n for (var _t = 0; _t < 1; _t += 0.05) {\n _v1[0] = quadraticAt(x0, x1, x2, _t);\n _v1[1] = quadraticAt(y0, y1, y2, _t);\n var d1 = v2DistSquare(_v0, _v1);\n if (d1 < d) {\n t = _t;\n d = d1;\n }\n }\n d = Infinity;\n\n // At most 32 iteration\n for (var i = 0; i < 32; i++) {\n if (interval < EPSILON_NUMERIC) {\n break;\n }\n var prev = t - interval;\n var next = t + interval;\n // t - interval\n _v1[0] = quadraticAt(x0, x1, x2, prev);\n _v1[1] = quadraticAt(y0, y1, y2, prev);\n\n var d1 = v2DistSquare(_v1, _v0);\n\n if (prev >= 0 && d1 < d) {\n t = prev;\n d = d1;\n }\n else {\n // t + interval\n _v2[0] = quadraticAt(x0, x1, x2, next);\n _v2[1] = quadraticAt(y0, y1, y2, next);\n var d2 = v2DistSquare(_v2, _v0);\n if (next <= 1 && d2 < d) {\n t = next;\n d = d2;\n }\n else {\n interval *= 0.5;\n }\n }\n }\n // t\n if (out) {\n out[0] = quadraticAt(x0, x1, x2, t);\n out[1] = quadraticAt(y0, y1, y2, t);\n }\n // console.log(interval, i);\n return mathSqrt(d);\n}\n","/**\n * @author Yi Shen(https://github.com/pissang)\n */\n\nimport * as vec2 from './vector';\nimport * as curve from './curve';\n\nvar mathMin = Math.min;\nvar mathMax = Math.max;\nvar mathSin = Math.sin;\nvar mathCos = Math.cos;\nvar PI2 = Math.PI * 2;\n\nvar start = vec2.create();\nvar end = vec2.create();\nvar extremity = vec2.create();\n\n/**\n * 从顶点数组中计算出最小包围盒,写入`min`和`max`中\n * @module zrender/core/bbox\n * @param {Array<Object>} points 顶点数组\n * @param {number} min\n * @param {number} max\n */\nexport function fromPoints(points, min, max) {\n if (points.length === 0) {\n return;\n }\n var p = points[0];\n var left = p[0];\n var right = p[0];\n var top = p[1];\n var bottom = p[1];\n var i;\n\n for (i = 1; i < points.length; i++) {\n p = points[i];\n left = mathMin(left, p[0]);\n right = mathMax(right, p[0]);\n top = mathMin(top, p[1]);\n bottom = mathMax(bottom, p[1]);\n }\n\n min[0] = left;\n min[1] = top;\n max[0] = right;\n max[1] = bottom;\n}\n\n/**\n * @memberOf module:zrender/core/bbox\n * @param {number} x0\n * @param {number} y0\n * @param {number} x1\n * @param {number} y1\n * @param {Array.<number>} min\n * @param {Array.<number>} max\n */\nexport function fromLine(x0, y0, x1, y1, min, max) {\n min[0] = mathMin(x0, x1);\n min[1] = mathMin(y0, y1);\n max[0] = mathMax(x0, x1);\n max[1] = mathMax(y0, y1);\n}\n\nvar xDim = [];\nvar yDim = [];\n/**\n * 从三阶贝塞尔曲线(p0, p1, p2, p3)中计算出最小包围盒,写入`min`和`max`中\n * @memberOf module:zrender/core/bbox\n * @param {number} x0\n * @param {number} y0\n * @param {number} x1\n * @param {number} y1\n * @param {number} x2\n * @param {number} y2\n * @param {number} x3\n * @param {number} y3\n * @param {Array.<number>} min\n * @param {Array.<number>} max\n */\nexport function fromCubic(\n x0, y0, x1, y1, x2, y2, x3, y3, min, max\n) {\n var cubicExtrema = curve.cubicExtrema;\n var cubicAt = curve.cubicAt;\n var i;\n var n = cubicExtrema(x0, x1, x2, x3, xDim);\n min[0] = Infinity;\n min[1] = Infinity;\n max[0] = -Infinity;\n max[1] = -Infinity;\n\n for (i = 0; i < n; i++) {\n var x = cubicAt(x0, x1, x2, x3, xDim[i]);\n min[0] = mathMin(x, min[0]);\n max[0] = mathMax(x, max[0]);\n }\n n = cubicExtrema(y0, y1, y2, y3, yDim);\n for (i = 0; i < n; i++) {\n var y = cubicAt(y0, y1, y2, y3, yDim[i]);\n min[1] = mathMin(y, min[1]);\n max[1] = mathMax(y, max[1]);\n }\n\n min[0] = mathMin(x0, min[0]);\n max[0] = mathMax(x0, max[0]);\n min[0] = mathMin(x3, min[0]);\n max[0] = mathMax(x3, max[0]);\n\n min[1] = mathMin(y0, min[1]);\n max[1] = mathMax(y0, max[1]);\n min[1] = mathMin(y3, min[1]);\n max[1] = mathMax(y3, max[1]);\n}\n\n/**\n * 从二阶贝塞尔曲线(p0, p1, p2)中计算出最小包围盒,写入`min`和`max`中\n * @memberOf module:zrender/core/bbox\n * @param {number} x0\n * @param {number} y0\n * @param {number} x1\n * @param {number} y1\n * @param {number} x2\n * @param {number} y2\n * @param {Array.<number>} min\n * @param {Array.<number>} max\n */\nexport function fromQuadratic(x0, y0, x1, y1, x2, y2, min, max) {\n var quadraticExtremum = curve.quadraticExtremum;\n var quadraticAt = curve.quadraticAt;\n // Find extremities, where derivative in x dim or y dim is zero\n var tx =\n mathMax(\n mathMin(quadraticExtremum(x0, x1, x2), 1), 0\n );\n var ty =\n mathMax(\n mathMin(quadraticExtremum(y0, y1, y2), 1), 0\n );\n\n var x = quadraticAt(x0, x1, x2, tx);\n var y = quadraticAt(y0, y1, y2, ty);\n\n min[0] = mathMin(x0, x2, x);\n min[1] = mathMin(y0, y2, y);\n max[0] = mathMax(x0, x2, x);\n max[1] = mathMax(y0, y2, y);\n}\n\n/**\n * 从圆弧中计算出最小包围盒,写入`min`和`max`中\n * @method\n * @memberOf module:zrender/core/bbox\n * @param {number} x\n * @param {number} y\n * @param {number} rx\n * @param {number} ry\n * @param {number} startAngle\n * @param {number} endAngle\n * @param {number} anticlockwise\n * @param {Array.<number>} min\n * @param {Array.<number>} max\n */\nexport function fromArc(\n x, y, rx, ry, startAngle, endAngle, anticlockwise, min, max\n) {\n var vec2Min = vec2.min;\n var vec2Max = vec2.max;\n\n var diff = Math.abs(startAngle - endAngle);\n\n\n if (diff % PI2 < 1e-4 && diff > 1e-4) {\n // Is a circle\n min[0] = x - rx;\n min[1] = y - ry;\n max[0] = x + rx;\n max[1] = y + ry;\n return;\n }\n\n start[0] = mathCos(startAngle) * rx + x;\n start[1] = mathSin(startAngle) * ry + y;\n\n end[0] = mathCos(endAngle) * rx + x;\n end[1] = mathSin(endAngle) * ry + y;\n\n vec2Min(min, start, end);\n vec2Max(max, start, end);\n\n // Thresh to [0, Math.PI * 2]\n startAngle = startAngle % (PI2);\n if (startAngle < 0) {\n startAngle = startAngle + PI2;\n }\n endAngle = endAngle % (PI2);\n if (endAngle < 0) {\n endAngle = endAngle + PI2;\n }\n\n if (startAngle > endAngle && !anticlockwise) {\n endAngle += PI2;\n }\n else if (startAngle < endAngle && anticlockwise) {\n startAngle += PI2;\n }\n if (anticlockwise) {\n var tmp = endAngle;\n endAngle = startAngle;\n startAngle = tmp;\n }\n\n // var number = 0;\n // var step = (anticlockwise ? -Math.PI : Math.PI) / 2;\n for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {\n if (angle > startAngle) {\n extremity[0] = mathCos(angle) * rx + x;\n extremity[1] = mathSin(angle) * ry + y;\n\n vec2Min(min, extremity, min);\n vec2Max(max, extremity, max);\n }\n }\n}\n","/**\n * Path 代理,可以在`buildPath`中用于替代`ctx`, 会保存每个path操作的命令到pathCommands属性中\n * 可以用于 isInsidePath 判断以及获取boundingRect\n *\n * @module zrender/core/PathProxy\n * @author Yi Shen (http://www.github.com/pissang)\n */\n\n// TODO getTotalLength, getPointAtLength\n\n/* global Float32Array */\n\nimport * as curve from './curve';\nimport * as vec2 from './vector';\nimport * as bbox from './bbox';\nimport BoundingRect from './BoundingRect';\nimport {devicePixelRatio as dpr} from '../config';\n\nvar CMD = {\n M: 1,\n L: 2,\n C: 3,\n Q: 4,\n A: 5,\n Z: 6,\n // Rect\n R: 7\n};\n\n// var CMD_MEM_SIZE = {\n// M: 3,\n// L: 3,\n// C: 7,\n// Q: 5,\n// A: 9,\n// R: 5,\n// Z: 1\n// };\n\nvar min = [];\nvar max = [];\nvar min2 = [];\nvar max2 = [];\nvar mathMin = Math.min;\nvar mathMax = Math.max;\nvar mathCos = Math.cos;\nvar mathSin = Math.sin;\nvar mathSqrt = Math.sqrt;\nvar mathAbs = Math.abs;\n\nvar hasTypedArray = typeof Float32Array !== 'undefined';\n\n/**\n * @alias module:zrender/core/PathProxy\n * @constructor\n */\nvar PathProxy = function (notSaveData) {\n\n this._saveData = !(notSaveData || false);\n\n if (this._saveData) {\n /**\n * Path data. Stored as flat array\n * @type {Array.<Object>}\n */\n this.data = [];\n }\n\n this._ctx = null;\n};\n\n/**\n * 快速计算Path包围盒(并不是最小包围盒)\n * @return {Object}\n */\nPathProxy.prototype = {\n\n constructor: PathProxy,\n\n _xi: 0,\n _yi: 0,\n\n _x0: 0,\n _y0: 0,\n // Unit x, Unit y. Provide for avoiding drawing that too short line segment\n _ux: 0,\n _uy: 0,\n\n _len: 0,\n\n _lineDash: null,\n\n _dashOffset: 0,\n\n _dashIdx: 0,\n\n _dashSum: 0,\n\n /**\n * @readOnly\n */\n setScale: function (sx, sy, segmentIgnoreThreshold) {\n // Compat. Previously there is no segmentIgnoreThreshold.\n segmentIgnoreThreshold = segmentIgnoreThreshold || 0;\n this._ux = mathAbs(segmentIgnoreThreshold / dpr / sx) || 0;\n this._uy = mathAbs(segmentIgnoreThreshold / dpr / sy) || 0;\n },\n\n getContext: function () {\n return this._ctx;\n },\n\n /**\n * @param {CanvasRenderingContext2D} ctx\n * @return {module:zrender/core/PathProxy}\n */\n beginPath: function (ctx) {\n\n this._ctx = ctx;\n\n ctx && ctx.beginPath();\n\n ctx && (this.dpr = ctx.dpr);\n\n // Reset\n if (this._saveData) {\n this._len = 0;\n }\n\n if (this._lineDash) {\n this._lineDash = null;\n\n this._dashOffset = 0;\n }\n\n return this;\n },\n\n /**\n * @param {number} x\n * @param {number} y\n * @return {module:zrender/core/PathProxy}\n */\n moveTo: function (x, y) {\n this.addData(CMD.M, x, y);\n this._ctx && this._ctx.moveTo(x, y);\n\n // x0, y0, xi, yi 是记录在 _dashedXXXXTo 方法中使用\n // xi, yi 记录当前点, x0, y0 在 closePath 的时候回到起始点。\n // 有可能在 beginPath 之后直接调用 lineTo,这时候 x0, y0 需要\n // 在 lineTo 方法中记录,这里先不考虑这种情况,dashed line 也只在 IE10- 中不支持\n this._x0 = x;\n this._y0 = y;\n\n this._xi = x;\n this._yi = y;\n\n return this;\n },\n\n /**\n * @param {number} x\n * @param {number} y\n * @return {module:zrender/core/PathProxy}\n */\n lineTo: function (x, y) {\n var exceedUnit = mathAbs(x - this._xi) > this._ux\n || mathAbs(y - this._yi) > this._uy\n // Force draw the first segment\n || this._len < 5;\n\n this.addData(CMD.L, x, y);\n\n if (this._ctx && exceedUnit) {\n this._needsDash() ? this._dashedLineTo(x, y)\n : this._ctx.lineTo(x, y);\n }\n if (exceedUnit) {\n this._xi = x;\n this._yi = y;\n }\n\n return this;\n },\n\n /**\n * @param {number} x1\n * @param {number} y1\n * @param {number} x2\n * @param {number} y2\n * @param {number} x3\n * @param {number} y3\n * @return {module:zrender/core/PathProxy}\n */\n bezierCurveTo: function (x1, y1, x2, y2, x3, y3) {\n this.addData(CMD.C, x1, y1, x2, y2, x3, y3);\n if (this._ctx) {\n this._needsDash() ? this._dashedBezierTo(x1, y1, x2, y2, x3, y3)\n : this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);\n }\n this._xi = x3;\n this._yi = y3;\n return this;\n },\n\n /**\n * @param {number} x1\n * @param {number} y1\n * @param {number} x2\n * @param {number} y2\n * @return {module:zrender/core/PathProxy}\n */\n quadraticCurveTo: function (x1, y1, x2, y2) {\n this.addData(CMD.Q, x1, y1, x2, y2);\n if (this._ctx) {\n this._needsDash() ? this._dashedQuadraticTo(x1, y1, x2, y2)\n : this._ctx.quadraticCurveTo(x1, y1, x2, y2);\n }\n this._xi = x2;\n this._yi = y2;\n return this;\n },\n\n /**\n * @param {number} cx\n * @param {number} cy\n * @param {number} r\n * @param {number} startAngle\n * @param {number} endAngle\n * @param {boolean} anticlockwise\n * @return {module:zrender/core/PathProxy}\n */\n arc: function (cx, cy, r, startAngle, endAngle, anticlockwise) {\n this.addData(\n CMD.A, cx, cy, r, r, startAngle, endAngle - startAngle, 0, anticlockwise ? 0 : 1\n );\n this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);\n\n this._xi = mathCos(endAngle) * r + cx;\n this._yi = mathSin(endAngle) * r + cy;\n return this;\n },\n\n // TODO\n arcTo: function (x1, y1, x2, y2, radius) {\n if (this._ctx) {\n this._ctx.arcTo(x1, y1, x2, y2, radius);\n }\n return this;\n },\n\n // TODO\n rect: function (x, y, w, h) {\n this._ctx && this._ctx.rect(x, y, w, h);\n this.addData(CMD.R, x, y, w, h);\n return this;\n },\n\n /**\n * @return {module:zrender/core/PathProxy}\n */\n closePath: function () {\n this.addData(CMD.Z);\n\n var ctx = this._ctx;\n var x0 = this._x0;\n var y0 = this._y0;\n if (ctx) {\n this._needsDash() && this._dashedLineTo(x0, y0);\n ctx.closePath();\n }\n\n this._xi = x0;\n this._yi = y0;\n return this;\n },\n\n /**\n * Context 从外部传入,因为有可能是 rebuildPath 完之后再 fill。\n * stroke 同样\n * @param {CanvasRenderingContext2D} ctx\n * @return {module:zrender/core/PathProxy}\n */\n fill: function (ctx) {\n ctx && ctx.fill();\n this.toStatic();\n },\n\n /**\n * @param {CanvasRenderingContext2D} ctx\n * @return {module:zrender/core/PathProxy}\n */\n stroke: function (ctx) {\n ctx && ctx.stroke();\n this.toStatic();\n },\n\n /**\n * 必须在其它绘制命令前调用\n * Must be invoked before all other path drawing methods\n * @return {module:zrender/core/PathProxy}\n */\n setLineDash: function (lineDash) {\n if (lineDash instanceof Array) {\n this._lineDash = lineDash;\n\n this._dashIdx = 0;\n\n var lineDashSum = 0;\n for (var i = 0; i < lineDash.length; i++) {\n lineDashSum += lineDash[i];\n }\n this._dashSum = lineDashSum;\n }\n return this;\n },\n\n /**\n * 必须在其它绘制命令前调用\n * Must be invoked before all other path drawing methods\n * @return {module:zrender/core/PathProxy}\n */\n setLineDashOffset: function (offset) {\n this._dashOffset = offset;\n return this;\n },\n\n /**\n *\n * @return {boolean}\n */\n len: function () {\n return this._len;\n },\n\n /**\n * 直接设置 Path 数据\n */\n setData: function (data) {\n\n var len = data.length;\n\n if (!(this.data && this.data.length === len) && hasTypedArray) {\n this.data = new Float32Array(len);\n }\n\n for (var i = 0; i < len; i++) {\n this.data[i] = data[i];\n }\n\n this._len = len;\n },\n\n /**\n * 添加子路径\n * @param {module:zrender/core/PathProxy|Array.<module:zrender/core/PathProxy>} path\n */\n appendPath: function (path) {\n if (!(path instanceof Array)) {\n path = [path];\n }\n var len = path.length;\n var appendSize = 0;\n var offset = this._len;\n for (var i = 0; i < len; i++) {\n appendSize += path[i].len();\n }\n if (hasTypedArray && (this.data instanceof Float32Array)) {\n this.data = new Float32Array(offset + appendSize);\n }\n for (var i = 0; i < len; i++) {\n var appendPathData = path[i].data;\n for (var k = 0; k < appendPathData.length; k++) {\n this.data[offset++] = appendPathData[k];\n }\n }\n this._len = offset;\n },\n\n /**\n * 填充 Path 数据。\n * 尽量复用而不申明新的数组。大部分图形重绘的指令数据长度都是不变的。\n */\n addData: function (cmd) {\n if (!this._saveData) {\n return;\n }\n\n var data = this.data;\n if (this._len + arguments.length > data.length) {\n // 因为之前的数组已经转换成静态的 Float32Array\n // 所以不够用时需要扩展一个新的动态数组\n this._expandData();\n data = this.data;\n }\n for (var i = 0; i < arguments.length; i++) {\n data[this._len++] = arguments[i];\n }\n\n this._prevCmd = cmd;\n },\n\n _expandData: function () {\n // Only if data is Float32Array\n if (!(this.data instanceof Array)) {\n var newData = [];\n for (var i = 0; i < this._len; i++) {\n newData[i] = this.data[i];\n }\n this.data = newData;\n }\n },\n\n /**\n * If needs js implemented dashed line\n * @return {boolean}\n * @private\n */\n _needsDash: function () {\n return this._lineDash;\n },\n\n _dashedLineTo: function (x1, y1) {\n var dashSum = this._dashSum;\n var offset = this._dashOffset;\n var lineDash = this._lineDash;\n var ctx = this._ctx;\n\n var x0 = this._xi;\n var y0 = this._yi;\n var dx = x1 - x0;\n var dy = y1 - y0;\n var dist = mathSqrt(dx * dx + dy * dy);\n var x = x0;\n var y = y0;\n var dash;\n var nDash = lineDash.length;\n var idx;\n dx /= dist;\n dy /= dist;\n\n if (offset < 0) {\n // Convert to positive offset\n offset = dashSum + offset;\n }\n offset %= dashSum;\n x -= offset * dx;\n y -= offset * dy;\n\n while ((dx > 0 && x <= x1) || (dx < 0 && x >= x1)\n || (dx === 0 && ((dy > 0 && y <= y1) || (dy < 0 && y >= y1)))) {\n idx = this._dashIdx;\n dash = lineDash[idx];\n x += dx * dash;\n y += dy * dash;\n this._dashIdx = (idx + 1) % nDash;\n // Skip positive offset\n if ((dx > 0 && x < x0) || (dx < 0 && x > x0) || (dy > 0 && y < y0) || (dy < 0 && y > y0)) {\n continue;\n }\n ctx[idx % 2 ? 'moveTo' : 'lineTo'](\n dx >= 0 ? mathMin(x, x1) : mathMax(x, x1),\n dy >= 0 ? mathMin(y, y1) : mathMax(y, y1)\n );\n }\n // Offset for next lineTo\n dx = x - x1;\n dy = y - y1;\n this._dashOffset = -mathSqrt(dx * dx + dy * dy);\n },\n\n // Not accurate dashed line to\n _dashedBezierTo: function (x1, y1, x2, y2, x3, y3) {\n var dashSum = this._dashSum;\n var offset = this._dashOffset;\n var lineDash = this._lineDash;\n var ctx = this._ctx;\n\n var x0 = this._xi;\n var y0 = this._yi;\n var t;\n var dx;\n var dy;\n var cubicAt = curve.cubicAt;\n var bezierLen = 0;\n var idx = this._dashIdx;\n var nDash = lineDash.length;\n\n var x;\n var y;\n\n var tmpLen = 0;\n\n if (offset < 0) {\n // Convert to positive offset\n offset = dashSum + offset;\n }\n offset %= dashSum;\n // Bezier approx length\n for (t = 0; t < 1; t += 0.1) {\n dx = cubicAt(x0, x1, x2, x3, t + 0.1)\n - cubicAt(x0, x1, x2, x3, t);\n dy = cubicAt(y0, y1, y2, y3, t + 0.1)\n - cubicAt(y0, y1, y2, y3, t);\n bezierLen += mathSqrt(dx * dx + dy * dy);\n }\n\n // Find idx after add offset\n for (; idx < nDash; idx++) {\n tmpLen += lineDash[idx];\n if (tmpLen > offset) {\n break;\n }\n }\n t = (tmpLen - offset) / bezierLen;\n\n while (t <= 1) {\n\n x = cubicAt(x0, x1, x2, x3, t);\n y = cubicAt(y0, y1, y2, y3, t);\n\n // Use line to approximate dashed bezier\n // Bad result if dash is long\n idx % 2 ? ctx.moveTo(x, y)\n : ctx.lineTo(x, y);\n\n t += lineDash[idx] / bezierLen;\n\n idx = (idx + 1) % nDash;\n }\n\n // Finish the last segment and calculate the new offset\n (idx % 2 !== 0) && ctx.lineTo(x3, y3);\n dx = x3 - x;\n dy = y3 - y;\n this._dashOffset = -mathSqrt(dx * dx + dy * dy);\n },\n\n _dashedQuadraticTo: function (x1, y1, x2, y2) {\n // Convert quadratic to cubic using degree elevation\n var x3 = x2;\n var y3 = y2;\n x2 = (x2 + 2 * x1) / 3;\n y2 = (y2 + 2 * y1) / 3;\n x1 = (this._xi + 2 * x1) / 3;\n y1 = (this._yi + 2 * y1) / 3;\n\n this._dashedBezierTo(x1, y1, x2, y2, x3, y3);\n },\n\n /**\n * 转成静态的 Float32Array 减少堆内存占用\n * Convert dynamic array to static Float32Array\n */\n toStatic: function () {\n var data = this.data;\n if (data instanceof Array) {\n data.length = this._len;\n if (hasTypedArray) {\n this.data = new Float32Array(data);\n }\n }\n },\n\n /**\n * @return {module:zrender/core/BoundingRect}\n */\n getBoundingRect: function () {\n min[0] = min[1] = min2[0] = min2[1] = Number.MAX_VALUE;\n max[0] = max[1] = max2[0] = max2[1] = -Number.MAX_VALUE;\n\n var data = this.data;\n var xi = 0;\n var yi = 0;\n var x0 = 0;\n var y0 = 0;\n\n for (var i = 0; i < data.length;) {\n var cmd = data[i++];\n\n if (i === 1) {\n // 如果第一个命令是 L, C, Q\n // 则 previous point 同绘制命令的第一个 point\n //\n // 第一个命令为 Arc 的情况下会在后面特殊处理\n xi = data[i];\n yi = data[i + 1];\n\n x0 = xi;\n y0 = yi;\n }\n\n switch (cmd) {\n case CMD.M:\n // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点\n // 在 closePath 的时候使用\n x0 = data[i++];\n y0 = data[i++];\n xi = x0;\n yi = y0;\n min2[0] = x0;\n min2[1] = y0;\n max2[0] = x0;\n max2[1] = y0;\n break;\n case CMD.L:\n bbox.fromLine(xi, yi, data[i], data[i + 1], min2, max2);\n xi = data[i++];\n yi = data[i++];\n break;\n case CMD.C:\n bbox.fromCubic(\n xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],\n min2, max2\n );\n xi = data[i++];\n yi = data[i++];\n break;\n case CMD.Q:\n bbox.fromQuadratic(\n xi, yi, data[i++], data[i++], data[i], data[i + 1],\n min2, max2\n );\n xi = data[i++];\n yi = data[i++];\n break;\n case CMD.A:\n // TODO Arc 判断的开销比较大\n var cx = data[i++];\n var cy = data[i++];\n var rx = data[i++];\n var ry = data[i++];\n var startAngle = data[i++];\n var endAngle = data[i++] + startAngle;\n // TODO Arc 旋转\n i += 1;\n var anticlockwise = 1 - data[i++];\n\n if (i === 1) {\n // 直接使用 arc 命令\n // 第一个命令起点还未定义\n x0 = mathCos(startAngle) * rx + cx;\n y0 = mathSin(startAngle) * ry + cy;\n }\n\n bbox.fromArc(\n cx, cy, rx, ry, startAngle, endAngle,\n anticlockwise, min2, max2\n );\n\n xi = mathCos(endAngle) * rx + cx;\n yi = mathSin(endAngle) * ry + cy;\n break;\n case CMD.R:\n x0 = xi = data[i++];\n y0 = yi = data[i++];\n var width = data[i++];\n var height = data[i++];\n // Use fromLine\n bbox.fromLine(x0, y0, x0 + width, y0 + height, min2, max2);\n break;\n case CMD.Z:\n xi = x0;\n yi = y0;\n break;\n }\n\n // Union\n vec2.min(min, min, min2);\n vec2.max(max, max, max2);\n }\n\n // No data\n if (i === 0) {\n min[0] = min[1] = max[0] = max[1] = 0;\n }\n\n return new BoundingRect(\n min[0], min[1], max[0] - min[0], max[1] - min[1]\n );\n },\n\n /**\n * Rebuild path from current data\n * Rebuild path will not consider javascript implemented line dash.\n * @param {CanvasRenderingContext2D} ctx\n */\n rebuildPath: function (ctx) {\n var d = this.data;\n var x0;\n var y0;\n var xi;\n var yi;\n var x;\n var y;\n var ux = this._ux;\n var uy = this._uy;\n var len = this._len;\n for (var i = 0; i < len;) {\n var cmd = d[i++];\n\n if (i === 1) {\n // 如果第一个命令是 L, C, Q\n // 则 previous point 同绘制命令的第一个 point\n //\n // 第一个命令为 Arc 的情况下会在后面特殊处理\n xi = d[i];\n yi = d[i + 1];\n\n x0 = xi;\n y0 = yi;\n }\n switch (cmd) {\n case CMD.M:\n x0 = xi = d[i++];\n y0 = yi = d[i++];\n ctx.moveTo(xi, yi);\n break;\n case CMD.L:\n x = d[i++];\n y = d[i++];\n // Not draw too small seg between\n if (mathAbs(x - xi) > ux || mathAbs(y - yi) > uy || i === len - 1) {\n ctx.lineTo(x, y);\n xi = x;\n yi = y;\n }\n break;\n case CMD.C:\n ctx.bezierCurveTo(\n d[i++], d[i++], d[i++], d[i++], d[i++], d[i++]\n );\n xi = d[i - 2];\n yi = d[i - 1];\n break;\n case CMD.Q:\n ctx.quadraticCurveTo(d[i++], d[i++], d[i++], d[i++]);\n xi = d[i - 2];\n yi = d[i - 1];\n break;\n case CMD.A:\n var cx = d[i++];\n var cy = d[i++];\n var rx = d[i++];\n var ry = d[i++];\n var theta = d[i++];\n var dTheta = d[i++];\n var psi = d[i++];\n var fs = d[i++];\n var r = (rx > ry) ? rx : ry;\n var scaleX = (rx > ry) ? 1 : rx / ry;\n var scaleY = (rx > ry) ? ry / rx : 1;\n var isEllipse = Math.abs(rx - ry) > 1e-3;\n var endAngle = theta + dTheta;\n if (isEllipse) {\n ctx.translate(cx, cy);\n ctx.rotate(psi);\n ctx.scale(scaleX, scaleY);\n ctx.arc(0, 0, r, theta, endAngle, 1 - fs);\n ctx.scale(1 / scaleX, 1 / scaleY);\n ctx.rotate(-psi);\n ctx.translate(-cx, -cy);\n }\n else {\n ctx.arc(cx, cy, r, theta, endAngle, 1 - fs);\n }\n\n if (i === 1) {\n // 直接使用 arc 命令\n // 第一个命令起点还未定义\n x0 = mathCos(theta) * rx + cx;\n y0 = mathSin(theta) * ry + cy;\n }\n xi = mathCos(endAngle) * rx + cx;\n yi = mathSin(endAngle) * ry + cy;\n break;\n case CMD.R:\n x0 = xi = d[i];\n y0 = yi = d[i + 1];\n ctx.rect(d[i++], d[i++], d[i++], d[i++]);\n break;\n case CMD.Z:\n ctx.closePath();\n xi = x0;\n yi = y0;\n }\n }\n }\n};\n\nPathProxy.CMD = CMD;\n\nexport default PathProxy;","\n/**\n * 线段包含判断\n * @param {number} x0\n * @param {number} y0\n * @param {number} x1\n * @param {number} y1\n * @param {number} lineWidth\n * @param {number} x\n * @param {number} y\n * @return {boolean}\n */\nexport function containStroke(x0, y0, x1, y1, lineWidth, x, y) {\n if (lineWidth === 0) {\n return false;\n }\n var _l = lineWidth;\n var _a = 0;\n var _b = x0;\n // Quick reject\n if (\n (y > y0 + _l && y > y1 + _l)\n || (y < y0 - _l && y < y1 - _l)\n || (x > x0 + _l && x > x1 + _l)\n || (x < x0 - _l && x < x1 - _l)\n ) {\n return false;\n }\n\n if (x0 !== x1) {\n _a = (y0 - y1) / (x0 - x1);\n _b = (x0 * y1 - x1 * y0) / (x0 - x1);\n }\n else {\n return Math.abs(x - x0) <= _l / 2;\n }\n var tmp = _a * x - y + _b;\n var _s = tmp * tmp / (_a * _a + 1);\n return _s <= _l / 2 * _l / 2;\n}","\nimport * as curve from '../core/curve';\n\n/**\n * 三次贝塞尔曲线描边包含判断\n * @param {number} x0\n * @param {number} y0\n * @param {number} x1\n * @param {number} y1\n * @param {number} x2\n * @param {number} y2\n * @param {number} x3\n * @param {number} y3\n * @param {number} lineWidth\n * @param {number} x\n * @param {number} y\n * @return {boolean}\n */\nexport function containStroke(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {\n if (lineWidth === 0) {\n return false;\n }\n var _l = lineWidth;\n // Quick reject\n if (\n (y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l)\n || (y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l)\n || (x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l)\n || (x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l)\n ) {\n return false;\n }\n var d = curve.cubicProjectPoint(\n x0, y0, x1, y1, x2, y2, x3, y3,\n x, y, null\n );\n return d <= _l / 2;\n}","import {quadraticProjectPoint} from '../core/curve';\n\n/**\n * 二次贝塞尔曲线描边包含判断\n * @param {number} x0\n * @param {number} y0\n * @param {number} x1\n * @param {number} y1\n * @param {number} x2\n * @param {number} y2\n * @param {number} lineWidth\n * @param {number} x\n * @param {number} y\n * @return {boolean}\n */\nexport function containStroke(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {\n if (lineWidth === 0) {\n return false;\n }\n var _l = lineWidth;\n // Quick reject\n if (\n (y > y0 + _l && y > y1 + _l && y > y2 + _l)\n || (y < y0 - _l && y < y1 - _l && y < y2 - _l)\n || (x > x0 + _l && x > x1 + _l && x > x2 + _l)\n || (x < x0 - _l && x < x1 - _l && x < x2 - _l)\n ) {\n return false;\n }\n var d = quadraticProjectPoint(\n x0, y0, x1, y1, x2, y2,\n x, y, null\n );\n return d <= _l / 2;\n}\n","\nvar PI2 = Math.PI * 2;\n\nexport function normalizeRadian(angle) {\n angle %= PI2;\n if (angle < 0) {\n angle += PI2;\n }\n return angle;\n}","\nimport {normalizeRadian} from './util';\n\nvar PI2 = Math.PI * 2;\n\n/**\n * 圆弧描边包含判断\n * @param {number} cx\n * @param {number} cy\n * @param {number} r\n * @param {number} startAngle\n * @param {number} endAngle\n * @param {boolean} anticlockwise\n * @param {number} lineWidth\n * @param {number} x\n * @param {number} y\n * @return {Boolean}\n */\nexport function containStroke(\n cx, cy, r, startAngle, endAngle, anticlockwise,\n lineWidth, x, y\n) {\n\n if (lineWidth === 0) {\n return false;\n }\n var _l = lineWidth;\n\n x -= cx;\n y -= cy;\n var d = Math.sqrt(x * x + y * y);\n\n if ((d - _l > r) || (d + _l < r)) {\n return false;\n }\n if (Math.abs(startAngle - endAngle) % PI2 < 1e-4) {\n // Is a circle\n return true;\n }\n if (anticlockwise) {\n var tmp = startAngle;\n startAngle = normalizeRadian(endAngle);\n endAngle = normalizeRadian(tmp);\n }\n else {\n startAngle = normalizeRadian(startAngle);\n endAngle = normalizeRadian(endAngle);\n }\n if (startAngle > endAngle) {\n endAngle += PI2;\n }\n\n var angle = Math.atan2(y, x);\n if (angle < 0) {\n angle += PI2;\n }\n return (angle >= startAngle && angle <= endAngle)\n || (angle + PI2 >= startAngle && angle + PI2 <= endAngle);\n}","\nexport default function windingLine(x0, y0, x1, y1, x, y) {\n if ((y > y0 && y > y1) || (y < y0 && y < y1)) {\n return 0;\n }\n // Ignore horizontal line\n if (y1 === y0) {\n return 0;\n }\n var dir = y1 < y0 ? 1 : -1;\n var t = (y - y0) / (y1 - y0);\n\n // Avoid winding error when intersection point is the connect point of two line of polygon\n if (t === 1 || t === 0) {\n dir = y1 < y0 ? 0.5 : -0.5;\n }\n\n var x_ = t * (x1 - x0) + x0;\n\n // If (x, y) on the line, considered as \"contain\".\n return x_ === x ? Infinity : x_ > x ? dir : 0;\n}","import PathProxy from '../core/PathProxy';\nimport * as line from './line';\nimport * as cubic from './cubic';\nimport * as quadratic from './quadratic';\nimport * as arc from './arc';\nimport {normalizeRadian} from './util';\nimport * as curve from '../core/curve';\nimport windingLine from './windingLine';\n\nvar CMD = PathProxy.CMD;\nvar PI2 = Math.PI * 2;\n\nvar EPSILON = 1e-4;\n\nfunction isAroundEqual(a, b) {\n return Math.abs(a - b) < EPSILON;\n}\n\n// 临时数组\nvar roots = [-1, -1, -1];\nvar extrema = [-1, -1];\n\nfunction swapExtrema() {\n var tmp = extrema[0];\n extrema[0] = extrema[1];\n extrema[1] = tmp;\n}\n\nfunction windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {\n // Quick reject\n if (\n (y > y0 && y > y1 && y > y2 && y > y3)\n || (y < y0 && y < y1 && y < y2 && y < y3)\n ) {\n return 0;\n }\n var nRoots = curve.cubicRootAt(y0, y1, y2, y3, y, roots);\n if (nRoots === 0) {\n return 0;\n }\n else {\n var w = 0;\n var nExtrema = -1;\n var y0_;\n var y1_;\n for (var i = 0; i < nRoots; i++) {\n var t = roots[i];\n\n // Avoid winding error when intersection point is the connect point of two line of polygon\n var unit = (t === 0 || t === 1) ? 0.5 : 1;\n\n var x_ = curve.cubicAt(x0, x1, x2, x3, t);\n if (x_ < x) { // Quick reject\n continue;\n }\n if (nExtrema < 0) {\n nExtrema = curve.cubicExtrema(y0, y1, y2, y3, extrema);\n if (extrema[1] < extrema[0] && nExtrema > 1) {\n swapExtrema();\n }\n y0_ = curve.cubicAt(y0, y1, y2, y3, extrema[0]);\n if (nExtrema > 1) {\n y1_ = curve.cubicAt(y0, y1, y2, y3, extrema[1]);\n }\n }\n if (nExtrema === 2) {\n // 分成三段单调函数\n if (t < extrema[0]) {\n w += y0_ < y0 ? unit : -unit;\n }\n else if (t < extrema[1]) {\n w += y1_ < y0_ ? unit : -unit;\n }\n else {\n w += y3 < y1_ ? unit : -unit;\n }\n }\n else {\n // 分成两段单调函数\n if (t < extrema[0]) {\n w += y0_ < y0 ? unit : -unit;\n }\n else {\n w += y3 < y0_ ? unit : -unit;\n }\n }\n }\n return w;\n }\n}\n\nfunction windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {\n // Quick reject\n if (\n (y > y0 && y > y1 && y > y2)\n || (y < y0 && y < y1 && y < y2)\n ) {\n return 0;\n }\n var nRoots = curve.quadraticRootAt(y0, y1, y2, y, roots);\n if (nRoots === 0) {\n return 0;\n }\n else {\n var t = curve.quadraticExtremum(y0, y1, y2);\n if (t >= 0 && t <= 1) {\n var w = 0;\n var y_ = curve.quadraticAt(y0, y1, y2, t);\n for (var i = 0; i < nRoots; i++) {\n // Remove one endpoint.\n var unit = (roots[i] === 0 || roots[i] === 1) ? 0.5 : 1;\n\n var x_ = curve.quadraticAt(x0, x1, x2, roots[i]);\n if (x_ < x) { // Quick reject\n continue;\n }\n if (roots[i] < t) {\n w += y_ < y0 ? unit : -unit;\n }\n else {\n w += y2 < y_ ? unit : -unit;\n }\n }\n return w;\n }\n else {\n // Remove one endpoint.\n var unit = (roots[0] === 0 || roots[0] === 1) ? 0.5 : 1;\n\n var x_ = curve.quadraticAt(x0, x1, x2, roots[0]);\n if (x_ < x) { // Quick reject\n return 0;\n }\n return y2 < y0 ? unit : -unit;\n }\n }\n}\n\n// TODO\n// Arc 旋转\nfunction windingArc(\n cx, cy, r, startAngle, endAngle, anticlockwise, x, y\n) {\n y -= cy;\n if (y > r || y < -r) {\n return 0;\n }\n var tmp = Math.sqrt(r * r - y * y);\n roots[0] = -tmp;\n roots[1] = tmp;\n\n var diff = Math.abs(startAngle - endAngle);\n if (diff < 1e-4) {\n return 0;\n }\n if (diff % PI2 < 1e-4) {\n // Is a circle\n startAngle = 0;\n endAngle = PI2;\n var dir = anticlockwise ? 1 : -1;\n if (x >= roots[0] + cx && x <= roots[1] + cx) {\n return dir;\n }\n else {\n return 0;\n }\n }\n\n if (anticlockwise) {\n var tmp = startAngle;\n startAngle = normalizeRadian(endAngle);\n endAngle = normalizeRadian(tmp);\n }\n else {\n startAngle = normalizeRadian(startAngle);\n endAngle = normalizeRadian(endAngle);\n }\n if (startAngle > endAngle) {\n endAngle += PI2;\n }\n\n var w = 0;\n for (var i = 0; i < 2; i++) {\n var x_ = roots[i];\n if (x_ + cx > x) {\n var angle = Math.atan2(y, x_);\n var dir = anticlockwise ? 1 : -1;\n if (angle < 0) {\n angle = PI2 + angle;\n }\n if (\n (angle >= startAngle && angle <= endAngle)\n || (angle + PI2 >= startAngle && angle + PI2 <= endAngle)\n ) {\n if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {\n dir = -dir;\n }\n w += dir;\n }\n }\n }\n return w;\n}\n\nfunction containPath(data, lineWidth, isStroke, x, y) {\n var w = 0;\n var xi = 0;\n var yi = 0;\n var x0 = 0;\n var y0 = 0;\n\n for (var i = 0; i < data.length;) {\n var cmd = data[i++];\n // Begin a new subpath\n if (cmd === CMD.M && i > 1) {\n // Close previous subpath\n if (!isStroke) {\n w += windingLine(xi, yi, x0, y0, x, y);\n }\n // 如果被任何一个 subpath 包含\n // if (w !== 0) {\n // return true;\n // }\n }\n\n if (i === 1) {\n // 如果第一个命令是 L, C, Q\n // 则 previous point 同绘制命令的第一个 point\n //\n // 第一个命令为 Arc 的情况下会在后面特殊处理\n xi = data[i];\n yi = data[i + 1];\n\n x0 = xi;\n y0 = yi;\n }\n\n switch (cmd) {\n case CMD.M:\n // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点\n // 在 closePath 的时候使用\n x0 = data[i++];\n y0 = data[i++];\n xi = x0;\n yi = y0;\n break;\n case CMD.L:\n if (isStroke) {\n if (line.containStroke(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {\n return true;\n }\n }\n else {\n // NOTE 在第一个命令为 L, C, Q 的时候会计算出 NaN\n w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;\n }\n xi = data[i++];\n yi = data[i++];\n break;\n case CMD.C:\n if (isStroke) {\n if (cubic.containStroke(xi, yi,\n data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],\n lineWidth, x, y\n )) {\n return true;\n }\n }\n else {\n w += windingCubic(\n xi, yi,\n data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],\n x, y\n ) || 0;\n }\n xi = data[i++];\n yi = data[i++];\n break;\n case CMD.Q:\n if (isStroke) {\n if (quadratic.containStroke(xi, yi,\n data[i++], data[i++], data[i], data[i + 1],\n lineWidth, x, y\n )) {\n return true;\n }\n }\n else {\n w += windingQuadratic(\n xi, yi,\n data[i++], data[i++], data[i], data[i + 1],\n x, y\n ) || 0;\n }\n xi = data[i++];\n yi = data[i++];\n break;\n case CMD.A:\n // TODO Arc 判断的开销比较大\n var cx = data[i++];\n var cy = data[i++];\n var rx = data[i++];\n var ry = data[i++];\n var theta = data[i++];\n var dTheta = data[i++];\n // TODO Arc 旋转\n i += 1;\n var anticlockwise = 1 - data[i++];\n var x1 = Math.cos(theta) * rx + cx;\n var y1 = Math.sin(theta) * ry + cy;\n // 不是直接使用 arc 命令\n if (i > 1) {\n w += windingLine(xi, yi, x1, y1, x, y);\n }\n else {\n // 第一个命令起点还未定义\n x0 = x1;\n y0 = y1;\n }\n // zr 使用scale来模拟椭圆, 这里也对x做一定的缩放\n var _x = (x - cx) * ry / rx + cx;\n if (isStroke) {\n if (arc.containStroke(\n cx, cy, ry, theta, theta + dTheta, anticlockwise,\n lineWidth, _x, y\n )) {\n return true;\n }\n }\n else {\n w += windingArc(\n cx, cy, ry, theta, theta + dTheta, anticlockwise,\n _x, y\n );\n }\n xi = Math.cos(theta + dTheta) * rx + cx;\n yi = Math.sin(theta + dTheta) * ry + cy;\n break;\n case CMD.R:\n x0 = xi = data[i++];\n y0 = yi = data[i++];\n var width = data[i++];\n var height = data[i++];\n var x1 = x0 + width;\n var y1 = y0 + height;\n if (isStroke) {\n if (line.containStroke(x0, y0, x1, y0, lineWidth, x, y)\n || line.containStroke(x1, y0, x1, y1, lineWidth, x, y)\n || line.containStroke(x1, y1, x0, y1, lineWidth, x, y)\n || line.containStroke(x0, y1, x0, y0, lineWidth, x, y)\n ) {\n return true;\n }\n }\n else {\n // FIXME Clockwise ?\n w += windingLine(x1, y0, x1, y1, x, y);\n w += windingLine(x0, y1, x0, y0, x, y);\n }\n break;\n case CMD.Z:\n if (isStroke) {\n if (line.containStroke(\n xi, yi, x0, y0, lineWidth, x, y\n )) {\n return true;\n }\n }\n else {\n // Close a subpath\n w += windingLine(xi, yi, x0, y0, x, y);\n // 如果被任何一个 subpath 包含\n // FIXME subpaths may overlap\n // if (w !== 0) {\n // return true;\n // }\n }\n xi = x0;\n yi = y0;\n break;\n }\n }\n if (!isStroke && !isAroundEqual(yi, y0)) {\n w += windingLine(xi, yi, x0, y0, x, y) || 0;\n }\n return w !== 0;\n}\n\nexport function contain(pathData, x, y) {\n return containPath(pathData, 0, false, x, y);\n}\n\nexport function containStroke(pathData, lineWidth, x, y) {\n return containPath(pathData, lineWidth, true, x, y);\n}","import Displayable from './Displayable';\nimport * as zrUtil from '../core/util';\nimport PathProxy from '../core/PathProxy';\nimport * as pathContain from '../contain/path';\nimport Pattern from './Pattern';\n\nvar getCanvasPattern = Pattern.prototype.getCanvasPattern;\n\nvar abs = Math.abs;\n\nvar pathProxyForDraw = new PathProxy(true);\n/**\n * @alias module:zrender/graphic/Path\n * @extends module:zrender/graphic/Displayable\n * @constructor\n * @param {Object} opts\n */\nfunction Path(opts) {\n Displayable.call(this, opts);\n\n /**\n * @type {module:zrender/core/PathProxy}\n * @readOnly\n */\n this.path = null;\n}\n\nPath.prototype = {\n\n constructor: Path,\n\n type: 'path',\n\n __dirtyPath: true,\n\n strokeContainThreshold: 5,\n\n // This item default to be false. But in map series in echarts,\n // in order to improve performance, it should be set to true,\n // so the shorty segment won't draw.\n segmentIgnoreThreshold: 0,\n\n /**\n * See `module:zrender/src/graphic/helper/subPixelOptimize`.\n * @type {boolean}\n */\n subPixelOptimize: false,\n\n brush: function (ctx, prevEl) {\n var style = this.style;\n var path = this.path || pathProxyForDraw;\n var hasStroke = style.hasStroke();\n var hasFill = style.hasFill();\n var fill = style.fill;\n var stroke = style.stroke;\n var hasFillGradient = hasFill && !!(fill.colorStops);\n var hasStrokeGradient = hasStroke && !!(stroke.colorStops);\n var hasFillPattern = hasFill && !!(fill.image);\n var hasStrokePattern = hasStroke && !!(stroke.image);\n\n style.bind(ctx, this, prevEl);\n this.setTransform(ctx);\n\n if (this.__dirty) {\n var rect;\n // Update gradient because bounding rect may changed\n if (hasFillGradient) {\n rect = rect || this.getBoundingRect();\n this._fillGradient = style.getGradient(ctx, fill, rect);\n }\n if (hasStrokeGradient) {\n rect = rect || this.getBoundingRect();\n this._strokeGradient = style.getGradient(ctx, stroke, rect);\n }\n }\n // Use the gradient or pattern\n if (hasFillGradient) {\n // PENDING If may have affect the state\n ctx.fillStyle = this._fillGradient;\n }\n else if (hasFillPattern) {\n ctx.fillStyle = getCanvasPattern.call(fill, ctx);\n }\n if (hasStrokeGradient) {\n ctx.strokeStyle = this._strokeGradient;\n }\n else if (hasStrokePattern) {\n ctx.strokeStyle = getCanvasPattern.call(stroke, ctx);\n }\n\n var lineDash = style.lineDash;\n var lineDashOffset = style.lineDashOffset;\n\n var ctxLineDash = !!ctx.setLineDash;\n\n // Update path sx, sy\n var scale = this.getGlobalScale();\n path.setScale(scale[0], scale[1], this.segmentIgnoreThreshold);\n\n // Proxy context\n // Rebuild path in following 2 cases\n // 1. Path is dirty\n // 2. Path needs javascript implemented lineDash stroking.\n // In this case, lineDash information will not be saved in PathProxy\n if (this.__dirtyPath\n || (lineDash && !ctxLineDash && hasStroke)\n ) {\n path.beginPath(ctx);\n\n // Setting line dash before build path\n if (lineDash && !ctxLineDash) {\n path.setLineDash(lineDash);\n path.setLineDashOffset(lineDashOffset);\n }\n\n this.buildPath(path, this.shape, false);\n\n // Clear path dirty flag\n if (this.path) {\n this.__dirtyPath = false;\n }\n }\n else {\n // Replay path building\n ctx.beginPath();\n this.path.rebuildPath(ctx);\n }\n\n if (hasFill) {\n if (style.fillOpacity != null) {\n var originalGlobalAlpha = ctx.globalAlpha;\n ctx.globalAlpha = style.fillOpacity * style.opacity;\n path.fill(ctx);\n ctx.globalAlpha = originalGlobalAlpha;\n }\n else {\n path.fill(ctx);\n }\n }\n\n if (lineDash && ctxLineDash) {\n ctx.setLineDash(lineDash);\n ctx.lineDashOffset = lineDashOffset;\n }\n\n if (hasStroke) {\n if (style.strokeOpacity != null) {\n var originalGlobalAlpha = ctx.globalAlpha;\n ctx.globalAlpha = style.strokeOpacity * style.opacity;\n path.stroke(ctx);\n ctx.globalAlpha = originalGlobalAlpha;\n }\n else {\n path.stroke(ctx);\n }\n }\n\n if (lineDash && ctxLineDash) {\n // PENDING\n // Remove lineDash\n ctx.setLineDash([]);\n }\n\n // Draw rect text\n if (style.text != null) {\n // Only restore transform when needs draw text.\n this.restoreTransform(ctx);\n this.drawRectText(ctx, this.getBoundingRect());\n }\n },\n\n // When bundling path, some shape may decide if use moveTo to begin a new subpath or closePath\n // Like in circle\n buildPath: function (ctx, shapeCfg, inBundle) {},\n\n createPathProxy: function () {\n this.path = new PathProxy();\n },\n\n getBoundingRect: function () {\n var rect = this._rect;\n var style = this.style;\n var needsUpdateRect = !rect;\n if (needsUpdateRect) {\n var path = this.path;\n if (!path) {\n // Create path on demand.\n path = this.path = new PathProxy();\n }\n if (this.__dirtyPath) {\n path.beginPath();\n this.buildPath(path, this.shape, false);\n }\n rect = path.getBoundingRect();\n }\n this._rect = rect;\n\n if (style.hasStroke()) {\n // Needs update rect with stroke lineWidth when\n // 1. Element changes scale or lineWidth\n // 2. Shape is changed\n var rectWithStroke = this._rectWithStroke || (this._rectWithStroke = rect.clone());\n if (this.__dirty || needsUpdateRect) {\n rectWithStroke.copy(rect);\n // FIXME Must after updateTransform\n var w = style.lineWidth;\n // PENDING, Min line width is needed when line is horizontal or vertical\n var lineScale = style.strokeNoScale ? this.getLineScale() : 1;\n\n // Only add extra hover lineWidth when there are no fill\n if (!style.hasFill()) {\n w = Math.max(w, this.strokeContainThreshold || 4);\n }\n // Consider line width\n // Line scale can't be 0;\n if (lineScale > 1e-10) {\n rectWithStroke.width += w / lineScale;\n rectWithStroke.height += w / lineScale;\n rectWithStroke.x -= w / lineScale / 2;\n rectWithStroke.y -= w / lineScale / 2;\n }\n }\n\n // Return rect with stroke\n return rectWithStroke;\n }\n\n return rect;\n },\n\n contain: function (x, y) {\n var localPos = this.transformCoordToLocal(x, y);\n var rect = this.getBoundingRect();\n var style = this.style;\n x = localPos[0];\n y = localPos[1];\n\n if (rect.contain(x, y)) {\n var pathData = this.path.data;\n if (style.hasStroke()) {\n var lineWidth = style.lineWidth;\n var lineScale = style.strokeNoScale ? this.getLineScale() : 1;\n // Line scale can't be 0;\n if (lineScale > 1e-10) {\n // Only add extra hover lineWidth when there are no fill\n if (!style.hasFill()) {\n lineWidth = Math.max(lineWidth, this.strokeContainThreshold);\n }\n if (pathContain.containStroke(\n pathData, lineWidth / lineScale, x, y\n )) {\n return true;\n }\n }\n }\n if (style.hasFill()) {\n return pathContain.contain(pathData, x, y);\n }\n }\n return false;\n },\n\n /**\n * @param {boolean} dirtyPath\n */\n dirty: function (dirtyPath) {\n if (dirtyPath == null) {\n dirtyPath = true;\n }\n // Only mark dirty, not mark clean\n if (dirtyPath) {\n this.__dirtyPath = dirtyPath;\n this._rect = null;\n }\n\n this.__dirty = this.__dirtyText = true;\n\n this.__zr && this.__zr.refresh();\n\n // Used as a clipping path\n if (this.__clipTarget) {\n this.__clipTarget.dirty();\n }\n },\n\n /**\n * Alias for animate('shape')\n * @param {boolean} loop\n */\n animateShape: function (loop) {\n return this.animate('shape', loop);\n },\n\n // Overwrite attrKV\n attrKV: function (key, value) {\n // FIXME\n if (key === 'shape') {\n this.setShape(value);\n this.__dirtyPath = true;\n this._rect = null;\n }\n else {\n Displayable.prototype.attrKV.call(this, key, value);\n }\n },\n\n /**\n * @param {Object|string} key\n * @param {*} value\n */\n setShape: function (key, value) {\n var shape = this.shape;\n // Path from string may not have shape\n if (shape) {\n if (zrUtil.isObject(key)) {\n for (var name in key) {\n if (key.hasOwnProperty(name)) {\n shape[name] = key[name];\n }\n }\n }\n else {\n shape[key] = value;\n }\n this.dirty(true);\n }\n return this;\n },\n\n getLineScale: function () {\n var m = this.transform;\n // Get the line scale.\n // Determinant of `m` means how much the area is enlarged by the\n // transformation. So its square root can be used as a scale factor\n // for width.\n return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10\n ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1]))\n : 1;\n }\n};\n\n/**\n * 扩展一个 Path element, 比如星形,圆等。\n * Extend a path element\n * @param {Object} props\n * @param {string} props.type Path type\n * @param {Function} props.init Initialize\n * @param {Function} props.buildPath Overwrite buildPath method\n * @param {Object} [props.style] Extended default style config\n * @param {Object} [props.shape] Extended default shape config\n */\nPath.extend = function (defaults) {\n var Sub = function (opts) {\n Path.call(this, opts);\n\n if (defaults.style) {\n // Extend default style\n this.style.extendFrom(defaults.style, false);\n }\n\n // Extend default shape\n var defaultShape = defaults.shape;\n if (defaultShape) {\n this.shape = this.shape || {};\n var thisShape = this.shape;\n for (var name in defaultShape) {\n if (\n !thisShape.hasOwnProperty(name)\n && defaultShape.hasOwnProperty(name)\n ) {\n thisShape[name] = defaultShape[name];\n }\n }\n }\n\n defaults.init && defaults.init.call(this, opts);\n };\n\n zrUtil.inherits(Sub, Path);\n\n // FIXME 不能 extend position, rotation 等引用对象\n for (var name in defaults) {\n // Extending prototype values and methods\n if (name !== 'style' && name !== 'shape') {\n Sub.prototype[name] = defaults[name];\n }\n }\n\n return Sub;\n};\n\nzrUtil.inherits(Path, Displayable);\n\nexport default Path;","import PathProxy from '../core/PathProxy';\nimport {applyTransform as v2ApplyTransform} from '../core/vector';\n\nvar CMD = PathProxy.CMD;\n\nvar points = [[], [], []];\nvar mathSqrt = Math.sqrt;\nvar mathAtan2 = Math.atan2;\n\nexport default function (path, m) {\n var data = path.data;\n var cmd;\n var nPoint;\n var i;\n var j;\n var k;\n var p;\n\n var M = CMD.M;\n var C = CMD.C;\n var L = CMD.L;\n var R = CMD.R;\n var A = CMD.A;\n var Q = CMD.Q;\n\n for (i = 0, j = 0; i < data.length;) {\n cmd = data[i++];\n j = i;\n nPoint = 0;\n\n switch (cmd) {\n case M:\n nPoint = 1;\n break;\n case L:\n nPoint = 1;\n break;\n case C:\n nPoint = 3;\n break;\n case Q:\n nPoint = 2;\n break;\n case A:\n var x = m[4];\n var y = m[5];\n var sx = mathSqrt(m[0] * m[0] + m[1] * m[1]);\n var sy = mathSqrt(m[2] * m[2] + m[3] * m[3]);\n var angle = mathAtan2(-m[1] / sy, m[0] / sx);\n // cx\n data[i] *= sx;\n data[i++] += x;\n // cy\n data[i] *= sy;\n data[i++] += y;\n // Scale rx and ry\n // FIXME Assume psi is 0 here\n data[i++] *= sx;\n data[i++] *= sy;\n\n // Start angle\n data[i++] += angle;\n // end angle\n data[i++] += angle;\n // FIXME psi\n i += 2;\n j = i;\n break;\n case R:\n // x0, y0\n p[0] = data[i++];\n p[1] = data[i++];\n v2ApplyTransform(p, p, m);\n data[j++] = p[0];\n data[j++] = p[1];\n // x1, y1\n p[0] += data[i++];\n p[1] += data[i++];\n v2ApplyTransform(p, p, m);\n data[j++] = p[0];\n data[j++] = p[1];\n }\n\n for (k = 0; k < nPoint; k++) {\n var p = points[k];\n p[0] = data[i++];\n p[1] = data[i++];\n\n v2ApplyTransform(p, p, m);\n // Write back\n data[j++] = p[0];\n data[j++] = p[1];\n }\n }\n}\n","import Path from '../graphic/Path';\nimport PathProxy from '../core/PathProxy';\nimport transformPath from './transformPath';\n\n// command chars\n// var cc = [\n// 'm', 'M', 'l', 'L', 'v', 'V', 'h', 'H', 'z', 'Z',\n// 'c', 'C', 'q', 'Q', 't', 'T', 's', 'S', 'a', 'A'\n// ];\n\nvar mathSqrt = Math.sqrt;\nvar mathSin = Math.sin;\nvar mathCos = Math.cos;\nvar PI = Math.PI;\n\nvar vMag = function (v) {\n return Math.sqrt(v[0] * v[0] + v[1] * v[1]);\n};\nvar vRatio = function (u, v) {\n return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));\n};\nvar vAngle = function (u, v) {\n return (u[0] * v[1] < u[1] * v[0] ? -1 : 1)\n * Math.acos(vRatio(u, v));\n};\n\nfunction processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {\n var psi = psiDeg * (PI / 180.0);\n var xp = mathCos(psi) * (x1 - x2) / 2.0\n + mathSin(psi) * (y1 - y2) / 2.0;\n var yp = -1 * mathSin(psi) * (x1 - x2) / 2.0\n + mathCos(psi) * (y1 - y2) / 2.0;\n\n var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);\n\n if (lambda > 1) {\n rx *= mathSqrt(lambda);\n ry *= mathSqrt(lambda);\n }\n\n var f = (fa === fs ? -1 : 1)\n * mathSqrt((((rx * rx) * (ry * ry))\n - ((rx * rx) * (yp * yp))\n - ((ry * ry) * (xp * xp))) / ((rx * rx) * (yp * yp)\n + (ry * ry) * (xp * xp))\n ) || 0;\n\n var cxp = f * rx * yp / ry;\n var cyp = f * -ry * xp / rx;\n\n var cx = (x1 + x2) / 2.0\n + mathCos(psi) * cxp\n - mathSin(psi) * cyp;\n var cy = (y1 + y2) / 2.0\n + mathSin(psi) * cxp\n + mathCos(psi) * cyp;\n\n var theta = vAngle([ 1, 0 ], [ (xp - cxp) / rx, (yp - cyp) / ry ]);\n var u = [ (xp - cxp) / rx, (yp - cyp) / ry ];\n var v = [ (-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry ];\n var dTheta = vAngle(u, v);\n\n if (vRatio(u, v) <= -1) {\n dTheta = PI;\n }\n if (vRatio(u, v) >= 1) {\n dTheta = 0;\n }\n if (fs === 0 && dTheta > 0) {\n dTheta = dTheta - 2 * PI;\n }\n if (fs === 1 && dTheta < 0) {\n dTheta = dTheta + 2 * PI;\n }\n\n path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);\n}\n\n\nvar commandReg = /([mlvhzcqtsa])([^mlvhzcqtsa]*)/ig;\n// Consider case:\n// (1) delimiter can be comma or space, where continuous commas\n// or spaces should be seen as one comma.\n// (2) value can be like:\n// '2e-4', 'l.5.9' (ignore 0), 'M-10-10', 'l-2.43e-1,34.9983',\n// 'l-.5E1,54', '121-23-44-11' (no delimiter)\nvar numberReg = /-?([0-9]*\\.)?[0-9]+([eE]-?[0-9]+)?/g;\n// var valueSplitReg = /[\\s,]+/;\n\nfunction createPathProxyFromString(data) {\n if (!data) {\n return new PathProxy();\n }\n\n // var data = data.replace(/-/g, ' -')\n // .replace(/ /g, ' ')\n // .replace(/ /g, ',')\n // .replace(/,,/g, ',');\n\n // var n;\n // create pipes so that we can split the data\n // for (n = 0; n < cc.length; n++) {\n // cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);\n // }\n\n // data = data.replace(/-/g, ',-');\n\n // create array\n // var arr = cs.split('|');\n // init context point\n var cpx = 0;\n var cpy = 0;\n var subpathX = cpx;\n var subpathY = cpy;\n var prevCmd;\n\n var path = new PathProxy();\n var CMD = PathProxy.CMD;\n\n // commandReg.lastIndex = 0;\n // var cmdResult;\n // while ((cmdResult = commandReg.exec(data)) != null) {\n // var cmdStr = cmdResult[1];\n // var cmdContent = cmdResult[2];\n\n var cmdList = data.match(commandReg);\n for (var l = 0; l < cmdList.length; l++) {\n var cmdText = cmdList[l];\n var cmdStr = cmdText.charAt(0);\n\n var cmd;\n\n // String#split is faster a little bit than String#replace or RegExp#exec.\n // var p = cmdContent.split(valueSplitReg);\n // var pLen = 0;\n // for (var i = 0; i < p.length; i++) {\n // // '' and other invalid str => NaN\n // var val = parseFloat(p[i]);\n // !isNaN(val) && (p[pLen++] = val);\n // }\n\n var p = cmdText.match(numberReg) || [];\n var pLen = p.length;\n for (var i = 0; i < pLen; i++) {\n p[i] = parseFloat(p[i]);\n }\n\n var off = 0;\n while (off < pLen) {\n var ctlPtx;\n var ctlPty;\n\n var rx;\n var ry;\n var psi;\n var fa;\n var fs;\n\n var x1 = cpx;\n var y1 = cpy;\n\n // convert l, H, h, V, and v to L\n switch (cmdStr) {\n case 'l':\n cpx += p[off++];\n cpy += p[off++];\n cmd = CMD.L;\n path.addData(cmd, cpx, cpy);\n break;\n case 'L':\n cpx = p[off++];\n cpy = p[off++];\n cmd = CMD.L;\n path.addData(cmd, cpx, cpy);\n break;\n case 'm':\n cpx += p[off++];\n cpy += p[off++];\n cmd = CMD.M;\n path.addData(cmd, cpx, cpy);\n subpathX = cpx;\n subpathY = cpy;\n cmdStr = 'l';\n break;\n case 'M':\n cpx = p[off++];\n cpy = p[off++];\n cmd = CMD.M;\n path.addData(cmd, cpx, cpy);\n subpathX = cpx;\n subpathY = cpy;\n cmdStr = 'L';\n break;\n case 'h':\n cpx += p[off++];\n cmd = CMD.L;\n path.addData(cmd, cpx, cpy);\n break;\n case 'H':\n cpx = p[off++];\n cmd = CMD.L;\n path.addData(cmd, cpx, cpy);\n break;\n case 'v':\n cpy += p[off++];\n cmd = CMD.L;\n path.addData(cmd, cpx, cpy);\n break;\n case 'V':\n cpy = p[off++];\n cmd = CMD.L;\n path.addData(cmd, cpx, cpy);\n break;\n case 'C':\n cmd = CMD.C;\n path.addData(\n cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]\n );\n cpx = p[off - 2];\n cpy = p[off - 1];\n break;\n case 'c':\n cmd = CMD.C;\n path.addData(\n cmd,\n p[off++] + cpx, p[off++] + cpy,\n p[off++] + cpx, p[off++] + cpy,\n p[off++] + cpx, p[off++] + cpy\n );\n cpx += p[off - 2];\n cpy += p[off - 1];\n break;\n case 'S':\n ctlPtx = cpx;\n ctlPty = cpy;\n var len = path.len();\n var pathData = path.data;\n if (prevCmd === CMD.C) {\n ctlPtx += cpx - pathData[len - 4];\n ctlPty += cpy - pathData[len - 3];\n }\n cmd = CMD.C;\n x1 = p[off++];\n y1 = p[off++];\n cpx = p[off++];\n cpy = p[off++];\n path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);\n break;\n case 's':\n ctlPtx = cpx;\n ctlPty = cpy;\n var len = path.len();\n var pathData = path.data;\n if (prevCmd === CMD.C) {\n ctlPtx += cpx - pathData[len - 4];\n ctlPty += cpy - pathData[len - 3];\n }\n cmd = CMD.C;\n x1 = cpx + p[off++];\n y1 = cpy + p[off++];\n cpx += p[off++];\n cpy += p[off++];\n path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);\n break;\n case 'Q':\n x1 = p[off++];\n y1 = p[off++];\n cpx = p[off++];\n cpy = p[off++];\n cmd = CMD.Q;\n path.addData(cmd, x1, y1, cpx, cpy);\n break;\n case 'q':\n x1 = p[off++] + cpx;\n y1 = p[off++] + cpy;\n cpx += p[off++];\n cpy += p[off++];\n cmd = CMD.Q;\n path.addData(cmd, x1, y1, cpx, cpy);\n break;\n case 'T':\n ctlPtx = cpx;\n ctlPty = cpy;\n var len = path.len();\n var pathData = path.data;\n if (prevCmd === CMD.Q) {\n ctlPtx += cpx - pathData[len - 4];\n ctlPty += cpy - pathData[len - 3];\n }\n cpx = p[off++];\n cpy = p[off++];\n cmd = CMD.Q;\n path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);\n break;\n case 't':\n ctlPtx = cpx;\n ctlPty = cpy;\n var len = path.len();\n var pathData = path.data;\n if (prevCmd === CMD.Q) {\n ctlPtx += cpx - pathData[len - 4];\n ctlPty += cpy - pathData[len - 3];\n }\n cpx += p[off++];\n cpy += p[off++];\n cmd = CMD.Q;\n path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);\n break;\n case 'A':\n rx = p[off++];\n ry = p[off++];\n psi = p[off++];\n fa = p[off++];\n fs = p[off++];\n\n x1 = cpx, y1 = cpy;\n cpx = p[off++];\n cpy = p[off++];\n cmd = CMD.A;\n processArc(\n x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path\n );\n break;\n case 'a':\n rx = p[off++];\n ry = p[off++];\n psi = p[off++];\n fa = p[off++];\n fs = p[off++];\n\n x1 = cpx, y1 = cpy;\n cpx += p[off++];\n cpy += p[off++];\n cmd = CMD.A;\n processArc(\n x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path\n );\n break;\n }\n }\n\n if (cmdStr === 'z' || cmdStr === 'Z') {\n cmd = CMD.Z;\n path.addData(cmd);\n // z may be in the middle of the path.\n cpx = subpathX;\n cpy = subpathY;\n }\n\n prevCmd = cmd;\n }\n\n path.toStatic();\n\n return path;\n}\n\n// TODO Optimize double memory cost problem\nfunction createPathOptions(str, opts) {\n var pathProxy = createPathProxyFromString(str);\n opts = opts || {};\n opts.buildPath = function (path) {\n if (path.setData) {\n path.setData(pathProxy.data);\n // Svg and vml renderer don't have context\n var ctx = path.getContext();\n if (ctx) {\n path.rebuildPath(ctx);\n }\n }\n else {\n var ctx = path;\n pathProxy.rebuildPath(ctx);\n }\n };\n\n opts.applyTransform = function (m) {\n transformPath(pathProxy, m);\n this.dirty(true);\n };\n\n return opts;\n}\n\n/**\n * Create a Path object from path string data\n * http://www.w3.org/TR/SVG/paths.html#PathData\n * @param {Object} opts Other options\n */\nexport function createFromString(str, opts) {\n return new Path(createPathOptions(str, opts));\n}\n\n/**\n * Create a Path class from path string data\n * @param {string} str\n * @param {Object} opts Other options\n */\nexport function extendFromString(str, opts) {\n return Path.extend(createPathOptions(str, opts));\n}\n\n/**\n * Merge multiple paths\n */\n// TODO Apply transform\n// TODO stroke dash\n// TODO Optimize double memory cost problem\nexport function mergePath(pathEls, opts) {\n var pathList = [];\n var len = pathEls.length;\n for (var i = 0; i < len; i++) {\n var pathEl = pathEls[i];\n if (!pathEl.path) {\n pathEl.createPathProxy();\n }\n if (pathEl.__dirtyPath) {\n pathEl.buildPath(pathEl.path, pathEl.shape, true);\n }\n pathList.push(pathEl.path);\n }\n\n var pathBundle = new Path(opts);\n // Need path proxy.\n pathBundle.createPathProxy();\n pathBundle.buildPath = function (path) {\n path.appendPath(pathList);\n // Svg and vml renderer don't have context\n var ctx = path.getContext();\n if (ctx) {\n path.rebuildPath(ctx);\n }\n };\n\n return pathBundle;\n}","import Displayable from './Displayable';\nimport * as zrUtil from '../core/util';\nimport * as textContain from '../contain/text';\nimport * as textHelper from './helper/text';\nimport {ContextCachedBy} from './constant';\n\n/**\n * @alias zrender/graphic/Text\n * @extends module:zrender/graphic/Displayable\n * @constructor\n * @param {Object} opts\n */\nvar Text = function (opts) { // jshint ignore:line\n Displayable.call(this, opts);\n};\n\nText.prototype = {\n\n constructor: Text,\n\n type: 'text',\n\n brush: function (ctx, prevEl) {\n var style = this.style;\n\n // Optimize, avoid normalize every time.\n this.__dirty && textHelper.normalizeTextStyle(style, true);\n\n // Use props with prefix 'text'.\n style.fill = style.stroke = style.shadowBlur = style.shadowColor =\n style.shadowOffsetX = style.shadowOffsetY = null;\n\n var text = style.text;\n // Convert to string\n text != null && (text += '');\n\n // Do not apply style.bind in Text node. Because the real bind job\n // is in textHelper.renderText, and performance of text render should\n // be considered.\n // style.bind(ctx, this, prevEl);\n\n if (!textHelper.needDrawText(text, style)) {\n // The current el.style is not applied\n // and should not be used as cache.\n ctx.__attrCachedBy = ContextCachedBy.NONE;\n return;\n }\n\n this.setTransform(ctx);\n\n textHelper.renderText(this, ctx, text, style, null, prevEl);\n\n this.restoreTransform(ctx);\n },\n\n getBoundingRect: function () {\n var style = this.style;\n\n // Optimize, avoid normalize every time.\n this.__dirty && textHelper.normalizeTextStyle(style, true);\n\n if (!this._rect) {\n var text = style.text;\n text != null ? (text += '') : (text = '');\n\n var rect = textContain.getBoundingRect(\n style.text + '',\n style.font,\n style.textAlign,\n style.textVerticalAlign,\n style.textPadding,\n style.textLineHeight,\n style.rich\n );\n\n rect.x += style.x || 0;\n rect.y += style.y || 0;\n\n if (textHelper.getStroke(style.textStroke, style.textStrokeWidth)) {\n var w = style.textStrokeWidth;\n rect.x -= w / 2;\n rect.y -= w / 2;\n rect.width += w;\n rect.height += w;\n }\n\n this._rect = rect;\n }\n\n return this._rect;\n }\n};\n\nzrUtil.inherits(Text, Displayable);\n\nexport default Text;","/**\n * 圆形\n * @module zrender/shape/Circle\n */\n\nimport Path from '../Path';\n\nexport default Path.extend({\n\n type: 'circle',\n\n shape: {\n cx: 0,\n cy: 0,\n r: 0\n },\n\n\n buildPath: function (ctx, shape, inBundle) {\n // Better stroking in ShapeBundle\n // Always do it may have performence issue ( fill may be 2x more cost)\n if (inBundle) {\n ctx.moveTo(shape.cx + shape.r, shape.cy);\n }\n // else {\n // if (ctx.allocate && !ctx.data.length) {\n // ctx.allocate(ctx.CMD_MEM_SIZE.A);\n // }\n // }\n // Better stroking in ShapeBundle\n // ctx.moveTo(shape.cx + shape.r, shape.cy);\n ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2, true);\n }\n});","import env from '../../core/env';\n\n// Fix weird bug in some version of IE11 (like 11.0.9600.178**),\n// where exception \"unexpected call to method or property access\"\n// might be thrown when calling ctx.fill or ctx.stroke after a path\n// whose area size is zero is drawn and ctx.clip() is called and\n// shadowBlur is set. See #4572, #3112, #5777.\n// (e.g.,\n// ctx.moveTo(10, 10);\n// ctx.lineTo(20, 10);\n// ctx.closePath();\n// ctx.clip();\n// ctx.shadowBlur = 10;\n// ...\n// ctx.fill();\n// )\n\nvar shadowTemp = [\n ['shadowBlur', 0],\n ['shadowColor', '#000'],\n ['shadowOffsetX', 0],\n ['shadowOffsetY', 0]\n];\n\nexport default function (orignalBrush) {\n\n // version string can be: '11.0'\n return (env.browser.ie && env.browser.version >= 11)\n\n ? function () {\n var clipPaths = this.__clipPaths;\n var style = this.style;\n var modified;\n\n if (clipPaths) {\n for (var i = 0; i < clipPaths.length; i++) {\n var clipPath = clipPaths[i];\n var shape = clipPath && clipPath.shape;\n var type = clipPath && clipPath.type;\n\n if (shape && (\n (type === 'sector' && shape.startAngle === shape.endAngle)\n || (type === 'rect' && (!shape.width || !shape.height))\n )) {\n for (var j = 0; j < shadowTemp.length; j++) {\n // It is save to put shadowTemp static, because shadowTemp\n // will be all modified each item brush called.\n shadowTemp[j][2] = style[shadowTemp[j][0]];\n style[shadowTemp[j][0]] = shadowTemp[j][1];\n }\n modified = true;\n break;\n }\n }\n }\n\n orignalBrush.apply(this, arguments);\n\n if (modified) {\n for (var j = 0; j < shadowTemp.length; j++) {\n style[shadowTemp[j][0]] = shadowTemp[j][2];\n }\n }\n }\n\n : orignalBrush;\n}\n","/**\n * 扇形\n * @module zrender/graphic/shape/Sector\n */\n\nimport Path from '../Path';\nimport fixClipWithShadow from '../helper/fixClipWithShadow';\n\nexport default Path.extend({\n\n type: 'sector',\n\n shape: {\n\n cx: 0,\n\n cy: 0,\n\n r0: 0,\n\n r: 0,\n\n startAngle: 0,\n\n endAngle: Math.PI * 2,\n\n clockwise: true\n },\n\n brush: fixClipWithShadow(Path.prototype.brush),\n\n buildPath: function (ctx, shape) {\n\n var x = shape.cx;\n var y = shape.cy;\n var r0 = Math.max(shape.r0 || 0, 0);\n var r = Math.max(shape.r, 0);\n var startAngle = shape.startAngle;\n var endAngle = shape.endAngle;\n var clockwise = shape.clockwise;\n\n var unitX = Math.cos(startAngle);\n var unitY = Math.sin(startAngle);\n\n ctx.moveTo(unitX * r0 + x, unitY * r0 + y);\n\n ctx.lineTo(unitX * r + x, unitY * r + y);\n\n ctx.arc(x, y, r, startAngle, endAngle, !clockwise);\n\n ctx.lineTo(\n Math.cos(endAngle) * r0 + x,\n Math.sin(endAngle) * r0 + y\n );\n\n if (r0 !== 0) {\n ctx.arc(x, y, r0, endAngle, startAngle, clockwise);\n }\n\n ctx.closePath();\n }\n});","/**\n * 圆环\n * @module zrender/graphic/shape/Ring\n */\n\nimport Path from '../Path';\n\nexport default Path.extend({\n\n type: 'ring',\n\n shape: {\n cx: 0,\n cy: 0,\n r: 0,\n r0: 0\n },\n\n buildPath: function (ctx, shape) {\n var x = shape.cx;\n var y = shape.cy;\n var PI2 = Math.PI * 2;\n ctx.moveTo(x + shape.r, y);\n ctx.arc(x, y, shape.r, 0, PI2, false);\n ctx.moveTo(x + shape.r0, y);\n ctx.arc(x, y, shape.r0, 0, PI2, true);\n }\n});","/**\n * Catmull-Rom spline 插值折线\n * @module zrender/shape/util/smoothSpline\n * @author pissang (https://www.github.com/pissang)\n * Kener (@Kener-林峰, kener.linfeng@gmail.com)\n * errorrik (errorrik@gmail.com)\n */\n\nimport {distance as v2Distance} from '../../core/vector';\n\n/**\n * @inner\n */\nfunction interpolate(p0, p1, p2, p3, t, t2, t3) {\n var v0 = (p2 - p0) * 0.5;\n var v1 = (p3 - p1) * 0.5;\n return (2 * (p1 - p2) + v0 + v1) * t3\n + (-3 * (p1 - p2) - 2 * v0 - v1) * t2\n + v0 * t + p1;\n}\n\n/**\n * @alias module:zrender/shape/util/smoothSpline\n * @param {Array} points 线段顶点数组\n * @param {boolean} isLoop\n * @return {Array}\n */\nexport default function (points, isLoop) {\n var len = points.length;\n var ret = [];\n\n var distance = 0;\n for (var i = 1; i < len; i++) {\n distance += v2Distance(points[i - 1], points[i]);\n }\n\n var segs = distance / 2;\n segs = segs < len ? len : segs;\n for (var i = 0; i < segs; i++) {\n var pos = i / (segs - 1) * (isLoop ? len : len - 1);\n var idx = Math.floor(pos);\n\n var w = pos - idx;\n\n var p0;\n var p1 = points[idx % len];\n var p2;\n var p3;\n if (!isLoop) {\n p0 = points[idx === 0 ? idx : idx - 1];\n p2 = points[idx > len - 2 ? len - 1 : idx + 1];\n p3 = points[idx > len - 3 ? len - 1 : idx + 2];\n }\n else {\n p0 = points[(idx - 1 + len) % len];\n p2 = points[(idx + 1) % len];\n p3 = points[(idx + 2) % len];\n }\n\n var w2 = w * w;\n var w3 = w * w2;\n\n ret.push([\n interpolate(p0[0], p1[0], p2[0], p3[0], w, w2, w3),\n interpolate(p0[1], p1[1], p2[1], p3[1], w, w2, w3)\n ]);\n }\n return ret;\n}","/**\n * 贝塞尔平滑曲线\n * @module zrender/shape/util/smoothBezier\n * @author pissang (https://www.github.com/pissang)\n * Kener (@Kener-林峰, kener.linfeng@gmail.com)\n * errorrik (errorrik@gmail.com)\n */\n\nimport {\n min as v2Min,\n max as v2Max,\n scale as v2Scale,\n distance as v2Distance,\n add as v2Add,\n clone as v2Clone,\n sub as v2Sub\n} from '../../core/vector';\n\n/**\n * 贝塞尔平滑曲线\n * @alias module:zrender/shape/util/smoothBezier\n * @param {Array} points 线段顶点数组\n * @param {number} smooth 平滑等级, 0-1\n * @param {boolean} isLoop\n * @param {Array} constraint 将计算出来的控制点约束在一个包围盒内\n * 比如 [[0, 0], [100, 100]], 这个包围盒会与\n * 整个折线的包围盒做一个并集用来约束控制点。\n * @param {Array} 计算出来的控制点数组\n */\nexport default function (points, smooth, isLoop, constraint) {\n var cps = [];\n\n var v = [];\n var v1 = [];\n var v2 = [];\n var prevPoint;\n var nextPoint;\n\n var min;\n var max;\n if (constraint) {\n min = [Infinity, Infinity];\n max = [-Infinity, -Infinity];\n for (var i = 0, len = points.length; i < len; i++) {\n v2Min(min, min, points[i]);\n v2Max(max, max, points[i]);\n }\n // 与指定的包围盒做并集\n v2Min(min, min, constraint[0]);\n v2Max(max, max, constraint[1]);\n }\n\n for (var i = 0, len = points.length; i < len; i++) {\n var point = points[i];\n\n if (isLoop) {\n prevPoint = points[i ? i - 1 : len - 1];\n nextPoint = points[(i + 1) % len];\n }\n else {\n if (i === 0 || i === len - 1) {\n cps.push(v2Clone(points[i]));\n continue;\n }\n else {\n prevPoint = points[i - 1];\n nextPoint = points[i + 1];\n }\n }\n\n v2Sub(v, nextPoint, prevPoint);\n\n // use degree to scale the handle length\n v2Scale(v, v, smooth);\n\n var d0 = v2Distance(point, prevPoint);\n var d1 = v2Distance(point, nextPoint);\n var sum = d0 + d1;\n if (sum !== 0) {\n d0 /= sum;\n d1 /= sum;\n }\n\n v2Scale(v1, v, -d0);\n v2Scale(v2, v, d1);\n var cp0 = v2Add([], point, v1);\n var cp1 = v2Add([], point, v2);\n if (constraint) {\n v2Max(cp0, cp0, min);\n v2Min(cp0, cp0, max);\n v2Max(cp1, cp1, min);\n v2Min(cp1, cp1, max);\n }\n cps.push(cp0);\n cps.push(cp1);\n }\n\n if (isLoop) {\n cps.push(cps.shift());\n }\n\n return cps;\n}","\nimport smoothSpline from './smoothSpline';\nimport smoothBezier from './smoothBezier';\n\nexport function buildPath(ctx, shape, closePath) {\n var points = shape.points;\n var smooth = shape.smooth;\n if (points && points.length >= 2) {\n if (smooth && smooth !== 'spline') {\n var controlPoints = smoothBezier(\n points, smooth, closePath, shape.smoothConstraint\n );\n\n ctx.moveTo(points[0][0], points[0][1]);\n var len = points.length;\n for (var i = 0; i < (closePath ? len : len - 1); i++) {\n var cp1 = controlPoints[i * 2];\n var cp2 = controlPoints[i * 2 + 1];\n var p = points[(i + 1) % len];\n ctx.bezierCurveTo(\n cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]\n );\n }\n }\n else {\n if (smooth === 'spline') {\n points = smoothSpline(points, closePath);\n }\n\n ctx.moveTo(points[0][0], points[0][1]);\n for (var i = 1, l = points.length; i < l; i++) {\n ctx.lineTo(points[i][0], points[i][1]);\n }\n }\n\n closePath && ctx.closePath();\n }\n}\n","/**\n * 多边形\n * @module zrender/shape/Polygon\n */\n\nimport Path from '../Path';\nimport * as polyHelper from '../helper/poly';\n\nexport default Path.extend({\n\n type: 'polygon',\n\n shape: {\n points: null,\n\n smooth: false,\n\n smoothConstraint: null\n },\n\n buildPath: function (ctx, shape) {\n polyHelper.buildPath(ctx, shape, true);\n }\n});","/**\n * @module zrender/graphic/shape/Polyline\n */\n\nimport Path from '../Path';\nimport * as polyHelper from '../helper/poly';\n\nexport default Path.extend({\n\n type: 'polyline',\n\n shape: {\n points: null,\n\n smooth: false,\n\n smoothConstraint: null\n },\n\n style: {\n stroke: '#000',\n\n fill: null\n },\n\n buildPath: function (ctx, shape) {\n polyHelper.buildPath(ctx, shape, false);\n }\n});","/**\n * Sub-pixel optimize for canvas rendering, prevent from blur\n * when rendering a thin vertical/horizontal line.\n */\n\nvar round = Math.round;\n\n/**\n * Sub pixel optimize line for canvas\n *\n * @param {Object} outputShape The modification will be performed on `outputShape`.\n * `outputShape` and `inputShape` can be the same object.\n * `outputShape` object can be used repeatly, because all of\n * the `x1`, `x2`, `y1`, `y2` will be assigned in this method.\n * @param {Object} [inputShape]\n * @param {number} [inputShape.x1]\n * @param {number} [inputShape.y1]\n * @param {number} [inputShape.x2]\n * @param {number} [inputShape.y2]\n * @param {Object} [style]\n * @param {number} [style.lineWidth] If `null`/`undefined`/`0`, do not optimize.\n */\nexport function subPixelOptimizeLine(outputShape, inputShape, style) {\n if (!inputShape) {\n return;\n }\n\n var x1 = inputShape.x1;\n var x2 = inputShape.x2;\n var y1 = inputShape.y1;\n var y2 = inputShape.y2;\n\n outputShape.x1 = x1;\n outputShape.x2 = x2;\n outputShape.y1 = y1;\n outputShape.y2 = y2;\n\n var lineWidth = style && style.lineWidth;\n if (!lineWidth) {\n return;\n }\n\n if (round(x1 * 2) === round(x2 * 2)) {\n outputShape.x1 = outputShape.x2 = subPixelOptimize(x1, lineWidth, true);\n }\n if (round(y1 * 2) === round(y2 * 2)) {\n outputShape.y1 = outputShape.y2 = subPixelOptimize(y1, lineWidth, true);\n }\n}\n\n/**\n * Sub pixel optimize rect for canvas\n *\n * @param {Object} outputShape The modification will be performed on `outputShape`.\n * `outputShape` and `inputShape` can be the same object.\n * `outputShape` object can be used repeatly, because all of\n * the `x`, `y`, `width`, `height` will be assigned in this method.\n * @param {Object} [inputShape]\n * @param {number} [inputShape.x]\n * @param {number} [inputShape.y]\n * @param {number} [inputShape.width]\n * @param {number} [inputShape.height]\n * @param {Object} [style]\n * @param {number} [style.lineWidth] If `null`/`undefined`/`0`, do not optimize.\n */\nexport function subPixelOptimizeRect(outputShape, inputShape, style) {\n if (!inputShape) {\n return;\n }\n\n var originX = inputShape.x;\n var originY = inputShape.y;\n var originWidth = inputShape.width;\n var originHeight = inputShape.height;\n\n outputShape.x = originX;\n outputShape.y = originY;\n outputShape.width = originWidth;\n outputShape.height = originHeight;\n\n var lineWidth = style && style.lineWidth;\n if (!lineWidth) {\n return;\n }\n\n outputShape.x = subPixelOptimize(originX, lineWidth, true);\n outputShape.y = subPixelOptimize(originY, lineWidth, true);\n outputShape.width = Math.max(\n subPixelOptimize(originX + originWidth, lineWidth, false) - outputShape.x,\n originWidth === 0 ? 0 : 1\n );\n outputShape.height = Math.max(\n subPixelOptimize(originY + originHeight, lineWidth, false) - outputShape.y,\n originHeight === 0 ? 0 : 1\n );\n}\n\n/**\n * Sub pixel optimize for canvas\n *\n * @param {number} position Coordinate, such as x, y\n * @param {number} lineWidth If `null`/`undefined`/`0`, do not optimize.\n * @param {boolean=} positiveOrNegative Default false (negative).\n * @return {number} Optimized position.\n */\nexport function subPixelOptimize(position, lineWidth, positiveOrNegative) {\n if (!lineWidth) {\n return position;\n }\n // Assure that (position + lineWidth / 2) is near integer edge,\n // otherwise line will be fuzzy in canvas.\n var doubledPosition = round(position * 2);\n return (doubledPosition + round(lineWidth)) % 2 === 0\n ? doubledPosition / 2\n : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;\n}\n","/**\n * 矩形\n * @module zrender/graphic/shape/Rect\n */\n\nimport Path from '../Path';\nimport * as roundRectHelper from '../helper/roundRect';\nimport {subPixelOptimizeRect} from '../helper/subPixelOptimize';\n\n// Avoid create repeatly.\nvar subPixelOptimizeOutputShape = {};\n\nexport default Path.extend({\n\n type: 'rect',\n\n shape: {\n // 左上、右上、右下、左下角的半径依次为r1、r2、r3、r4\n // r缩写为1 相当于 [1, 1, 1, 1]\n // r缩写为[1] 相当于 [1, 1, 1, 1]\n // r缩写为[1, 2] 相当于 [1, 2, 1, 2]\n // r缩写为[1, 2, 3] 相当于 [1, 2, 3, 2]\n r: 0,\n\n x: 0,\n y: 0,\n width: 0,\n height: 0\n },\n\n buildPath: function (ctx, shape) {\n var x;\n var y;\n var width;\n var height;\n\n if (this.subPixelOptimize) {\n subPixelOptimizeRect(subPixelOptimizeOutputShape, shape, this.style);\n x = subPixelOptimizeOutputShape.x;\n y = subPixelOptimizeOutputShape.y;\n width = subPixelOptimizeOutputShape.width;\n height = subPixelOptimizeOutputShape.height;\n subPixelOptimizeOutputShape.r = shape.r;\n shape = subPixelOptimizeOutputShape;\n }\n else {\n x = shape.x;\n y = shape.y;\n width = shape.width;\n height = shape.height;\n }\n\n if (!shape.r) {\n ctx.rect(x, y, width, height);\n }\n else {\n roundRectHelper.buildPath(ctx, shape);\n }\n ctx.closePath();\n return;\n }\n});","/**\n * 直线\n * @module zrender/graphic/shape/Line\n */\n\nimport Path from '../Path';\nimport {subPixelOptimizeLine} from '../helper/subPixelOptimize';\n\n// Avoid create repeatly.\nvar subPixelOptimizeOutputShape = {};\n\nexport default Path.extend({\n\n type: 'line',\n\n shape: {\n // Start point\n x1: 0,\n y1: 0,\n // End point\n x2: 0,\n y2: 0,\n\n percent: 1\n },\n\n style: {\n stroke: '#000',\n fill: null\n },\n\n buildPath: function (ctx, shape) {\n var x1;\n var y1;\n var x2;\n var y2;\n\n if (this.subPixelOptimize) {\n subPixelOptimizeLine(subPixelOptimizeOutputShape, shape, this.style);\n x1 = subPixelOptimizeOutputShape.x1;\n y1 = subPixelOptimizeOutputShape.y1;\n x2 = subPixelOptimizeOutputShape.x2;\n y2 = subPixelOptimizeOutputShape.y2;\n }\n else {\n x1 = shape.x1;\n y1 = shape.y1;\n x2 = shape.x2;\n y2 = shape.y2;\n }\n\n var percent = shape.percent;\n\n if (percent === 0) {\n return;\n }\n\n ctx.moveTo(x1, y1);\n\n if (percent < 1) {\n x2 = x1 * (1 - percent) + x2 * percent;\n y2 = y1 * (1 - percent) + y2 * percent;\n }\n ctx.lineTo(x2, y2);\n },\n\n /**\n * Get point at percent\n * @param {number} percent\n * @return {Array.<number>}\n */\n pointAt: function (p) {\n var shape = this.shape;\n return [\n shape.x1 * (1 - p) + shape.x2 * p,\n shape.y1 * (1 - p) + shape.y2 * p\n ];\n }\n});","/**\n * 贝塞尔曲线\n * @module zrender/shape/BezierCurve\n */\n\nimport Path from '../Path';\nimport * as vec2 from '../../core/vector';\nimport {\n quadraticSubdivide,\n cubicSubdivide,\n quadraticAt,\n cubicAt,\n quadraticDerivativeAt,\n cubicDerivativeAt\n} from '../../core/curve';\n\nvar out = [];\n\nfunction someVectorAt(shape, t, isTangent) {\n var cpx2 = shape.cpx2;\n var cpy2 = shape.cpy2;\n if (cpx2 === null || cpy2 === null) {\n return [\n (isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t),\n (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)\n ];\n }\n else {\n return [\n (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t),\n (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)\n ];\n }\n}\n\nexport default Path.extend({\n\n type: 'bezier-curve',\n\n shape: {\n x1: 0,\n y1: 0,\n x2: 0,\n y2: 0,\n cpx1: 0,\n cpy1: 0,\n // cpx2: 0,\n // cpy2: 0\n\n // Curve show percent, for animating\n percent: 1\n },\n\n style: {\n stroke: '#000',\n fill: null\n },\n\n buildPath: function (ctx, shape) {\n var x1 = shape.x1;\n var y1 = shape.y1;\n var x2 = shape.x2;\n var y2 = shape.y2;\n var cpx1 = shape.cpx1;\n var cpy1 = shape.cpy1;\n var cpx2 = shape.cpx2;\n var cpy2 = shape.cpy2;\n var percent = shape.percent;\n if (percent === 0) {\n return;\n }\n\n ctx.moveTo(x1, y1);\n\n if (cpx2 == null || cpy2 == null) {\n if (percent < 1) {\n quadraticSubdivide(\n x1, cpx1, x2, percent, out\n );\n cpx1 = out[1];\n x2 = out[2];\n quadraticSubdivide(\n y1, cpy1, y2, percent, out\n );\n cpy1 = out[1];\n y2 = out[2];\n }\n\n ctx.quadraticCurveTo(\n cpx1, cpy1,\n x2, y2\n );\n }\n else {\n if (percent < 1) {\n cubicSubdivide(\n x1, cpx1, cpx2, x2, percent, out\n );\n cpx1 = out[1];\n cpx2 = out[2];\n x2 = out[3];\n cubicSubdivide(\n y1, cpy1, cpy2, y2, percent, out\n );\n cpy1 = out[1];\n cpy2 = out[2];\n y2 = out[3];\n }\n ctx.bezierCurveTo(\n cpx1, cpy1,\n cpx2, cpy2,\n x2, y2\n );\n }\n },\n\n /**\n * Get point at percent\n * @param {number} t\n * @return {Array.<number>}\n */\n pointAt: function (t) {\n return someVectorAt(this.shape, t, false);\n },\n\n /**\n * Get tangent at percent\n * @param {number} t\n * @return {Array.<number>}\n */\n tangentAt: function (t) {\n var p = someVectorAt(this.shape, t, true);\n return vec2.normalize(p, p);\n }\n});","/**\n * 圆弧\n * @module zrender/graphic/shape/Arc\n */\n\nimport Path from '../Path';\n\nexport default Path.extend({\n\n type: 'arc',\n\n shape: {\n\n cx: 0,\n\n cy: 0,\n\n r: 0,\n\n startAngle: 0,\n\n endAngle: Math.PI * 2,\n\n clockwise: true\n },\n\n style: {\n\n stroke: '#000',\n\n fill: null\n },\n\n buildPath: function (ctx, shape) {\n\n var x = shape.cx;\n var y = shape.cy;\n var r = Math.max(shape.r, 0);\n var startAngle = shape.startAngle;\n var endAngle = shape.endAngle;\n var clockwise = shape.clockwise;\n\n var unitX = Math.cos(startAngle);\n var unitY = Math.sin(startAngle);\n\n ctx.moveTo(unitX * r + x, unitY * r + y);\n ctx.arc(x, y, r, startAngle, endAngle, !clockwise);\n }\n});","// CompoundPath to improve performance\n\nimport Path from './Path';\n\nexport default Path.extend({\n\n type: 'compound',\n\n shape: {\n\n paths: null\n },\n\n _updatePathDirty: function () {\n var dirtyPath = this.__dirtyPath;\n var paths = this.shape.paths;\n for (var i = 0; i < paths.length; i++) {\n // Mark as dirty if any subpath is dirty\n dirtyPath = dirtyPath || paths[i].__dirtyPath;\n }\n this.__dirtyPath = dirtyPath;\n this.__dirty = this.__dirty || dirtyPath;\n },\n\n beforeBrush: function () {\n this._updatePathDirty();\n var paths = this.shape.paths || [];\n var scale = this.getGlobalScale();\n // Update path scale\n for (var i = 0; i < paths.length; i++) {\n if (!paths[i].path) {\n paths[i].createPathProxy();\n }\n paths[i].path.setScale(scale[0], scale[1], paths[i].segmentIgnoreThreshold);\n }\n },\n\n buildPath: function (ctx, shape) {\n var paths = shape.paths || [];\n for (var i = 0; i < paths.length; i++) {\n paths[i].buildPath(ctx, paths[i].shape, true);\n }\n },\n\n afterBrush: function () {\n var paths = this.shape.paths || [];\n for (var i = 0; i < paths.length; i++) {\n paths[i].__dirtyPath = false;\n }\n },\n\n getBoundingRect: function () {\n this._updatePathDirty();\n return Path.prototype.getBoundingRect.call(this);\n }\n});","\n/**\n * @param {Array.<Object>} colorStops\n */\nvar Gradient = function (colorStops) {\n\n this.colorStops = colorStops || [];\n\n};\n\nGradient.prototype = {\n\n constructor: Gradient,\n\n addColorStop: function (offset, color) {\n this.colorStops.push({\n\n offset: offset,\n\n color: color\n });\n }\n\n};\n\nexport default Gradient;","import * as zrUtil from '../core/util';\nimport Gradient from './Gradient';\n\n/**\n * x, y, x2, y2 are all percent from 0 to 1\n * @param {number} [x=0]\n * @param {number} [y=0]\n * @param {number} [x2=1]\n * @param {number} [y2=0]\n * @param {Array.<Object>} colorStops\n * @param {boolean} [globalCoord=false]\n */\nvar LinearGradient = function (x, y, x2, y2, colorStops, globalCoord) {\n // Should do nothing more in this constructor. Because gradient can be\n // declard by `color: {type: 'linear', colorStops: ...}`, where\n // this constructor will not be called.\n\n this.x = x == null ? 0 : x;\n\n this.y = y == null ? 0 : y;\n\n this.x2 = x2 == null ? 1 : x2;\n\n this.y2 = y2 == null ? 0 : y2;\n\n // Can be cloned\n this.type = 'linear';\n\n // If use global coord\n this.global = globalCoord || false;\n\n Gradient.call(this, colorStops);\n};\n\nLinearGradient.prototype = {\n\n constructor: LinearGradient\n};\n\nzrUtil.inherits(LinearGradient, Gradient);\n\nexport default LinearGradient;","import * as zrUtil from '../core/util';\nimport Gradient from './Gradient';\n\n/**\n * x, y, r are all percent from 0 to 1\n * @param {number} [x=0.5]\n * @param {number} [y=0.5]\n * @param {number} [r=0.5]\n * @param {Array.<Object>} [colorStops]\n * @param {boolean} [globalCoord=false]\n */\nvar RadialGradient = function (x, y, r, colorStops, globalCoord) {\n // Should do nothing more in this constructor. Because gradient can be\n // declard by `color: {type: 'radial', colorStops: ...}`, where\n // this constructor will not be called.\n\n this.x = x == null ? 0.5 : x;\n\n this.y = y == null ? 0.5 : y;\n\n this.r = r == null ? 0.5 : r;\n\n // Can be cloned\n this.type = 'radial';\n\n // If use global coord\n this.global = globalCoord || false;\n\n Gradient.call(this, colorStops);\n};\n\nRadialGradient.prototype = {\n\n constructor: RadialGradient\n};\n\nzrUtil.inherits(RadialGradient, Gradient);\n\nexport default RadialGradient;","/**\n * Displayable for incremental rendering. It will be rendered in a separate layer\n * IncrementalDisplay have two main methods. `clearDisplayables` and `addDisplayables`\n * addDisplayables will render the added displayables incremetally.\n *\n * It use a not clearFlag to tell the painter don't clear the layer if it's the first element.\n */\nimport { inherits } from '../core/util';\nimport Displayble from './Displayable';\nimport BoundingRect from '../core/BoundingRect';\n\n// TODO Style override ?\nfunction IncrementalDisplayble(opts) {\n\n Displayble.call(this, opts);\n\n this._displayables = [];\n\n this._temporaryDisplayables = [];\n\n this._cursor = 0;\n\n this.notClear = true;\n}\n\nIncrementalDisplayble.prototype.incremental = true;\n\nIncrementalDisplayble.prototype.clearDisplaybles = function () {\n this._displayables = [];\n this._temporaryDisplayables = [];\n this._cursor = 0;\n this.dirty();\n\n this.notClear = false;\n};\n\nIncrementalDisplayble.prototype.addDisplayable = function (displayable, notPersistent) {\n if (notPersistent) {\n this._temporaryDisplayables.push(displayable);\n }\n else {\n this._displayables.push(displayable);\n }\n this.dirty();\n};\n\nIncrementalDisplayble.prototype.addDisplayables = function (displayables, notPersistent) {\n notPersistent = notPersistent || false;\n for (var i = 0; i < displayables.length; i++) {\n this.addDisplayable(displayables[i], notPersistent);\n }\n};\n\nIncrementalDisplayble.prototype.eachPendingDisplayable = function (cb) {\n for (var i = this._cursor; i < this._displayables.length; i++) {\n cb && cb(this._displayables[i]);\n }\n for (var i = 0; i < this._temporaryDisplayables.length; i++) {\n cb && cb(this._temporaryDisplayables[i]);\n }\n};\n\nIncrementalDisplayble.prototype.update = function () {\n this.updateTransform();\n for (var i = this._cursor; i < this._displayables.length; i++) {\n var displayable = this._displayables[i];\n // PENDING\n displayable.parent = this;\n displayable.update();\n displayable.parent = null;\n }\n for (var i = 0; i < this._temporaryDisplayables.length; i++) {\n var displayable = this._temporaryDisplayables[i];\n // PENDING\n displayable.parent = this;\n displayable.update();\n displayable.parent = null;\n }\n};\n\nIncrementalDisplayble.prototype.brush = function (ctx, prevEl) {\n // Render persistant displayables.\n for (var i = this._cursor; i < this._displayables.length; i++) {\n var displayable = this._displayables[i];\n displayable.beforeBrush && displayable.beforeBrush(ctx);\n displayable.brush(ctx, i === this._cursor ? null : this._displayables[i - 1]);\n displayable.afterBrush && displayable.afterBrush(ctx);\n }\n this._cursor = i;\n // Render temporary displayables.\n for (var i = 0; i < this._temporaryDisplayables.length; i++) {\n var displayable = this._temporaryDisplayables[i];\n displayable.beforeBrush && displayable.beforeBrush(ctx);\n displayable.brush(ctx, i === 0 ? null : this._temporaryDisplayables[i - 1]);\n displayable.afterBrush && displayable.afterBrush(ctx);\n }\n\n this._temporaryDisplayables = [];\n\n this.notClear = true;\n};\n\nvar m = [];\nIncrementalDisplayble.prototype.getBoundingRect = function () {\n if (!this._rect) {\n var rect = new BoundingRect(Infinity, Infinity, -Infinity, -Infinity);\n for (var i = 0; i < this._displayables.length; i++) {\n var displayable = this._displayables[i];\n var childRect = displayable.getBoundingRect().clone();\n if (displayable.needLocalTransform()) {\n childRect.applyTransform(displayable.getLocalTransform(m));\n }\n rect.union(childRect);\n }\n this._rect = rect;\n }\n return this._rect;\n};\n\nIncrementalDisplayble.prototype.contain = function (x, y) {\n var localPos = this.transformCoordToLocal(x, y);\n var rect = this.getBoundingRect();\n\n if (rect.contain(localPos[0], localPos[1])) {\n for (var i = 0; i < this._displayables.length; i++) {\n var displayable = this._displayables[i];\n if (displayable.contain(x, y)) {\n return true;\n }\n }\n }\n return false;\n};\n\ninherits(IncrementalDisplayble, Displayble);\n\nexport default IncrementalDisplayble;","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport * as zrUtil from 'zrender/src/core/util';\nimport * as pathTool from 'zrender/src/tool/path';\nimport * as colorTool from 'zrender/src/tool/color';\nimport * as matrix from 'zrender/src/core/matrix';\nimport * as vector from 'zrender/src/core/vector';\nimport Path from 'zrender/src/graphic/Path';\nimport Transformable from 'zrender/src/mixin/Transformable';\nimport ZImage from 'zrender/src/graphic/Image';\nimport Group from 'zrender/src/container/Group';\nimport Text from 'zrender/src/graphic/Text';\nimport Circle from 'zrender/src/graphic/shape/Circle';\nimport Sector from 'zrender/src/graphic/shape/Sector';\nimport Ring from 'zrender/src/graphic/shape/Ring';\nimport Polygon from 'zrender/src/graphic/shape/Polygon';\nimport Polyline from 'zrender/src/graphic/shape/Polyline';\nimport Rect from 'zrender/src/graphic/shape/Rect';\nimport Line from 'zrender/src/graphic/shape/Line';\nimport BezierCurve from 'zrender/src/graphic/shape/BezierCurve';\nimport Arc from 'zrender/src/graphic/shape/Arc';\nimport CompoundPath from 'zrender/src/graphic/CompoundPath';\nimport LinearGradient from 'zrender/src/graphic/LinearGradient';\nimport RadialGradient from 'zrender/src/graphic/RadialGradient';\nimport BoundingRect from 'zrender/src/core/BoundingRect';\nimport IncrementalDisplayable from 'zrender/src/graphic/IncrementalDisplayable';\nimport * as subPixelOptimizeUtil from 'zrender/src/graphic/helper/subPixelOptimize';\n\n\nvar mathMax = Math.max;\nvar mathMin = Math.min;\n\nvar EMPTY_OBJ = {};\n\nexport var Z2_EMPHASIS_LIFT = 1;\n\n// key: label model property nane, value: style property name.\nexport var CACHED_LABEL_STYLE_PROPERTIES = {\n color: 'textFill',\n textBorderColor: 'textStroke',\n textBorderWidth: 'textStrokeWidth'\n};\n\nvar EMPHASIS = 'emphasis';\nvar NORMAL = 'normal';\n\n// Reserve 0 as default.\nvar _highlightNextDigit = 1;\nvar _highlightKeyMap = {};\n\nvar _customShapeMap = {};\n\n\n/**\n * Extend shape with parameters\n */\nexport function extendShape(opts) {\n return Path.extend(opts);\n}\n\n/**\n * Extend path\n */\nexport function extendPath(pathData, opts) {\n return pathTool.extendFromString(pathData, opts);\n}\n\n/**\n * Register a user defined shape.\n * The shape class can be fetched by `getShapeClass`\n * This method will overwrite the registered shapes, including\n * the registered built-in shapes, if using the same `name`.\n * The shape can be used in `custom series` and\n * `graphic component` by declaring `{type: name}`.\n *\n * @param {string} name\n * @param {Object} ShapeClass Can be generated by `extendShape`.\n */\nexport function registerShape(name, ShapeClass) {\n _customShapeMap[name] = ShapeClass;\n}\n\n/**\n * Find shape class registered by `registerShape`. Usually used in\n * fetching user defined shape.\n *\n * [Caution]:\n * (1) This method **MUST NOT be used inside echarts !!!**, unless it is prepared\n * to use user registered shapes.\n * Because the built-in shape (see `getBuiltInShape`) will be registered by\n * `registerShape` by default. That enables users to get both built-in\n * shapes as well as the shapes belonging to themsleves. But users can overwrite\n * the built-in shapes by using names like 'circle', 'rect' via calling\n * `registerShape`. So the echarts inner featrues should not fetch shapes from here\n * in case that it is overwritten by users, except that some features, like\n * `custom series`, `graphic component`, do it deliberately.\n *\n * (2) In the features like `custom series`, `graphic component`, the user input\n * `{tpye: 'xxx'}` does not only specify shapes but also specify other graphic\n * elements like `'group'`, `'text'`, `'image'` or event `'path'`. Those names\n * are reserved names, that is, if some user register a shape named `'image'`,\n * the shape will not be used. If we intending to add some more reserved names\n * in feature, that might bring break changes (disable some existing user shape\n * names). But that case probably rearly happen. So we dont make more mechanism\n * to resolve this issue here.\n *\n * @param {string} name\n * @return {Object} The shape class. If not found, return nothing.\n */\nexport function getShapeClass(name) {\n if (_customShapeMap.hasOwnProperty(name)) {\n return _customShapeMap[name];\n }\n}\n\n/**\n * Create a path element from path data string\n * @param {string} pathData\n * @param {Object} opts\n * @param {module:zrender/core/BoundingRect} rect\n * @param {string} [layout=cover] 'center' or 'cover'\n */\nexport function makePath(pathData, opts, rect, layout) {\n var path = pathTool.createFromString(pathData, opts);\n if (rect) {\n if (layout === 'center') {\n rect = centerGraphic(rect, path.getBoundingRect());\n }\n resizePath(path, rect);\n }\n return path;\n}\n\n/**\n * Create a image element from image url\n * @param {string} imageUrl image url\n * @param {Object} opts options\n * @param {module:zrender/core/BoundingRect} rect constrain rect\n * @param {string} [layout=cover] 'center' or 'cover'\n */\nexport function makeImage(imageUrl, rect, layout) {\n var path = new ZImage({\n style: {\n image: imageUrl,\n x: rect.x,\n y: rect.y,\n width: rect.width,\n height: rect.height\n },\n onload: function (img) {\n if (layout === 'center') {\n var boundingRect = {\n width: img.width,\n height: img.height\n };\n path.setStyle(centerGraphic(rect, boundingRect));\n }\n }\n });\n return path;\n}\n\n/**\n * Get position of centered element in bounding box.\n *\n * @param {Object} rect element local bounding box\n * @param {Object} boundingRect constraint bounding box\n * @return {Object} element position containing x, y, width, and height\n */\nfunction centerGraphic(rect, boundingRect) {\n // Set rect to center, keep width / height ratio.\n var aspect = boundingRect.width / boundingRect.height;\n var width = rect.height * aspect;\n var height;\n if (width <= rect.width) {\n height = rect.height;\n }\n else {\n width = rect.width;\n height = width / aspect;\n }\n var cx = rect.x + rect.width / 2;\n var cy = rect.y + rect.height / 2;\n\n return {\n x: cx - width / 2,\n y: cy - height / 2,\n width: width,\n height: height\n };\n}\n\nexport var mergePath = pathTool.mergePath;\n\n/**\n * Resize a path to fit the rect\n * @param {module:zrender/graphic/Path} path\n * @param {Object} rect\n */\nexport function resizePath(path, rect) {\n if (!path.applyTransform) {\n return;\n }\n\n var pathRect = path.getBoundingRect();\n\n var m = pathRect.calculateTransform(rect);\n\n path.applyTransform(m);\n}\n\n/**\n * Sub pixel optimize line for canvas\n *\n * @param {Object} param\n * @param {Object} [param.shape]\n * @param {number} [param.shape.x1]\n * @param {number} [param.shape.y1]\n * @param {number} [param.shape.x2]\n * @param {number} [param.shape.y2]\n * @param {Object} [param.style]\n * @param {number} [param.style.lineWidth]\n * @return {Object} Modified param\n */\nexport function subPixelOptimizeLine(param) {\n subPixelOptimizeUtil.subPixelOptimizeLine(param.shape, param.shape, param.style);\n return param;\n}\n\n/**\n * Sub pixel optimize rect for canvas\n *\n * @param {Object} param\n * @param {Object} [param.shape]\n * @param {number} [param.shape.x]\n * @param {number} [param.shape.y]\n * @param {number} [param.shape.width]\n * @param {number} [param.shape.height]\n * @param {Object} [param.style]\n * @param {number} [param.style.lineWidth]\n * @return {Object} Modified param\n */\nexport function subPixelOptimizeRect(param) {\n subPixelOptimizeUtil.subPixelOptimizeRect(param.shape, param.shape, param.style);\n return param;\n}\n\n/**\n * Sub pixel optimize for canvas\n *\n * @param {number} position Coordinate, such as x, y\n * @param {number} lineWidth Should be nonnegative integer.\n * @param {boolean=} positiveOrNegative Default false (negative).\n * @return {number} Optimized position.\n */\nexport var subPixelOptimize = subPixelOptimizeUtil.subPixelOptimize;\n\n\nfunction hasFillOrStroke(fillOrStroke) {\n return fillOrStroke != null && fillOrStroke !== 'none';\n}\n\n// Most lifted color are duplicated.\nvar liftedColorMap = zrUtil.createHashMap();\nvar liftedColorCount = 0;\n\nfunction liftColor(color) {\n if (typeof color !== 'string') {\n return color;\n }\n var liftedColor = liftedColorMap.get(color);\n if (!liftedColor) {\n liftedColor = colorTool.lift(color, -0.1);\n if (liftedColorCount < 10000) {\n liftedColorMap.set(color, liftedColor);\n liftedColorCount++;\n }\n }\n return liftedColor;\n}\n\nfunction cacheElementStl(el) {\n if (!el.__hoverStlDirty) {\n return;\n }\n el.__hoverStlDirty = false;\n\n var hoverStyle = el.__hoverStl;\n if (!hoverStyle) {\n el.__cachedNormalStl = el.__cachedNormalZ2 = null;\n return;\n }\n\n var normalStyle = el.__cachedNormalStl = {};\n el.__cachedNormalZ2 = el.z2;\n var elStyle = el.style;\n\n for (var name in hoverStyle) {\n // See comment in `singleEnterEmphasis`.\n if (hoverStyle[name] != null) {\n normalStyle[name] = elStyle[name];\n }\n }\n\n // Always cache fill and stroke to normalStyle for lifting color.\n normalStyle.fill = elStyle.fill;\n normalStyle.stroke = elStyle.stroke;\n}\n\nfunction singleEnterEmphasis(el) {\n var hoverStl = el.__hoverStl;\n\n if (!hoverStl || el.__highlighted) {\n return;\n }\n\n var zr = el.__zr;\n\n var useHoverLayer = el.useHoverLayer && zr && zr.painter.type === 'canvas';\n el.__highlighted = useHoverLayer ? 'layer' : 'plain';\n\n if (el.isGroup || (!zr && el.useHoverLayer)) {\n return;\n }\n\n var elTarget = el;\n var targetStyle = el.style;\n\n if (useHoverLayer) {\n elTarget = zr.addHover(el);\n targetStyle = elTarget.style;\n }\n\n rollbackDefaultTextStyle(targetStyle);\n\n if (!useHoverLayer) {\n cacheElementStl(elTarget);\n }\n\n // styles can be:\n // {\n // label: {\n // show: false,\n // position: 'outside',\n // fontSize: 18\n // },\n // emphasis: {\n // label: {\n // show: true\n // }\n // }\n // },\n // where properties of `emphasis` may not appear in `normal`. We previously use\n // module:echarts/util/model#defaultEmphasis to merge `normal` to `emphasis`.\n // But consider rich text and setOption in merge mode, it is impossible to cover\n // all properties in merge. So we use merge mode when setting style here.\n // But we choose the merge strategy that only properties that is not `null/undefined`.\n // Because when making a textStyle (espacially rich text), it is not easy to distinguish\n // `hasOwnProperty` and `null/undefined` in code, so we trade them as the same for simplicity.\n // But this strategy brings a trouble that `null/undefined` can not be used to remove\n // style any more in `emphasis`. Users can both set properties directly on normal and\n // emphasis to avoid this issue, or we might support `'none'` for this case if required.\n targetStyle.extendFrom(hoverStl);\n\n setDefaultHoverFillStroke(targetStyle, hoverStl, 'fill');\n setDefaultHoverFillStroke(targetStyle, hoverStl, 'stroke');\n\n applyDefaultTextStyle(targetStyle);\n\n if (!useHoverLayer) {\n el.dirty(false);\n el.z2 += Z2_EMPHASIS_LIFT;\n }\n}\n\nfunction setDefaultHoverFillStroke(targetStyle, hoverStyle, prop) {\n if (!hasFillOrStroke(hoverStyle[prop]) && hasFillOrStroke(targetStyle[prop])) {\n targetStyle[prop] = liftColor(targetStyle[prop]);\n }\n}\n\nfunction singleEnterNormal(el) {\n var highlighted = el.__highlighted;\n\n if (!highlighted) {\n return;\n }\n\n el.__highlighted = false;\n\n if (el.isGroup) {\n return;\n }\n\n if (highlighted === 'layer') {\n el.__zr && el.__zr.removeHover(el);\n }\n else {\n var style = el.style;\n\n var normalStl = el.__cachedNormalStl;\n if (normalStl) {\n rollbackDefaultTextStyle(style);\n el.setStyle(normalStl);\n applyDefaultTextStyle(style);\n }\n // `__cachedNormalZ2` will not be reset if calling `setElementHoverStyle`\n // when `el` is on emphasis state. So here by comparing with 1, we try\n // hard to make the bug case rare.\n var normalZ2 = el.__cachedNormalZ2;\n if (normalZ2 != null && el.z2 - normalZ2 === Z2_EMPHASIS_LIFT) {\n el.z2 = normalZ2;\n }\n }\n}\n\nfunction traverseUpdate(el, updater, commonParam) {\n // If root is group, also enter updater for `highDownOnUpdate`.\n var fromState = NORMAL;\n var toState = NORMAL;\n var trigger;\n // See the rule of `highDownOnUpdate` on `graphic.setAsHighDownDispatcher`.\n el.__highlighted && (fromState = EMPHASIS, trigger = true);\n updater(el, commonParam);\n el.__highlighted && (toState = EMPHASIS, trigger = true);\n\n el.isGroup && el.traverse(function (child) {\n !child.isGroup && updater(child, commonParam);\n });\n\n trigger && el.__highDownOnUpdate && el.__highDownOnUpdate(fromState, toState);\n}\n\n/**\n * Set hover style (namely \"emphasis style\") of element, based on the current\n * style of the given `el`.\n * This method should be called after all of the normal styles have been adopted\n * to the `el`. See the reason on `setHoverStyle`.\n *\n * @param {module:zrender/Element} el Should not be `zrender/container/Group`.\n * @param {Object} [el.hoverStyle] Can be set on el or its descendants,\n * e.g., `el.hoverStyle = ...; graphic.setHoverStyle(el); `.\n * Often used when item group has a label element and it's hoverStyle is different.\n * @param {Object|boolean} [hoverStl] The specified hover style.\n * If set as `false`, disable the hover style.\n * Similarly, The `el.hoverStyle` can alse be set\n * as `false` to disable the hover style.\n * Otherwise, use the default hover style if not provided.\n */\nexport function setElementHoverStyle(el, hoverStl) {\n // For performance consideration, it might be better to make the \"hover style\" only the\n // difference properties from the \"normal style\", but not a entire copy of all styles.\n hoverStl = el.__hoverStl = hoverStl !== false && (el.hoverStyle || hoverStl || {});\n el.__hoverStlDirty = true;\n\n // FIXME\n // It is not completely right to save \"normal\"/\"emphasis\" flag on elements.\n // It probably should be saved on `data` of series. Consider the cases:\n // (1) A highlighted elements are moved out of the view port and re-enter\n // again by dataZoom.\n // (2) call `setOption` and replace elements totally when they are highlighted.\n if (el.__highlighted) {\n // Consider the case:\n // The styles of a highlighted `el` is being updated. The new \"emphasis style\"\n // should be adapted to the `el`. Notice here new \"normal styles\" should have\n // been set outside and the cached \"normal style\" is out of date.\n el.__cachedNormalStl = null;\n // Do not clear `__cachedNormalZ2` here, because setting `z2` is not a constraint\n // of this method. In most cases, `z2` is not set and hover style should be able\n // to rollback. Of course, that would bring bug, but only in a rare case, see\n // `doSingleLeaveHover` for details.\n singleEnterNormal(el);\n\n singleEnterEmphasis(el);\n }\n}\n\nfunction onElementMouseOver(e) {\n !shouldSilent(this, e)\n // \"emphasis\" event highlight has higher priority than mouse highlight.\n && !this.__highByOuter\n && traverseUpdate(this, singleEnterEmphasis);\n}\n\nfunction onElementMouseOut(e) {\n !shouldSilent(this, e)\n // \"emphasis\" event highlight has higher priority than mouse highlight.\n && !this.__highByOuter\n && traverseUpdate(this, singleEnterNormal);\n}\n\nfunction onElementEmphasisEvent(highlightDigit) {\n this.__highByOuter |= 1 << (highlightDigit || 0);\n traverseUpdate(this, singleEnterEmphasis);\n}\n\nfunction onElementNormalEvent(highlightDigit) {\n !(this.__highByOuter &= ~(1 << (highlightDigit || 0)))\n && traverseUpdate(this, singleEnterNormal);\n}\n\nfunction shouldSilent(el, e) {\n return el.__highDownSilentOnTouch && e.zrByTouch;\n}\n\n/**\n * Set hover style (namely \"emphasis style\") of element,\n * based on the current style of the given `el`.\n *\n * (1)\n * **CONSTRAINTS** for this method:\n * <A> This method MUST be called after all of the normal styles having been adopted\n * to the `el`.\n * <B> The input `hoverStyle` (that is, \"emphasis style\") MUST be the subset of the\n * \"normal style\" having been set to the el.\n * <C> `color` MUST be one of the \"normal styles\" (because color might be lifted as\n * a default hover style).\n *\n * The reason: this method treat the current style of the `el` as the \"normal style\"\n * and cache them when enter/update the \"emphasis style\". Consider the case: the `el`\n * is in \"emphasis\" state and `setOption`/`dispatchAction` trigger the style updating\n * logic, where the el should shift from the original emphasis style to the new\n * \"emphasis style\" and should be able to \"downplay\" back to the new \"normal style\".\n *\n * Indeed, it is error-prone to make a interface has so many constraints, but I have\n * not found a better solution yet to fit the backward compatibility, performance and\n * the current programming style.\n *\n * (2)\n * Call the method for a \"root\" element once. Do not call it for each descendants.\n * If the descendants elemenets of a group has itself hover style different from the\n * root group, we can simply mount the style on `el.hoverStyle` for them, but should\n * not call this method for them.\n *\n * (3) These input parameters can be set directly on `el`:\n *\n * @param {module:zrender/Element} el\n * @param {Object} [el.hoverStyle] See `graphic.setElementHoverStyle`.\n * @param {boolean} [el.highDownSilentOnTouch=false] See `graphic.setAsHighDownDispatcher`.\n * @param {Function} [el.highDownOnUpdate] See `graphic.setAsHighDownDispatcher`.\n * @param {Object|boolean} [hoverStyle] See `graphic.setElementHoverStyle`.\n */\nexport function setHoverStyle(el, hoverStyle) {\n setAsHighDownDispatcher(el, true);\n traverseUpdate(el, setElementHoverStyle, hoverStyle);\n}\n\n/**\n * @param {module:zrender/Element} el\n * @param {Function} [el.highDownOnUpdate] Called when state updated.\n * Since `setHoverStyle` has the constraint that it must be called after\n * all of the normal style updated, `highDownOnUpdate` is not needed to\n * trigger if both `fromState` and `toState` is 'normal', and needed to\n * trigger if both `fromState` and `toState` is 'emphasis', which enables\n * to sync outside style settings to \"emphasis\" state.\n * @this {string} This dispatcher `el`.\n * @param {string} fromState Can be \"normal\" or \"emphasis\".\n * `fromState` might equal to `toState`,\n * for example, when this method is called when `el` is\n * on \"emphasis\" state.\n * @param {string} toState Can be \"normal\" or \"emphasis\".\n *\n * FIXME\n * CAUTION: Do not expose `highDownOnUpdate` outside echarts.\n * Because it is not a complete solution. The update\n * listener should not have been mount in element,\n * and the normal/emphasis state should not have\n * mantained on elements.\n *\n * @param {boolean} [el.highDownSilentOnTouch=false]\n * In touch device, mouseover event will be trigger on touchstart event\n * (see module:zrender/dom/HandlerProxy). By this mechanism, we can\n * conveniently use hoverStyle when tap on touch screen without additional\n * code for compatibility.\n * But if the chart/component has select feature, which usually also use\n * hoverStyle, there might be conflict between 'select-highlight' and\n * 'hover-highlight' especially when roam is enabled (see geo for example).\n * In this case, `highDownSilentOnTouch` should be used to disable\n * hover-highlight on touch device.\n * @param {boolean} [asDispatcher=true] If `false`, do not set as \"highDownDispatcher\".\n */\nexport function setAsHighDownDispatcher(el, asDispatcher) {\n var disable = asDispatcher === false;\n // Make `highDownSilentOnTouch` and `highDownOnUpdate` only work after\n // `setAsHighDownDispatcher` called. Avoid it is modified by user unexpectedly.\n el.__highDownSilentOnTouch = el.highDownSilentOnTouch;\n el.__highDownOnUpdate = el.highDownOnUpdate;\n\n // Simple optimize, since this method might be\n // called for each elements of a group in some cases.\n if (!disable || el.__highDownDispatcher) {\n var method = disable ? 'off' : 'on';\n\n // Duplicated function will be auto-ignored, see Eventful.js.\n el[method]('mouseover', onElementMouseOver)[method]('mouseout', onElementMouseOut);\n // Emphasis, normal can be triggered manually by API or other components like hover link.\n el[method]('emphasis', onElementEmphasisEvent)[method]('normal', onElementNormalEvent);\n // Also keep previous record.\n el.__highByOuter = el.__highByOuter || 0;\n\n el.__highDownDispatcher = !disable;\n }\n}\n\n/**\n * @param {module:zrender/src/Element} el\n * @return {boolean}\n */\nexport function isHighDownDispatcher(el) {\n return !!(el && el.__highDownDispatcher);\n}\n\n/**\n * Support hightlight/downplay record on each elements.\n * For the case: hover highlight/downplay (legend, visualMap, ...) and\n * user triggerred hightlight/downplay should not conflict.\n * Only all of the highlightDigit cleared, return to normal.\n * @param {string} highlightKey\n * @return {number} highlightDigit\n */\nexport function getHighlightDigit(highlightKey) {\n var highlightDigit = _highlightKeyMap[highlightKey];\n if (highlightDigit == null && _highlightNextDigit <= 32) {\n highlightDigit = _highlightKeyMap[highlightKey] = _highlightNextDigit++;\n }\n return highlightDigit;\n}\n\n/**\n * See more info in `setTextStyleCommon`.\n * @param {Object|module:zrender/graphic/Style} normalStyle\n * @param {Object} emphasisStyle\n * @param {module:echarts/model/Model} normalModel\n * @param {module:echarts/model/Model} emphasisModel\n * @param {Object} opt Check `opt` of `setTextStyleCommon` to find other props.\n * @param {string|Function} [opt.defaultText]\n * @param {module:echarts/model/Model} [opt.labelFetcher] Fetch text by\n * `opt.labelFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex, opt.labelProp)`\n * @param {number} [opt.labelDataIndex] Fetch text by\n * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex, opt.labelProp)`\n * @param {number} [opt.labelDimIndex] Fetch text by\n * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex, opt.labelProp)`\n * @param {string} [opt.labelProp] Fetch text by\n * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex, opt.labelProp)`\n * @param {Object} [normalSpecified]\n * @param {Object} [emphasisSpecified]\n */\nexport function setLabelStyle(\n normalStyle, emphasisStyle,\n normalModel, emphasisModel,\n opt,\n normalSpecified, emphasisSpecified\n) {\n opt = opt || EMPTY_OBJ;\n var labelFetcher = opt.labelFetcher;\n var labelDataIndex = opt.labelDataIndex;\n var labelDimIndex = opt.labelDimIndex;\n var labelProp = opt.labelProp;\n\n // This scenario, `label.normal.show = true; label.emphasis.show = false`,\n // is not supported util someone requests.\n\n var showNormal = normalModel.getShallow('show');\n var showEmphasis = emphasisModel.getShallow('show');\n\n // Consider performance, only fetch label when necessary.\n // If `normal.show` is `false` and `emphasis.show` is `true` and `emphasis.formatter` is not set,\n // label should be displayed, where text is fetched by `normal.formatter` or `opt.defaultText`.\n var baseText;\n if (showNormal || showEmphasis) {\n if (labelFetcher) {\n baseText = labelFetcher.getFormattedLabel(labelDataIndex, 'normal', null, labelDimIndex, labelProp);\n }\n if (baseText == null) {\n baseText = zrUtil.isFunction(opt.defaultText) ? opt.defaultText(labelDataIndex, opt) : opt.defaultText;\n }\n }\n var normalStyleText = showNormal ? baseText : null;\n var emphasisStyleText = showEmphasis\n ? zrUtil.retrieve2(\n labelFetcher\n ? labelFetcher.getFormattedLabel(labelDataIndex, 'emphasis', null, labelDimIndex, labelProp)\n : null,\n baseText\n )\n : null;\n\n // Optimize: If style.text is null, text will not be drawn.\n if (normalStyleText != null || emphasisStyleText != null) {\n // Always set `textStyle` even if `normalStyle.text` is null, because default\n // values have to be set on `normalStyle`.\n // If we set default values on `emphasisStyle`, consider case:\n // Firstly, `setOption(... label: {normal: {text: null}, emphasis: {show: true}} ...);`\n // Secondly, `setOption(... label: {noraml: {show: true, text: 'abc', color: 'red'} ...);`\n // Then the 'red' will not work on emphasis.\n setTextStyle(normalStyle, normalModel, normalSpecified, opt);\n setTextStyle(emphasisStyle, emphasisModel, emphasisSpecified, opt, true);\n }\n\n normalStyle.text = normalStyleText;\n emphasisStyle.text = emphasisStyleText;\n}\n\n/**\n * Modify label style manually.\n * Only works after `setLabelStyle` and `setElementHoverStyle` called.\n *\n * @param {module:zrender/src/Element} el\n * @param {Object} [normalStyleProps] optional\n * @param {Object} [emphasisStyleProps] optional\n */\nexport function modifyLabelStyle(el, normalStyleProps, emphasisStyleProps) {\n var elStyle = el.style;\n if (normalStyleProps) {\n rollbackDefaultTextStyle(elStyle);\n el.setStyle(normalStyleProps);\n applyDefaultTextStyle(elStyle);\n }\n elStyle = el.__hoverStl;\n if (emphasisStyleProps && elStyle) {\n rollbackDefaultTextStyle(elStyle);\n zrUtil.extend(elStyle, emphasisStyleProps);\n applyDefaultTextStyle(elStyle);\n }\n}\n\n/**\n * Set basic textStyle properties.\n * See more info in `setTextStyleCommon`.\n * @param {Object|module:zrender/graphic/Style} textStyle\n * @param {module:echarts/model/Model} model\n * @param {Object} [specifiedTextStyle] Can be overrided by settings in model.\n * @param {Object} [opt] See `opt` of `setTextStyleCommon`.\n * @param {boolean} [isEmphasis]\n */\nexport function setTextStyle(\n textStyle, textStyleModel, specifiedTextStyle, opt, isEmphasis\n) {\n setTextStyleCommon(textStyle, textStyleModel, opt, isEmphasis);\n specifiedTextStyle && zrUtil.extend(textStyle, specifiedTextStyle);\n // textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);\n\n return textStyle;\n}\n\n/**\n * Set text option in the style.\n * See more info in `setTextStyleCommon`.\n * @deprecated\n * @param {Object} textStyle\n * @param {module:echarts/model/Model} labelModel\n * @param {string|boolean} defaultColor Default text color.\n * If set as false, it will be processed as a emphasis style.\n */\nexport function setText(textStyle, labelModel, defaultColor) {\n var opt = {isRectText: true};\n var isEmphasis;\n\n if (defaultColor === false) {\n isEmphasis = true;\n }\n else {\n // Support setting color as 'auto' to get visual color.\n opt.autoColor = defaultColor;\n }\n setTextStyleCommon(textStyle, labelModel, opt, isEmphasis);\n // textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);\n}\n\n/**\n * The uniform entry of set text style, that is, retrieve style definitions\n * from `model` and set to `textStyle` object.\n *\n * Never in merge mode, but in overwrite mode, that is, all of the text style\n * properties will be set. (Consider the states of normal and emphasis and\n * default value can be adopted, merge would make the logic too complicated\n * to manage.)\n *\n * The `textStyle` object can either be a plain object or an instance of\n * `zrender/src/graphic/Style`, and either be the style of normal or emphasis.\n * After this mothod called, the `textStyle` object can then be used in\n * `el.setStyle(textStyle)` or `el.hoverStyle = textStyle`.\n *\n * Default value will be adopted and `insideRollbackOpt` will be created.\n * See `applyDefaultTextStyle` `rollbackDefaultTextStyle` for more details.\n *\n * opt: {\n * disableBox: boolean, Whether diable drawing box of block (outer most).\n * isRectText: boolean,\n * autoColor: string, specify a color when color is 'auto',\n * for textFill, textStroke, textBackgroundColor, and textBorderColor.\n * If autoColor specified, it is used as default textFill.\n * useInsideStyle:\n * `true`: Use inside style (textFill, textStroke, textStrokeWidth)\n * if `textFill` is not specified.\n * `false`: Do not use inside style.\n * `null/undefined`: use inside style if `isRectText` is true and\n * `textFill` is not specified and textPosition contains `'inside'`.\n * forceRich: boolean\n * }\n */\nfunction setTextStyleCommon(textStyle, textStyleModel, opt, isEmphasis) {\n // Consider there will be abnormal when merge hover style to normal style if given default value.\n opt = opt || EMPTY_OBJ;\n\n if (opt.isRectText) {\n var textPosition;\n if (opt.getTextPosition) {\n textPosition = opt.getTextPosition(textStyleModel, isEmphasis);\n }\n else {\n textPosition = textStyleModel.getShallow('position')\n || (isEmphasis ? null : 'inside');\n // 'outside' is not a valid zr textPostion value, but used\n // in bar series, and magric type should be considered.\n textPosition === 'outside' && (textPosition = 'top');\n }\n\n textStyle.textPosition = textPosition;\n textStyle.textOffset = textStyleModel.getShallow('offset');\n var labelRotate = textStyleModel.getShallow('rotate');\n labelRotate != null && (labelRotate *= Math.PI / 180);\n textStyle.textRotation = labelRotate;\n textStyle.textDistance = zrUtil.retrieve2(\n textStyleModel.getShallow('distance'), isEmphasis ? null : 5\n );\n }\n\n var ecModel = textStyleModel.ecModel;\n var globalTextStyle = ecModel && ecModel.option.textStyle;\n\n // Consider case:\n // {\n // data: [{\n // value: 12,\n // label: {\n // rich: {\n // // no 'a' here but using parent 'a'.\n // }\n // }\n // }],\n // rich: {\n // a: { ... }\n // }\n // }\n var richItemNames = getRichItemNames(textStyleModel);\n var richResult;\n if (richItemNames) {\n richResult = {};\n for (var name in richItemNames) {\n if (richItemNames.hasOwnProperty(name)) {\n // Cascade is supported in rich.\n var richTextStyle = textStyleModel.getModel(['rich', name]);\n // In rich, never `disableBox`.\n // FIXME: consider `label: {formatter: '{a|xx}', color: 'blue', rich: {a: {}}}`,\n // the default color `'blue'` will not be adopted if no color declared in `rich`.\n // That might confuses users. So probably we should put `textStyleModel` as the\n // root ancestor of the `richTextStyle`. But that would be a break change.\n setTokenTextStyle(richResult[name] = {}, richTextStyle, globalTextStyle, opt, isEmphasis);\n }\n }\n }\n textStyle.rich = richResult;\n\n setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isEmphasis, true);\n\n if (opt.forceRich && !opt.textStyle) {\n opt.textStyle = {};\n }\n\n return textStyle;\n}\n\n// Consider case:\n// {\n// data: [{\n// value: 12,\n// label: {\n// rich: {\n// // no 'a' here but using parent 'a'.\n// }\n// }\n// }],\n// rich: {\n// a: { ... }\n// }\n// }\nfunction getRichItemNames(textStyleModel) {\n // Use object to remove duplicated names.\n var richItemNameMap;\n while (textStyleModel && textStyleModel !== textStyleModel.ecModel) {\n var rich = (textStyleModel.option || EMPTY_OBJ).rich;\n if (rich) {\n richItemNameMap = richItemNameMap || {};\n for (var name in rich) {\n if (rich.hasOwnProperty(name)) {\n richItemNameMap[name] = 1;\n }\n }\n }\n textStyleModel = textStyleModel.parentModel;\n }\n return richItemNameMap;\n}\n\nfunction setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isEmphasis, isBlock) {\n // In merge mode, default value should not be given.\n globalTextStyle = !isEmphasis && globalTextStyle || EMPTY_OBJ;\n\n textStyle.textFill = getAutoColor(textStyleModel.getShallow('color'), opt)\n || globalTextStyle.color;\n textStyle.textStroke = getAutoColor(textStyleModel.getShallow('textBorderColor'), opt)\n || globalTextStyle.textBorderColor;\n textStyle.textStrokeWidth = zrUtil.retrieve2(\n textStyleModel.getShallow('textBorderWidth'),\n globalTextStyle.textBorderWidth\n );\n\n if (!isEmphasis) {\n if (isBlock) {\n textStyle.insideRollbackOpt = opt;\n applyDefaultTextStyle(textStyle);\n }\n\n // Set default finally.\n if (textStyle.textFill == null) {\n textStyle.textFill = opt.autoColor;\n }\n }\n\n // Do not use `getFont` here, because merge should be supported, where\n // part of these properties may be changed in emphasis style, and the\n // others should remain their original value got from normal style.\n textStyle.fontStyle = textStyleModel.getShallow('fontStyle') || globalTextStyle.fontStyle;\n textStyle.fontWeight = textStyleModel.getShallow('fontWeight') || globalTextStyle.fontWeight;\n textStyle.fontSize = textStyleModel.getShallow('fontSize') || globalTextStyle.fontSize;\n textStyle.fontFamily = textStyleModel.getShallow('fontFamily') || globalTextStyle.fontFamily;\n\n textStyle.textAlign = textStyleModel.getShallow('align');\n textStyle.textVerticalAlign = textStyleModel.getShallow('verticalAlign')\n || textStyleModel.getShallow('baseline');\n\n textStyle.textLineHeight = textStyleModel.getShallow('lineHeight');\n textStyle.textWidth = textStyleModel.getShallow('width');\n textStyle.textHeight = textStyleModel.getShallow('height');\n textStyle.textTag = textStyleModel.getShallow('tag');\n\n if (!isBlock || !opt.disableBox) {\n textStyle.textBackgroundColor = getAutoColor(textStyleModel.getShallow('backgroundColor'), opt);\n textStyle.textPadding = textStyleModel.getShallow('padding');\n textStyle.textBorderColor = getAutoColor(textStyleModel.getShallow('borderColor'), opt);\n textStyle.textBorderWidth = textStyleModel.getShallow('borderWidth');\n textStyle.textBorderRadius = textStyleModel.getShallow('borderRadius');\n\n textStyle.textBoxShadowColor = textStyleModel.getShallow('shadowColor');\n textStyle.textBoxShadowBlur = textStyleModel.getShallow('shadowBlur');\n textStyle.textBoxShadowOffsetX = textStyleModel.getShallow('shadowOffsetX');\n textStyle.textBoxShadowOffsetY = textStyleModel.getShallow('shadowOffsetY');\n }\n\n textStyle.textShadowColor = textStyleModel.getShallow('textShadowColor')\n || globalTextStyle.textShadowColor;\n textStyle.textShadowBlur = textStyleModel.getShallow('textShadowBlur')\n || globalTextStyle.textShadowBlur;\n textStyle.textShadowOffsetX = textStyleModel.getShallow('textShadowOffsetX')\n || globalTextStyle.textShadowOffsetX;\n textStyle.textShadowOffsetY = textStyleModel.getShallow('textShadowOffsetY')\n || globalTextStyle.textShadowOffsetY;\n}\n\nfunction getAutoColor(color, opt) {\n return color !== 'auto' ? color : (opt && opt.autoColor) ? opt.autoColor : null;\n}\n\n/**\n * Give some default value to the input `textStyle` object, based on the current settings\n * in this `textStyle` object.\n *\n * The Scenario:\n * when text position is `inside` and `textFill` is not specified, we show\n * text border by default for better view. But it should be considered that text position\n * might be changed when hovering or being emphasis, where the `insideRollback` is used to\n * restore the style.\n *\n * Usage (& NOTICE):\n * When a style object (eithor plain object or instance of `zrender/src/graphic/Style`) is\n * about to be modified on its text related properties, `rollbackDefaultTextStyle` should\n * be called before the modification and `applyDefaultTextStyle` should be called after that.\n * (For the case that all of the text related properties is reset, like `setTextStyleCommon`\n * does, `rollbackDefaultTextStyle` is not needed to be called).\n */\nfunction applyDefaultTextStyle(textStyle) {\n var textPosition = textStyle.textPosition;\n var opt = textStyle.insideRollbackOpt;\n var insideRollback;\n\n if (opt && textStyle.textFill == null) {\n var autoColor = opt.autoColor;\n var isRectText = opt.isRectText;\n var useInsideStyle = opt.useInsideStyle;\n\n var useInsideStyleCache = useInsideStyle !== false\n && (useInsideStyle === true\n || (isRectText\n && textPosition\n // textPosition can be [10, 30]\n && typeof textPosition === 'string'\n && textPosition.indexOf('inside') >= 0\n )\n );\n var useAutoColorCache = !useInsideStyleCache && autoColor != null;\n\n // All of the props declared in `CACHED_LABEL_STYLE_PROPERTIES` are to be cached.\n if (useInsideStyleCache || useAutoColorCache) {\n insideRollback = {\n textFill: textStyle.textFill,\n textStroke: textStyle.textStroke,\n textStrokeWidth: textStyle.textStrokeWidth\n };\n }\n if (useInsideStyleCache) {\n textStyle.textFill = '#fff';\n // Consider text with #fff overflow its container.\n if (textStyle.textStroke == null) {\n textStyle.textStroke = autoColor;\n textStyle.textStrokeWidth == null && (textStyle.textStrokeWidth = 2);\n }\n }\n if (useAutoColorCache) {\n textStyle.textFill = autoColor;\n }\n }\n\n // Always set `insideRollback`, so that the previous one can be cleared.\n textStyle.insideRollback = insideRollback;\n}\n\n/**\n * Consider the case: in a scatter,\n * label: {\n * normal: {position: 'inside'},\n * emphasis: {position: 'top'}\n * }\n * In the normal state, the `textFill` will be set as '#fff' for pretty view (see\n * `applyDefaultTextStyle`), but when switching to emphasis state, the `textFill`\n * should be retured to 'autoColor', but not keep '#fff'.\n */\nfunction rollbackDefaultTextStyle(style) {\n var insideRollback = style.insideRollback;\n if (insideRollback) {\n // Reset all of the props in `CACHED_LABEL_STYLE_PROPERTIES`.\n style.textFill = insideRollback.textFill;\n style.textStroke = insideRollback.textStroke;\n style.textStrokeWidth = insideRollback.textStrokeWidth;\n style.insideRollback = null;\n }\n}\n\nexport function getFont(opt, ecModel) {\n var gTextStyleModel = ecModel && ecModel.getModel('textStyle');\n return zrUtil.trim([\n // FIXME in node-canvas fontWeight is before fontStyle\n opt.fontStyle || gTextStyleModel && gTextStyleModel.getShallow('fontStyle') || '',\n opt.fontWeight || gTextStyleModel && gTextStyleModel.getShallow('fontWeight') || '',\n (opt.fontSize || gTextStyleModel && gTextStyleModel.getShallow('fontSize') || 12) + 'px',\n opt.fontFamily || gTextStyleModel && gTextStyleModel.getShallow('fontFamily') || 'sans-serif'\n ].join(' '));\n}\n\nfunction animateOrSetProps(isUpdate, el, props, animatableModel, dataIndex, cb) {\n if (typeof dataIndex === 'function') {\n cb = dataIndex;\n dataIndex = null;\n }\n // Do not check 'animation' property directly here. Consider this case:\n // animation model is an `itemModel`, whose does not have `isAnimationEnabled`\n // but its parent model (`seriesModel`) does.\n var animationEnabled = animatableModel && animatableModel.isAnimationEnabled();\n\n if (animationEnabled) {\n var postfix = isUpdate ? 'Update' : '';\n var duration = animatableModel.getShallow('animationDuration' + postfix);\n var animationEasing = animatableModel.getShallow('animationEasing' + postfix);\n var animationDelay = animatableModel.getShallow('animationDelay' + postfix);\n if (typeof animationDelay === 'function') {\n animationDelay = animationDelay(\n dataIndex,\n animatableModel.getAnimationDelayParams\n ? animatableModel.getAnimationDelayParams(el, dataIndex)\n : null\n );\n }\n if (typeof duration === 'function') {\n duration = duration(dataIndex);\n }\n\n duration > 0\n ? el.animateTo(props, duration, animationDelay || 0, animationEasing, cb, !!cb)\n : (el.stopAnimation(), el.attr(props), cb && cb());\n }\n else {\n el.stopAnimation();\n el.attr(props);\n cb && cb();\n }\n}\n\n/**\n * Update graphic element properties with or without animation according to the\n * configuration in series.\n *\n * Caution: this method will stop previous animation.\n * So do not use this method to one element twice before\n * animation starts, unless you know what you are doing.\n *\n * @param {module:zrender/Element} el\n * @param {Object} props\n * @param {module:echarts/model/Model} [animatableModel]\n * @param {number} [dataIndex]\n * @param {Function} [cb]\n * @example\n * graphic.updateProps(el, {\n * position: [100, 100]\n * }, seriesModel, dataIndex, function () { console.log('Animation done!'); });\n * // Or\n * graphic.updateProps(el, {\n * position: [100, 100]\n * }, seriesModel, function () { console.log('Animation done!'); });\n */\nexport function updateProps(el, props, animatableModel, dataIndex, cb) {\n animateOrSetProps(true, el, props, animatableModel, dataIndex, cb);\n}\n\n/**\n * Init graphic element properties with or without animation according to the\n * configuration in series.\n *\n * Caution: this method will stop previous animation.\n * So do not use this method to one element twice before\n * animation starts, unless you know what you are doing.\n *\n * @param {module:zrender/Element} el\n * @param {Object} props\n * @param {module:echarts/model/Model} [animatableModel]\n * @param {number} [dataIndex]\n * @param {Function} cb\n */\nexport function initProps(el, props, animatableModel, dataIndex, cb) {\n animateOrSetProps(false, el, props, animatableModel, dataIndex, cb);\n}\n\n/**\n * Get transform matrix of target (param target),\n * in coordinate of its ancestor (param ancestor)\n *\n * @param {module:zrender/mixin/Transformable} target\n * @param {module:zrender/mixin/Transformable} [ancestor]\n */\nexport function getTransform(target, ancestor) {\n var mat = matrix.identity([]);\n\n while (target && target !== ancestor) {\n matrix.mul(mat, target.getLocalTransform(), mat);\n target = target.parent;\n }\n\n return mat;\n}\n\n/**\n * Apply transform to an vertex.\n * @param {Array.<number>} target [x, y]\n * @param {Array.<number>|TypedArray.<number>|Object} transform Can be:\n * + Transform matrix: like [1, 0, 0, 1, 0, 0]\n * + {position, rotation, scale}, the same as `zrender/Transformable`.\n * @param {boolean=} invert Whether use invert matrix.\n * @return {Array.<number>} [x, y]\n */\nexport function applyTransform(target, transform, invert) {\n if (transform && !zrUtil.isArrayLike(transform)) {\n transform = Transformable.getLocalTransform(transform);\n }\n\n if (invert) {\n transform = matrix.invert([], transform);\n }\n return vector.applyTransform([], target, transform);\n}\n\n/**\n * @param {string} direction 'left' 'right' 'top' 'bottom'\n * @param {Array.<number>} transform Transform matrix: like [1, 0, 0, 1, 0, 0]\n * @param {boolean=} invert Whether use invert matrix.\n * @return {string} Transformed direction. 'left' 'right' 'top' 'bottom'\n */\nexport function transformDirection(direction, transform, invert) {\n\n // Pick a base, ensure that transform result will not be (0, 0).\n var hBase = (transform[4] === 0 || transform[5] === 0 || transform[0] === 0)\n ? 1 : Math.abs(2 * transform[4] / transform[0]);\n var vBase = (transform[4] === 0 || transform[5] === 0 || transform[2] === 0)\n ? 1 : Math.abs(2 * transform[4] / transform[2]);\n\n var vertex = [\n direction === 'left' ? -hBase : direction === 'right' ? hBase : 0,\n direction === 'top' ? -vBase : direction === 'bottom' ? vBase : 0\n ];\n\n vertex = applyTransform(vertex, transform, invert);\n\n return Math.abs(vertex[0]) > Math.abs(vertex[1])\n ? (vertex[0] > 0 ? 'right' : 'left')\n : (vertex[1] > 0 ? 'bottom' : 'top');\n}\n\n/**\n * Apply group transition animation from g1 to g2.\n * If no animatableModel, no animation.\n */\nexport function groupTransition(g1, g2, animatableModel, cb) {\n if (!g1 || !g2) {\n return;\n }\n\n function getElMap(g) {\n var elMap = {};\n g.traverse(function (el) {\n if (!el.isGroup && el.anid) {\n elMap[el.anid] = el;\n }\n });\n return elMap;\n }\n function getAnimatableProps(el) {\n var obj = {\n position: vector.clone(el.position),\n rotation: el.rotation\n };\n if (el.shape) {\n obj.shape = zrUtil.extend({}, el.shape);\n }\n return obj;\n }\n var elMap1 = getElMap(g1);\n\n g2.traverse(function (el) {\n if (!el.isGroup && el.anid) {\n var oldEl = elMap1[el.anid];\n if (oldEl) {\n var newProp = getAnimatableProps(el);\n el.attr(getAnimatableProps(oldEl));\n updateProps(el, newProp, animatableModel, el.dataIndex);\n }\n // else {\n // if (el.previousProps) {\n // graphic.updateProps\n // }\n // }\n }\n });\n}\n\n/**\n * @param {Array.<Array.<number>>} points Like: [[23, 44], [53, 66], ...]\n * @param {Object} rect {x, y, width, height}\n * @return {Array.<Array.<number>>} A new clipped points.\n */\nexport function clipPointsByRect(points, rect) {\n // FIXME: this way migth be incorrect when grpahic clipped by a corner.\n // and when element have border.\n return zrUtil.map(points, function (point) {\n var x = point[0];\n x = mathMax(x, rect.x);\n x = mathMin(x, rect.x + rect.width);\n var y = point[1];\n y = mathMax(y, rect.y);\n y = mathMin(y, rect.y + rect.height);\n return [x, y];\n });\n}\n\n/**\n * @param {Object} targetRect {x, y, width, height}\n * @param {Object} rect {x, y, width, height}\n * @return {Object} A new clipped rect. If rect size are negative, return undefined.\n */\nexport function clipRectByRect(targetRect, rect) {\n var x = mathMax(targetRect.x, rect.x);\n var x2 = mathMin(targetRect.x + targetRect.width, rect.x + rect.width);\n var y = mathMax(targetRect.y, rect.y);\n var y2 = mathMin(targetRect.y + targetRect.height, rect.y + rect.height);\n\n // If the total rect is cliped, nothing, including the border,\n // should be painted. So return undefined.\n if (x2 >= x && y2 >= y) {\n return {\n x: x,\n y: y,\n width: x2 - x,\n height: y2 - y\n };\n }\n}\n\n/**\n * @param {string} iconStr Support 'image://' or 'path://' or direct svg path.\n * @param {Object} [opt] Properties of `module:zrender/Element`, except `style`.\n * @param {Object} [rect] {x, y, width, height}\n * @return {module:zrender/Element} Icon path or image element.\n */\nexport function createIcon(iconStr, opt, rect) {\n opt = zrUtil.extend({rectHover: true}, opt);\n var style = opt.style = {strokeNoScale: true};\n rect = rect || {x: -1, y: -1, width: 2, height: 2};\n\n if (iconStr) {\n return iconStr.indexOf('image://') === 0\n ? (\n style.image = iconStr.slice(8),\n zrUtil.defaults(style, rect),\n new ZImage(opt)\n )\n : (\n makePath(\n iconStr.replace('path://', ''),\n opt,\n rect,\n 'center'\n )\n );\n }\n}\n\n/**\n * Return `true` if the given line (line `a`) and the given polygon\n * are intersect.\n * Note that we do not count colinear as intersect here because no\n * requirement for that. We could do that if required in future.\n *\n * @param {number} a1x\n * @param {number} a1y\n * @param {number} a2x\n * @param {number} a2y\n * @param {Array.<Array.<number>>} points Points of the polygon.\n * @return {boolean}\n */\nexport function linePolygonIntersect(a1x, a1y, a2x, a2y, points) {\n for (var i = 0, p2 = points[points.length - 1]; i < points.length; i++) {\n var p = points[i];\n if (lineLineIntersect(a1x, a1y, a2x, a2y, p[0], p[1], p2[0], p2[1])) {\n return true;\n }\n p2 = p;\n }\n}\n\n/**\n * Return `true` if the given two lines (line `a` and line `b`)\n * are intersect.\n * Note that we do not count colinear as intersect here because no\n * requirement for that. We could do that if required in future.\n *\n * @param {number} a1x\n * @param {number} a1y\n * @param {number} a2x\n * @param {number} a2y\n * @param {number} b1x\n * @param {number} b1y\n * @param {number} b2x\n * @param {number} b2y\n * @return {boolean}\n */\nexport function lineLineIntersect(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y) {\n // let `vec_m` to be `vec_a2 - vec_a1` and `vec_n` to be `vec_b2 - vec_b1`.\n var mx = a2x - a1x;\n var my = a2y - a1y;\n var nx = b2x - b1x;\n var ny = b2y - b1y;\n\n // `vec_m` and `vec_n` are parallel iff\n // exising `k` such that `vec_m = k · vec_n`, equivalent to `vec_m X vec_n = 0`.\n var nmCrossProduct = crossProduct2d(nx, ny, mx, my);\n if (nearZero(nmCrossProduct)) {\n return false;\n }\n\n // `vec_m` and `vec_n` are intersect iff\n // existing `p` and `q` in [0, 1] such that `vec_a1 + p * vec_m = vec_b1 + q * vec_n`,\n // such that `q = ((vec_a1 - vec_b1) X vec_m) / (vec_n X vec_m)`\n // and `p = ((vec_a1 - vec_b1) X vec_n) / (vec_n X vec_m)`.\n var b1a1x = a1x - b1x;\n var b1a1y = a1y - b1y;\n var q = crossProduct2d(b1a1x, b1a1y, mx, my) / nmCrossProduct;\n if (q < 0 || q > 1) {\n return false;\n }\n var p = crossProduct2d(b1a1x, b1a1y, nx, ny) / nmCrossProduct;\n if (p < 0 || p > 1) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Cross product of 2-dimension vector.\n */\nfunction crossProduct2d(x1, y1, x2, y2) {\n return x1 * y2 - x2 * y1;\n}\n\nfunction nearZero(val) {\n return val <= (1e-6) && val >= -(1e-6);\n}\n\n// Register built-in shapes. These shapes might be overwirtten\n// by users, although we do not recommend that.\nregisterShape('circle', Circle);\nregisterShape('sector', Sector);\nregisterShape('ring', Ring);\nregisterShape('polygon', Polygon);\nregisterShape('polyline', Polyline);\nregisterShape('rect', Rect);\nregisterShape('line', Line);\nregisterShape('bezierCurve', BezierCurve);\nregisterShape('arc', Arc);\n\nexport {\n Group,\n ZImage as Image,\n Text,\n Circle,\n Sector,\n Ring,\n Polygon,\n Polyline,\n Rect,\n Line,\n BezierCurve,\n Arc,\n IncrementalDisplayable,\n CompoundPath,\n LinearGradient,\n RadialGradient,\n BoundingRect\n};\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport * as textContain from 'zrender/src/contain/text';\nimport * as graphicUtil from '../../util/graphic';\n\nvar PATH_COLOR = ['textStyle', 'color'];\n\nexport default {\n /**\n * Get color property or get color from option.textStyle.color\n * @param {boolean} [isEmphasis]\n * @return {string}\n */\n getTextColor: function (isEmphasis) {\n var ecModel = this.ecModel;\n return this.getShallow('color')\n || (\n (!isEmphasis && ecModel) ? ecModel.get(PATH_COLOR) : null\n );\n },\n\n /**\n * Create font string from fontStyle, fontWeight, fontSize, fontFamily\n * @return {string}\n */\n getFont: function () {\n return graphicUtil.getFont({\n fontStyle: this.getShallow('fontStyle'),\n fontWeight: this.getShallow('fontWeight'),\n fontSize: this.getShallow('fontSize'),\n fontFamily: this.getShallow('fontFamily')\n }, this.ecModel);\n },\n\n getTextRect: function (text) {\n return textContain.getBoundingRect(\n text,\n this.getFont(),\n this.getShallow('align'),\n this.getShallow('verticalAlign') || this.getShallow('baseline'),\n this.getShallow('padding'),\n this.getShallow('lineHeight'),\n this.getShallow('rich'),\n this.getShallow('truncateText')\n );\n }\n};","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport makeStyleMapper from './makeStyleMapper';\n\nvar getItemStyle = makeStyleMapper(\n [\n ['fill', 'color'],\n ['stroke', 'borderColor'],\n ['lineWidth', 'borderWidth'],\n ['opacity'],\n ['shadowBlur'],\n ['shadowOffsetX'],\n ['shadowOffsetY'],\n ['shadowColor'],\n ['textPosition'],\n ['textAlign']\n ]\n);\n\nexport default {\n getItemStyle: function (excludes, includes) {\n var style = getItemStyle(this, excludes, includes);\n var lineDash = this.getBorderLineDash();\n lineDash && (style.lineDash = lineDash);\n return style;\n },\n\n getBorderLineDash: function () {\n var lineType = this.get('borderType');\n return (lineType === 'solid' || lineType == null) ? null\n : (lineType === 'dashed' ? [5, 5] : [1, 1]);\n }\n};","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\n/**\n * @module echarts/model/Model\n */\n\nimport * as zrUtil from 'zrender/src/core/util';\nimport env from 'zrender/src/core/env';\nimport {makeInner} from '../util/model';\nimport {enableClassExtend, enableClassCheck} from '../util/clazz';\n\nimport lineStyleMixin from './mixin/lineStyle';\nimport areaStyleMixin from './mixin/areaStyle';\nimport textStyleMixin from './mixin/textStyle';\nimport itemStyleMixin from './mixin/itemStyle';\n\nvar mixin = zrUtil.mixin;\nvar inner = makeInner();\n\n/**\n * @alias module:echarts/model/Model\n * @constructor\n * @param {Object} [option]\n * @param {module:echarts/model/Model} [parentModel]\n * @param {module:echarts/model/Global} [ecModel]\n */\nfunction Model(option, parentModel, ecModel) {\n /**\n * @type {module:echarts/model/Model}\n * @readOnly\n */\n this.parentModel = parentModel;\n\n /**\n * @type {module:echarts/model/Global}\n * @readOnly\n */\n this.ecModel = ecModel;\n\n /**\n * @type {Object}\n * @protected\n */\n this.option = option;\n\n // Simple optimization\n // if (this.init) {\n // if (arguments.length <= 4) {\n // this.init(option, parentModel, ecModel, extraOpt);\n // }\n // else {\n // this.init.apply(this, arguments);\n // }\n // }\n}\n\nModel.prototype = {\n\n constructor: Model,\n\n /**\n * Model 的初始化函数\n * @param {Object} option\n */\n init: null,\n\n /**\n * 从新的 Option merge\n */\n mergeOption: function (option) {\n zrUtil.merge(this.option, option, true);\n },\n\n /**\n * @param {string|Array.<string>} path\n * @param {boolean} [ignoreParent=false]\n * @return {*}\n */\n get: function (path, ignoreParent) {\n if (path == null) {\n return this.option;\n }\n\n return doGet(\n this.option,\n this.parsePath(path),\n !ignoreParent && getParent(this, path)\n );\n },\n\n /**\n * @param {string} key\n * @param {boolean} [ignoreParent=false]\n * @return {*}\n */\n getShallow: function (key, ignoreParent) {\n var option = this.option;\n\n var val = option == null ? option : option[key];\n var parentModel = !ignoreParent && getParent(this, key);\n if (val == null && parentModel) {\n val = parentModel.getShallow(key);\n }\n return val;\n },\n\n /**\n * @param {string|Array.<string>} [path]\n * @param {module:echarts/model/Model} [parentModel]\n * @return {module:echarts/model/Model}\n */\n getModel: function (path, parentModel) {\n var obj = path == null\n ? this.option\n : doGet(this.option, path = this.parsePath(path));\n\n var thisParentModel;\n parentModel = parentModel || (\n (thisParentModel = getParent(this, path))\n && thisParentModel.getModel(path)\n );\n\n return new Model(obj, parentModel, this.ecModel);\n },\n\n /**\n * If model has option\n */\n isEmpty: function () {\n return this.option == null;\n },\n\n restoreData: function () {},\n\n // Pending\n clone: function () {\n var Ctor = this.constructor;\n return new Ctor(zrUtil.clone(this.option));\n },\n\n setReadOnly: function (properties) {\n // clazzUtil.setReadOnly(this, properties);\n },\n\n // If path is null/undefined, return null/undefined.\n parsePath: function (path) {\n if (typeof path === 'string') {\n path = path.split('.');\n }\n return path;\n },\n\n /**\n * @param {Function} getParentMethod\n * param {Array.<string>|string} path\n * return {module:echarts/model/Model}\n */\n customizeGetParent: function (getParentMethod) {\n inner(this).getParent = getParentMethod;\n },\n\n isAnimationEnabled: function () {\n if (!env.node) {\n if (this.option.animation != null) {\n return !!this.option.animation;\n }\n else if (this.parentModel) {\n return this.parentModel.isAnimationEnabled();\n }\n }\n }\n\n};\n\nfunction doGet(obj, pathArr, parentModel) {\n for (var i = 0; i < pathArr.length; i++) {\n // Ignore empty\n if (!pathArr[i]) {\n continue;\n }\n // obj could be number/string/... (like 0)\n obj = (obj && typeof obj === 'object') ? obj[pathArr[i]] : null;\n if (obj == null) {\n break;\n }\n }\n if (obj == null && parentModel) {\n obj = parentModel.get(pathArr);\n }\n return obj;\n}\n\n// `path` can be null/undefined\nfunction getParent(model, path) {\n var getParentMethod = inner(model).getParent;\n return getParentMethod ? getParentMethod.call(model, path) : model.parentModel;\n}\n\n// Enable Model.extend.\nenableClassExtend(Model);\nenableClassCheck(Model);\n\nmixin(Model, lineStyleMixin);\nmixin(Model, areaStyleMixin);\nmixin(Model, textStyleMixin);\nmixin(Model, itemStyleMixin);\n\nexport default Model;","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport * as zrUtil from 'zrender/src/core/util';\nimport {parseClassType} from './clazz';\n\nvar base = 0;\n\n/**\n * @public\n * @param {string} type\n * @return {string}\n */\nexport function getUID(type) {\n // Considering the case of crossing js context,\n // use Math.random to make id as unique as possible.\n return [(type || ''), base++, Math.random().toFixed(5)].join('_');\n}\n\n/**\n * @inner\n */\nexport function enableSubTypeDefaulter(entity) {\n\n var subTypeDefaulters = {};\n\n entity.registerSubTypeDefaulter = function (componentType, defaulter) {\n componentType = parseClassType(componentType);\n subTypeDefaulters[componentType.main] = defaulter;\n };\n\n entity.determineSubType = function (componentType, option) {\n var type = option.type;\n if (!type) {\n var componentTypeMain = parseClassType(componentType).main;\n if (entity.hasSubTypes(componentType) && subTypeDefaulters[componentTypeMain]) {\n type = subTypeDefaulters[componentTypeMain](option);\n }\n }\n return type;\n };\n\n return entity;\n}\n\n/**\n * Topological travel on Activity Network (Activity On Vertices).\n * Dependencies is defined in Model.prototype.dependencies, like ['xAxis', 'yAxis'].\n *\n * If 'xAxis' or 'yAxis' is absent in componentTypeList, just ignore it in topology.\n *\n * If there is circle dependencey, Error will be thrown.\n *\n */\nexport function enableTopologicalTravel(entity, dependencyGetter) {\n\n /**\n * @public\n * @param {Array.<string>} targetNameList Target Component type list.\n * Can be ['aa', 'bb', 'aa.xx']\n * @param {Array.<string>} fullNameList By which we can build dependency graph.\n * @param {Function} callback Params: componentType, dependencies.\n * @param {Object} context Scope of callback.\n */\n entity.topologicalTravel = function (targetNameList, fullNameList, callback, context) {\n if (!targetNameList.length) {\n return;\n }\n\n var result = makeDepndencyGraph(fullNameList);\n var graph = result.graph;\n var stack = result.noEntryList;\n\n var targetNameSet = {};\n zrUtil.each(targetNameList, function (name) {\n targetNameSet[name] = true;\n });\n\n while (stack.length) {\n var currComponentType = stack.pop();\n var currVertex = graph[currComponentType];\n var isInTargetNameSet = !!targetNameSet[currComponentType];\n if (isInTargetNameSet) {\n callback.call(context, currComponentType, currVertex.originalDeps.slice());\n delete targetNameSet[currComponentType];\n }\n zrUtil.each(\n currVertex.successor,\n isInTargetNameSet ? removeEdgeAndAdd : removeEdge\n );\n }\n\n zrUtil.each(targetNameSet, function () {\n throw new Error('Circle dependency may exists');\n });\n\n function removeEdge(succComponentType) {\n graph[succComponentType].entryCount--;\n if (graph[succComponentType].entryCount === 0) {\n stack.push(succComponentType);\n }\n }\n\n // Consider this case: legend depends on series, and we call\n // chart.setOption({series: [...]}), where only series is in option.\n // If we do not have 'removeEdgeAndAdd', legendModel.mergeOption will\n // not be called, but only sereis.mergeOption is called. Thus legend\n // have no chance to update its local record about series (like which\n // name of series is available in legend).\n function removeEdgeAndAdd(succComponentType) {\n targetNameSet[succComponentType] = true;\n removeEdge(succComponentType);\n }\n };\n\n /**\n * DepndencyGraph: {Object}\n * key: conponentType,\n * value: {\n * successor: [conponentTypes...],\n * originalDeps: [conponentTypes...],\n * entryCount: {number}\n * }\n */\n function makeDepndencyGraph(fullNameList) {\n var graph = {};\n var noEntryList = [];\n\n zrUtil.each(fullNameList, function (name) {\n\n var thisItem = createDependencyGraphItem(graph, name);\n var originalDeps = thisItem.originalDeps = dependencyGetter(name);\n\n var availableDeps = getAvailableDependencies(originalDeps, fullNameList);\n thisItem.entryCount = availableDeps.length;\n if (thisItem.entryCount === 0) {\n noEntryList.push(name);\n }\n\n zrUtil.each(availableDeps, function (dependentName) {\n if (zrUtil.indexOf(thisItem.predecessor, dependentName) < 0) {\n thisItem.predecessor.push(dependentName);\n }\n var thatItem = createDependencyGraphItem(graph, dependentName);\n if (zrUtil.indexOf(thatItem.successor, dependentName) < 0) {\n thatItem.successor.push(name);\n }\n });\n });\n\n return {graph: graph, noEntryList: noEntryList};\n }\n\n function createDependencyGraphItem(graph, name) {\n if (!graph[name]) {\n graph[name] = {predecessor: [], successor: []};\n }\n return graph[name];\n }\n\n function getAvailableDependencies(originalDeps, fullNameList) {\n var availableDeps = [];\n zrUtil.each(originalDeps, function (dep) {\n zrUtil.indexOf(fullNameList, dep) >= 0 && availableDeps.push(dep);\n });\n return availableDeps;\n }\n}\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\n/*\n* A third-party license is embeded for some of the code in this file:\n* The method \"quantile\" was copied from \"d3.js\".\n* (See more details in the comment of the method below.)\n* The use of the source code of this file is also subject to the terms\n* and consitions of the license of \"d3.js\" (BSD-3Clause, see\n* </licenses/LICENSE-d3>).\n*/\n\nimport * as zrUtil from 'zrender/src/core/util';\n\nvar RADIAN_EPSILON = 1e-4;\n\nfunction _trim(str) {\n return str.replace(/^\\s+|\\s+$/g, '');\n}\n\n/**\n * Linear mapping a value from domain to range\n * @memberOf module:echarts/util/number\n * @param {(number|Array.<number>)} val\n * @param {Array.<number>} domain Domain extent domain[0] can be bigger than domain[1]\n * @param {Array.<number>} range Range extent range[0] can be bigger than range[1]\n * @param {boolean} clamp\n * @return {(number|Array.<number>}\n */\nexport function linearMap(val, domain, range, clamp) {\n var subDomain = domain[1] - domain[0];\n var subRange = range[1] - range[0];\n\n if (subDomain === 0) {\n return subRange === 0\n ? range[0]\n : (range[0] + range[1]) / 2;\n }\n\n // Avoid accuracy problem in edge, such as\n // 146.39 - 62.83 === 83.55999999999999.\n // See echarts/test/ut/spec/util/number.js#linearMap#accuracyError\n // It is a little verbose for efficiency considering this method\n // is a hotspot.\n if (clamp) {\n if (subDomain > 0) {\n if (val <= domain[0]) {\n return range[0];\n }\n else if (val >= domain[1]) {\n return range[1];\n }\n }\n else {\n if (val >= domain[0]) {\n return range[0];\n }\n else if (val <= domain[1]) {\n return range[1];\n }\n }\n }\n else {\n if (val === domain[0]) {\n return range[0];\n }\n if (val === domain[1]) {\n return range[1];\n }\n }\n\n return (val - domain[0]) / subDomain * subRange + range[0];\n}\n\n/**\n * Convert a percent string to absolute number.\n * Returns NaN if percent is not a valid string or number\n * @memberOf module:echarts/util/number\n * @param {string|number} percent\n * @param {number} all\n * @return {number}\n */\nexport function parsePercent(percent, all) {\n switch (percent) {\n case 'center':\n case 'middle':\n percent = '50%';\n break;\n case 'left':\n case 'top':\n percent = '0%';\n break;\n case 'right':\n case 'bottom':\n percent = '100%';\n break;\n }\n if (typeof percent === 'string') {\n if (_trim(percent).match(/%$/)) {\n return parseFloat(percent) / 100 * all;\n }\n\n return parseFloat(percent);\n }\n\n return percent == null ? NaN : +percent;\n}\n\n/**\n * (1) Fix rounding error of float numbers.\n * (2) Support return string to avoid scientific notation like '3.5e-7'.\n *\n * @param {number} x\n * @param {number} [precision]\n * @param {boolean} [returnStr]\n * @return {number|string}\n */\nexport function round(x, precision, returnStr) {\n if (precision == null) {\n precision = 10;\n }\n // Avoid range error\n precision = Math.min(Math.max(0, precision), 20);\n x = (+x).toFixed(precision);\n return returnStr ? x : +x;\n}\n\n/**\n * asc sort arr.\n * The input arr will be modified.\n *\n * @param {Array} arr\n * @return {Array} The input arr.\n */\nexport function asc(arr) {\n arr.sort(function (a, b) {\n return a - b;\n });\n return arr;\n}\n\n/**\n * Get precision\n * @param {number} val\n */\nexport function getPrecision(val) {\n val = +val;\n if (isNaN(val)) {\n return 0;\n }\n // It is much faster than methods converting number to string as follows\n // var tmp = val.toString();\n // return tmp.length - 1 - tmp.indexOf('.');\n // especially when precision is low\n var e = 1;\n var count = 0;\n while (Math.round(val * e) / e !== val) {\n e *= 10;\n count++;\n }\n return count;\n}\n\n/**\n * @param {string|number} val\n * @return {number}\n */\nexport function getPrecisionSafe(val) {\n var str = val.toString();\n\n // Consider scientific notation: '3.4e-12' '3.4e+12'\n var eIndex = str.indexOf('e');\n if (eIndex > 0) {\n var precision = +str.slice(eIndex + 1);\n return precision < 0 ? -precision : 0;\n }\n else {\n var dotIndex = str.indexOf('.');\n return dotIndex < 0 ? 0 : str.length - 1 - dotIndex;\n }\n}\n\n/**\n * Minimal dicernible data precisioin according to a single pixel.\n *\n * @param {Array.<number>} dataExtent\n * @param {Array.<number>} pixelExtent\n * @return {number} precision\n */\nexport function getPixelPrecision(dataExtent, pixelExtent) {\n var log = Math.log;\n var LN10 = Math.LN10;\n var dataQuantity = Math.floor(log(dataExtent[1] - dataExtent[0]) / LN10);\n var sizeQuantity = Math.round(log(Math.abs(pixelExtent[1] - pixelExtent[0])) / LN10);\n // toFixed() digits argument must be between 0 and 20.\n var precision = Math.min(Math.max(-dataQuantity + sizeQuantity, 0), 20);\n return !isFinite(precision) ? 20 : precision;\n}\n\n/**\n * Get a data of given precision, assuring the sum of percentages\n * in valueList is 1.\n * The largest remainer method is used.\n * https://en.wikipedia.org/wiki/Largest_remainder_method\n *\n * @param {Array.<number>} valueList a list of all data\n * @param {number} idx index of the data to be processed in valueList\n * @param {number} precision integer number showing digits of precision\n * @return {number} percent ranging from 0 to 100\n */\nexport function getPercentWithPrecision(valueList, idx, precision) {\n if (!valueList[idx]) {\n return 0;\n }\n\n var sum = zrUtil.reduce(valueList, function (acc, val) {\n return acc + (isNaN(val) ? 0 : val);\n }, 0);\n if (sum === 0) {\n return 0;\n }\n\n var digits = Math.pow(10, precision);\n var votesPerQuota = zrUtil.map(valueList, function (val) {\n return (isNaN(val) ? 0 : val) / sum * digits * 100;\n });\n var targetSeats = digits * 100;\n\n var seats = zrUtil.map(votesPerQuota, function (votes) {\n // Assign automatic seats.\n return Math.floor(votes);\n });\n var currentSum = zrUtil.reduce(seats, function (acc, val) {\n return acc + val;\n }, 0);\n\n var remainder = zrUtil.map(votesPerQuota, function (votes, idx) {\n return votes - seats[idx];\n });\n\n // Has remainding votes.\n while (currentSum < targetSeats) {\n // Find next largest remainder.\n var max = Number.NEGATIVE_INFINITY;\n var maxId = null;\n for (var i = 0, len = remainder.length; i < len; ++i) {\n if (remainder[i] > max) {\n max = remainder[i];\n maxId = i;\n }\n }\n\n // Add a vote to max remainder.\n ++seats[maxId];\n remainder[maxId] = 0;\n ++currentSum;\n }\n\n return seats[idx] / digits;\n}\n\n// Number.MAX_SAFE_INTEGER, ie do not support.\nexport var MAX_SAFE_INTEGER = 9007199254740991;\n\n/**\n * To 0 - 2 * PI, considering negative radian.\n * @param {number} radian\n * @return {number}\n */\nexport function remRadian(radian) {\n var pi2 = Math.PI * 2;\n return (radian % pi2 + pi2) % pi2;\n}\n\n/**\n * @param {type} radian\n * @return {boolean}\n */\nexport function isRadianAroundZero(val) {\n return val > -RADIAN_EPSILON && val < RADIAN_EPSILON;\n}\n\n/* eslint-disable */\nvar TIME_REG = /^(?:(\\d{4})(?:[-\\/](\\d{1,2})(?:[-\\/](\\d{1,2})(?:[T ](\\d{1,2})(?::(\\d\\d)(?::(\\d\\d)(?:[.,](\\d+))?)?)?(Z|[\\+\\-]\\d\\d:?\\d\\d)?)?)?)?)?$/; // jshint ignore:line\n/* eslint-enable */\n\n/**\n * @param {string|Date|number} value These values can be accepted:\n * + An instance of Date, represent a time in its own time zone.\n * + Or string in a subset of ISO 8601, only including:\n * + only year, month, date: '2012-03', '2012-03-01', '2012-03-01 05', '2012-03-01 05:06',\n * + separated with T or space: '2012-03-01T12:22:33.123', '2012-03-01 12:22:33.123',\n * + time zone: '2012-03-01T12:22:33Z', '2012-03-01T12:22:33+8000', '2012-03-01T12:22:33-05:00',\n * all of which will be treated as local time if time zone is not specified\n * (see <https://momentjs.com/>).\n * + Or other string format, including (all of which will be treated as loacal time):\n * '2012', '2012-3-1', '2012/3/1', '2012/03/01',\n * '2009/6/12 2:00', '2009/6/12 2:05:08', '2009/6/12 2:05:08.123'\n * + a timestamp, which represent a time in UTC.\n * @return {Date} date\n */\nexport function parseDate(value) {\n if (value instanceof Date) {\n return value;\n }\n else if (typeof value === 'string') {\n // Different browsers parse date in different way, so we parse it manually.\n // Some other issues:\n // new Date('1970-01-01') is UTC,\n // new Date('1970/01/01') and new Date('1970-1-01') is local.\n // See issue #3623\n var match = TIME_REG.exec(value);\n\n if (!match) {\n // return Invalid Date.\n return new Date(NaN);\n }\n\n // Use local time when no timezone offset specifed.\n if (!match[8]) {\n // match[n] can only be string or undefined.\n // But take care of '12' + 1 => '121'.\n return new Date(\n +match[1],\n +(match[2] || 1) - 1,\n +match[3] || 1,\n +match[4] || 0,\n +(match[5] || 0),\n +match[6] || 0,\n +match[7] || 0\n );\n }\n // Timezoneoffset of Javascript Date has considered DST (Daylight Saving Time,\n // https://tc39.github.io/ecma262/#sec-daylight-saving-time-adjustment).\n // For example, system timezone is set as \"Time Zone: America/Toronto\",\n // then these code will get different result:\n // `new Date(1478411999999).getTimezoneOffset(); // get 240`\n // `new Date(1478412000000).getTimezoneOffset(); // get 300`\n // So we should not use `new Date`, but use `Date.UTC`.\n else {\n var hour = +match[4] || 0;\n if (match[8].toUpperCase() !== 'Z') {\n hour -= match[8].slice(0, 3);\n }\n return new Date(Date.UTC(\n +match[1],\n +(match[2] || 1) - 1,\n +match[3] || 1,\n hour,\n +(match[5] || 0),\n +match[6] || 0,\n +match[7] || 0\n ));\n }\n }\n else if (value == null) {\n return new Date(NaN);\n }\n\n return new Date(Math.round(value));\n}\n\n/**\n * Quantity of a number. e.g. 0.1, 1, 10, 100\n *\n * @param {number} val\n * @return {number}\n */\nexport function quantity(val) {\n return Math.pow(10, quantityExponent(val));\n}\n\n/**\n * Exponent of the quantity of a number\n * e.g., 1234 equals to 1.234*10^3, so quantityExponent(1234) is 3\n *\n * @param {number} val non-negative value\n * @return {number}\n */\nexport function quantityExponent(val) {\n if (val === 0) {\n return 0;\n }\n\n var exp = Math.floor(Math.log(val) / Math.LN10);\n /**\n * exp is expected to be the rounded-down result of the base-10 log of val.\n * But due to the precision loss with Math.log(val), we need to restore it\n * using 10^exp to make sure we can get val back from exp. #11249\n */\n if (val / Math.pow(10, exp) >= 10) {\n exp++;\n }\n return exp;\n}\n\n/**\n * find a “nice” number approximately equal to x. Round the number if round = true,\n * take ceiling if round = false. The primary observation is that the “nicest”\n * numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.\n *\n * See \"Nice Numbers for Graph Labels\" of Graphic Gems.\n *\n * @param {number} val Non-negative value.\n * @param {boolean} round\n * @return {number}\n */\nexport function nice(val, round) {\n var exponent = quantityExponent(val);\n var exp10 = Math.pow(10, exponent);\n var f = val / exp10; // 1 <= f < 10\n var nf;\n if (round) {\n if (f < 1.5) {\n nf = 1;\n }\n else if (f < 2.5) {\n nf = 2;\n }\n else if (f < 4) {\n nf = 3;\n }\n else if (f < 7) {\n nf = 5;\n }\n else {\n nf = 10;\n }\n }\n else {\n if (f < 1) {\n nf = 1;\n }\n else if (f < 2) {\n nf = 2;\n }\n else if (f < 3) {\n nf = 3;\n }\n else if (f < 5) {\n nf = 5;\n }\n else {\n nf = 10;\n }\n }\n val = nf * exp10;\n\n // Fix 3 * 0.1 === 0.30000000000000004 issue (see IEEE 754).\n // 20 is the uppper bound of toFixed.\n return exponent >= -20 ? +val.toFixed(exponent < 0 ? -exponent : 0) : val;\n}\n\n/**\n * This code was copied from \"d3.js\"\n * <https://github.com/d3/d3/blob/9cc9a875e636a1dcf36cc1e07bdf77e1ad6e2c74/src/arrays/quantile.js>.\n * See the license statement at the head of this file.\n * @param {Array.<number>} ascArr\n */\nexport function quantile(ascArr, p) {\n var H = (ascArr.length - 1) * p + 1;\n var h = Math.floor(H);\n var v = +ascArr[h - 1];\n var e = H - h;\n return e ? v + e * (ascArr[h] - v) : v;\n}\n\n/**\n * Order intervals asc, and split them when overlap.\n * expect(numberUtil.reformIntervals([\n * {interval: [18, 62], close: [1, 1]},\n * {interval: [-Infinity, -70], close: [0, 0]},\n * {interval: [-70, -26], close: [1, 1]},\n * {interval: [-26, 18], close: [1, 1]},\n * {interval: [62, 150], close: [1, 1]},\n * {interval: [106, 150], close: [1, 1]},\n * {interval: [150, Infinity], close: [0, 0]}\n * ])).toEqual([\n * {interval: [-Infinity, -70], close: [0, 0]},\n * {interval: [-70, -26], close: [1, 1]},\n * {interval: [-26, 18], close: [0, 1]},\n * {interval: [18, 62], close: [0, 1]},\n * {interval: [62, 150], close: [0, 1]},\n * {interval: [150, Infinity], close: [0, 0]}\n * ]);\n * @param {Array.<Object>} list, where `close` mean open or close\n * of the interval, and Infinity can be used.\n * @return {Array.<Object>} The origin list, which has been reformed.\n */\nexport function reformIntervals(list) {\n list.sort(function (a, b) {\n return littleThan(a, b, 0) ? -1 : 1;\n });\n\n var curr = -Infinity;\n var currClose = 1;\n for (var i = 0; i < list.length;) {\n var interval = list[i].interval;\n var close = list[i].close;\n\n for (var lg = 0; lg < 2; lg++) {\n if (interval[lg] <= curr) {\n interval[lg] = curr;\n close[lg] = !lg ? 1 - currClose : 1;\n }\n curr = interval[lg];\n currClose = close[lg];\n }\n\n if (interval[0] === interval[1] && close[0] * close[1] !== 1) {\n list.splice(i, 1);\n }\n else {\n i++;\n }\n }\n\n return list;\n\n function littleThan(a, b, lg) {\n return a.interval[lg] < b.interval[lg]\n || (\n a.interval[lg] === b.interval[lg]\n && (\n (a.close[lg] - b.close[lg] === (!lg ? 1 : -1))\n || (!lg && littleThan(a, b, 1))\n )\n );\n }\n}\n\n/**\n * parseFloat NaNs numeric-cast false positives (null|true|false|\"\")\n * ...but misinterprets leading-number strings, particularly hex literals (\"0x...\")\n * subtraction forces infinities to NaN\n *\n * @param {*} v\n * @return {boolean}\n */\nexport function isNumeric(v) {\n return v - parseFloat(v) >= 0;\n}\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport * as zrUtil from 'zrender/src/core/util';\nimport * as textContain from 'zrender/src/contain/text';\nimport * as numberUtil from './number';\n// import Text from 'zrender/src/graphic/Text';\n\n/**\n * add commas after every three numbers\n * @param {string|number} x\n * @return {string}\n */\nexport function addCommas(x) {\n if (isNaN(x)) {\n return '-';\n }\n x = (x + '').split('.');\n return x[0].replace(/(\\d{1,3})(?=(?:\\d{3})+(?!\\d))/g, '$1,')\n + (x.length > 1 ? ('.' + x[1]) : '');\n}\n\n/**\n * @param {string} str\n * @param {boolean} [upperCaseFirst=false]\n * @return {string} str\n */\nexport function toCamelCase(str, upperCaseFirst) {\n str = (str || '').toLowerCase().replace(/-(.)/g, function (match, group1) {\n return group1.toUpperCase();\n });\n\n if (upperCaseFirst && str) {\n str = str.charAt(0).toUpperCase() + str.slice(1);\n }\n\n return str;\n}\n\nexport var normalizeCssArray = zrUtil.normalizeCssArray;\n\n\nvar replaceReg = /([&<>\"'])/g;\nvar replaceMap = {\n '&': '&amp;',\n '<': '&lt;',\n '>': '&gt;',\n '\"': '&quot;',\n '\\'': '&#39;'\n};\n\nexport function encodeHTML(source) {\n return source == null\n ? ''\n : (source + '').replace(replaceReg, function (str, c) {\n return replaceMap[c];\n });\n}\n\nvar TPL_VAR_ALIAS = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];\n\nvar wrapVar = function (varName, seriesIdx) {\n return '{' + varName + (seriesIdx == null ? '' : seriesIdx) + '}';\n};\n\n/**\n * Template formatter\n * @param {string} tpl\n * @param {Array.<Object>|Object} paramsList\n * @param {boolean} [encode=false]\n * @return {string}\n */\nexport function formatTpl(tpl, paramsList, encode) {\n if (!zrUtil.isArray(paramsList)) {\n paramsList = [paramsList];\n }\n var seriesLen = paramsList.length;\n if (!seriesLen) {\n return '';\n }\n\n var $vars = paramsList[0].$vars || [];\n for (var i = 0; i < $vars.length; i++) {\n var alias = TPL_VAR_ALIAS[i];\n tpl = tpl.replace(wrapVar(alias), wrapVar(alias, 0));\n }\n for (var seriesIdx = 0; seriesIdx < seriesLen; seriesIdx++) {\n for (var k = 0; k < $vars.length; k++) {\n var val = paramsList[seriesIdx][$vars[k]];\n tpl = tpl.replace(\n wrapVar(TPL_VAR_ALIAS[k], seriesIdx),\n encode ? encodeHTML(val) : val\n );\n }\n }\n\n return tpl;\n}\n\n/**\n * simple Template formatter\n *\n * @param {string} tpl\n * @param {Object} param\n * @param {boolean} [encode=false]\n * @return {string}\n */\nexport function formatTplSimple(tpl, param, encode) {\n zrUtil.each(param, function (value, key) {\n tpl = tpl.replace(\n '{' + key + '}',\n encode ? encodeHTML(value) : value\n );\n });\n return tpl;\n}\n\n/**\n * @param {Object|string} [opt] If string, means color.\n * @param {string} [opt.color]\n * @param {string} [opt.extraCssText]\n * @param {string} [opt.type='item'] 'item' or 'subItem'\n * @param {string} [opt.renderMode='html'] render mode of tooltip, 'html' or 'richText'\n * @param {string} [opt.markerId='X'] id name for marker. If only one marker is in a rich text, this can be omitted.\n * @return {string}\n */\nexport function getTooltipMarker(opt, extraCssText) {\n opt = zrUtil.isString(opt) ? {color: opt, extraCssText: extraCssText} : (opt || {});\n var color = opt.color;\n var type = opt.type;\n var extraCssText = opt.extraCssText;\n var renderMode = opt.renderMode || 'html';\n var markerId = opt.markerId || 'X';\n\n if (!color) {\n return '';\n }\n\n if (renderMode === 'html') {\n return type === 'subItem'\n ? '<span style=\"display:inline-block;vertical-align:middle;margin-right:8px;margin-left:3px;'\n + 'border-radius:4px;width:4px;height:4px;background-color:'\n + encodeHTML(color) + ';' + (extraCssText || '') + '\"></span>'\n : '<span style=\"display:inline-block;margin-right:5px;'\n + 'border-radius:10px;width:10px;height:10px;background-color:'\n + encodeHTML(color) + ';' + (extraCssText || '') + '\"></span>';\n }\n else {\n // Space for rich element marker\n return {\n renderMode: renderMode,\n content: '{marker' + markerId + '|} ',\n style: {\n color: color\n }\n };\n }\n}\n\nfunction pad(str, len) {\n str += '';\n return '0000'.substr(0, len - str.length) + str;\n}\n\n\n/**\n * ISO Date format\n * @param {string} tpl\n * @param {number} value\n * @param {boolean} [isUTC=false] Default in local time.\n * see `module:echarts/scale/Time`\n * and `module:echarts/util/number#parseDate`.\n * @inner\n */\nexport function formatTime(tpl, value, isUTC) {\n if (tpl === 'week'\n || tpl === 'month'\n || tpl === 'quarter'\n || tpl === 'half-year'\n || tpl === 'year'\n ) {\n tpl = 'MM-dd\\nyyyy';\n }\n\n var date = numberUtil.parseDate(value);\n var utc = isUTC ? 'UTC' : '';\n var y = date['get' + utc + 'FullYear']();\n var M = date['get' + utc + 'Month']() + 1;\n var d = date['get' + utc + 'Date']();\n var h = date['get' + utc + 'Hours']();\n var m = date['get' + utc + 'Minutes']();\n var s = date['get' + utc + 'Seconds']();\n var S = date['get' + utc + 'Milliseconds']();\n\n tpl = tpl.replace('MM', pad(M, 2))\n .replace('M', M)\n .replace('yyyy', y)\n .replace('yy', y % 100)\n .replace('dd', pad(d, 2))\n .replace('d', d)\n .replace('hh', pad(h, 2))\n .replace('h', h)\n .replace('mm', pad(m, 2))\n .replace('m', m)\n .replace('ss', pad(s, 2))\n .replace('s', s)\n .replace('SSS', pad(S, 3));\n\n return tpl;\n}\n\n/**\n * Capital first\n * @param {string} str\n * @return {string}\n */\nexport function capitalFirst(str) {\n return str ? str.charAt(0).toUpperCase() + str.substr(1) : str;\n}\n\nexport var truncateText = textContain.truncateText;\n\n/**\n * @public\n * @param {Object} opt\n * @param {string} opt.text\n * @param {string} opt.font\n * @param {string} [opt.textAlign='left']\n * @param {string} [opt.textVerticalAlign='top']\n * @param {Array.<number>} [opt.textPadding]\n * @param {number} [opt.textLineHeight]\n * @param {Object} [opt.rich]\n * @param {Object} [opt.truncate]\n * @return {Object} {x, y, width, height, lineHeight}\n */\nexport function getTextBoundingRect(opt) {\n return textContain.getBoundingRect(\n opt.text,\n opt.font,\n opt.textAlign,\n opt.textVerticalAlign,\n opt.textPadding,\n opt.textLineHeight,\n opt.rich,\n opt.truncate\n );\n}\n\n/**\n * @deprecated\n * the `textLineHeight` was added later.\n * For backward compatiblility, put it as the last parameter.\n * But deprecated this interface. Please use `getTextBoundingRect` instead.\n */\nexport function getTextRect(\n text, font, textAlign, textVerticalAlign, textPadding, rich, truncate, textLineHeight\n) {\n return textContain.getBoundingRect(\n text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate\n );\n}\n\n/**\n * open new tab\n * @param {string} link url\n * @param {string} target blank or self\n */\nexport function windowOpen(link, target) {\n if (target === '_blank' || target === 'blank') {\n var blank = window.open();\n blank.opener = null;\n blank.location = link;\n }\n else {\n window.open(link, target);\n }\n}\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\n// Layout helpers for each component positioning\n\nimport * as zrUtil from 'zrender/src/core/util';\nimport BoundingRect from 'zrender/src/core/BoundingRect';\nimport {parsePercent} from './number';\nimport * as formatUtil from './format';\n\nvar each = zrUtil.each;\n\n/**\n * @public\n */\nexport var LOCATION_PARAMS = [\n 'left', 'right', 'top', 'bottom', 'width', 'height'\n];\n\n/**\n * @public\n */\nexport var HV_NAMES = [\n ['width', 'left', 'right'],\n ['height', 'top', 'bottom']\n];\n\nfunction boxLayout(orient, group, gap, maxWidth, maxHeight) {\n var x = 0;\n var y = 0;\n\n if (maxWidth == null) {\n maxWidth = Infinity;\n }\n if (maxHeight == null) {\n maxHeight = Infinity;\n }\n var currentLineMaxSize = 0;\n\n group.eachChild(function (child, idx) {\n var position = child.position;\n var rect = child.getBoundingRect();\n var nextChild = group.childAt(idx + 1);\n var nextChildRect = nextChild && nextChild.getBoundingRect();\n var nextX;\n var nextY;\n\n if (orient === 'horizontal') {\n var moveX = rect.width + (nextChildRect ? (-nextChildRect.x + rect.x) : 0);\n nextX = x + moveX;\n // Wrap when width exceeds maxWidth or meet a `newline` group\n // FIXME compare before adding gap?\n if (nextX > maxWidth || child.newline) {\n x = 0;\n nextX = moveX;\n y += currentLineMaxSize + gap;\n currentLineMaxSize = rect.height;\n }\n else {\n // FIXME: consider rect.y is not `0`?\n currentLineMaxSize = Math.max(currentLineMaxSize, rect.height);\n }\n }\n else {\n var moveY = rect.height + (nextChildRect ? (-nextChildRect.y + rect.y) : 0);\n nextY = y + moveY;\n // Wrap when width exceeds maxHeight or meet a `newline` group\n if (nextY > maxHeight || child.newline) {\n x += currentLineMaxSize + gap;\n y = 0;\n nextY = moveY;\n currentLineMaxSize = rect.width;\n }\n else {\n currentLineMaxSize = Math.max(currentLineMaxSize, rect.width);\n }\n }\n\n if (child.newline) {\n return;\n }\n\n position[0] = x;\n position[1] = y;\n\n orient === 'horizontal'\n ? (x = nextX + gap)\n : (y = nextY + gap);\n });\n}\n\n/**\n * VBox or HBox layouting\n * @param {string} orient\n * @param {module:zrender/container/Group} group\n * @param {number} gap\n * @param {number} [width=Infinity]\n * @param {number} [height=Infinity]\n */\nexport var box = boxLayout;\n\n/**\n * VBox layouting\n * @param {module:zrender/container/Group} group\n * @param {number} gap\n * @param {number} [width=Infinity]\n * @param {number} [height=Infinity]\n */\nexport var vbox = zrUtil.curry(boxLayout, 'vertical');\n\n/**\n * HBox layouting\n * @param {module:zrender/container/Group} group\n * @param {number} gap\n * @param {number} [width=Infinity]\n * @param {number} [height=Infinity]\n */\nexport var hbox = zrUtil.curry(boxLayout, 'horizontal');\n\n/**\n * If x or x2 is not specified or 'center' 'left' 'right',\n * the width would be as long as possible.\n * If y or y2 is not specified or 'middle' 'top' 'bottom',\n * the height would be as long as possible.\n *\n * @param {Object} positionInfo\n * @param {number|string} [positionInfo.x]\n * @param {number|string} [positionInfo.y]\n * @param {number|string} [positionInfo.x2]\n * @param {number|string} [positionInfo.y2]\n * @param {Object} containerRect {width, height}\n * @param {string|number} margin\n * @return {Object} {width, height}\n */\nexport function getAvailableSize(positionInfo, containerRect, margin) {\n var containerWidth = containerRect.width;\n var containerHeight = containerRect.height;\n\n var x = parsePercent(positionInfo.x, containerWidth);\n var y = parsePercent(positionInfo.y, containerHeight);\n var x2 = parsePercent(positionInfo.x2, containerWidth);\n var y2 = parsePercent(positionInfo.y2, containerHeight);\n\n (isNaN(x) || isNaN(parseFloat(positionInfo.x))) && (x = 0);\n (isNaN(x2) || isNaN(parseFloat(positionInfo.x2))) && (x2 = containerWidth);\n (isNaN(y) || isNaN(parseFloat(positionInfo.y))) && (y = 0);\n (isNaN(y2) || isNaN(parseFloat(positionInfo.y2))) && (y2 = containerHeight);\n\n margin = formatUtil.normalizeCssArray(margin || 0);\n\n return {\n width: Math.max(x2 - x - margin[1] - margin[3], 0),\n height: Math.max(y2 - y - margin[0] - margin[2], 0)\n };\n}\n\n/**\n * Parse position info.\n *\n * @param {Object} positionInfo\n * @param {number|string} [positionInfo.left]\n * @param {number|string} [positionInfo.top]\n * @param {number|string} [positionInfo.right]\n * @param {number|string} [positionInfo.bottom]\n * @param {number|string} [positionInfo.width]\n * @param {number|string} [positionInfo.height]\n * @param {number|string} [positionInfo.aspect] Aspect is width / height\n * @param {Object} containerRect\n * @param {string|number} [margin]\n *\n * @return {module:zrender/core/BoundingRect}\n */\nexport function getLayoutRect(\n positionInfo, containerRect, margin\n) {\n margin = formatUtil.normalizeCssArray(margin || 0);\n\n var containerWidth = containerRect.width;\n var containerHeight = containerRect.height;\n\n var left = parsePercent(positionInfo.left, containerWidth);\n var top = parsePercent(positionInfo.top, containerHeight);\n var right = parsePercent(positionInfo.right, containerWidth);\n var bottom = parsePercent(positionInfo.bottom, containerHeight);\n var width = parsePercent(positionInfo.width, containerWidth);\n var height = parsePercent(positionInfo.height, containerHeight);\n\n var verticalMargin = margin[2] + margin[0];\n var horizontalMargin = margin[1] + margin[3];\n var aspect = positionInfo.aspect;\n\n // If width is not specified, calculate width from left and right\n if (isNaN(width)) {\n width = containerWidth - right - horizontalMargin - left;\n }\n if (isNaN(height)) {\n height = containerHeight - bottom - verticalMargin - top;\n }\n\n if (aspect != null) {\n // If width and height are not given\n // 1. Graph should not exceeds the container\n // 2. Aspect must be keeped\n // 3. Graph should take the space as more as possible\n // FIXME\n // Margin is not considered, because there is no case that both\n // using margin and aspect so far.\n if (isNaN(width) && isNaN(height)) {\n if (aspect > containerWidth / containerHeight) {\n width = containerWidth * 0.8;\n }\n else {\n height = containerHeight * 0.8;\n }\n }\n\n // Calculate width or height with given aspect\n if (isNaN(width)) {\n width = aspect * height;\n }\n if (isNaN(height)) {\n height = width / aspect;\n }\n }\n\n // If left is not specified, calculate left from right and width\n if (isNaN(left)) {\n left = containerWidth - right - width - horizontalMargin;\n }\n if (isNaN(top)) {\n top = containerHeight - bottom - height - verticalMargin;\n }\n\n // Align left and top\n switch (positionInfo.left || positionInfo.right) {\n case 'center':\n left = containerWidth / 2 - width / 2 - margin[3];\n break;\n case 'right':\n left = containerWidth - width - horizontalMargin;\n break;\n }\n switch (positionInfo.top || positionInfo.bottom) {\n case 'middle':\n case 'center':\n top = containerHeight / 2 - height / 2 - margin[0];\n break;\n case 'bottom':\n top = containerHeight - height - verticalMargin;\n break;\n }\n // If something is wrong and left, top, width, height are calculated as NaN\n left = left || 0;\n top = top || 0;\n if (isNaN(width)) {\n // Width may be NaN if only one value is given except width\n width = containerWidth - horizontalMargin - left - (right || 0);\n }\n if (isNaN(height)) {\n // Height may be NaN if only one value is given except height\n height = containerHeight - verticalMargin - top - (bottom || 0);\n }\n\n var rect = new BoundingRect(left + margin[3], top + margin[0], width, height);\n rect.margin = margin;\n return rect;\n}\n\n\n/**\n * Position a zr element in viewport\n * Group position is specified by either\n * {left, top}, {right, bottom}\n * If all properties exists, right and bottom will be igonred.\n *\n * Logic:\n * 1. Scale (against origin point in parent coord)\n * 2. Rotate (against origin point in parent coord)\n * 3. Traslate (with el.position by this method)\n * So this method only fixes the last step 'Traslate', which does not affect\n * scaling and rotating.\n *\n * If be called repeatly with the same input el, the same result will be gotten.\n *\n * @param {module:zrender/Element} el Should have `getBoundingRect` method.\n * @param {Object} positionInfo\n * @param {number|string} [positionInfo.left]\n * @param {number|string} [positionInfo.top]\n * @param {number|string} [positionInfo.right]\n * @param {number|string} [positionInfo.bottom]\n * @param {number|string} [positionInfo.width] Only for opt.boundingModel: 'raw'\n * @param {number|string} [positionInfo.height] Only for opt.boundingModel: 'raw'\n * @param {Object} containerRect\n * @param {string|number} margin\n * @param {Object} [opt]\n * @param {Array.<number>} [opt.hv=[1,1]] Only horizontal or only vertical.\n * @param {Array.<number>} [opt.boundingMode='all']\n * Specify how to calculate boundingRect when locating.\n * 'all': Position the boundingRect that is transformed and uioned\n * both itself and its descendants.\n * This mode simplies confine the elements in the bounding\n * of their container (e.g., using 'right: 0').\n * 'raw': Position the boundingRect that is not transformed and only itself.\n * This mode is useful when you want a element can overflow its\n * container. (Consider a rotated circle needs to be located in a corner.)\n * In this mode positionInfo.width/height can only be number.\n */\nexport function positionElement(el, positionInfo, containerRect, margin, opt) {\n var h = !opt || !opt.hv || opt.hv[0];\n var v = !opt || !opt.hv || opt.hv[1];\n var boundingMode = opt && opt.boundingMode || 'all';\n\n if (!h && !v) {\n return;\n }\n\n var rect;\n if (boundingMode === 'raw') {\n rect = el.type === 'group'\n ? new BoundingRect(0, 0, +positionInfo.width || 0, +positionInfo.height || 0)\n : el.getBoundingRect();\n }\n else {\n rect = el.getBoundingRect();\n if (el.needLocalTransform()) {\n var transform = el.getLocalTransform();\n // Notice: raw rect may be inner object of el,\n // which should not be modified.\n rect = rect.clone();\n rect.applyTransform(transform);\n }\n }\n\n // The real width and height can not be specified but calculated by the given el.\n positionInfo = getLayoutRect(\n zrUtil.defaults(\n {width: rect.width, height: rect.height},\n positionInfo\n ),\n containerRect,\n margin\n );\n\n // Because 'tranlate' is the last step in transform\n // (see zrender/core/Transformable#getLocalTransform),\n // we can just only modify el.position to get final result.\n var elPos = el.position;\n var dx = h ? positionInfo.x - rect.x : 0;\n var dy = v ? positionInfo.y - rect.y : 0;\n\n el.attr('position', boundingMode === 'raw' ? [dx, dy] : [elPos[0] + dx, elPos[1] + dy]);\n}\n\n/**\n * @param {Object} option Contains some of the properties in HV_NAMES.\n * @param {number} hvIdx 0: horizontal; 1: vertical.\n */\nexport function sizeCalculable(option, hvIdx) {\n return option[HV_NAMES[hvIdx][0]] != null\n || (option[HV_NAMES[hvIdx][1]] != null && option[HV_NAMES[hvIdx][2]] != null);\n}\n\n/**\n * Consider Case:\n * When defulat option has {left: 0, width: 100}, and we set {right: 0}\n * through setOption or media query, using normal zrUtil.merge will cause\n * {right: 0} does not take effect.\n *\n * @example\n * ComponentModel.extend({\n * init: function () {\n * ...\n * var inputPositionParams = layout.getLayoutParams(option);\n * this.mergeOption(inputPositionParams);\n * },\n * mergeOption: function (newOption) {\n * newOption && zrUtil.merge(thisOption, newOption, true);\n * layout.mergeLayoutParam(thisOption, newOption);\n * }\n * });\n *\n * @param {Object} targetOption\n * @param {Object} newOption\n * @param {Object|string} [opt]\n * @param {boolean|Array.<boolean>} [opt.ignoreSize=false] Used for the components\n * that width (or height) should not be calculated by left and right (or top and bottom).\n */\nexport function mergeLayoutParam(targetOption, newOption, opt) {\n !zrUtil.isObject(opt) && (opt = {});\n\n var ignoreSize = opt.ignoreSize;\n !zrUtil.isArray(ignoreSize) && (ignoreSize = [ignoreSize, ignoreSize]);\n\n var hResult = merge(HV_NAMES[0], 0);\n var vResult = merge(HV_NAMES[1], 1);\n\n copy(HV_NAMES[0], targetOption, hResult);\n copy(HV_NAMES[1], targetOption, vResult);\n\n function merge(names, hvIdx) {\n var newParams = {};\n var newValueCount = 0;\n var merged = {};\n var mergedValueCount = 0;\n var enoughParamNumber = 2;\n\n each(names, function (name) {\n merged[name] = targetOption[name];\n });\n each(names, function (name) {\n // Consider case: newOption.width is null, which is\n // set by user for removing width setting.\n hasProp(newOption, name) && (newParams[name] = merged[name] = newOption[name]);\n hasValue(newParams, name) && newValueCount++;\n hasValue(merged, name) && mergedValueCount++;\n });\n\n if (ignoreSize[hvIdx]) {\n // Only one of left/right is premitted to exist.\n if (hasValue(newOption, names[1])) {\n merged[names[2]] = null;\n }\n else if (hasValue(newOption, names[2])) {\n merged[names[1]] = null;\n }\n return merged;\n }\n\n // Case: newOption: {width: ..., right: ...},\n // or targetOption: {right: ...} and newOption: {width: ...},\n // There is no conflict when merged only has params count\n // little than enoughParamNumber.\n if (mergedValueCount === enoughParamNumber || !newValueCount) {\n return merged;\n }\n // Case: newOption: {width: ..., right: ...},\n // Than we can make sure user only want those two, and ignore\n // all origin params in targetOption.\n else if (newValueCount >= enoughParamNumber) {\n return newParams;\n }\n else {\n // Chose another param from targetOption by priority.\n for (var i = 0; i < names.length; i++) {\n var name = names[i];\n if (!hasProp(newParams, name) && hasProp(targetOption, name)) {\n newParams[name] = targetOption[name];\n break;\n }\n }\n return newParams;\n }\n }\n\n function hasProp(obj, name) {\n return obj.hasOwnProperty(name);\n }\n\n function hasValue(obj, name) {\n return obj[name] != null && obj[name] !== 'auto';\n }\n\n function copy(names, target, source) {\n each(names, function (name) {\n target[name] = source[name];\n });\n }\n}\n\n/**\n * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.\n * @param {Object} source\n * @return {Object} Result contains those props.\n */\nexport function getLayoutParams(source) {\n return copyLayoutParams({}, source);\n}\n\n/**\n * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.\n * @param {Object} source\n * @return {Object} Result contains those props.\n */\nexport function copyLayoutParams(target, source) {\n source && target && each(LOCATION_PARAMS, function (name) {\n source.hasOwnProperty(name) && (target[name] = source[name]);\n });\n return target;\n}\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\n\nexport default {\n getBoxLayoutParams: function () {\n return {\n left: this.get('left'),\n top: this.get('top'),\n right: this.get('right'),\n bottom: this.get('bottom'),\n width: this.get('width'),\n height: this.get('height')\n };\n }\n};","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\n/**\n * Component model\n *\n * @module echarts/model/Component\n */\n\nimport * as zrUtil from 'zrender/src/core/util';\nimport Model from './Model';\nimport * as componentUtil from '../util/component';\nimport {enableClassManagement, parseClassType} from '../util/clazz';\nimport {makeInner} from '../util/model';\nimport * as layout from '../util/layout';\nimport boxLayoutMixin from './mixin/boxLayout';\n\nvar inner = makeInner();\n\n/**\n * @alias module:echarts/model/Component\n * @constructor\n * @param {Object} option\n * @param {module:echarts/model/Model} parentModel\n * @param {module:echarts/model/Model} ecModel\n */\nvar ComponentModel = Model.extend({\n\n type: 'component',\n\n /**\n * @readOnly\n * @type {string}\n */\n id: '',\n\n /**\n * Because simplified concept is probably better, series.name (or component.name)\n * has been having too many resposibilities:\n * (1) Generating id (which requires name in option should not be modified).\n * (2) As an index to mapping series when merging option or calling API (a name\n * can refer to more then one components, which is convinient is some case).\n * (3) Display.\n * @readOnly\n */\n name: '',\n\n /**\n * @readOnly\n * @type {string}\n */\n mainType: '',\n\n /**\n * @readOnly\n * @type {string}\n */\n subType: '',\n\n /**\n * @readOnly\n * @type {number}\n */\n componentIndex: 0,\n\n /**\n * @type {Object}\n * @protected\n */\n defaultOption: null,\n\n /**\n * @type {module:echarts/model/Global}\n * @readOnly\n */\n ecModel: null,\n\n /**\n * key: componentType\n * value: Component model list, can not be null.\n * @type {Object.<string, Array.<module:echarts/model/Model>>}\n * @readOnly\n */\n dependentModels: [],\n\n /**\n * @type {string}\n * @readOnly\n */\n uid: null,\n\n /**\n * Support merge layout params.\n * Only support 'box' now (left/right/top/bottom/width/height).\n * @type {string|Object} Object can be {ignoreSize: true}\n * @readOnly\n */\n layoutMode: null,\n\n $constructor: function (option, parentModel, ecModel, extraOpt) {\n Model.call(this, option, parentModel, ecModel, extraOpt);\n\n this.uid = componentUtil.getUID('ec_cpt_model');\n },\n\n init: function (option, parentModel, ecModel, extraOpt) {\n this.mergeDefaultAndTheme(option, ecModel);\n },\n\n mergeDefaultAndTheme: function (option, ecModel) {\n var layoutMode = this.layoutMode;\n var inputPositionParams = layoutMode\n ? layout.getLayoutParams(option) : {};\n\n var themeModel = ecModel.getTheme();\n zrUtil.merge(option, themeModel.get(this.mainType));\n zrUtil.merge(option, this.getDefaultOption());\n\n if (layoutMode) {\n layout.mergeLayoutParam(option, inputPositionParams, layoutMode);\n }\n },\n\n mergeOption: function (option, extraOpt) {\n zrUtil.merge(this.option, option, true);\n\n var layoutMode = this.layoutMode;\n if (layoutMode) {\n layout.mergeLayoutParam(this.option, option, layoutMode);\n }\n },\n\n // Hooker after init or mergeOption\n optionUpdated: function (newCptOption, isInit) {},\n\n getDefaultOption: function () {\n var fields = inner(this);\n if (!fields.defaultOption) {\n var optList = [];\n var Class = this.constructor;\n while (Class) {\n var opt = Class.prototype.defaultOption;\n opt && optList.push(opt);\n Class = Class.superClass;\n }\n\n var defaultOption = {};\n for (var i = optList.length - 1; i >= 0; i--) {\n defaultOption = zrUtil.merge(defaultOption, optList[i], true);\n }\n fields.defaultOption = defaultOption;\n }\n return fields.defaultOption;\n },\n\n getReferringComponents: function (mainType) {\n return this.ecModel.queryComponents({\n mainType: mainType,\n index: this.get(mainType + 'Index', true),\n id: this.get(mainType + 'Id', true)\n });\n }\n\n});\n\n// Reset ComponentModel.extend, add preConstruct.\n// clazzUtil.enableClassExtend(\n// ComponentModel,\n// function (option, parentModel, ecModel, extraOpt) {\n// // Set dependentModels, componentIndex, name, id, mainType, subType.\n// zrUtil.extend(this, extraOpt);\n\n// this.uid = componentUtil.getUID('componentModel');\n\n// // this.setReadOnly([\n// // 'type', 'id', 'uid', 'name', 'mainType', 'subType',\n// // 'dependentModels', 'componentIndex'\n// // ]);\n// }\n// );\n\n// Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.\nenableClassManagement(\n ComponentModel, {registerWhenExtend: true}\n);\ncomponentUtil.enableSubTypeDefaulter(ComponentModel);\n\n// Add capability of ComponentModel.topologicalTravel.\ncomponentUtil.enableTopologicalTravel(ComponentModel, getDependencies);\n\nfunction getDependencies(componentType) {\n var deps = [];\n zrUtil.each(ComponentModel.getClassesByMainType(componentType), function (Clazz) {\n deps = deps.concat(Clazz.prototype.dependencies || []);\n });\n\n // Ensure main type.\n deps = zrUtil.map(deps, function (type) {\n return parseClassType(type).main;\n });\n\n // Hack dataset for convenience.\n if (componentType !== 'dataset' && zrUtil.indexOf(deps, 'dataset') <= 0) {\n deps.unshift('dataset');\n }\n\n return deps;\n}\n\nzrUtil.mixin(ComponentModel, boxLayoutMixin);\n\nexport default ComponentModel;","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\n\nvar platform = '';\n// Navigator not exists in node\nif (typeof navigator !== 'undefined') {\n platform = navigator.platform || '';\n}\n\nexport default {\n // backgroundColor: 'rgba(0,0,0,0)',\n\n // https://dribbble.com/shots/1065960-Infographic-Pie-chart-visualization\n // color: ['#5793f3', '#d14a61', '#fd9c35', '#675bba', '#fec42c', '#dd4444', '#d4df5a', '#cd4870'],\n // Light colors:\n // color: ['#bcd3bb', '#e88f70', '#edc1a5', '#9dc5c8', '#e1e8c8', '#7b7c68', '#e5b5b5', '#f0b489', '#928ea8', '#bda29a'],\n // color: ['#cc5664', '#9bd6ec', '#ea946e', '#8acaaa', '#f1ec64', '#ee8686', '#a48dc1', '#5da6bc', '#b9dcae'],\n // Dark colors:\n color: [\n '#c23531', '#2f4554', '#61a0a8', '#d48265', '#91c7ae', '#749f83',\n '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3'\n ],\n\n gradientColor: ['#f6efa6', '#d88273', '#bf444c'],\n\n // If xAxis and yAxis declared, grid is created by default.\n // grid: {},\n\n textStyle: {\n // color: '#000',\n // decoration: 'none',\n // PENDING\n fontFamily: platform.match(/^Win/) ? 'Microsoft YaHei' : 'sans-serif',\n // fontFamily: 'Arial, Verdana, sans-serif',\n fontSize: 12,\n fontStyle: 'normal',\n fontWeight: 'normal'\n },\n\n // http://blogs.adobe.com/webplatform/2014/02/24/using-blend-modes-in-html-canvas/\n // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation\n // Default is source-over\n blendMode: null,\n\n animation: 'auto',\n animationDuration: 1000,\n animationDurationUpdate: 300,\n animationEasing: 'exponentialOut',\n animationEasingUpdate: 'cubicOut',\n\n animationThreshold: 2000,\n // Configuration for progressive/incremental rendering\n progressiveThreshold: 3000,\n progressive: 400,\n\n // Threshold of if use single hover layer to optimize.\n // It is recommended that `hoverLayerThreshold` is equivalent to or less than\n // `progressiveThreshold`, otherwise hover will cause restart of progressive,\n // which is unexpected.\n // see example <echarts/test/heatmap-large.html>.\n hoverLayerThreshold: 3000,\n\n // See: module:echarts/scale/Time\n useUTC: false\n};","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport {makeInner, normalizeToArray} from '../../util/model';\n\nvar inner = makeInner();\n\nfunction getNearestColorPalette(colors, requestColorNum) {\n var paletteNum = colors.length;\n // TODO colors must be in order\n for (var i = 0; i < paletteNum; i++) {\n if (colors[i].length > requestColorNum) {\n return colors[i];\n }\n }\n return colors[paletteNum - 1];\n}\n\nexport default {\n clearColorPalette: function () {\n inner(this).colorIdx = 0;\n inner(this).colorNameMap = {};\n },\n\n /**\n * @param {string} name MUST NOT be null/undefined. Otherwise call this function\n * twise with the same parameters will get different result.\n * @param {Object} [scope=this]\n * @param {Object} [requestColorNum]\n * @return {string} color string.\n */\n getColorFromPalette: function (name, scope, requestColorNum) {\n scope = scope || this;\n var scopeFields = inner(scope);\n var colorIdx = scopeFields.colorIdx || 0;\n var colorNameMap = scopeFields.colorNameMap = scopeFields.colorNameMap || {};\n // Use `hasOwnProperty` to avoid conflict with Object.prototype.\n if (colorNameMap.hasOwnProperty(name)) {\n return colorNameMap[name];\n }\n var defaultColorPalette = normalizeToArray(this.get('color', true));\n var layeredColorPalette = this.get('colorLayer', true);\n var colorPalette = ((requestColorNum == null || !layeredColorPalette)\n ? defaultColorPalette : getNearestColorPalette(layeredColorPalette, requestColorNum));\n\n // In case can't find in layered color palette.\n colorPalette = colorPalette || defaultColorPalette;\n\n if (!colorPalette || !colorPalette.length) {\n return;\n }\n\n var color = colorPalette[colorIdx];\n if (name) {\n colorNameMap[name] = color;\n }\n scopeFields.colorIdx = (colorIdx + 1) % colorPalette.length;\n\n return color;\n }\n};\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\n// Avoid typo.\nexport var SOURCE_FORMAT_ORIGINAL = 'original';\nexport var SOURCE_FORMAT_ARRAY_ROWS = 'arrayRows';\nexport var SOURCE_FORMAT_OBJECT_ROWS = 'objectRows';\nexport var SOURCE_FORMAT_KEYED_COLUMNS = 'keyedColumns';\nexport var SOURCE_FORMAT_UNKNOWN = 'unknown';\n// ??? CHANGE A NAME\nexport var SOURCE_FORMAT_TYPED_ARRAY = 'typedArray';\n\nexport var SERIES_LAYOUT_BY_COLUMN = 'column';\nexport var SERIES_LAYOUT_BY_ROW = 'row';\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport {createHashMap, isTypedArray} from 'zrender/src/core/util';\nimport {enableClassCheck} from '../util/clazz';\nimport {\n SOURCE_FORMAT_ORIGINAL,\n SERIES_LAYOUT_BY_COLUMN,\n SOURCE_FORMAT_UNKNOWN,\n SOURCE_FORMAT_TYPED_ARRAY,\n SOURCE_FORMAT_KEYED_COLUMNS\n} from './helper/sourceType';\n\n/**\n * [sourceFormat]\n *\n * + \"original\":\n * This format is only used in series.data, where\n * itemStyle can be specified in data item.\n *\n * + \"arrayRows\":\n * [\n * ['product', 'score', 'amount'],\n * ['Matcha Latte', 89.3, 95.8],\n * ['Milk Tea', 92.1, 89.4],\n * ['Cheese Cocoa', 94.4, 91.2],\n * ['Walnut Brownie', 85.4, 76.9]\n * ]\n *\n * + \"objectRows\":\n * [\n * {product: 'Matcha Latte', score: 89.3, amount: 95.8},\n * {product: 'Milk Tea', score: 92.1, amount: 89.4},\n * {product: 'Cheese Cocoa', score: 94.4, amount: 91.2},\n * {product: 'Walnut Brownie', score: 85.4, amount: 76.9}\n * ]\n *\n * + \"keyedColumns\":\n * {\n * 'product': ['Matcha Latte', 'Milk Tea', 'Cheese Cocoa', 'Walnut Brownie'],\n * 'count': [823, 235, 1042, 988],\n * 'score': [95.8, 81.4, 91.2, 76.9]\n * }\n *\n * + \"typedArray\"\n *\n * + \"unknown\"\n */\n\n/**\n * @constructor\n * @param {Object} fields\n * @param {string} fields.sourceFormat\n * @param {Array|Object} fields.fromDataset\n * @param {Array|Object} [fields.data]\n * @param {string} [seriesLayoutBy='column']\n * @param {Array.<Object|string>} [dimensionsDefine]\n * @param {Objet|HashMap} [encodeDefine]\n * @param {number} [startIndex=0]\n * @param {number} [dimensionsDetectCount]\n */\nfunction Source(fields) {\n\n /**\n * @type {boolean}\n */\n this.fromDataset = fields.fromDataset;\n\n /**\n * Not null/undefined.\n * @type {Array|Object}\n */\n this.data = fields.data || (\n fields.sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS ? {} : []\n );\n\n /**\n * See also \"detectSourceFormat\".\n * Not null/undefined.\n * @type {string}\n */\n this.sourceFormat = fields.sourceFormat || SOURCE_FORMAT_UNKNOWN;\n\n /**\n * 'row' or 'column'\n * Not null/undefined.\n * @type {string} seriesLayoutBy\n */\n this.seriesLayoutBy = fields.seriesLayoutBy || SERIES_LAYOUT_BY_COLUMN;\n\n /**\n * dimensions definition in option.\n * can be null/undefined.\n * @type {Array.<Object|string>}\n */\n this.dimensionsDefine = fields.dimensionsDefine;\n\n /**\n * encode definition in option.\n * can be null/undefined.\n * @type {Objet|HashMap}\n */\n this.encodeDefine = fields.encodeDefine && createHashMap(fields.encodeDefine);\n\n /**\n * Not null/undefined, uint.\n * @type {number}\n */\n this.startIndex = fields.startIndex || 0;\n\n /**\n * Can be null/undefined (when unknown), uint.\n * @type {number}\n */\n this.dimensionsDetectCount = fields.dimensionsDetectCount;\n}\n\n/**\n * Wrap original series data for some compatibility cases.\n */\nSource.seriesDataToSource = function (data) {\n return new Source({\n data: data,\n sourceFormat: isTypedArray(data)\n ? SOURCE_FORMAT_TYPED_ARRAY\n : SOURCE_FORMAT_ORIGINAL,\n fromDataset: false\n });\n};\n\nenableClassCheck(Source);\n\nexport default Source;","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport {__DEV__} from '../../config';\nimport {makeInner, getDataItemValue} from '../../util/model';\nimport {\n createHashMap,\n each,\n map,\n isArray,\n isString,\n isObject,\n isTypedArray,\n isArrayLike,\n extend,\n assert\n} from 'zrender/src/core/util';\nimport Source from '../Source';\n\nimport {\n SOURCE_FORMAT_ORIGINAL,\n SOURCE_FORMAT_ARRAY_ROWS,\n SOURCE_FORMAT_OBJECT_ROWS,\n SOURCE_FORMAT_KEYED_COLUMNS,\n SOURCE_FORMAT_UNKNOWN,\n SOURCE_FORMAT_TYPED_ARRAY,\n SERIES_LAYOUT_BY_ROW\n} from './sourceType';\n\n// The result of `guessOrdinal`.\nexport var BE_ORDINAL = {\n Must: 1, // Encounter string but not '-' and not number-like.\n Might: 2, // Encounter string but number-like.\n Not: 3 // Other cases\n};\n\nvar inner = makeInner();\n\n/**\n * @see {module:echarts/data/Source}\n * @param {module:echarts/component/dataset/DatasetModel} datasetModel\n * @return {string} sourceFormat\n */\nexport function detectSourceFormat(datasetModel) {\n var data = datasetModel.option.source;\n var sourceFormat = SOURCE_FORMAT_UNKNOWN;\n\n if (isTypedArray(data)) {\n sourceFormat = SOURCE_FORMAT_TYPED_ARRAY;\n }\n else if (isArray(data)) {\n // FIXME Whether tolerate null in top level array?\n if (data.length === 0) {\n sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;\n }\n\n for (var i = 0, len = data.length; i < len; i++) {\n var item = data[i];\n\n if (item == null) {\n continue;\n }\n else if (isArray(item)) {\n sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;\n break;\n }\n else if (isObject(item)) {\n sourceFormat = SOURCE_FORMAT_OBJECT_ROWS;\n break;\n }\n }\n }\n else if (isObject(data)) {\n for (var key in data) {\n if (data.hasOwnProperty(key) && isArrayLike(data[key])) {\n sourceFormat = SOURCE_FORMAT_KEYED_COLUMNS;\n break;\n }\n }\n }\n else if (data != null) {\n throw new Error('Invalid data');\n }\n\n inner(datasetModel).sourceFormat = sourceFormat;\n}\n\n/**\n * [Scenarios]:\n * (1) Provide source data directly:\n * series: {\n * encode: {...},\n * dimensions: [...]\n * seriesLayoutBy: 'row',\n * data: [[...]]\n * }\n * (2) Refer to datasetModel.\n * series: [{\n * encode: {...}\n * // Ignore datasetIndex means `datasetIndex: 0`\n * // and the dimensions defination in dataset is used\n * }, {\n * encode: {...},\n * seriesLayoutBy: 'column',\n * datasetIndex: 1\n * }]\n *\n * Get data from series itself or datset.\n * @return {module:echarts/data/Source} source\n */\nexport function getSource(seriesModel) {\n return inner(seriesModel).source;\n}\n\n/**\n * MUST be called before mergeOption of all series.\n * @param {module:echarts/model/Global} ecModel\n */\nexport function resetSourceDefaulter(ecModel) {\n // `datasetMap` is used to make default encode.\n inner(ecModel).datasetMap = createHashMap();\n}\n\n/**\n * [Caution]:\n * MUST be called after series option merged and\n * before \"series.getInitailData()\" called.\n *\n * [The rule of making default encode]:\n * Category axis (if exists) alway map to the first dimension.\n * Each other axis occupies a subsequent dimension.\n *\n * [Why make default encode]:\n * Simplify the typing of encode in option, avoiding the case like that:\n * series: [{encode: {x: 0, y: 1}}, {encode: {x: 0, y: 2}}, {encode: {x: 0, y: 3}}],\n * where the \"y\" have to be manually typed as \"1, 2, 3, ...\".\n *\n * @param {module:echarts/model/Series} seriesModel\n */\nexport function prepareSource(seriesModel) {\n var seriesOption = seriesModel.option;\n\n var data = seriesOption.data;\n var sourceFormat = isTypedArray(data)\n ? SOURCE_FORMAT_TYPED_ARRAY : SOURCE_FORMAT_ORIGINAL;\n var fromDataset = false;\n\n var seriesLayoutBy = seriesOption.seriesLayoutBy;\n var sourceHeader = seriesOption.sourceHeader;\n var dimensionsDefine = seriesOption.dimensions;\n\n var datasetModel = getDatasetModel(seriesModel);\n if (datasetModel) {\n var datasetOption = datasetModel.option;\n\n data = datasetOption.source;\n sourceFormat = inner(datasetModel).sourceFormat;\n fromDataset = true;\n\n // These settings from series has higher priority.\n seriesLayoutBy = seriesLayoutBy || datasetOption.seriesLayoutBy;\n sourceHeader == null && (sourceHeader = datasetOption.sourceHeader);\n dimensionsDefine = dimensionsDefine || datasetOption.dimensions;\n }\n\n var completeResult = completeBySourceData(\n data, sourceFormat, seriesLayoutBy, sourceHeader, dimensionsDefine\n );\n\n inner(seriesModel).source = new Source({\n data: data,\n fromDataset: fromDataset,\n seriesLayoutBy: seriesLayoutBy,\n sourceFormat: sourceFormat,\n dimensionsDefine: completeResult.dimensionsDefine,\n startIndex: completeResult.startIndex,\n dimensionsDetectCount: completeResult.dimensionsDetectCount,\n // Note: dataset option does not have `encode`.\n encodeDefine: seriesOption.encode\n });\n}\n\n// return {startIndex, dimensionsDefine, dimensionsCount}\nfunction completeBySourceData(data, sourceFormat, seriesLayoutBy, sourceHeader, dimensionsDefine) {\n if (!data) {\n return {dimensionsDefine: normalizeDimensionsDefine(dimensionsDefine)};\n }\n\n var dimensionsDetectCount;\n var startIndex;\n\n if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {\n // Rule: Most of the first line are string: it is header.\n // Caution: consider a line with 5 string and 1 number,\n // it still can not be sure it is a head, because the\n // 5 string may be 5 values of category columns.\n if (sourceHeader === 'auto' || sourceHeader == null) {\n arrayRowsTravelFirst(function (val) {\n // '-' is regarded as null/undefined.\n if (val != null && val !== '-') {\n if (isString(val)) {\n startIndex == null && (startIndex = 1);\n }\n else {\n startIndex = 0;\n }\n }\n // 10 is an experience number, avoid long loop.\n }, seriesLayoutBy, data, 10);\n }\n else {\n startIndex = sourceHeader ? 1 : 0;\n }\n\n if (!dimensionsDefine && startIndex === 1) {\n dimensionsDefine = [];\n arrayRowsTravelFirst(function (val, index) {\n dimensionsDefine[index] = val != null ? val : '';\n }, seriesLayoutBy, data);\n }\n\n dimensionsDetectCount = dimensionsDefine\n ? dimensionsDefine.length\n : seriesLayoutBy === SERIES_LAYOUT_BY_ROW\n ? data.length\n : data[0]\n ? data[0].length\n : null;\n }\n else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {\n if (!dimensionsDefine) {\n dimensionsDefine = objectRowsCollectDimensions(data);\n }\n }\n else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {\n if (!dimensionsDefine) {\n dimensionsDefine = [];\n each(data, function (colArr, key) {\n dimensionsDefine.push(key);\n });\n }\n }\n else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {\n var value0 = getDataItemValue(data[0]);\n dimensionsDetectCount = isArray(value0) && value0.length || 1;\n }\n else if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {\n if (__DEV__) {\n assert(!!dimensionsDefine, 'dimensions must be given if data is TypedArray.');\n }\n }\n\n return {\n startIndex: startIndex,\n dimensionsDefine: normalizeDimensionsDefine(dimensionsDefine),\n dimensionsDetectCount: dimensionsDetectCount\n };\n}\n\n// Consider dimensions defined like ['A', 'price', 'B', 'price', 'C', 'price'],\n// which is reasonable. But dimension name is duplicated.\n// Returns undefined or an array contains only object without null/undefiend or string.\nfunction normalizeDimensionsDefine(dimensionsDefine) {\n if (!dimensionsDefine) {\n // The meaning of null/undefined is different from empty array.\n return;\n }\n var nameMap = createHashMap();\n return map(dimensionsDefine, function (item, index) {\n item = extend({}, isObject(item) ? item : {name: item});\n\n // User can set null in dimensions.\n // We dont auto specify name, othewise a given name may\n // cause it be refered unexpectedly.\n if (item.name == null) {\n return item;\n }\n\n // Also consider number form like 2012.\n item.name += '';\n // User may also specify displayName.\n // displayName will always exists except user not\n // specified or dim name is not specified or detected.\n // (A auto generated dim name will not be used as\n // displayName).\n if (item.displayName == null) {\n item.displayName = item.name;\n }\n\n var exist = nameMap.get(item.name);\n if (!exist) {\n nameMap.set(item.name, {count: 1});\n }\n else {\n item.name += '-' + exist.count++;\n }\n\n return item;\n });\n}\n\nfunction arrayRowsTravelFirst(cb, seriesLayoutBy, data, maxLoop) {\n maxLoop == null && (maxLoop = Infinity);\n if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {\n for (var i = 0; i < data.length && i < maxLoop; i++) {\n cb(data[i] ? data[i][0] : null, i);\n }\n }\n else {\n var value0 = data[0] || [];\n for (var i = 0; i < value0.length && i < maxLoop; i++) {\n cb(value0[i], i);\n }\n }\n}\n\nfunction objectRowsCollectDimensions(data) {\n var firstIndex = 0;\n var obj;\n while (firstIndex < data.length && !(obj = data[firstIndex++])) {} // jshint ignore: line\n if (obj) {\n var dimensions = [];\n each(obj, function (value, key) {\n dimensions.push(key);\n });\n return dimensions;\n }\n}\n\n/**\n * [The strategy of the arrengment of data dimensions for dataset]:\n * \"value way\": all axes are non-category axes. So series one by one take\n * several (the number is coordSysDims.length) dimensions from dataset.\n * The result of data arrengment of data dimensions like:\n * | ser0_x | ser0_y | ser1_x | ser1_y | ser2_x | ser2_y |\n * \"category way\": at least one axis is category axis. So the the first data\n * dimension is always mapped to the first category axis and shared by\n * all of the series. The other data dimensions are taken by series like\n * \"value way\" does.\n * The result of data arrengment of data dimensions like:\n * | ser_shared_x | ser0_y | ser1_y | ser2_y |\n *\n * @param {Array.<Object|string>} coordDimensions [{name: <string>, type: <string>, dimsDef: <Array>}, ...]\n * @param {module:model/Series} seriesModel\n * @param {module:data/Source} source\n * @return {Object} encode Never be `null/undefined`.\n */\nexport function makeSeriesEncodeForAxisCoordSys(coordDimensions, seriesModel, source) {\n var encode = {};\n\n var datasetModel = getDatasetModel(seriesModel);\n // Currently only make default when using dataset, util more reqirements occur.\n if (!datasetModel || !coordDimensions) {\n return encode;\n }\n\n var encodeItemName = [];\n var encodeSeriesName = [];\n\n var ecModel = seriesModel.ecModel;\n var datasetMap = inner(ecModel).datasetMap;\n var key = datasetModel.uid + '_' + source.seriesLayoutBy;\n\n var baseCategoryDimIndex;\n var categoryWayValueDimStart;\n coordDimensions = coordDimensions.slice();\n each(coordDimensions, function (coordDimInfo, coordDimIdx) {\n !isObject(coordDimInfo) && (coordDimensions[coordDimIdx] = {name: coordDimInfo});\n if (coordDimInfo.type === 'ordinal' && baseCategoryDimIndex == null) {\n baseCategoryDimIndex = coordDimIdx;\n categoryWayValueDimStart = getDataDimCountOnCoordDim(coordDimensions[coordDimIdx]);\n }\n encode[coordDimInfo.name] = [];\n });\n\n var datasetRecord = datasetMap.get(key)\n || datasetMap.set(key, {categoryWayDim: categoryWayValueDimStart, valueWayDim: 0});\n\n // TODO\n // Auto detect first time axis and do arrangement.\n each(coordDimensions, function (coordDimInfo, coordDimIdx) {\n var coordDimName = coordDimInfo.name;\n var count = getDataDimCountOnCoordDim(coordDimInfo);\n\n // In value way.\n if (baseCategoryDimIndex == null) {\n var start = datasetRecord.valueWayDim;\n pushDim(encode[coordDimName], start, count);\n pushDim(encodeSeriesName, start, count);\n datasetRecord.valueWayDim += count;\n\n // ??? TODO give a better default series name rule?\n // especially when encode x y specified.\n // consider: when mutiple series share one dimension\n // category axis, series name should better use\n // the other dimsion name. On the other hand, use\n // both dimensions name.\n }\n // In category way, the first category axis.\n else if (baseCategoryDimIndex === coordDimIdx) {\n pushDim(encode[coordDimName], 0, count);\n pushDim(encodeItemName, 0, count);\n }\n // In category way, the other axis.\n else {\n var start = datasetRecord.categoryWayDim;\n pushDim(encode[coordDimName], start, count);\n pushDim(encodeSeriesName, start, count);\n datasetRecord.categoryWayDim += count;\n }\n });\n\n function pushDim(dimIdxArr, idxFrom, idxCount) {\n for (var i = 0; i < idxCount; i++) {\n dimIdxArr.push(idxFrom + i);\n }\n }\n\n function getDataDimCountOnCoordDim(coordDimInfo) {\n var dimsDef = coordDimInfo.dimsDef;\n return dimsDef ? dimsDef.length : 1;\n }\n\n encodeItemName.length && (encode.itemName = encodeItemName);\n encodeSeriesName.length && (encode.seriesName = encodeSeriesName);\n\n return encode;\n}\n\n/**\n * Work for data like [{name: ..., value: ...}, ...].\n *\n * @param {module:model/Series} seriesModel\n * @param {module:data/Source} source\n * @return {Object} encode Never be `null/undefined`.\n */\nexport function makeSeriesEncodeForNameBased(seriesModel, source, dimCount) {\n var encode = {};\n\n var datasetModel = getDatasetModel(seriesModel);\n // Currently only make default when using dataset, util more reqirements occur.\n if (!datasetModel) {\n return encode;\n }\n\n var sourceFormat = source.sourceFormat;\n var dimensionsDefine = source.dimensionsDefine;\n\n var potentialNameDimIndex;\n if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS || sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {\n each(dimensionsDefine, function (dim, idx) {\n if ((isObject(dim) ? dim.name : dim) === 'name') {\n potentialNameDimIndex = idx;\n }\n });\n }\n\n // idxResult: {v, n}.\n var idxResult = (function () {\n\n var idxRes0 = {};\n var idxRes1 = {};\n var guessRecords = [];\n\n // 5 is an experience value.\n for (var i = 0, len = Math.min(5, dimCount); i < len; i++) {\n var guessResult = doGuessOrdinal(\n source.data, sourceFormat, source.seriesLayoutBy,\n dimensionsDefine, source.startIndex, i\n );\n guessRecords.push(guessResult);\n var isPureNumber = guessResult === BE_ORDINAL.Not;\n\n // [Strategy of idxRes0]: find the first BE_ORDINAL.Not as the value dim,\n // and then find a name dim with the priority:\n // \"BE_ORDINAL.Might|BE_ORDINAL.Must\" > \"other dim\" > \"the value dim itself\".\n if (isPureNumber && idxRes0.v == null && i !== potentialNameDimIndex) {\n idxRes0.v = i;\n }\n if (idxRes0.n == null\n || (idxRes0.n === idxRes0.v)\n || (!isPureNumber && guessRecords[idxRes0.n] === BE_ORDINAL.Not)\n ) {\n idxRes0.n = i;\n }\n if (fulfilled(idxRes0) && guessRecords[idxRes0.n] !== BE_ORDINAL.Not) {\n return idxRes0;\n }\n\n // [Strategy of idxRes1]: if idxRes0 not satisfied (that is, no BE_ORDINAL.Not),\n // find the first BE_ORDINAL.Might as the value dim,\n // and then find a name dim with the priority:\n // \"other dim\" > \"the value dim itself\".\n // That is for backward compat: number-like (e.g., `'3'`, `'55'`) can be\n // treated as number.\n if (!isPureNumber) {\n if (guessResult === BE_ORDINAL.Might && idxRes1.v == null && i !== potentialNameDimIndex) {\n idxRes1.v = i;\n }\n if (idxRes1.n == null || (idxRes1.n === idxRes1.v)) {\n idxRes1.n = i;\n }\n }\n }\n\n function fulfilled(idxResult) {\n return idxResult.v != null && idxResult.n != null;\n }\n\n return fulfilled(idxRes0) ? idxRes0 : fulfilled(idxRes1) ? idxRes1 : null;\n })();\n\n if (idxResult) {\n encode.value = idxResult.v;\n // `potentialNameDimIndex` has highest priority.\n var nameDimIndex = potentialNameDimIndex != null ? potentialNameDimIndex : idxResult.n;\n // By default, label use itemName in charts.\n // So we dont set encodeLabel here.\n encode.itemName = [nameDimIndex];\n encode.seriesName = [nameDimIndex];\n }\n\n return encode;\n}\n\n/**\n * If return null/undefined, indicate that should not use datasetModel.\n */\nfunction getDatasetModel(seriesModel) {\n var option = seriesModel.option;\n // Caution: consider the scenario:\n // A dataset is declared and a series is not expected to use the dataset,\n // and at the beginning `setOption({series: { noData })` (just prepare other\n // option but no data), then `setOption({series: {data: [...]}); In this case,\n // the user should set an empty array to avoid that dataset is used by default.\n var thisData = option.data;\n if (!thisData) {\n return seriesModel.ecModel.getComponent('dataset', option.datasetIndex || 0);\n }\n}\n\n/**\n * The rule should not be complex, otherwise user might not\n * be able to known where the data is wrong.\n * The code is ugly, but how to make it neat?\n *\n * @param {module:echars/data/Source} source\n * @param {number} dimIndex\n * @return {BE_ORDINAL} guess result.\n */\nexport function guessOrdinal(source, dimIndex) {\n return doGuessOrdinal(\n source.data,\n source.sourceFormat,\n source.seriesLayoutBy,\n source.dimensionsDefine,\n source.startIndex,\n dimIndex\n );\n}\n\n// dimIndex may be overflow source data.\n// return {BE_ORDINAL}\nfunction doGuessOrdinal(\n data, sourceFormat, seriesLayoutBy, dimensionsDefine, startIndex, dimIndex\n) {\n var result;\n // Experience value.\n var maxLoop = 5;\n\n if (isTypedArray(data)) {\n return BE_ORDINAL.Not;\n }\n\n // When sourceType is 'objectRows' or 'keyedColumns', dimensionsDefine\n // always exists in source.\n var dimName;\n var dimType;\n if (dimensionsDefine) {\n var dimDefItem = dimensionsDefine[dimIndex];\n if (isObject(dimDefItem)) {\n dimName = dimDefItem.name;\n dimType = dimDefItem.type;\n }\n else if (isString(dimDefItem)) {\n dimName = dimDefItem;\n }\n }\n\n if (dimType != null) {\n return dimType === 'ordinal' ? BE_ORDINAL.Must : BE_ORDINAL.Not;\n }\n\n if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {\n if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {\n var sample = data[dimIndex];\n for (var i = 0; i < (sample || []).length && i < maxLoop; i++) {\n if ((result = detectValue(sample[startIndex + i])) != null) {\n return result;\n }\n }\n }\n else {\n for (var i = 0; i < data.length && i < maxLoop; i++) {\n var row = data[startIndex + i];\n if (row && (result = detectValue(row[dimIndex])) != null) {\n return result;\n }\n }\n }\n }\n else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {\n if (!dimName) {\n return BE_ORDINAL.Not;\n }\n for (var i = 0; i < data.length && i < maxLoop; i++) {\n var item = data[i];\n if (item && (result = detectValue(item[dimName])) != null) {\n return result;\n }\n }\n }\n else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {\n if (!dimName) {\n return BE_ORDINAL.Not;\n }\n var sample = data[dimName];\n if (!sample || isTypedArray(sample)) {\n return BE_ORDINAL.Not;\n }\n for (var i = 0; i < sample.length && i < maxLoop; i++) {\n if ((result = detectValue(sample[i])) != null) {\n return result;\n }\n }\n }\n else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {\n for (var i = 0; i < data.length && i < maxLoop; i++) {\n var item = data[i];\n var val = getDataItemValue(item);\n if (!isArray(val)) {\n return BE_ORDINAL.Not;\n }\n if ((result = detectValue(val[dimIndex])) != null) {\n return result;\n }\n }\n }\n\n function detectValue(val) {\n var beStr = isString(val);\n // Consider usage convenience, '1', '2' will be treated as \"number\".\n // `isFinit('')` get `true`.\n if (val != null && isFinite(val) && val !== '') {\n return beStr ? BE_ORDINAL.Might : BE_ORDINAL.Not;\n }\n else if (beStr && val !== '-') {\n return BE_ORDINAL.Must;\n }\n }\n\n return BE_ORDINAL.Not;\n}\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\n/**\n * ECharts global model\n *\n * @module {echarts/model/Global}\n */\n\n\n/**\n * Caution: If the mechanism should be changed some day, these cases\n * should be considered:\n *\n * (1) In `merge option` mode, if using the same option to call `setOption`\n * many times, the result should be the same (try our best to ensure that).\n * (2) In `merge option` mode, if a component has no id/name specified, it\n * will be merged by index, and the result sequence of the components is\n * consistent to the original sequence.\n * (3) `reset` feature (in toolbox). Find detailed info in comments about\n * `mergeOption` in module:echarts/model/OptionManager.\n */\n\nimport {__DEV__} from '../config';\nimport {\n each, filter, map, isArray, indexOf, isObject, isString,\n createHashMap, assert, clone, merge, extend, mixin\n} from 'zrender/src/core/util';\nimport * as modelUtil from '../util/model';\nimport Model from './Model';\nimport ComponentModel from './Component';\nimport globalDefault from './globalDefault';\nimport colorPaletteMixin from './mixin/colorPalette';\nimport {resetSourceDefaulter} from '../data/helper/sourceHelper';\n\nvar OPTION_INNER_KEY = '\\0_ec_inner';\n\n/**\n * @alias module:echarts/model/Global\n *\n * @param {Object} option\n * @param {module:echarts/model/Model} parentModel\n * @param {Object} theme\n */\nvar GlobalModel = Model.extend({\n\n init: function (option, parentModel, theme, optionManager) {\n theme = theme || {};\n\n this.option = null; // Mark as not initialized.\n\n /**\n * @type {module:echarts/model/Model}\n * @private\n */\n this._theme = new Model(theme);\n\n /**\n * @type {module:echarts/model/OptionManager}\n */\n this._optionManager = optionManager;\n },\n\n setOption: function (option, optionPreprocessorFuncs) {\n assert(\n !(OPTION_INNER_KEY in option),\n 'please use chart.getOption()'\n );\n\n this._optionManager.setOption(option, optionPreprocessorFuncs);\n\n this.resetOption(null);\n },\n\n /**\n * @param {string} type null/undefined: reset all.\n * 'recreate': force recreate all.\n * 'timeline': only reset timeline option\n * 'media': only reset media query option\n * @return {boolean} Whether option changed.\n */\n resetOption: function (type) {\n var optionChanged = false;\n var optionManager = this._optionManager;\n\n if (!type || type === 'recreate') {\n var baseOption = optionManager.mountOption(type === 'recreate');\n\n if (!this.option || type === 'recreate') {\n initBase.call(this, baseOption);\n }\n else {\n this.restoreData();\n this.mergeOption(baseOption);\n }\n optionChanged = true;\n }\n\n if (type === 'timeline' || type === 'media') {\n this.restoreData();\n }\n\n if (!type || type === 'recreate' || type === 'timeline') {\n var timelineOption = optionManager.getTimelineOption(this);\n timelineOption && (this.mergeOption(timelineOption), optionChanged = true);\n }\n\n if (!type || type === 'recreate' || type === 'media') {\n var mediaOptions = optionManager.getMediaOption(this, this._api);\n if (mediaOptions.length) {\n each(mediaOptions, function (mediaOption) {\n this.mergeOption(mediaOption, optionChanged = true);\n }, this);\n }\n }\n\n return optionChanged;\n },\n\n /**\n * @protected\n */\n mergeOption: function (newOption) {\n var option = this.option;\n var componentsMap = this._componentsMap;\n var newCptTypes = [];\n\n resetSourceDefaulter(this);\n\n // If no component class, merge directly.\n // For example: color, animaiton options, etc.\n each(newOption, function (componentOption, mainType) {\n if (componentOption == null) {\n return;\n }\n\n if (!ComponentModel.hasClass(mainType)) {\n // globalSettingTask.dirty();\n option[mainType] = option[mainType] == null\n ? clone(componentOption)\n : merge(option[mainType], componentOption, true);\n }\n else if (mainType) {\n newCptTypes.push(mainType);\n }\n });\n\n ComponentModel.topologicalTravel(\n newCptTypes, ComponentModel.getAllClassMainTypes(), visitComponent, this\n );\n\n function visitComponent(mainType, dependencies) {\n\n var newCptOptionList = modelUtil.normalizeToArray(newOption[mainType]);\n\n var mapResult = modelUtil.mappingToExists(\n componentsMap.get(mainType), newCptOptionList\n );\n\n modelUtil.makeIdAndName(mapResult);\n\n // Set mainType and complete subType.\n each(mapResult, function (item, index) {\n var opt = item.option;\n if (isObject(opt)) {\n item.keyInfo.mainType = mainType;\n item.keyInfo.subType = determineSubType(mainType, opt, item.exist);\n }\n });\n\n var dependentModels = getComponentsByTypes(\n componentsMap, dependencies\n );\n\n option[mainType] = [];\n componentsMap.set(mainType, []);\n\n each(mapResult, function (resultItem, index) {\n var componentModel = resultItem.exist;\n var newCptOption = resultItem.option;\n\n assert(\n isObject(newCptOption) || componentModel,\n 'Empty component definition'\n );\n\n // Consider where is no new option and should be merged using {},\n // see removeEdgeAndAdd in topologicalTravel and\n // ComponentModel.getAllClassMainTypes.\n if (!newCptOption) {\n componentModel.mergeOption({}, this);\n componentModel.optionUpdated({}, false);\n }\n else {\n var ComponentModelClass = ComponentModel.getClass(\n mainType, resultItem.keyInfo.subType, true\n );\n\n if (componentModel && componentModel.constructor === ComponentModelClass) {\n componentModel.name = resultItem.keyInfo.name;\n // componentModel.settingTask && componentModel.settingTask.dirty();\n componentModel.mergeOption(newCptOption, this);\n componentModel.optionUpdated(newCptOption, false);\n }\n else {\n // PENDING Global as parent ?\n var extraOpt = extend(\n {\n dependentModels: dependentModels,\n componentIndex: index\n },\n resultItem.keyInfo\n );\n componentModel = new ComponentModelClass(\n newCptOption, this, this, extraOpt\n );\n extend(componentModel, extraOpt);\n componentModel.init(newCptOption, this, this, extraOpt);\n\n // Call optionUpdated after init.\n // newCptOption has been used as componentModel.option\n // and may be merged with theme and default, so pass null\n // to avoid confusion.\n componentModel.optionUpdated(null, true);\n }\n }\n\n componentsMap.get(mainType)[index] = componentModel;\n option[mainType][index] = componentModel.option;\n }, this);\n\n // Backup series for filtering.\n if (mainType === 'series') {\n createSeriesIndices(this, componentsMap.get('series'));\n }\n }\n\n this._seriesIndicesMap = createHashMap(\n this._seriesIndices = this._seriesIndices || []\n );\n },\n\n /**\n * Get option for output (cloned option and inner info removed)\n * @public\n * @return {Object}\n */\n getOption: function () {\n var option = clone(this.option);\n\n each(option, function (opts, mainType) {\n if (ComponentModel.hasClass(mainType)) {\n var opts = modelUtil.normalizeToArray(opts);\n for (var i = opts.length - 1; i >= 0; i--) {\n // Remove options with inner id.\n if (modelUtil.isIdInner(opts[i])) {\n opts.splice(i, 1);\n }\n }\n option[mainType] = opts;\n }\n });\n\n delete option[OPTION_INNER_KEY];\n\n return option;\n },\n\n /**\n * @return {module:echarts/model/Model}\n */\n getTheme: function () {\n return this._theme;\n },\n\n /**\n * @param {string} mainType\n * @param {number} [idx=0]\n * @return {module:echarts/model/Component}\n */\n getComponent: function (mainType, idx) {\n var list = this._componentsMap.get(mainType);\n if (list) {\n return list[idx || 0];\n }\n },\n\n /**\n * If none of index and id and name used, return all components with mainType.\n * @param {Object} condition\n * @param {string} condition.mainType\n * @param {string} [condition.subType] If ignore, only query by mainType\n * @param {number|Array.<number>} [condition.index] Either input index or id or name.\n * @param {string|Array.<string>} [condition.id] Either input index or id or name.\n * @param {string|Array.<string>} [condition.name] Either input index or id or name.\n * @return {Array.<module:echarts/model/Component>}\n */\n queryComponents: function (condition) {\n var mainType = condition.mainType;\n if (!mainType) {\n return [];\n }\n\n var index = condition.index;\n var id = condition.id;\n var name = condition.name;\n\n var cpts = this._componentsMap.get(mainType);\n\n if (!cpts || !cpts.length) {\n return [];\n }\n\n var result;\n\n if (index != null) {\n if (!isArray(index)) {\n index = [index];\n }\n result = filter(map(index, function (idx) {\n return cpts[idx];\n }), function (val) {\n return !!val;\n });\n }\n else if (id != null) {\n var isIdArray = isArray(id);\n result = filter(cpts, function (cpt) {\n return (isIdArray && indexOf(id, cpt.id) >= 0)\n || (!isIdArray && cpt.id === id);\n });\n }\n else if (name != null) {\n var isNameArray = isArray(name);\n result = filter(cpts, function (cpt) {\n return (isNameArray && indexOf(name, cpt.name) >= 0)\n || (!isNameArray && cpt.name === name);\n });\n }\n else {\n // Return all components with mainType\n result = cpts.slice();\n }\n\n return filterBySubType(result, condition);\n },\n\n /**\n * The interface is different from queryComponents,\n * which is convenient for inner usage.\n *\n * @usage\n * var result = findComponents(\n * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}}\n * );\n * var result = findComponents(\n * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}}\n * );\n * var result = findComponents(\n * {mainType: 'series',\n * filter: function (model, index) {...}}\n * );\n * // result like [component0, componnet1, ...]\n *\n * @param {Object} condition\n * @param {string} condition.mainType Mandatory.\n * @param {string} [condition.subType] Optional.\n * @param {Object} [condition.query] like {xxxIndex, xxxId, xxxName},\n * where xxx is mainType.\n * If query attribute is null/undefined or has no index/id/name,\n * do not filtering by query conditions, which is convenient for\n * no-payload situations or when target of action is global.\n * @param {Function} [condition.filter] parameter: component, return boolean.\n * @return {Array.<module:echarts/model/Component>}\n */\n findComponents: function (condition) {\n var query = condition.query;\n var mainType = condition.mainType;\n\n var queryCond = getQueryCond(query);\n var result = queryCond\n ? this.queryComponents(queryCond)\n : this._componentsMap.get(mainType);\n\n return doFilter(filterBySubType(result, condition));\n\n function getQueryCond(q) {\n var indexAttr = mainType + 'Index';\n var idAttr = mainType + 'Id';\n var nameAttr = mainType + 'Name';\n return q && (\n q[indexAttr] != null\n || q[idAttr] != null\n || q[nameAttr] != null\n )\n ? {\n mainType: mainType,\n // subType will be filtered finally.\n index: q[indexAttr],\n id: q[idAttr],\n name: q[nameAttr]\n }\n : null;\n }\n\n function doFilter(res) {\n return condition.filter\n ? filter(res, condition.filter)\n : res;\n }\n },\n\n /**\n * @usage\n * eachComponent('legend', function (legendModel, index) {\n * ...\n * });\n * eachComponent(function (componentType, model, index) {\n * // componentType does not include subType\n * // (componentType is 'xxx' but not 'xxx.aa')\n * });\n * eachComponent(\n * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}},\n * function (model, index) {...}\n * );\n * eachComponent(\n * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}},\n * function (model, index) {...}\n * );\n *\n * @param {string|Object=} mainType When mainType is object, the definition\n * is the same as the method 'findComponents'.\n * @param {Function} cb\n * @param {*} context\n */\n eachComponent: function (mainType, cb, context) {\n var componentsMap = this._componentsMap;\n\n if (typeof mainType === 'function') {\n context = cb;\n cb = mainType;\n componentsMap.each(function (components, componentType) {\n each(components, function (component, index) {\n cb.call(context, componentType, component, index);\n });\n });\n }\n else if (isString(mainType)) {\n each(componentsMap.get(mainType), cb, context);\n }\n else if (isObject(mainType)) {\n var queryResult = this.findComponents(mainType);\n each(queryResult, cb, context);\n }\n },\n\n /**\n * @param {string} name\n * @return {Array.<module:echarts/model/Series>}\n */\n getSeriesByName: function (name) {\n var series = this._componentsMap.get('series');\n return filter(series, function (oneSeries) {\n return oneSeries.name === name;\n });\n },\n\n /**\n * @param {number} seriesIndex\n * @return {module:echarts/model/Series}\n */\n getSeriesByIndex: function (seriesIndex) {\n return this._componentsMap.get('series')[seriesIndex];\n },\n\n /**\n * Get series list before filtered by type.\n * FIXME: rename to getRawSeriesByType?\n *\n * @param {string} subType\n * @return {Array.<module:echarts/model/Series>}\n */\n getSeriesByType: function (subType) {\n var series = this._componentsMap.get('series');\n return filter(series, function (oneSeries) {\n return oneSeries.subType === subType;\n });\n },\n\n /**\n * @return {Array.<module:echarts/model/Series>}\n */\n getSeries: function () {\n return this._componentsMap.get('series').slice();\n },\n\n /**\n * @return {number}\n */\n getSeriesCount: function () {\n return this._componentsMap.get('series').length;\n },\n\n /**\n * After filtering, series may be different\n * frome raw series.\n *\n * @param {Function} cb\n * @param {*} context\n */\n eachSeries: function (cb, context) {\n assertSeriesInitialized(this);\n each(this._seriesIndices, function (rawSeriesIndex) {\n var series = this._componentsMap.get('series')[rawSeriesIndex];\n cb.call(context, series, rawSeriesIndex);\n }, this);\n },\n\n /**\n * Iterate raw series before filtered.\n *\n * @param {Function} cb\n * @param {*} context\n */\n eachRawSeries: function (cb, context) {\n each(this._componentsMap.get('series'), cb, context);\n },\n\n /**\n * After filtering, series may be different.\n * frome raw series.\n *\n * @param {string} subType.\n * @param {Function} cb\n * @param {*} context\n */\n eachSeriesByType: function (subType, cb, context) {\n assertSeriesInitialized(this);\n each(this._seriesIndices, function (rawSeriesIndex) {\n var series = this._componentsMap.get('series')[rawSeriesIndex];\n if (series.subType === subType) {\n cb.call(context, series, rawSeriesIndex);\n }\n }, this);\n },\n\n /**\n * Iterate raw series before filtered of given type.\n *\n * @parma {string} subType\n * @param {Function} cb\n * @param {*} context\n */\n eachRawSeriesByType: function (subType, cb, context) {\n return each(this.getSeriesByType(subType), cb, context);\n },\n\n /**\n * @param {module:echarts/model/Series} seriesModel\n */\n isSeriesFiltered: function (seriesModel) {\n assertSeriesInitialized(this);\n return this._seriesIndicesMap.get(seriesModel.componentIndex) == null;\n },\n\n /**\n * @return {Array.<number>}\n */\n getCurrentSeriesIndices: function () {\n return (this._seriesIndices || []).slice();\n },\n\n /**\n * @param {Function} cb\n * @param {*} context\n */\n filterSeries: function (cb, context) {\n assertSeriesInitialized(this);\n var filteredSeries = filter(\n this._componentsMap.get('series'), cb, context\n );\n createSeriesIndices(this, filteredSeries);\n },\n\n restoreData: function (payload) {\n var componentsMap = this._componentsMap;\n\n createSeriesIndices(this, componentsMap.get('series'));\n\n var componentTypes = [];\n componentsMap.each(function (components, componentType) {\n componentTypes.push(componentType);\n });\n\n ComponentModel.topologicalTravel(\n componentTypes,\n ComponentModel.getAllClassMainTypes(),\n function (componentType, dependencies) {\n each(componentsMap.get(componentType), function (component) {\n (componentType !== 'series' || !isNotTargetSeries(component, payload))\n && component.restoreData();\n });\n }\n );\n }\n\n});\n\nfunction isNotTargetSeries(seriesModel, payload) {\n if (payload) {\n var index = payload.seiresIndex;\n var id = payload.seriesId;\n var name = payload.seriesName;\n return (index != null && seriesModel.componentIndex !== index)\n || (id != null && seriesModel.id !== id)\n || (name != null && seriesModel.name !== name);\n }\n}\n\n/**\n * @inner\n */\nfunction mergeTheme(option, theme) {\n // PENDING\n // NOT use `colorLayer` in theme if option has `color`\n var notMergeColorLayer = option.color && !option.colorLayer;\n\n each(theme, function (themeItem, name) {\n if (name === 'colorLayer' && notMergeColorLayer) {\n return;\n }\n // 如果有 component model 则把具体的 merge 逻辑交给该 model 处理\n if (!ComponentModel.hasClass(name)) {\n if (typeof themeItem === 'object') {\n option[name] = !option[name]\n ? clone(themeItem)\n : merge(option[name], themeItem, false);\n }\n else {\n if (option[name] == null) {\n option[name] = themeItem;\n }\n }\n }\n });\n}\n\nfunction initBase(baseOption) {\n baseOption = baseOption;\n\n // Using OPTION_INNER_KEY to mark that this option can not be used outside,\n // i.e. `chart.setOption(chart.getModel().option);` is forbiden.\n this.option = {};\n this.option[OPTION_INNER_KEY] = 1;\n\n /**\n * Init with series: [], in case of calling findSeries method\n * before series initialized.\n * @type {Object.<string, Array.<module:echarts/model/Model>>}\n * @private\n */\n this._componentsMap = createHashMap({series: []});\n\n /**\n * Mapping between filtered series list and raw series list.\n * key: filtered series indices, value: raw series indices.\n * @type {Array.<nubmer>}\n * @private\n */\n this._seriesIndices;\n\n this._seriesIndicesMap;\n\n mergeTheme(baseOption, this._theme.option);\n\n // TODO Needs clone when merging to the unexisted property\n merge(baseOption, globalDefault, false);\n\n this.mergeOption(baseOption);\n}\n\n/**\n * @inner\n * @param {Array.<string>|string} types model types\n * @return {Object} key: {string} type, value: {Array.<Object>} models\n */\nfunction getComponentsByTypes(componentsMap, types) {\n if (!isArray(types)) {\n types = types ? [types] : [];\n }\n\n var ret = {};\n each(types, function (type) {\n ret[type] = (componentsMap.get(type) || []).slice();\n });\n\n return ret;\n}\n\n/**\n * @inner\n */\nfunction determineSubType(mainType, newCptOption, existComponent) {\n var subType = newCptOption.type\n ? newCptOption.type\n : existComponent\n ? existComponent.subType\n // Use determineSubType only when there is no existComponent.\n : ComponentModel.determineSubType(mainType, newCptOption);\n\n // tooltip, markline, markpoint may always has no subType\n return subType;\n}\n\n/**\n * @inner\n */\nfunction createSeriesIndices(ecModel, seriesModels) {\n ecModel._seriesIndicesMap = createHashMap(\n ecModel._seriesIndices = map(seriesModels, function (series) {\n return series.componentIndex;\n }) || []\n );\n}\n\n/**\n * @inner\n */\nfunction filterBySubType(components, condition) {\n // Using hasOwnProperty for restrict. Consider\n // subType is undefined in user payload.\n return condition.hasOwnProperty('subType')\n ? filter(components, function (cpt) {\n return cpt.subType === condition.subType;\n })\n : components;\n}\n\n/**\n * @inner\n */\nfunction assertSeriesInitialized(ecModel) {\n // Components that use _seriesIndices should depends on series component,\n // which make sure that their initialization is after series.\n if (__DEV__) {\n if (!ecModel._seriesIndices) {\n throw new Error('Option should contains series.');\n }\n }\n}\n\nmixin(GlobalModel, colorPaletteMixin);\n\nexport default GlobalModel;\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport * as zrUtil from 'zrender/src/core/util';\n\nvar echartsAPIList = [\n 'getDom', 'getZr', 'getWidth', 'getHeight', 'getDevicePixelRatio', 'dispatchAction', 'isDisposed',\n 'on', 'off', 'getDataURL', 'getConnectedDataURL', 'getModel', 'getOption',\n 'getViewOfComponentModel', 'getViewOfSeriesModel'\n];\n// And `getCoordinateSystems` and `getComponentByElement` will be injected in echarts.js\n\nfunction ExtensionAPI(chartInstance) {\n zrUtil.each(echartsAPIList, function (name) {\n this[name] = zrUtil.bind(chartInstance[name], chartInstance);\n }, this);\n}\n\nexport default ExtensionAPI;","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport * as zrUtil from 'zrender/src/core/util';\n\nvar coordinateSystemCreators = {};\n\nfunction CoordinateSystemManager() {\n\n this._coordinateSystems = [];\n}\n\nCoordinateSystemManager.prototype = {\n\n constructor: CoordinateSystemManager,\n\n create: function (ecModel, api) {\n var coordinateSystems = [];\n zrUtil.each(coordinateSystemCreators, function (creater, type) {\n var list = creater.create(ecModel, api);\n coordinateSystems = coordinateSystems.concat(list || []);\n });\n\n this._coordinateSystems = coordinateSystems;\n },\n\n update: function (ecModel, api) {\n zrUtil.each(this._coordinateSystems, function (coordSys) {\n coordSys.update && coordSys.update(ecModel, api);\n });\n },\n\n getCoordinateSystems: function () {\n return this._coordinateSystems.slice();\n }\n};\n\nCoordinateSystemManager.register = function (type, coordinateSystemCreator) {\n coordinateSystemCreators[type] = coordinateSystemCreator;\n};\n\nCoordinateSystemManager.get = function (type) {\n return coordinateSystemCreators[type];\n};\n\nexport default CoordinateSystemManager;","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\n/**\n * ECharts option manager\n *\n * @module {echarts/model/OptionManager}\n */\n\n\nimport * as zrUtil from 'zrender/src/core/util';\nimport * as modelUtil from '../util/model';\nimport ComponentModel from './Component';\n\nvar each = zrUtil.each;\nvar clone = zrUtil.clone;\nvar map = zrUtil.map;\nvar merge = zrUtil.merge;\n\nvar QUERY_REG = /^(min|max)?(.+)$/;\n\n/**\n * TERM EXPLANATIONS:\n *\n * [option]:\n *\n * An object that contains definitions of components. For example:\n * var option = {\n * title: {...},\n * legend: {...},\n * visualMap: {...},\n * series: [\n * {data: [...]},\n * {data: [...]},\n * ...\n * ]\n * };\n *\n * [rawOption]:\n *\n * An object input to echarts.setOption. 'rawOption' may be an\n * 'option', or may be an object contains multi-options. For example:\n * var option = {\n * baseOption: {\n * title: {...},\n * legend: {...},\n * series: [\n * {data: [...]},\n * {data: [...]},\n * ...\n * ]\n * },\n * timeline: {...},\n * options: [\n * {title: {...}, series: {data: [...]}},\n * {title: {...}, series: {data: [...]}},\n * ...\n * ],\n * media: [\n * {\n * query: {maxWidth: 320},\n * option: {series: {x: 20}, visualMap: {show: false}}\n * },\n * {\n * query: {minWidth: 320, maxWidth: 720},\n * option: {series: {x: 500}, visualMap: {show: true}}\n * },\n * {\n * option: {series: {x: 1200}, visualMap: {show: true}}\n * }\n * ]\n * };\n *\n * @alias module:echarts/model/OptionManager\n * @param {module:echarts/ExtensionAPI} api\n */\nfunction OptionManager(api) {\n\n /**\n * @private\n * @type {module:echarts/ExtensionAPI}\n */\n this._api = api;\n\n /**\n * @private\n * @type {Array.<number>}\n */\n this._timelineOptions = [];\n\n /**\n * @private\n * @type {Array.<Object>}\n */\n this._mediaList = [];\n\n /**\n * @private\n * @type {Object}\n */\n this._mediaDefault;\n\n /**\n * -1, means default.\n * empty means no media.\n * @private\n * @type {Array.<number>}\n */\n this._currentMediaIndices = [];\n\n /**\n * @private\n * @type {Object}\n */\n this._optionBackup;\n\n /**\n * @private\n * @type {Object}\n */\n this._newBaseOption;\n}\n\n// timeline.notMerge is not supported in ec3. Firstly there is rearly\n// case that notMerge is needed. Secondly supporting 'notMerge' requires\n// rawOption cloned and backuped when timeline changed, which does no\n// good to performance. What's more, that both timeline and setOption\n// method supply 'notMerge' brings complex and some problems.\n// Consider this case:\n// (step1) chart.setOption({timeline: {notMerge: false}, ...}, false);\n// (step2) chart.setOption({timeline: {notMerge: true}, ...}, false);\n\nOptionManager.prototype = {\n\n constructor: OptionManager,\n\n /**\n * @public\n * @param {Object} rawOption Raw option.\n * @param {module:echarts/model/Global} ecModel\n * @param {Array.<Function>} optionPreprocessorFuncs\n * @return {Object} Init option\n */\n setOption: function (rawOption, optionPreprocessorFuncs) {\n if (rawOption) {\n // That set dat primitive is dangerous if user reuse the data when setOption again.\n zrUtil.each(modelUtil.normalizeToArray(rawOption.series), function (series) {\n series && series.data && zrUtil.isTypedArray(series.data) && zrUtil.setAsPrimitive(series.data);\n });\n }\n\n // Caution: some series modify option data, if do not clone,\n // it should ensure that the repeat modify correctly\n // (create a new object when modify itself).\n rawOption = clone(rawOption);\n\n // FIXME\n // 如果 timeline options 或者 media 中设置了某个属性,而baseOption中没有设置,则进行警告。\n\n var oldOptionBackup = this._optionBackup;\n var newParsedOption = parseRawOption.call(\n this, rawOption, optionPreprocessorFuncs, !oldOptionBackup\n );\n this._newBaseOption = newParsedOption.baseOption;\n\n // For setOption at second time (using merge mode);\n if (oldOptionBackup) {\n // Only baseOption can be merged.\n mergeOption(oldOptionBackup.baseOption, newParsedOption.baseOption);\n\n // For simplicity, timeline options and media options do not support merge,\n // that is, if you `setOption` twice and both has timeline options, the latter\n // timeline opitons will not be merged to the formers, but just substitude them.\n if (newParsedOption.timelineOptions.length) {\n oldOptionBackup.timelineOptions = newParsedOption.timelineOptions;\n }\n if (newParsedOption.mediaList.length) {\n oldOptionBackup.mediaList = newParsedOption.mediaList;\n }\n if (newParsedOption.mediaDefault) {\n oldOptionBackup.mediaDefault = newParsedOption.mediaDefault;\n }\n }\n else {\n this._optionBackup = newParsedOption;\n }\n },\n\n /**\n * @param {boolean} isRecreate\n * @return {Object}\n */\n mountOption: function (isRecreate) {\n var optionBackup = this._optionBackup;\n\n // TODO\n // 如果没有reset功能则不clone。\n\n this._timelineOptions = map(optionBackup.timelineOptions, clone);\n this._mediaList = map(optionBackup.mediaList, clone);\n this._mediaDefault = clone(optionBackup.mediaDefault);\n this._currentMediaIndices = [];\n\n return clone(isRecreate\n // this._optionBackup.baseOption, which is created at the first `setOption`\n // called, and is merged into every new option by inner method `mergeOption`\n // each time `setOption` called, can be only used in `isRecreate`, because\n // its reliability is under suspicion. In other cases option merge is\n // performed by `model.mergeOption`.\n ? optionBackup.baseOption : this._newBaseOption\n );\n },\n\n /**\n * @param {module:echarts/model/Global} ecModel\n * @return {Object}\n */\n getTimelineOption: function (ecModel) {\n var option;\n var timelineOptions = this._timelineOptions;\n\n if (timelineOptions.length) {\n // getTimelineOption can only be called after ecModel inited,\n // so we can get currentIndex from timelineModel.\n var timelineModel = ecModel.getComponent('timeline');\n if (timelineModel) {\n option = clone(\n timelineOptions[timelineModel.getCurrentIndex()],\n true\n );\n }\n }\n\n return option;\n },\n\n /**\n * @param {module:echarts/model/Global} ecModel\n * @return {Array.<Object>}\n */\n getMediaOption: function (ecModel) {\n var ecWidth = this._api.getWidth();\n var ecHeight = this._api.getHeight();\n var mediaList = this._mediaList;\n var mediaDefault = this._mediaDefault;\n var indices = [];\n var result = [];\n\n // No media defined.\n if (!mediaList.length && !mediaDefault) {\n return result;\n }\n\n // Multi media may be applied, the latter defined media has higher priority.\n for (var i = 0, len = mediaList.length; i < len; i++) {\n if (applyMediaQuery(mediaList[i].query, ecWidth, ecHeight)) {\n indices.push(i);\n }\n }\n\n // FIXME\n // 是否mediaDefault应该强制用户设置,否则可能修改不能回归。\n if (!indices.length && mediaDefault) {\n indices = [-1];\n }\n\n if (indices.length && !indicesEquals(indices, this._currentMediaIndices)) {\n result = map(indices, function (index) {\n return clone(\n index === -1 ? mediaDefault.option : mediaList[index].option\n );\n });\n }\n // Otherwise return nothing.\n\n this._currentMediaIndices = indices;\n\n return result;\n }\n};\n\nfunction parseRawOption(rawOption, optionPreprocessorFuncs, isNew) {\n var timelineOptions = [];\n var mediaList = [];\n var mediaDefault;\n var baseOption;\n\n // Compatible with ec2.\n var timelineOpt = rawOption.timeline;\n\n if (rawOption.baseOption) {\n baseOption = rawOption.baseOption;\n }\n\n // For timeline\n if (timelineOpt || rawOption.options) {\n baseOption = baseOption || {};\n timelineOptions = (rawOption.options || []).slice();\n }\n\n // For media query\n if (rawOption.media) {\n baseOption = baseOption || {};\n var media = rawOption.media;\n each(media, function (singleMedia) {\n if (singleMedia && singleMedia.option) {\n if (singleMedia.query) {\n mediaList.push(singleMedia);\n }\n else if (!mediaDefault) {\n // Use the first media default.\n mediaDefault = singleMedia;\n }\n }\n });\n }\n\n // For normal option\n if (!baseOption) {\n baseOption = rawOption;\n }\n\n // Set timelineOpt to baseOption in ec3,\n // which is convenient for merge option.\n if (!baseOption.timeline) {\n baseOption.timeline = timelineOpt;\n }\n\n // Preprocess.\n each([baseOption].concat(timelineOptions)\n .concat(zrUtil.map(mediaList, function (media) {\n return media.option;\n })),\n function (option) {\n each(optionPreprocessorFuncs, function (preProcess) {\n preProcess(option, isNew);\n });\n }\n );\n\n return {\n baseOption: baseOption,\n timelineOptions: timelineOptions,\n mediaDefault: mediaDefault,\n mediaList: mediaList\n };\n}\n\n/**\n * @see <http://www.w3.org/TR/css3-mediaqueries/#media1>\n * Support: width, height, aspectRatio\n * Can use max or min as prefix.\n */\nfunction applyMediaQuery(query, ecWidth, ecHeight) {\n var realMap = {\n width: ecWidth,\n height: ecHeight,\n aspectratio: ecWidth / ecHeight // lowser case for convenientce.\n };\n\n var applicatable = true;\n\n zrUtil.each(query, function (value, attr) {\n var matched = attr.match(QUERY_REG);\n\n if (!matched || !matched[1] || !matched[2]) {\n return;\n }\n\n var operator = matched[1];\n var realAttr = matched[2].toLowerCase();\n\n if (!compare(realMap[realAttr], value, operator)) {\n applicatable = false;\n }\n });\n\n return applicatable;\n}\n\nfunction compare(real, expect, operator) {\n if (operator === 'min') {\n return real >= expect;\n }\n else if (operator === 'max') {\n return real <= expect;\n }\n else { // Equals\n return real === expect;\n }\n}\n\nfunction indicesEquals(indices1, indices2) {\n // indices is always order by asc and has only finite number.\n return indices1.join(',') === indices2.join(',');\n}\n\n/**\n * Consider case:\n * `chart.setOption(opt1);`\n * Then user do some interaction like dataZoom, dataView changing.\n * `chart.setOption(opt2);`\n * Then user press 'reset button' in toolbox.\n *\n * After doing that all of the interaction effects should be reset, the\n * chart should be the same as the result of invoke\n * `chart.setOption(opt1); chart.setOption(opt2);`.\n *\n * Although it is not able ensure that\n * `chart.setOption(opt1); chart.setOption(opt2);` is equivalents to\n * `chart.setOption(merge(opt1, opt2));` exactly,\n * this might be the only simple way to implement that feature.\n *\n * MEMO: We've considered some other approaches:\n * 1. Each model handle its self restoration but not uniform treatment.\n * (Too complex in logic and error-prone)\n * 2. Use a shadow ecModel. (Performace expensive)\n */\nfunction mergeOption(oldOption, newOption) {\n newOption = newOption || {};\n\n each(newOption, function (newCptOpt, mainType) {\n if (newCptOpt == null) {\n return;\n }\n\n var oldCptOpt = oldOption[mainType];\n\n if (!ComponentModel.hasClass(mainType)) {\n oldOption[mainType] = merge(oldCptOpt, newCptOpt, true);\n }\n else {\n newCptOpt = modelUtil.normalizeToArray(newCptOpt);\n oldCptOpt = modelUtil.normalizeToArray(oldCptOpt);\n\n var mapResult = modelUtil.mappingToExists(oldCptOpt, newCptOpt);\n\n oldOption[mainType] = map(mapResult, function (item) {\n return (item.option && item.exist)\n ? merge(item.exist, item.option, true)\n : (item.exist || item.option);\n });\n }\n });\n}\n\nexport default OptionManager;","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport * as zrUtil from 'zrender/src/core/util';\nimport * as modelUtil from '../../util/model';\n\nvar each = zrUtil.each;\nvar isObject = zrUtil.isObject;\n\nvar POSSIBLE_STYLES = [\n 'areaStyle', 'lineStyle', 'nodeStyle', 'linkStyle',\n 'chordStyle', 'label', 'labelLine'\n];\n\nfunction compatEC2ItemStyle(opt) {\n var itemStyleOpt = opt && opt.itemStyle;\n if (!itemStyleOpt) {\n return;\n }\n for (var i = 0, len = POSSIBLE_STYLES.length; i < len; i++) {\n var styleName = POSSIBLE_STYLES[i];\n var normalItemStyleOpt = itemStyleOpt.normal;\n var emphasisItemStyleOpt = itemStyleOpt.emphasis;\n if (normalItemStyleOpt && normalItemStyleOpt[styleName]) {\n opt[styleName] = opt[styleName] || {};\n if (!opt[styleName].normal) {\n opt[styleName].normal = normalItemStyleOpt[styleName];\n }\n else {\n zrUtil.merge(opt[styleName].normal, normalItemStyleOpt[styleName]);\n }\n normalItemStyleOpt[styleName] = null;\n }\n if (emphasisItemStyleOpt && emphasisItemStyleOpt[styleName]) {\n opt[styleName] = opt[styleName] || {};\n if (!opt[styleName].emphasis) {\n opt[styleName].emphasis = emphasisItemStyleOpt[styleName];\n }\n else {\n zrUtil.merge(opt[styleName].emphasis, emphasisItemStyleOpt[styleName]);\n }\n emphasisItemStyleOpt[styleName] = null;\n }\n }\n}\n\nfunction convertNormalEmphasis(opt, optType, useExtend) {\n if (opt && opt[optType] && (opt[optType].normal || opt[optType].emphasis)) {\n var normalOpt = opt[optType].normal;\n var emphasisOpt = opt[optType].emphasis;\n\n if (normalOpt) {\n // Timeline controlStyle has other properties besides normal and emphasis\n if (useExtend) {\n opt[optType].normal = opt[optType].emphasis = null;\n zrUtil.defaults(opt[optType], normalOpt);\n }\n else {\n opt[optType] = normalOpt;\n }\n }\n if (emphasisOpt) {\n opt.emphasis = opt.emphasis || {};\n opt.emphasis[optType] = emphasisOpt;\n }\n }\n}\n\nfunction removeEC3NormalStatus(opt) {\n convertNormalEmphasis(opt, 'itemStyle');\n convertNormalEmphasis(opt, 'lineStyle');\n convertNormalEmphasis(opt, 'areaStyle');\n convertNormalEmphasis(opt, 'label');\n convertNormalEmphasis(opt, 'labelLine');\n // treemap\n convertNormalEmphasis(opt, 'upperLabel');\n // graph\n convertNormalEmphasis(opt, 'edgeLabel');\n}\n\nfunction compatTextStyle(opt, propName) {\n // Check whether is not object (string\\null\\undefined ...)\n var labelOptSingle = isObject(opt) && opt[propName];\n var textStyle = isObject(labelOptSingle) && labelOptSingle.textStyle;\n if (textStyle) {\n for (var i = 0, len = modelUtil.TEXT_STYLE_OPTIONS.length; i < len; i++) {\n var propName = modelUtil.TEXT_STYLE_OPTIONS[i];\n if (textStyle.hasOwnProperty(propName)) {\n labelOptSingle[propName] = textStyle[propName];\n }\n }\n }\n}\n\nfunction compatEC3CommonStyles(opt) {\n if (opt) {\n removeEC3NormalStatus(opt);\n compatTextStyle(opt, 'label');\n opt.emphasis && compatTextStyle(opt.emphasis, 'label');\n }\n}\n\nfunction processSeries(seriesOpt) {\n if (!isObject(seriesOpt)) {\n return;\n }\n\n compatEC2ItemStyle(seriesOpt);\n removeEC3NormalStatus(seriesOpt);\n\n compatTextStyle(seriesOpt, 'label');\n // treemap\n compatTextStyle(seriesOpt, 'upperLabel');\n // graph\n compatTextStyle(seriesOpt, 'edgeLabel');\n if (seriesOpt.emphasis) {\n compatTextStyle(seriesOpt.emphasis, 'label');\n // treemap\n compatTextStyle(seriesOpt.emphasis, 'upperLabel');\n // graph\n compatTextStyle(seriesOpt.emphasis, 'edgeLabel');\n }\n\n var markPoint = seriesOpt.markPoint;\n if (markPoint) {\n compatEC2ItemStyle(markPoint);\n compatEC3CommonStyles(markPoint);\n }\n\n var markLine = seriesOpt.markLine;\n if (markLine) {\n compatEC2ItemStyle(markLine);\n compatEC3CommonStyles(markLine);\n }\n\n var markArea = seriesOpt.markArea;\n if (markArea) {\n compatEC3CommonStyles(markArea);\n }\n\n var data = seriesOpt.data;\n\n // Break with ec3: if `setOption` again, there may be no `type` in option,\n // then the backward compat based on option type will not be performed.\n\n if (seriesOpt.type === 'graph') {\n data = data || seriesOpt.nodes;\n var edgeData = seriesOpt.links || seriesOpt.edges;\n if (edgeData && !zrUtil.isTypedArray(edgeData)) {\n for (var i = 0; i < edgeData.length; i++) {\n compatEC3CommonStyles(edgeData[i]);\n }\n }\n zrUtil.each(seriesOpt.categories, function (opt) {\n removeEC3NormalStatus(opt);\n });\n }\n\n if (data && !zrUtil.isTypedArray(data)) {\n for (var i = 0; i < data.length; i++) {\n compatEC3CommonStyles(data[i]);\n }\n }\n\n // mark point data\n var markPoint = seriesOpt.markPoint;\n if (markPoint && markPoint.data) {\n var mpData = markPoint.data;\n for (var i = 0; i < mpData.length; i++) {\n compatEC3CommonStyles(mpData[i]);\n }\n }\n // mark line data\n var markLine = seriesOpt.markLine;\n if (markLine && markLine.data) {\n var mlData = markLine.data;\n for (var i = 0; i < mlData.length; i++) {\n if (zrUtil.isArray(mlData[i])) {\n compatEC3CommonStyles(mlData[i][0]);\n compatEC3CommonStyles(mlData[i][1]);\n }\n else {\n compatEC3CommonStyles(mlData[i]);\n }\n }\n }\n\n // Series\n if (seriesOpt.type === 'gauge') {\n compatTextStyle(seriesOpt, 'axisLabel');\n compatTextStyle(seriesOpt, 'title');\n compatTextStyle(seriesOpt, 'detail');\n }\n else if (seriesOpt.type === 'treemap') {\n convertNormalEmphasis(seriesOpt.breadcrumb, 'itemStyle');\n zrUtil.each(seriesOpt.levels, function (opt) {\n removeEC3NormalStatus(opt);\n });\n }\n else if (seriesOpt.type === 'tree') {\n removeEC3NormalStatus(seriesOpt.leaves);\n }\n // sunburst starts from ec4, so it does not need to compat levels.\n}\n\nfunction toArr(o) {\n return zrUtil.isArray(o) ? o : o ? [o] : [];\n}\n\nfunction toObj(o) {\n return (zrUtil.isArray(o) ? o[0] : o) || {};\n}\n\nexport default function (option, isTheme) {\n each(toArr(option.series), function (seriesOpt) {\n isObject(seriesOpt) && processSeries(seriesOpt);\n });\n\n var axes = ['xAxis', 'yAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'parallelAxis', 'radar'];\n isTheme && axes.push('valueAxis', 'categoryAxis', 'logAxis', 'timeAxis');\n\n each(\n axes,\n function (axisName) {\n each(toArr(option[axisName]), function (axisOpt) {\n if (axisOpt) {\n compatTextStyle(axisOpt, 'axisLabel');\n compatTextStyle(axisOpt.axisPointer, 'label');\n }\n });\n }\n );\n\n each(toArr(option.parallel), function (parallelOpt) {\n var parallelAxisDefault = parallelOpt && parallelOpt.parallelAxisDefault;\n compatTextStyle(parallelAxisDefault, 'axisLabel');\n compatTextStyle(parallelAxisDefault && parallelAxisDefault.axisPointer, 'label');\n });\n\n each(toArr(option.calendar), function (calendarOpt) {\n convertNormalEmphasis(calendarOpt, 'itemStyle');\n compatTextStyle(calendarOpt, 'dayLabel');\n compatTextStyle(calendarOpt, 'monthLabel');\n compatTextStyle(calendarOpt, 'yearLabel');\n });\n\n // radar.name.textStyle\n each(toArr(option.radar), function (radarOpt) {\n compatTextStyle(radarOpt, 'name');\n });\n\n each(toArr(option.geo), function (geoOpt) {\n if (isObject(geoOpt)) {\n compatEC3CommonStyles(geoOpt);\n each(toArr(geoOpt.regions), function (regionObj) {\n compatEC3CommonStyles(regionObj);\n });\n }\n });\n\n each(toArr(option.timeline), function (timelineOpt) {\n compatEC3CommonStyles(timelineOpt);\n convertNormalEmphasis(timelineOpt, 'label');\n convertNormalEmphasis(timelineOpt, 'itemStyle');\n convertNormalEmphasis(timelineOpt, 'controlStyle', true);\n\n var data = timelineOpt.data;\n zrUtil.isArray(data) && zrUtil.each(data, function (item) {\n if (zrUtil.isObject(item)) {\n convertNormalEmphasis(item, 'label');\n convertNormalEmphasis(item, 'itemStyle');\n }\n });\n });\n\n each(toArr(option.toolbox), function (toolboxOpt) {\n convertNormalEmphasis(toolboxOpt, 'iconStyle');\n each(toolboxOpt.feature, function (featureOpt) {\n convertNormalEmphasis(featureOpt, 'iconStyle');\n });\n });\n\n compatTextStyle(toObj(option.axisPointer), 'label');\n compatTextStyle(toObj(option.tooltip).axisPointer, 'label');\n}","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\n// Compatitable with 2.0\n\nimport {each, isArray, isObject} from 'zrender/src/core/util';\nimport compatStyle from './helper/compatStyle';\nimport {normalizeToArray} from '../util/model';\n\nfunction get(opt, path) {\n path = path.split(',');\n var obj = opt;\n for (var i = 0; i < path.length; i++) {\n obj = obj && obj[path[i]];\n if (obj == null) {\n break;\n }\n }\n return obj;\n}\n\nfunction set(opt, path, val, overwrite) {\n path = path.split(',');\n var obj = opt;\n var key;\n for (var i = 0; i < path.length - 1; i++) {\n key = path[i];\n if (obj[key] == null) {\n obj[key] = {};\n }\n obj = obj[key];\n }\n if (overwrite || obj[path[i]] == null) {\n obj[path[i]] = val;\n }\n}\n\nfunction compatLayoutProperties(option) {\n each(LAYOUT_PROPERTIES, function (prop) {\n if (prop[0] in option && !(prop[1] in option)) {\n option[prop[1]] = option[prop[0]];\n }\n });\n}\n\nvar LAYOUT_PROPERTIES = [\n ['x', 'left'], ['y', 'top'], ['x2', 'right'], ['y2', 'bottom']\n];\n\nvar COMPATITABLE_COMPONENTS = [\n 'grid', 'geo', 'parallel', 'legend', 'toolbox', 'title', 'visualMap', 'dataZoom', 'timeline'\n];\n\nexport default function (option, isTheme) {\n compatStyle(option, isTheme);\n\n // Make sure series array for model initialization.\n option.series = normalizeToArray(option.series);\n\n each(option.series, function (seriesOpt) {\n if (!isObject(seriesOpt)) {\n return;\n }\n\n var seriesType = seriesOpt.type;\n\n if (seriesType === 'line') {\n if (seriesOpt.clipOverflow != null) {\n seriesOpt.clip = seriesOpt.clipOverflow;\n }\n }\n else if (seriesType === 'pie' || seriesType === 'gauge') {\n if (seriesOpt.clockWise != null) {\n seriesOpt.clockwise = seriesOpt.clockWise;\n }\n }\n else if (seriesType === 'gauge') {\n var pointerColor = get(seriesOpt, 'pointer.color');\n pointerColor != null\n && set(seriesOpt, 'itemStyle.color', pointerColor);\n }\n\n compatLayoutProperties(seriesOpt);\n });\n\n // dataRange has changed to visualMap\n if (option.dataRange) {\n option.visualMap = option.dataRange;\n }\n\n each(COMPATITABLE_COMPONENTS, function (componentName) {\n var options = option[componentName];\n if (options) {\n if (!isArray(options)) {\n options = [options];\n }\n each(options, function (option) {\n compatLayoutProperties(option);\n });\n }\n });\n}","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport {createHashMap, each} from 'zrender/src/core/util';\n\n// (1) [Caution]: the logic is correct based on the premises:\n// data processing stage is blocked in stream.\n// See <module:echarts/stream/Scheduler#performDataProcessorTasks>\n// (2) Only register once when import repeatly.\n// Should be executed after series filtered and before stack calculation.\nexport default function (ecModel) {\n var stackInfoMap = createHashMap();\n ecModel.eachSeries(function (seriesModel) {\n var stack = seriesModel.get('stack');\n // Compatibal: when `stack` is set as '', do not stack.\n if (stack) {\n var stackInfoList = stackInfoMap.get(stack) || stackInfoMap.set(stack, []);\n var data = seriesModel.getData();\n\n var stackInfo = {\n // Used for calculate axis extent automatically.\n stackResultDimension: data.getCalculationInfo('stackResultDimension'),\n stackedOverDimension: data.getCalculationInfo('stackedOverDimension'),\n stackedDimension: data.getCalculationInfo('stackedDimension'),\n stackedByDimension: data.getCalculationInfo('stackedByDimension'),\n isStackedByIndex: data.getCalculationInfo('isStackedByIndex'),\n data: data,\n seriesModel: seriesModel\n };\n\n // If stacked on axis that do not support data stack.\n if (!stackInfo.stackedDimension\n || !(stackInfo.isStackedByIndex || stackInfo.stackedByDimension)\n ) {\n return;\n }\n\n stackInfoList.length && data.setCalculationInfo(\n 'stackedOnSeries', stackInfoList[stackInfoList.length - 1].seriesModel\n );\n\n stackInfoList.push(stackInfo);\n }\n });\n\n stackInfoMap.each(calculateStack);\n}\n\nfunction calculateStack(stackInfoList) {\n each(stackInfoList, function (targetStackInfo, idxInStack) {\n var resultVal = [];\n var resultNaN = [NaN, NaN];\n var dims = [targetStackInfo.stackResultDimension, targetStackInfo.stackedOverDimension];\n var targetData = targetStackInfo.data;\n var isStackedByIndex = targetStackInfo.isStackedByIndex;\n\n // Should not write on raw data, because stack series model list changes\n // depending on legend selection.\n var newData = targetData.map(dims, function (v0, v1, dataIndex) {\n var sum = targetData.get(targetStackInfo.stackedDimension, dataIndex);\n\n // Consider `connectNulls` of line area, if value is NaN, stackedOver\n // should also be NaN, to draw a appropriate belt area.\n if (isNaN(sum)) {\n return resultNaN;\n }\n\n var byValue;\n var stackedDataRawIndex;\n\n if (isStackedByIndex) {\n stackedDataRawIndex = targetData.getRawIndex(dataIndex);\n }\n else {\n byValue = targetData.get(targetStackInfo.stackedByDimension, dataIndex);\n }\n\n // If stackOver is NaN, chart view will render point on value start.\n var stackedOver = NaN;\n\n for (var j = idxInStack - 1; j >= 0; j--) {\n var stackInfo = stackInfoList[j];\n\n // Has been optimized by inverted indices on `stackedByDimension`.\n if (!isStackedByIndex) {\n stackedDataRawIndex = stackInfo.data.rawIndexOf(stackInfo.stackedByDimension, byValue);\n }\n\n if (stackedDataRawIndex >= 0) {\n var val = stackInfo.data.getByRawIndex(stackInfo.stackResultDimension, stackedDataRawIndex);\n\n // Considering positive stack, negative stack and empty data\n if ((sum >= 0 && val > 0) // Positive stack\n || (sum <= 0 && val < 0) // Negative stack\n ) {\n sum += val;\n stackedOver = val;\n break;\n }\n }\n }\n\n resultVal[0] = sum;\n resultVal[1] = stackedOver;\n\n return resultVal;\n });\n\n targetData.hostModel.setData(newData);\n // Update for consequent calculation\n targetStackInfo.data = newData;\n });\n}\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\n// TODO\n// ??? refactor? check the outer usage of data provider.\n// merge with defaultDimValueGetter?\n\nimport {__DEV__} from '../../config';\nimport {isTypedArray, extend, assert, each, isObject} from 'zrender/src/core/util';\nimport {getDataItemValue, isDataItemOption} from '../../util/model';\nimport {parseDate} from '../../util/number';\nimport Source from '../Source';\nimport {\n SOURCE_FORMAT_TYPED_ARRAY,\n SOURCE_FORMAT_ARRAY_ROWS,\n SOURCE_FORMAT_ORIGINAL,\n SOURCE_FORMAT_OBJECT_ROWS\n} from './sourceType';\n\n/**\n * If normal array used, mutable chunk size is supported.\n * If typed array used, chunk size must be fixed.\n */\nexport function DefaultDataProvider(source, dimSize) {\n if (!Source.isInstance(source)) {\n source = Source.seriesDataToSource(source);\n }\n this._source = source;\n\n var data = this._data = source.data;\n var sourceFormat = source.sourceFormat;\n\n // Typed array. TODO IE10+?\n if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {\n if (__DEV__) {\n if (dimSize == null) {\n throw new Error('Typed array data must specify dimension size');\n }\n }\n this._offset = 0;\n this._dimSize = dimSize;\n this._data = data;\n }\n\n var methods = providerMethods[\n sourceFormat === SOURCE_FORMAT_ARRAY_ROWS\n ? sourceFormat + '_' + source.seriesLayoutBy\n : sourceFormat\n ];\n\n if (__DEV__) {\n assert(methods, 'Invalide sourceFormat: ' + sourceFormat);\n }\n\n extend(this, methods);\n}\n\nvar providerProto = DefaultDataProvider.prototype;\n// If data is pure without style configuration\nproviderProto.pure = false;\n// If data is persistent and will not be released after use.\nproviderProto.persistent = true;\n\n// ???! FIXME legacy data provider do not has method getSource\nproviderProto.getSource = function () {\n return this._source;\n};\n\nvar providerMethods = {\n\n 'arrayRows_column': {\n pure: true,\n count: function () {\n return Math.max(0, this._data.length - this._source.startIndex);\n },\n getItem: function (idx) {\n return this._data[idx + this._source.startIndex];\n },\n appendData: appendDataSimply\n },\n\n 'arrayRows_row': {\n pure: true,\n count: function () {\n var row = this._data[0];\n return row ? Math.max(0, row.length - this._source.startIndex) : 0;\n },\n getItem: function (idx) {\n idx += this._source.startIndex;\n var item = [];\n var data = this._data;\n for (var i = 0; i < data.length; i++) {\n var row = data[i];\n item.push(row ? row[idx] : null);\n }\n return item;\n },\n appendData: function () {\n throw new Error('Do not support appendData when set seriesLayoutBy: \"row\".');\n }\n },\n\n 'objectRows': {\n pure: true,\n count: countSimply,\n getItem: getItemSimply,\n appendData: appendDataSimply\n },\n\n 'keyedColumns': {\n pure: true,\n count: function () {\n var dimName = this._source.dimensionsDefine[0].name;\n var col = this._data[dimName];\n return col ? col.length : 0;\n },\n getItem: function (idx) {\n var item = [];\n var dims = this._source.dimensionsDefine;\n for (var i = 0; i < dims.length; i++) {\n var col = this._data[dims[i].name];\n item.push(col ? col[idx] : null);\n }\n return item;\n },\n appendData: function (newData) {\n var data = this._data;\n each(newData, function (newCol, key) {\n var oldCol = data[key] || (data[key] = []);\n for (var i = 0; i < (newCol || []).length; i++) {\n oldCol.push(newCol[i]);\n }\n });\n }\n },\n\n 'original': {\n count: countSimply,\n getItem: getItemSimply,\n appendData: appendDataSimply\n },\n\n 'typedArray': {\n persistent: false,\n pure: true,\n count: function () {\n return this._data ? (this._data.length / this._dimSize) : 0;\n },\n getItem: function (idx, out) {\n idx = idx - this._offset;\n out = out || [];\n var offset = this._dimSize * idx;\n for (var i = 0; i < this._dimSize; i++) {\n out[i] = this._data[offset + i];\n }\n return out;\n },\n appendData: function (newData) {\n if (__DEV__) {\n assert(\n isTypedArray(newData),\n 'Added data must be TypedArray if data in initialization is TypedArray'\n );\n }\n\n this._data = newData;\n },\n\n // Clean self if data is already used.\n clean: function () {\n // PENDING\n this._offset += this.count();\n this._data = null;\n }\n }\n};\n\nfunction countSimply() {\n return this._data.length;\n}\nfunction getItemSimply(idx) {\n return this._data[idx];\n}\nfunction appendDataSimply(newData) {\n for (var i = 0; i < newData.length; i++) {\n this._data.push(newData[i]);\n }\n}\n\n\n\nvar rawValueGetters = {\n\n arrayRows: getRawValueSimply,\n\n objectRows: function (dataItem, dataIndex, dimIndex, dimName) {\n return dimIndex != null ? dataItem[dimName] : dataItem;\n },\n\n keyedColumns: getRawValueSimply,\n\n original: function (dataItem, dataIndex, dimIndex, dimName) {\n // FIXME\n // In some case (markpoint in geo (geo-map.html)), dataItem\n // is {coord: [...]}\n var value = getDataItemValue(dataItem);\n return (dimIndex == null || !(value instanceof Array))\n ? value\n : value[dimIndex];\n },\n\n typedArray: getRawValueSimply\n};\n\nfunction getRawValueSimply(dataItem, dataIndex, dimIndex, dimName) {\n return dimIndex != null ? dataItem[dimIndex] : dataItem;\n}\n\n\nexport var defaultDimValueGetters = {\n\n arrayRows: getDimValueSimply,\n\n objectRows: function (dataItem, dimName, dataIndex, dimIndex) {\n return converDataValue(dataItem[dimName], this._dimensionInfos[dimName]);\n },\n\n keyedColumns: getDimValueSimply,\n\n original: function (dataItem, dimName, dataIndex, dimIndex) {\n // Performance sensitive, do not use modelUtil.getDataItemValue.\n // If dataItem is an plain object with no value field, the var `value`\n // will be assigned with the object, but it will be tread correctly\n // in the `convertDataValue`.\n var value = dataItem && (dataItem.value == null ? dataItem : dataItem.value);\n\n // If any dataItem is like { value: 10 }\n if (!this._rawData.pure && isDataItemOption(dataItem)) {\n this.hasItemOption = true;\n }\n return converDataValue(\n (value instanceof Array)\n ? value[dimIndex]\n // If value is a single number or something else not array.\n : value,\n this._dimensionInfos[dimName]\n );\n },\n\n typedArray: function (dataItem, dimName, dataIndex, dimIndex) {\n return dataItem[dimIndex];\n }\n\n};\n\nfunction getDimValueSimply(dataItem, dimName, dataIndex, dimIndex) {\n return converDataValue(dataItem[dimIndex], this._dimensionInfos[dimName]);\n}\n\n/**\n * This helper method convert value in data.\n * @param {string|number|Date} value\n * @param {Object|string} [dimInfo] If string (like 'x'), dimType defaults 'number'.\n * If \"dimInfo.ordinalParseAndSave\", ordinal value can be parsed.\n */\nfunction converDataValue(value, dimInfo) {\n // Performance sensitive.\n var dimType = dimInfo && dimInfo.type;\n if (dimType === 'ordinal') {\n // If given value is a category string\n var ordinalMeta = dimInfo && dimInfo.ordinalMeta;\n return ordinalMeta\n ? ordinalMeta.parseAndCollect(value)\n : value;\n }\n\n if (dimType === 'time'\n // spead up when using timestamp\n && typeof value !== 'number'\n && value != null\n && value !== '-'\n ) {\n value = +parseDate(value);\n }\n\n // dimType defaults 'number'.\n // If dimType is not ordinal and value is null or undefined or NaN or '-',\n // parse to NaN.\n return (value == null || value === '')\n ? NaN\n // If string (like '-'), using '+' parse to NaN\n // If object, also parse to NaN\n : +value;\n}\n\n// ??? FIXME can these logic be more neat: getRawValue, getRawDataItem,\n// Consider persistent.\n// Caution: why use raw value to display on label or tooltip?\n// A reason is to avoid format. For example time value we do not know\n// how to format is expected. More over, if stack is used, calculated\n// value may be 0.91000000001, which have brings trouble to display.\n// TODO: consider how to treat null/undefined/NaN when display?\n/**\n * @param {module:echarts/data/List} data\n * @param {number} dataIndex\n * @param {string|number} [dim] dimName or dimIndex\n * @return {Array.<number>|string|number} can be null/undefined.\n */\nexport function retrieveRawValue(data, dataIndex, dim) {\n if (!data) {\n return;\n }\n\n // Consider data may be not persistent.\n var dataItem = data.getRawDataItem(dataIndex);\n\n if (dataItem == null) {\n return;\n }\n\n var sourceFormat = data.getProvider().getSource().sourceFormat;\n var dimName;\n var dimIndex;\n\n var dimInfo = data.getDimensionInfo(dim);\n if (dimInfo) {\n dimName = dimInfo.name;\n dimIndex = dimInfo.index;\n }\n\n return rawValueGetters[sourceFormat](dataItem, dataIndex, dimIndex, dimName);\n}\n\n/**\n * Compatible with some cases (in pie, map) like:\n * data: [{name: 'xx', value: 5, selected: true}, ...]\n * where only sourceFormat is 'original' and 'objectRows' supported.\n *\n * ??? TODO\n * Supported detail options in data item when using 'arrayRows'.\n *\n * @param {module:echarts/data/List} data\n * @param {number} dataIndex\n * @param {string} attr like 'selected'\n */\nexport function retrieveRawAttr(data, dataIndex, attr) {\n if (!data) {\n return;\n }\n\n var sourceFormat = data.getProvider().getSource().sourceFormat;\n\n if (sourceFormat !== SOURCE_FORMAT_ORIGINAL\n && sourceFormat !== SOURCE_FORMAT_OBJECT_ROWS\n ) {\n return;\n }\n\n var dataItem = data.getRawDataItem(dataIndex);\n if (sourceFormat === SOURCE_FORMAT_ORIGINAL && !isObject(dataItem)) {\n dataItem = null;\n }\n if (dataItem) {\n return dataItem[attr];\n }\n}\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport {retrieveRawValue} from '../../data/helper/dataProvider';\nimport {getTooltipMarker, formatTpl} from '../../util/format';\nimport { getTooltipRenderMode } from '../../util/model';\n\nvar DIMENSION_LABEL_REG = /\\{@(.+?)\\}/g;\n\n// PENDING A little ugly\nexport default {\n /**\n * Get params for formatter\n * @param {number} dataIndex\n * @param {string} [dataType]\n * @return {Object}\n */\n getDataParams: function (dataIndex, dataType) {\n var data = this.getData(dataType);\n var rawValue = this.getRawValue(dataIndex, dataType);\n var rawDataIndex = data.getRawIndex(dataIndex);\n var name = data.getName(dataIndex);\n var itemOpt = data.getRawDataItem(dataIndex);\n var color = data.getItemVisual(dataIndex, 'color');\n var borderColor = data.getItemVisual(dataIndex, 'borderColor');\n var tooltipModel = this.ecModel.getComponent('tooltip');\n var renderModeOption = tooltipModel && tooltipModel.get('renderMode');\n var renderMode = getTooltipRenderMode(renderModeOption);\n var mainType = this.mainType;\n var isSeries = mainType === 'series';\n var userOutput = data.userOutput;\n\n return {\n componentType: mainType,\n componentSubType: this.subType,\n componentIndex: this.componentIndex,\n seriesType: isSeries ? this.subType : null,\n seriesIndex: this.seriesIndex,\n seriesId: isSeries ? this.id : null,\n seriesName: isSeries ? this.name : null,\n name: name,\n dataIndex: rawDataIndex,\n data: itemOpt,\n dataType: dataType,\n value: rawValue,\n color: color,\n borderColor: borderColor,\n dimensionNames: userOutput ? userOutput.dimensionNames : null,\n encode: userOutput ? userOutput.encode : null,\n marker: getTooltipMarker({\n color: color,\n renderMode: renderMode\n }),\n\n // Param name list for mapping `a`, `b`, `c`, `d`, `e`\n $vars: ['seriesName', 'name', 'value']\n };\n },\n\n /**\n * Format label\n * @param {number} dataIndex\n * @param {string} [status='normal'] 'normal' or 'emphasis'\n * @param {string} [dataType]\n * @param {number} [dimIndex] Only used in some chart that\n * use formatter in different dimensions, like radar.\n * @param {string} [labelProp='label']\n * @return {string} If not formatter, return null/undefined\n */\n getFormattedLabel: function (dataIndex, status, dataType, dimIndex, labelProp) {\n status = status || 'normal';\n var data = this.getData(dataType);\n var itemModel = data.getItemModel(dataIndex);\n\n var params = this.getDataParams(dataIndex, dataType);\n if (dimIndex != null && (params.value instanceof Array)) {\n params.value = params.value[dimIndex];\n }\n\n var formatter = itemModel.get(\n status === 'normal'\n ? [labelProp || 'label', 'formatter']\n : [status, labelProp || 'label', 'formatter']\n );\n\n if (typeof formatter === 'function') {\n params.status = status;\n params.dimensionIndex = dimIndex;\n return formatter(params);\n }\n else if (typeof formatter === 'string') {\n var str = formatTpl(formatter, params);\n\n // Support 'aaa{@[3]}bbb{@product}ccc'.\n // Do not support '}' in dim name util have to.\n return str.replace(DIMENSION_LABEL_REG, function (origin, dim) {\n var len = dim.length;\n if (dim.charAt(0) === '[' && dim.charAt(len - 1) === ']') {\n dim = +dim.slice(1, len - 1); // Also: '[]' => 0\n }\n return retrieveRawValue(data, dataIndex, dim);\n });\n }\n },\n\n /**\n * Get raw value in option\n * @param {number} idx\n * @param {string} [dataType]\n * @return {Array|number|string}\n */\n getRawValue: function (idx, dataType) {\n return retrieveRawValue(this.getData(dataType), idx);\n },\n\n /**\n * Should be implemented.\n * @param {number} dataIndex\n * @param {boolean} [multipleSeries=false]\n * @param {number} [dataType]\n * @return {string} tooltip string\n */\n formatTooltip: function () {\n // Empty function\n }\n};\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport {assert, isArray} from 'zrender/src/core/util';\nimport { __DEV__ } from '../config';\n\n/**\n * @param {Object} define\n * @return See the return of `createTask`.\n */\nexport function createTask(define) {\n return new Task(define);\n}\n\n/**\n * @constructor\n * @param {Object} define\n * @param {Function} define.reset Custom reset\n * @param {Function} [define.plan] Returns 'reset' indicate reset immediately.\n * @param {Function} [define.count] count is used to determin data task.\n * @param {Function} [define.onDirty] count is used to determin data task.\n */\nfunction Task(define) {\n define = define || {};\n\n this._reset = define.reset;\n this._plan = define.plan;\n this._count = define.count;\n this._onDirty = define.onDirty;\n\n this._dirty = true;\n\n // Context must be specified implicitly, to\n // avoid miss update context when model changed.\n this.context;\n}\n\nvar taskProto = Task.prototype;\n\n/**\n * @param {Object} performArgs\n * @param {number} [performArgs.step] Specified step.\n * @param {number} [performArgs.skip] Skip customer perform call.\n * @param {number} [performArgs.modBy] Sampling window size.\n * @param {number} [performArgs.modDataCount] Sampling count.\n */\ntaskProto.perform = function (performArgs) {\n var upTask = this._upstream;\n var skip = performArgs && performArgs.skip;\n\n // TODO some refactor.\n // Pull data. Must pull data each time, because context.data\n // may be updated by Series.setData.\n if (this._dirty && upTask) {\n var context = this.context;\n context.data = context.outputData = upTask.context.outputData;\n }\n\n if (this.__pipeline) {\n this.__pipeline.currentTask = this;\n }\n\n var planResult;\n if (this._plan && !skip) {\n planResult = this._plan(this.context);\n }\n\n // Support sharding by mod, which changes the render sequence and makes the rendered graphic\n // elements uniformed distributed when progress, especially when moving or zooming.\n var lastModBy = normalizeModBy(this._modBy);\n var lastModDataCount = this._modDataCount || 0;\n var modBy = normalizeModBy(performArgs && performArgs.modBy);\n var modDataCount = performArgs && performArgs.modDataCount || 0;\n if (lastModBy !== modBy || lastModDataCount !== modDataCount) {\n planResult = 'reset';\n }\n\n function normalizeModBy(val) {\n !(val >= 1) && (val = 1); // jshint ignore:line\n return val;\n }\n\n var forceFirstProgress;\n if (this._dirty || planResult === 'reset') {\n this._dirty = false;\n forceFirstProgress = reset(this, skip);\n }\n\n this._modBy = modBy;\n this._modDataCount = modDataCount;\n\n var step = performArgs && performArgs.step;\n\n if (upTask) {\n\n if (__DEV__) {\n assert(upTask._outputDueEnd != null);\n }\n this._dueEnd = upTask._outputDueEnd;\n }\n // DataTask or overallTask\n else {\n if (__DEV__) {\n assert(!this._progress || this._count);\n }\n this._dueEnd = this._count ? this._count(this.context) : Infinity;\n }\n\n // Note: Stubs, that its host overall task let it has progress, has progress.\n // If no progress, pass index from upstream to downstream each time plan called.\n if (this._progress) {\n var start = this._dueIndex;\n var end = Math.min(\n step != null ? this._dueIndex + step : Infinity,\n this._dueEnd\n );\n\n if (!skip && (forceFirstProgress || start < end)) {\n var progress = this._progress;\n if (isArray(progress)) {\n for (var i = 0; i < progress.length; i++) {\n doProgress(this, progress[i], start, end, modBy, modDataCount);\n }\n }\n else {\n doProgress(this, progress, start, end, modBy, modDataCount);\n }\n }\n\n this._dueIndex = end;\n // If no `outputDueEnd`, assume that output data and\n // input data is the same, so use `dueIndex` as `outputDueEnd`.\n var outputDueEnd = this._settedOutputEnd != null\n ? this._settedOutputEnd : end;\n\n if (__DEV__) {\n // ??? Can not rollback.\n assert(outputDueEnd >= this._outputDueEnd);\n }\n\n this._outputDueEnd = outputDueEnd;\n }\n else {\n // (1) Some overall task has no progress.\n // (2) Stubs, that its host overall task do not let it has progress, has no progress.\n // This should always be performed so it can be passed to downstream.\n this._dueIndex = this._outputDueEnd = this._settedOutputEnd != null\n ? this._settedOutputEnd : this._dueEnd;\n }\n\n return this.unfinished();\n};\n\nvar iterator = (function () {\n\n var end;\n var current;\n var modBy;\n var modDataCount;\n var winCount;\n\n var it = {\n reset: function (s, e, sStep, sCount) {\n current = s;\n end = e;\n\n modBy = sStep;\n modDataCount = sCount;\n winCount = Math.ceil(modDataCount / modBy);\n\n it.next = (modBy > 1 && modDataCount > 0) ? modNext : sequentialNext;\n }\n };\n\n return it;\n\n function sequentialNext() {\n return current < end ? current++ : null;\n }\n\n function modNext() {\n var dataIndex = (current % winCount) * modBy + Math.ceil(current / winCount);\n var result = current >= end\n ? null\n : dataIndex < modDataCount\n ? dataIndex\n // If modDataCount is smaller than data.count() (consider `appendData` case),\n // Use normal linear rendering mode.\n : current;\n current++;\n return result;\n }\n})();\n\ntaskProto.dirty = function () {\n this._dirty = true;\n this._onDirty && this._onDirty(this.context);\n};\n\nfunction doProgress(taskIns, progress, start, end, modBy, modDataCount) {\n iterator.reset(start, end, modBy, modDataCount);\n taskIns._callingProgress = progress;\n taskIns._callingProgress({\n start: start, end: end, count: end - start, next: iterator.next\n }, taskIns.context);\n}\n\nfunction reset(taskIns, skip) {\n taskIns._dueIndex = taskIns._outputDueEnd = taskIns._dueEnd = 0;\n taskIns._settedOutputEnd = null;\n\n var progress;\n var forceFirstProgress;\n\n if (!skip && taskIns._reset) {\n progress = taskIns._reset(taskIns.context);\n if (progress && progress.progress) {\n forceFirstProgress = progress.forceFirstProgress;\n progress = progress.progress;\n }\n // To simplify no progress checking, array must has item.\n if (isArray(progress) && !progress.length) {\n progress = null;\n }\n }\n\n taskIns._progress = progress;\n taskIns._modBy = taskIns._modDataCount = null;\n\n var downstream = taskIns._downstream;\n downstream && downstream.dirty();\n\n return forceFirstProgress;\n}\n\n/**\n * @return {boolean}\n */\ntaskProto.unfinished = function () {\n return this._progress && this._dueIndex < this._dueEnd;\n};\n\n/**\n * @param {Object} downTask The downstream task.\n * @return {Object} The downstream task.\n */\ntaskProto.pipe = function (downTask) {\n if (__DEV__) {\n assert(downTask && !downTask._disposed && downTask !== this);\n }\n\n // If already downstream, do not dirty downTask.\n if (this._downstream !== downTask || this._dirty) {\n this._downstream = downTask;\n downTask._upstream = this;\n downTask.dirty();\n }\n};\n\ntaskProto.dispose = function () {\n if (this._disposed) {\n return;\n }\n\n this._upstream && (this._upstream._downstream = null);\n this._downstream && (this._downstream._upstream = null);\n\n this._dirty = false;\n this._disposed = true;\n};\n\ntaskProto.getUpstream = function () {\n return this._upstream;\n};\n\ntaskProto.getDownstream = function () {\n return this._downstream;\n};\n\ntaskProto.setOutputEnd = function (end) {\n // This only happend in dataTask, dataZoom, map, currently.\n // where dataZoom do not set end each time, but only set\n // when reset. So we should record the setted end, in case\n // that the stub of dataZoom perform again and earse the\n // setted end by upstream.\n this._outputDueEnd = this._settedOutputEnd = end;\n};\n\n\n///////////////////////////////////////////////////////////\n// For stream debug (Should be commented out after used!)\n// Usage: printTask(this, 'begin');\n// Usage: printTask(this, null, {someExtraProp});\n// function printTask(task, prefix, extra) {\n// window.ecTaskUID == null && (window.ecTaskUID = 0);\n// task.uidDebug == null && (task.uidDebug = `task_${window.ecTaskUID++}`);\n// task.agent && task.agent.uidDebug == null && (task.agent.uidDebug = `task_${window.ecTaskUID++}`);\n// var props = [];\n// if (task.__pipeline) {\n// var val = `${task.__idxInPipeline}/${task.__pipeline.tail.__idxInPipeline} ${task.agent ? '(stub)' : ''}`;\n// props.push({text: 'idx', value: val});\n// } else {\n// var stubCount = 0;\n// task.agentStubMap.each(() => stubCount++);\n// props.push({text: 'idx', value: `overall (stubs: ${stubCount})`});\n// }\n// props.push({text: 'uid', value: task.uidDebug});\n// if (task.__pipeline) {\n// props.push({text: 'pid', value: task.__pipeline.id});\n// task.agent && props.push(\n// {text: 'stubFor', value: task.agent.uidDebug}\n// );\n// }\n// props.push(\n// {text: 'dirty', value: task._dirty},\n// {text: 'dueIndex', value: task._dueIndex},\n// {text: 'dueEnd', value: task._dueEnd},\n// {text: 'outputDueEnd', value: task._outputDueEnd}\n// );\n// if (extra) {\n// Object.keys(extra).forEach(key => {\n// props.push({text: key, value: extra[key]});\n// });\n// }\n// var args = ['color: blue'];\n// var msg = `%c[${prefix || 'T'}] %c` + props.map(item => (\n// args.push('color: black', 'color: red'),\n// `${item.text}: %c${item.value}`\n// )).join('%c, ');\n// console.log.apply(console, [msg].concat(args));\n// // console.log(this);\n// }\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport {__DEV__} from '../config';\nimport * as zrUtil from 'zrender/src/core/util';\nimport env from 'zrender/src/core/env';\nimport {\n formatTime,\n encodeHTML,\n addCommas,\n getTooltipMarker\n} from '../util/format';\nimport * as modelUtil from '../util/model';\nimport ComponentModel from './Component';\nimport colorPaletteMixin from './mixin/colorPalette';\nimport dataFormatMixin from '../model/mixin/dataFormat';\nimport {\n getLayoutParams,\n mergeLayoutParam\n} from '../util/layout';\nimport {createTask} from '../stream/task';\nimport {\n prepareSource,\n getSource\n} from '../data/helper/sourceHelper';\nimport {retrieveRawValue} from '../data/helper/dataProvider';\n\nvar inner = modelUtil.makeInner();\n\nvar SeriesModel = ComponentModel.extend({\n\n type: 'series.__base__',\n\n /**\n * @readOnly\n */\n seriesIndex: 0,\n\n // coodinateSystem will be injected in the echarts/CoordinateSystem\n coordinateSystem: null,\n\n /**\n * @type {Object}\n * @protected\n */\n defaultOption: null,\n\n /**\n * legend visual provider to the legend component\n * @type {Object}\n */\n // PENDING\n legendVisualProvider: null,\n\n /**\n * Access path of color for visual\n */\n visualColorAccessPath: 'itemStyle.color',\n\n /**\n * Access path of borderColor for visual\n */\n visualBorderColorAccessPath: 'itemStyle.borderColor',\n\n /**\n * Support merge layout params.\n * Only support 'box' now (left/right/top/bottom/width/height).\n * @type {string|Object} Object can be {ignoreSize: true}\n * @readOnly\n */\n layoutMode: null,\n\n init: function (option, parentModel, ecModel, extraOpt) {\n\n /**\n * @type {number}\n * @readOnly\n */\n this.seriesIndex = this.componentIndex;\n\n this.dataTask = createTask({\n count: dataTaskCount,\n reset: dataTaskReset\n });\n this.dataTask.context = {model: this};\n\n this.mergeDefaultAndTheme(option, ecModel);\n\n prepareSource(this);\n\n\n var data = this.getInitialData(option, ecModel);\n wrapData(data, this);\n this.dataTask.context.data = data;\n\n if (__DEV__) {\n zrUtil.assert(data, 'getInitialData returned invalid data.');\n }\n\n /**\n * @type {module:echarts/data/List|module:echarts/data/Tree|module:echarts/data/Graph}\n * @private\n */\n inner(this).dataBeforeProcessed = data;\n\n // If we reverse the order (make data firstly, and then make\n // dataBeforeProcessed by cloneShallow), cloneShallow will\n // cause data.graph.data !== data when using\n // module:echarts/data/Graph or module:echarts/data/Tree.\n // See module:echarts/data/helper/linkList\n\n // Theoretically, it is unreasonable to call `seriesModel.getData()` in the model\n // init or merge stage, because the data can be restored. So we do not `restoreData`\n // and `setData` here, which forbids calling `seriesModel.getData()` in this stage.\n // Call `seriesModel.getRawData()` instead.\n // this.restoreData();\n\n autoSeriesName(this);\n },\n\n /**\n * Util for merge default and theme to option\n * @param {Object} option\n * @param {module:echarts/model/Global} ecModel\n */\n mergeDefaultAndTheme: function (option, ecModel) {\n var layoutMode = this.layoutMode;\n var inputPositionParams = layoutMode\n ? getLayoutParams(option) : {};\n\n // Backward compat: using subType on theme.\n // But if name duplicate between series subType\n // (for example: parallel) add component mainType,\n // add suffix 'Series'.\n var themeSubType = this.subType;\n if (ComponentModel.hasClass(themeSubType)) {\n themeSubType += 'Series';\n }\n zrUtil.merge(\n option,\n ecModel.getTheme().get(this.subType)\n );\n zrUtil.merge(option, this.getDefaultOption());\n\n // Default label emphasis `show`\n modelUtil.defaultEmphasis(option, 'label', ['show']);\n\n this.fillDataTextStyle(option.data);\n\n if (layoutMode) {\n mergeLayoutParam(option, inputPositionParams, layoutMode);\n }\n },\n\n mergeOption: function (newSeriesOption, ecModel) {\n // this.settingTask.dirty();\n\n newSeriesOption = zrUtil.merge(this.option, newSeriesOption, true);\n this.fillDataTextStyle(newSeriesOption.data);\n\n var layoutMode = this.layoutMode;\n if (layoutMode) {\n mergeLayoutParam(this.option, newSeriesOption, layoutMode);\n }\n\n prepareSource(this);\n\n var data = this.getInitialData(newSeriesOption, ecModel);\n wrapData(data, this);\n this.dataTask.dirty();\n this.dataTask.context.data = data;\n\n inner(this).dataBeforeProcessed = data;\n\n autoSeriesName(this);\n },\n\n fillDataTextStyle: function (data) {\n // Default data label emphasis `show`\n // FIXME Tree structure data ?\n // FIXME Performance ?\n if (data && !zrUtil.isTypedArray(data)) {\n var props = ['show'];\n for (var i = 0; i < data.length; i++) {\n if (data[i] && data[i].label) {\n modelUtil.defaultEmphasis(data[i], 'label', props);\n }\n }\n }\n },\n\n /**\n * Init a data structure from data related option in series\n * Must be overwritten\n */\n getInitialData: function () {},\n\n /**\n * Append data to list\n * @param {Object} params\n * @param {Array|TypedArray} params.data\n */\n appendData: function (params) {\n // FIXME ???\n // (1) If data from dataset, forbidden append.\n // (2) support append data of dataset.\n var data = this.getRawData();\n data.appendData(params.data);\n },\n\n /**\n * Consider some method like `filter`, `map` need make new data,\n * We should make sure that `seriesModel.getData()` get correct\n * data in the stream procedure. So we fetch data from upstream\n * each time `task.perform` called.\n * @param {string} [dataType]\n * @return {module:echarts/data/List}\n */\n getData: function (dataType) {\n var task = getCurrentTask(this);\n if (task) {\n var data = task.context.data;\n return dataType == null ? data : data.getLinkedData(dataType);\n }\n else {\n // When series is not alive (that may happen when click toolbox\n // restore or setOption with not merge mode), series data may\n // be still need to judge animation or something when graphic\n // elements want to know whether fade out.\n return inner(this).data;\n }\n },\n\n /**\n * @param {module:echarts/data/List} data\n */\n setData: function (data) {\n var task = getCurrentTask(this);\n if (task) {\n var context = task.context;\n // Consider case: filter, data sample.\n if (context.data !== data && task.modifyOutputEnd) {\n task.setOutputEnd(data.count());\n }\n context.outputData = data;\n // Caution: setData should update context.data,\n // Because getData may be called multiply in a\n // single stage and expect to get the data just\n // set. (For example, AxisProxy, x y both call\n // getData and setDate sequentially).\n // So the context.data should be fetched from\n // upstream each time when a stage starts to be\n // performed.\n if (task !== this.dataTask) {\n context.data = data;\n }\n }\n inner(this).data = data;\n },\n\n /**\n * @see {module:echarts/data/helper/sourceHelper#getSource}\n * @return {module:echarts/data/Source} source\n */\n getSource: function () {\n return getSource(this);\n },\n\n /**\n * Get data before processed\n * @return {module:echarts/data/List}\n */\n getRawData: function () {\n return inner(this).dataBeforeProcessed;\n },\n\n /**\n * Get base axis if has coordinate system and has axis.\n * By default use coordSys.getBaseAxis();\n * Can be overrided for some chart.\n * @return {type} description\n */\n getBaseAxis: function () {\n var coordSys = this.coordinateSystem;\n return coordSys && coordSys.getBaseAxis && coordSys.getBaseAxis();\n },\n\n // FIXME\n /**\n * Default tooltip formatter\n *\n * @param {number} dataIndex\n * @param {boolean} [multipleSeries=false]\n * @param {number} [dataType]\n * @param {string} [renderMode='html'] valid values: 'html' and 'richText'.\n * 'html' is used for rendering tooltip in extra DOM form, and the result\n * string is used as DOM HTML content.\n * 'richText' is used for rendering tooltip in rich text form, for those where\n * DOM operation is not supported.\n * @return {Object} formatted tooltip with `html` and `markers`\n */\n formatTooltip: function (dataIndex, multipleSeries, dataType, renderMode) {\n\n var series = this;\n renderMode = renderMode || 'html';\n var newLine = renderMode === 'html' ? '<br/>' : '\\n';\n var isRichText = renderMode === 'richText';\n var markers = {};\n var markerId = 0;\n\n function formatArrayValue(value) {\n // ??? TODO refactor these logic.\n // check: category-no-encode-has-axis-data in dataset.html\n var vertially = zrUtil.reduce(value, function (vertially, val, idx) {\n var dimItem = data.getDimensionInfo(idx);\n return vertially |= dimItem && dimItem.tooltip !== false && dimItem.displayName != null;\n }, 0);\n\n var result = [];\n\n tooltipDims.length\n ? zrUtil.each(tooltipDims, function (dim) {\n setEachItem(retrieveRawValue(data, dataIndex, dim), dim);\n })\n // By default, all dims is used on tooltip.\n : zrUtil.each(value, setEachItem);\n\n function setEachItem(val, dim) {\n var dimInfo = data.getDimensionInfo(dim);\n // If `dimInfo.tooltip` is not set, show tooltip.\n if (!dimInfo || dimInfo.otherDims.tooltip === false) {\n return;\n }\n var dimType = dimInfo.type;\n var markName = 'sub' + series.seriesIndex + 'at' + markerId;\n var dimHead = getTooltipMarker({\n color: color,\n type: 'subItem',\n renderMode: renderMode,\n markerId: markName\n });\n\n var dimHeadStr = typeof dimHead === 'string' ? dimHead : dimHead.content;\n var valStr = (vertially\n ? dimHeadStr + encodeHTML(dimInfo.displayName || '-') + ': '\n : ''\n )\n // FIXME should not format time for raw data?\n + encodeHTML(dimType === 'ordinal'\n ? val + ''\n : dimType === 'time'\n ? (multipleSeries ? '' : formatTime('yyyy/MM/dd hh:mm:ss', val))\n : addCommas(val)\n );\n valStr && result.push(valStr);\n\n if (isRichText) {\n markers[markName] = color;\n ++markerId;\n }\n }\n\n var newLine = vertially ? (isRichText ? '\\n' : '<br/>') : '';\n var content = newLine + result.join(newLine || ', ');\n return {\n renderMode: renderMode,\n content: content,\n style: markers\n };\n }\n\n function formatSingleValue(val) {\n // return encodeHTML(addCommas(val));\n return {\n renderMode: renderMode,\n content: encodeHTML(addCommas(val)),\n style: markers\n };\n }\n\n var data = this.getData();\n var tooltipDims = data.mapDimension('defaultedTooltip', true);\n var tooltipDimLen = tooltipDims.length;\n var value = this.getRawValue(dataIndex);\n var isValueArr = zrUtil.isArray(value);\n\n var color = data.getItemVisual(dataIndex, 'color');\n if (zrUtil.isObject(color) && color.colorStops) {\n color = (color.colorStops[0] || {}).color;\n }\n color = color || 'transparent';\n\n // Complicated rule for pretty tooltip.\n var formattedValue = (tooltipDimLen > 1 || (isValueArr && !tooltipDimLen))\n ? formatArrayValue(value)\n : tooltipDimLen\n ? formatSingleValue(retrieveRawValue(data, dataIndex, tooltipDims[0]))\n : formatSingleValue(isValueArr ? value[0] : value);\n var content = formattedValue.content;\n\n var markName = series.seriesIndex + 'at' + markerId;\n var colorEl = getTooltipMarker({\n color: color,\n type: 'item',\n renderMode: renderMode,\n markerId: markName\n });\n markers[markName] = color;\n ++markerId;\n\n var name = data.getName(dataIndex);\n\n var seriesName = this.name;\n if (!modelUtil.isNameSpecified(this)) {\n seriesName = '';\n }\n seriesName = seriesName\n ? encodeHTML(seriesName) + (!multipleSeries ? newLine : ': ')\n : '';\n\n var colorStr = typeof colorEl === 'string' ? colorEl : colorEl.content;\n var html = !multipleSeries\n ? seriesName + colorStr\n + (name\n ? encodeHTML(name) + ': ' + content\n : content\n )\n : colorStr + seriesName + content;\n\n return {\n html: html,\n markers: markers\n };\n },\n\n /**\n * @return {boolean}\n */\n isAnimationEnabled: function () {\n if (env.node) {\n return false;\n }\n\n var animationEnabled = this.getShallow('animation');\n if (animationEnabled) {\n if (this.getData().count() > this.getShallow('animationThreshold')) {\n animationEnabled = false;\n }\n }\n return animationEnabled;\n },\n\n restoreData: function () {\n this.dataTask.dirty();\n },\n\n getColorFromPalette: function (name, scope, requestColorNum) {\n var ecModel = this.ecModel;\n // PENDING\n var color = colorPaletteMixin.getColorFromPalette.call(this, name, scope, requestColorNum);\n if (!color) {\n color = ecModel.getColorFromPalette(name, scope, requestColorNum);\n }\n return color;\n },\n\n /**\n * Use `data.mapDimension(coordDim, true)` instead.\n * @deprecated\n */\n coordDimToDataDim: function (coordDim) {\n return this.getRawData().mapDimension(coordDim, true);\n },\n\n /**\n * Get progressive rendering count each step\n * @return {number}\n */\n getProgressive: function () {\n return this.get('progressive');\n },\n\n /**\n * Get progressive rendering count each step\n * @return {number}\n */\n getProgressiveThreshold: function () {\n return this.get('progressiveThreshold');\n },\n\n /**\n * Get data indices for show tooltip content. See tooltip.\n * @abstract\n * @param {Array.<string>|string} dim\n * @param {Array.<number>} value\n * @param {module:echarts/coord/single/SingleAxis} baseAxis\n * @return {Object} {dataIndices, nestestValue}.\n */\n getAxisTooltipData: null,\n\n /**\n * See tooltip.\n * @abstract\n * @param {number} dataIndex\n * @return {Array.<number>} Point of tooltip. null/undefined can be returned.\n */\n getTooltipPosition: null,\n\n /**\n * @see {module:echarts/stream/Scheduler}\n */\n pipeTask: null,\n\n /**\n * Convinient for override in extended class.\n * @protected\n * @type {Function}\n */\n preventIncremental: null,\n\n /**\n * @public\n * @readOnly\n * @type {Object}\n */\n pipelineContext: null\n\n});\n\n\nzrUtil.mixin(SeriesModel, dataFormatMixin);\nzrUtil.mixin(SeriesModel, colorPaletteMixin);\n\n/**\n * MUST be called after `prepareSource` called\n * Here we need to make auto series, especially for auto legend. But we\n * do not modify series.name in option to avoid side effects.\n */\nfunction autoSeriesName(seriesModel) {\n // User specified name has higher priority, otherwise it may cause\n // series can not be queried unexpectedly.\n var name = seriesModel.name;\n if (!modelUtil.isNameSpecified(seriesModel)) {\n seriesModel.name = getSeriesAutoName(seriesModel) || name;\n }\n}\n\nfunction getSeriesAutoName(seriesModel) {\n var data = seriesModel.getRawData();\n var dataDims = data.mapDimension('seriesName', true);\n var nameArr = [];\n zrUtil.each(dataDims, function (dataDim) {\n var dimInfo = data.getDimensionInfo(dataDim);\n dimInfo.displayName && nameArr.push(dimInfo.displayName);\n });\n return nameArr.join(' ');\n}\n\nfunction dataTaskCount(context) {\n return context.model.getRawData().count();\n}\n\nfunction dataTaskReset(context) {\n var seriesModel = context.model;\n seriesModel.setData(seriesModel.getRawData().cloneShallow());\n return dataTaskProgress;\n}\n\nfunction dataTaskProgress(param, context) {\n // Avoid repead cloneShallow when data just created in reset.\n if (context.outputData && param.end > context.outputData.count()) {\n context.model.getRawData().cloneShallow(context.outputData);\n }\n}\n\n// TODO refactor\nfunction wrapData(data, seriesModel) {\n zrUtil.each(data.CHANGABLE_METHODS, function (methodName) {\n data.wrapMethod(methodName, zrUtil.curry(onDataSelfChange, seriesModel));\n });\n}\n\nfunction onDataSelfChange(seriesModel) {\n var task = getCurrentTask(seriesModel);\n if (task) {\n // Consider case: filter, selectRange\n task.setOutputEnd(this.count());\n }\n}\n\nfunction getCurrentTask(seriesModel) {\n var scheduler = (seriesModel.ecModel || {}).scheduler;\n var pipeline = scheduler && scheduler.getPipeline(seriesModel.uid);\n\n if (pipeline) {\n // When pipline finished, the currrentTask keep the last\n // task (renderTask).\n var task = pipeline.currentTask;\n if (task) {\n var agentStubMap = task.agentStubMap;\n if (agentStubMap) {\n task = agentStubMap.get(seriesModel.uid);\n }\n }\n return task;\n }\n}\n\nexport default SeriesModel;\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport Group from 'zrender/src/container/Group';\nimport * as componentUtil from '../util/component';\nimport * as clazzUtil from '../util/clazz';\n\nvar Component = function () {\n /**\n * @type {module:zrender/container/Group}\n * @readOnly\n */\n this.group = new Group();\n\n /**\n * @type {string}\n * @readOnly\n */\n this.uid = componentUtil.getUID('viewComponent');\n};\n\nComponent.prototype = {\n\n constructor: Component,\n\n init: function (ecModel, api) {},\n\n render: function (componentModel, ecModel, api, payload) {},\n\n dispose: function () {},\n\n /**\n * @param {string} eventType\n * @param {Object} query\n * @param {module:zrender/Element} targetEl\n * @param {Object} packedEvent\n * @return {boolen} Pass only when return `true`.\n */\n filterForExposedEvent: null\n\n};\n\nvar componentProto = Component.prototype;\ncomponentProto.updateView =\n componentProto.updateLayout =\n componentProto.updateVisual =\n function (seriesModel, ecModel, api, payload) {\n // Do nothing;\n };\n// Enable Component.extend.\nclazzUtil.enableClassExtend(Component);\n\n// Enable capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.\nclazzUtil.enableClassManagement(Component, {registerWhenExtend: true});\n\nexport default Component;","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport {makeInner} from '../../util/model';\n\n/**\n * @return {string} If large mode changed, return string 'reset';\n */\nexport default function () {\n var inner = makeInner();\n\n return function (seriesModel) {\n var fields = inner(seriesModel);\n var pipelineContext = seriesModel.pipelineContext;\n\n var originalLarge = fields.large;\n var originalProgressive = fields.progressiveRender;\n\n // FIXME: if the planner works on a filtered series, `pipelineContext` does not\n // exists. See #11611 . Probably we need to modify this structure, see the comment\n // on `performRawSeries` in `Schedular.js`.\n var large = fields.large = pipelineContext && pipelineContext.large;\n var progressive = fields.progressiveRender = pipelineContext && pipelineContext.progressiveRender;\n\n return !!((originalLarge ^ large) || (originalProgressive ^ progressive)) && 'reset';\n };\n}\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport {each} from 'zrender/src/core/util';\nimport Group from 'zrender/src/container/Group';\nimport * as componentUtil from '../util/component';\nimport * as clazzUtil from '../util/clazz';\nimport * as modelUtil from '../util/model';\nimport * as graphicUtil from '../util/graphic';\nimport {createTask} from '../stream/task';\nimport createRenderPlanner from '../chart/helper/createRenderPlanner';\n\nvar inner = modelUtil.makeInner();\nvar renderPlanner = createRenderPlanner();\n\nfunction Chart() {\n\n /**\n * @type {module:zrender/container/Group}\n * @readOnly\n */\n this.group = new Group();\n\n /**\n * @type {string}\n * @readOnly\n */\n this.uid = componentUtil.getUID('viewChart');\n\n this.renderTask = createTask({\n plan: renderTaskPlan,\n reset: renderTaskReset\n });\n this.renderTask.context = {view: this};\n}\n\nChart.prototype = {\n\n type: 'chart',\n\n /**\n * Init the chart.\n * @param {module:echarts/model/Global} ecModel\n * @param {module:echarts/ExtensionAPI} api\n */\n init: function (ecModel, api) {},\n\n /**\n * Render the chart.\n * @param {module:echarts/model/Series} seriesModel\n * @param {module:echarts/model/Global} ecModel\n * @param {module:echarts/ExtensionAPI} api\n * @param {Object} payload\n */\n render: function (seriesModel, ecModel, api, payload) {},\n\n /**\n * Highlight series or specified data item.\n * @param {module:echarts/model/Series} seriesModel\n * @param {module:echarts/model/Global} ecModel\n * @param {module:echarts/ExtensionAPI} api\n * @param {Object} payload\n */\n highlight: function (seriesModel, ecModel, api, payload) {\n toggleHighlight(seriesModel.getData(), payload, 'emphasis');\n },\n\n /**\n * Downplay series or specified data item.\n * @param {module:echarts/model/Series} seriesModel\n * @param {module:echarts/model/Global} ecModel\n * @param {module:echarts/ExtensionAPI} api\n * @param {Object} payload\n */\n downplay: function (seriesModel, ecModel, api, payload) {\n toggleHighlight(seriesModel.getData(), payload, 'normal');\n },\n\n /**\n * Remove self.\n * @param {module:echarts/model/Global} ecModel\n * @param {module:echarts/ExtensionAPI} api\n */\n remove: function (ecModel, api) {\n this.group.removeAll();\n },\n\n /**\n * Dispose self.\n * @param {module:echarts/model/Global} ecModel\n * @param {module:echarts/ExtensionAPI} api\n */\n dispose: function () {},\n\n /**\n * Rendering preparation in progressive mode.\n * @param {module:echarts/model/Series} seriesModel\n * @param {module:echarts/model/Global} ecModel\n * @param {module:echarts/ExtensionAPI} api\n * @param {Object} payload\n */\n incrementalPrepareRender: null,\n\n /**\n * Render in progressive mode.\n * @param {Object} params See taskParams in `stream/task.js`\n * @param {module:echarts/model/Series} seriesModel\n * @param {module:echarts/model/Global} ecModel\n * @param {module:echarts/ExtensionAPI} api\n * @param {Object} payload\n */\n incrementalRender: null,\n\n /**\n * Update transform directly.\n * @param {module:echarts/model/Series} seriesModel\n * @param {module:echarts/model/Global} ecModel\n * @param {module:echarts/ExtensionAPI} api\n * @param {Object} payload\n * @return {Object} {update: true}\n */\n updateTransform: null,\n\n /**\n * The view contains the given point.\n * @interface\n * @param {Array.<number>} point\n * @return {boolean}\n */\n // containPoint: function () {}\n\n /**\n * @param {string} eventType\n * @param {Object} query\n * @param {module:zrender/Element} targetEl\n * @param {Object} packedEvent\n * @return {boolen} Pass only when return `true`.\n */\n filterForExposedEvent: null\n\n};\n\nvar chartProto = Chart.prototype;\nchartProto.updateView =\nchartProto.updateLayout =\nchartProto.updateVisual =\n function (seriesModel, ecModel, api, payload) {\n this.render(seriesModel, ecModel, api, payload);\n };\n\n/**\n * Set state of single element\n * @param {module:zrender/Element} el\n * @param {string} state 'normal'|'emphasis'\n * @param {number} highlightDigit\n */\nfunction elSetState(el, state, highlightDigit) {\n if (el) {\n el.trigger(state, highlightDigit);\n if (el.isGroup\n // Simple optimize.\n && !graphicUtil.isHighDownDispatcher(el)\n ) {\n for (var i = 0, len = el.childCount(); i < len; i++) {\n elSetState(el.childAt(i), state, highlightDigit);\n }\n }\n }\n}\n\n/**\n * @param {module:echarts/data/List} data\n * @param {Object} payload\n * @param {string} state 'normal'|'emphasis'\n */\nfunction toggleHighlight(data, payload, state) {\n var dataIndex = modelUtil.queryDataIndex(data, payload);\n\n var highlightDigit = (payload && payload.highlightKey != null)\n ? graphicUtil.getHighlightDigit(payload.highlightKey)\n : null;\n\n if (dataIndex != null) {\n each(modelUtil.normalizeToArray(dataIndex), function (dataIdx) {\n elSetState(data.getItemGraphicEl(dataIdx), state, highlightDigit);\n });\n }\n else {\n data.eachItemGraphicEl(function (el) {\n elSetState(el, state, highlightDigit);\n });\n }\n}\n\n// Enable Chart.extend.\nclazzUtil.enableClassExtend(Chart, ['dispose']);\n\n// Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.\nclazzUtil.enableClassManagement(Chart, {registerWhenExtend: true});\n\nChart.markUpdateMethod = function (payload, methodName) {\n inner(payload).updateMethod = methodName;\n};\n\nfunction renderTaskPlan(context) {\n return renderPlanner(context.model);\n}\n\nfunction renderTaskReset(context) {\n var seriesModel = context.model;\n var ecModel = context.ecModel;\n var api = context.api;\n var payload = context.payload;\n // ???! remove updateView updateVisual\n var progressiveRender = seriesModel.pipelineContext.progressiveRender;\n var view = context.view;\n\n var updateMethod = payload && inner(payload).updateMethod;\n var methodName = progressiveRender\n ? 'incrementalPrepareRender'\n : (updateMethod && view[updateMethod])\n ? updateMethod\n // `appendData` is also supported when data amount\n // is less than progressive threshold.\n : 'render';\n\n if (methodName !== 'render') {\n view[methodName](seriesModel, ecModel, api, payload);\n }\n\n return progressMethodMap[methodName];\n}\n\nvar progressMethodMap = {\n incrementalPrepareRender: {\n progress: function (params, context) {\n context.view.incrementalRender(\n params, context.model, context.ecModel, context.api, context.payload\n );\n }\n },\n render: {\n // Put view.render in `progress` to support appendData. But in this case\n // view.render should not be called in reset, otherwise it will be called\n // twise. Use `forceFirstProgress` to make sure that view.render is called\n // in any cases.\n forceFirstProgress: true,\n progress: function (params, context) {\n context.view.render(\n context.model, context.ecModel, context.api, context.payload\n );\n }\n }\n};\n\nexport default Chart;","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\n\nvar ORIGIN_METHOD = '\\0__throttleOriginMethod';\nvar RATE = '\\0__throttleRate';\nvar THROTTLE_TYPE = '\\0__throttleType';\n\n/**\n * @public\n * @param {(Function)} fn\n * @param {number} [delay=0] Unit: ms.\n * @param {boolean} [debounce=false]\n * true: If call interval less than `delay`, only the last call works.\n * false: If call interval less than `delay, call works on fixed rate.\n * @return {(Function)} throttled fn.\n */\nexport function throttle(fn, delay, debounce) {\n\n var currCall;\n var lastCall = 0;\n var lastExec = 0;\n var timer = null;\n var diff;\n var scope;\n var args;\n var debounceNextCall;\n\n delay = delay || 0;\n\n function exec() {\n lastExec = (new Date()).getTime();\n timer = null;\n fn.apply(scope, args || []);\n }\n\n var cb = function () {\n currCall = (new Date()).getTime();\n scope = this;\n args = arguments;\n var thisDelay = debounceNextCall || delay;\n var thisDebounce = debounceNextCall || debounce;\n debounceNextCall = null;\n diff = currCall - (thisDebounce ? lastCall : lastExec) - thisDelay;\n\n clearTimeout(timer);\n\n // Here we should make sure that: the `exec` SHOULD NOT be called later\n // than a new call of `cb`, that is, preserving the command order. Consider\n // calculating \"scale rate\" when roaming as an example. When a call of `cb`\n // happens, either the `exec` is called dierectly, or the call is delayed.\n // But the delayed call should never be later than next call of `cb`. Under\n // this assurance, we can simply update view state each time `dispatchAction`\n // triggered by user roaming, but not need to add extra code to avoid the\n // state being \"rolled-back\".\n if (thisDebounce) {\n timer = setTimeout(exec, thisDelay);\n }\n else {\n if (diff >= 0) {\n exec();\n }\n else {\n timer = setTimeout(exec, -diff);\n }\n }\n\n lastCall = currCall;\n };\n\n /**\n * Clear throttle.\n * @public\n */\n cb.clear = function () {\n if (timer) {\n clearTimeout(timer);\n timer = null;\n }\n };\n\n /**\n * Enable debounce once.\n */\n cb.debounceNextCall = function (debounceDelay) {\n debounceNextCall = debounceDelay;\n };\n\n return cb;\n}\n\n/**\n * Create throttle method or update throttle rate.\n *\n * @example\n * ComponentView.prototype.render = function () {\n * ...\n * throttle.createOrUpdate(\n * this,\n * '_dispatchAction',\n * this.model.get('throttle'),\n * 'fixRate'\n * );\n * };\n * ComponentView.prototype.remove = function () {\n * throttle.clear(this, '_dispatchAction');\n * };\n * ComponentView.prototype.dispose = function () {\n * throttle.clear(this, '_dispatchAction');\n * };\n *\n * @public\n * @param {Object} obj\n * @param {string} fnAttr\n * @param {number} [rate]\n * @param {string} [throttleType='fixRate'] 'fixRate' or 'debounce'\n * @return {Function} throttled function.\n */\nexport function createOrUpdate(obj, fnAttr, rate, throttleType) {\n var fn = obj[fnAttr];\n\n if (!fn) {\n return;\n }\n\n var originFn = fn[ORIGIN_METHOD] || fn;\n var lastThrottleType = fn[THROTTLE_TYPE];\n var lastRate = fn[RATE];\n\n if (lastRate !== rate || lastThrottleType !== throttleType) {\n if (rate == null || !throttleType) {\n return (obj[fnAttr] = originFn);\n }\n\n fn = obj[fnAttr] = throttle(\n originFn, rate, throttleType === 'debounce'\n );\n fn[ORIGIN_METHOD] = originFn;\n fn[THROTTLE_TYPE] = throttleType;\n fn[RATE] = rate;\n }\n\n return fn;\n}\n\n/**\n * Clear throttle. Example see throttle.createOrUpdate.\n *\n * @public\n * @param {Object} obj\n * @param {string} fnAttr\n */\nexport function clear(obj, fnAttr) {\n var fn = obj[fnAttr];\n if (fn && fn[ORIGIN_METHOD]) {\n obj[fnAttr] = fn[ORIGIN_METHOD];\n }\n}\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport Gradient from 'zrender/src/graphic/Gradient';\nimport {isFunction} from 'zrender/src/core/util';\n\nexport default {\n createOnAllSeries: true,\n performRawSeries: true,\n reset: function (seriesModel, ecModel) {\n var data = seriesModel.getData();\n var colorAccessPath = (seriesModel.visualColorAccessPath || 'itemStyle.color').split('.');\n // Set in itemStyle\n var color = seriesModel.get(colorAccessPath);\n var colorCallback = (isFunction(color) && !(color instanceof Gradient))\n ? color : null;\n // Default color\n if (!color || colorCallback) {\n color = seriesModel.getColorFromPalette(\n // TODO series count changed.\n seriesModel.name, null, ecModel.getSeriesCount()\n );\n }\n\n data.setVisual('color', color);\n\n var borderColorAccessPath = (seriesModel.visualBorderColorAccessPath || 'itemStyle.borderColor').split('.');\n var borderColor = seriesModel.get(borderColorAccessPath);\n data.setVisual('borderColor', borderColor);\n\n // Only visible series has each data be visual encoded\n if (!ecModel.isSeriesFiltered(seriesModel)) {\n if (colorCallback) {\n data.each(function (idx) {\n data.setItemVisual(\n idx, 'color', colorCallback(seriesModel.getDataParams(idx))\n );\n });\n }\n\n // itemStyle in each data item\n var dataEach = function (data, idx) {\n var itemModel = data.getItemModel(idx);\n var color = itemModel.get(colorAccessPath, true);\n var borderColor = itemModel.get(borderColorAccessPath, true);\n if (color != null) {\n data.setItemVisual(idx, 'color', color);\n }\n if (borderColor != null) {\n data.setItemVisual(idx, 'borderColor', borderColor);\n }\n };\n\n return { dataEach: data.hasItemOption ? dataEach : null };\n }\n }\n};\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\n/**\n * Language: (Simplified) Chinese.\n */\n\nexport default {\n legend: {\n selector: {\n all: '全选',\n inverse: '反选'\n }\n },\n toolbox: {\n brush: {\n title: {\n rect: '矩形选择',\n polygon: '圈选',\n lineX: '横向选择',\n lineY: '纵向选择',\n keep: '保持选择',\n clear: '清除选择'\n }\n },\n dataView: {\n title: '数据视图',\n lang: ['数据视图', '关闭', '刷新']\n },\n dataZoom: {\n title: {\n zoom: '区域缩放',\n back: '区域缩放还原'\n }\n },\n magicType: {\n title: {\n line: '切换为折线图',\n bar: '切换为柱状图',\n stack: '切换为堆叠',\n tiled: '切换为平铺'\n }\n },\n restore: {\n title: '还原'\n },\n saveAsImage: {\n title: '保存为图片',\n lang: ['右键另存为图片']\n }\n },\n series: {\n typeNames: {\n pie: '饼图',\n bar: '柱状图',\n line: '折线图',\n scatter: '散点图',\n effectScatter: '涟漪散点图',\n radar: '雷达图',\n tree: '树图',\n treemap: '矩形树图',\n boxplot: '箱型图',\n candlestick: 'K线图',\n k: 'K线图',\n heatmap: '热力图',\n map: '地图',\n parallel: '平行坐标图',\n lines: '线图',\n graph: '关系图',\n sankey: '桑基图',\n funnel: '漏斗图',\n gauge: '仪表盘图',\n pictorialBar: '象形柱图',\n themeRiver: '主题河流图',\n sunburst: '旭日图'\n }\n },\n aria: {\n general: {\n withTitle: '这是一个关于“{title}”的图表。',\n withoutTitle: '这是一个图表,'\n },\n series: {\n single: {\n prefix: '',\n withName: '图表类型是{seriesType},表示{seriesName}。',\n withoutName: '图表类型是{seriesType}。'\n },\n multiple: {\n prefix: '它由{seriesCount}个图表系列组成。',\n withName: '第{seriesId}个系列是一个表示{seriesName}的{seriesType},',\n withoutName: '第{seriesId}个系列是一个{seriesType},',\n separator: {\n middle: ';',\n end: '。'\n }\n }\n },\n data: {\n allData: '其数据是——',\n partialData: '其中,前{displayCnt}项是——',\n withName: '{name}的数据是{value}',\n withoutName: '{value}',\n separator: {\n middle: ',',\n end: ''\n }\n }\n }\n};\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport * as zrUtil from 'zrender/src/core/util';\nimport lang from '../lang';\nimport { retrieveRawValue } from '../data/helper/dataProvider';\n\nexport default function (dom, ecModel) {\n var ariaModel = ecModel.getModel('aria');\n if (!ariaModel.get('show')) {\n return;\n }\n else if (ariaModel.get('description')) {\n dom.setAttribute('aria-label', ariaModel.get('description'));\n return;\n }\n\n var seriesCnt = 0;\n ecModel.eachSeries(function (seriesModel, idx) {\n ++seriesCnt;\n }, this);\n\n var maxDataCnt = ariaModel.get('data.maxCount') || 10;\n var maxSeriesCnt = ariaModel.get('series.maxCount') || 10;\n var displaySeriesCnt = Math.min(seriesCnt, maxSeriesCnt);\n\n var ariaLabel;\n if (seriesCnt < 1) {\n // No series, no aria label\n return;\n }\n else {\n var title = getTitle();\n if (title) {\n ariaLabel = replace(getConfig('general.withTitle'), {\n title: title\n });\n }\n else {\n ariaLabel = getConfig('general.withoutTitle');\n }\n\n var seriesLabels = [];\n var prefix = seriesCnt > 1\n ? 'series.multiple.prefix'\n : 'series.single.prefix';\n ariaLabel += replace(getConfig(prefix), { seriesCount: seriesCnt });\n\n ecModel.eachSeries(function (seriesModel, idx) {\n if (idx < displaySeriesCnt) {\n var seriesLabel;\n\n var seriesName = seriesModel.get('name');\n var seriesTpl = 'series.'\n + (seriesCnt > 1 ? 'multiple' : 'single') + '.';\n seriesLabel = getConfig(seriesName\n ? seriesTpl + 'withName'\n : seriesTpl + 'withoutName');\n\n seriesLabel = replace(seriesLabel, {\n seriesId: seriesModel.seriesIndex,\n seriesName: seriesModel.get('name'),\n seriesType: getSeriesTypeName(seriesModel.subType)\n });\n\n var data = seriesModel.getData();\n window.data = data;\n if (data.count() > maxDataCnt) {\n // Show part of data\n seriesLabel += replace(getConfig('data.partialData'), {\n displayCnt: maxDataCnt\n });\n }\n else {\n seriesLabel += getConfig('data.allData');\n }\n\n var dataLabels = [];\n for (var i = 0; i < data.count(); i++) {\n if (i < maxDataCnt) {\n var name = data.getName(i);\n var value = retrieveRawValue(data, i);\n dataLabels.push(\n replace(\n name\n ? getConfig('data.withName')\n : getConfig('data.withoutName'),\n {\n name: name,\n value: value\n }\n )\n );\n }\n }\n seriesLabel += dataLabels\n .join(getConfig('data.separator.middle'))\n + getConfig('data.separator.end');\n\n seriesLabels.push(seriesLabel);\n }\n });\n\n ariaLabel += seriesLabels\n .join(getConfig('series.multiple.separator.middle'))\n + getConfig('series.multiple.separator.end');\n\n dom.setAttribute('aria-label', ariaLabel);\n }\n\n function replace(str, keyValues) {\n if (typeof str !== 'string') {\n return str;\n }\n\n var result = str;\n zrUtil.each(keyValues, function (value, key) {\n result = result.replace(\n new RegExp('\\\\{\\\\s*' + key + '\\\\s*\\\\}', 'g'),\n value\n );\n });\n return result;\n }\n\n function getConfig(path) {\n var userConfig = ariaModel.get(path);\n if (userConfig == null) {\n var pathArr = path.split('.');\n var result = lang.aria;\n for (var i = 0; i < pathArr.length; ++i) {\n result = result[pathArr[i]];\n }\n return result;\n }\n else {\n return userConfig;\n }\n }\n\n function getTitle() {\n var title = ecModel.getModel('title').option;\n if (title && title.length) {\n title = title[0];\n }\n return title && title.text;\n }\n\n function getSeriesTypeName(type) {\n return lang.series.typeNames[type] || '自定义图';\n }\n}\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport * as zrUtil from 'zrender/src/core/util';\nimport * as graphic from '../util/graphic';\nimport * as textContain from 'zrender/src/contain/text';\n\nvar PI = Math.PI;\n\n/**\n * @param {module:echarts/ExtensionAPI} api\n * @param {Object} [opts]\n * @param {string} [opts.text]\n * @param {string} [opts.color]\n * @param {string} [opts.textColor]\n * @return {module:zrender/Element}\n */\nexport default function (api, opts) {\n opts = opts || {};\n zrUtil.defaults(opts, {\n text: 'loading',\n textColor: '#000',\n fontSize: '12px',\n maskColor: 'rgba(255, 255, 255, 0.8)',\n showSpinner: true,\n color: '#c23531',\n spinnerRadius: 10,\n lineWidth: 5,\n zlevel: 0\n });\n var group = new graphic.Group();\n var mask = new graphic.Rect({\n style: {\n fill: opts.maskColor\n },\n zlevel: opts.zlevel,\n z: 10000\n });\n group.add(mask);\n var font = opts.fontSize + ' sans-serif';\n var labelRect = new graphic.Rect({\n style: {\n fill: 'none',\n text: opts.text,\n font: font,\n textPosition: 'right',\n textDistance: 10,\n textFill: opts.textColor\n },\n zlevel: opts.zlevel,\n z: 10001\n });\n group.add(labelRect);\n if (opts.showSpinner) {\n var arc = new graphic.Arc({\n shape: {\n startAngle: -PI / 2,\n endAngle: -PI / 2 + 0.1,\n r: opts.spinnerRadius\n },\n style: {\n stroke: opts.color,\n lineCap: 'round',\n lineWidth: opts.lineWidth\n },\n zlevel: opts.zlevel,\n z: 10001\n });\n arc.animateShape(true)\n .when(1000, {\n endAngle: PI * 3 / 2\n })\n .start('circularInOut');\n arc.animateShape(true)\n .when(1000, {\n startAngle: PI * 3 / 2\n })\n .delay(300)\n .start('circularInOut');\n group.add(arc);\n }\n // Inject resize\n group.resize = function () {\n var textWidth = textContain.getWidth(opts.text, font);\n var r = opts.showSpinner ? opts.spinnerRadius : 0;\n // cx = (containerWidth - arcDiameter - textDistance - textWidth) / 2\n // textDistance needs to be calculated when both animation and text exist\n var cx = (api.getWidth() - r * 2 - (opts.showSpinner && textWidth ? 10 : 0) - textWidth) / 2\n // only show the text\n - (opts.showSpinner ? 0 : textWidth / 2);\n var cy = api.getHeight() / 2;\n opts.showSpinner && arc.setShape({\n cx: cx,\n cy: cy\n });\n labelRect.setShape({\n x: cx - r,\n y: cy - r,\n width: r * 2,\n height: r * 2\n });\n\n mask.setShape({\n x: 0,\n y: 0,\n width: api.getWidth(),\n height: api.getHeight()\n });\n };\n group.resize();\n return group;\n}","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\n/**\n * @module echarts/stream/Scheduler\n */\n\nimport {each, map, isFunction, createHashMap, noop} from 'zrender/src/core/util';\nimport {createTask} from './task';\nimport {getUID} from '../util/component';\nimport GlobalModel from '../model/Global';\nimport ExtensionAPI from '../ExtensionAPI';\nimport {normalizeToArray} from '../util/model';\n\n/**\n * @constructor\n */\nfunction Scheduler(ecInstance, api, dataProcessorHandlers, visualHandlers) {\n this.ecInstance = ecInstance;\n this.api = api;\n this.unfinished;\n\n // Fix current processors in case that in some rear cases that\n // processors might be registered after echarts instance created.\n // Register processors incrementally for a echarts instance is\n // not supported by this stream architecture.\n var dataProcessorHandlers = this._dataProcessorHandlers = dataProcessorHandlers.slice();\n var visualHandlers = this._visualHandlers = visualHandlers.slice();\n this._allHandlers = dataProcessorHandlers.concat(visualHandlers);\n\n /**\n * @private\n * @type {\n * [handlerUID: string]: {\n * seriesTaskMap?: {\n * [seriesUID: string]: Task\n * },\n * overallTask?: Task\n * }\n * }\n */\n this._stageTaskMap = createHashMap();\n}\n\nvar proto = Scheduler.prototype;\n\n/**\n * @param {module:echarts/model/Global} ecModel\n * @param {Object} payload\n */\nproto.restoreData = function (ecModel, payload) {\n // TODO: Only restore needed series and components, but not all components.\n // Currently `restoreData` of all of the series and component will be called.\n // But some independent components like `title`, `legend`, `graphic`, `toolbox`,\n // `tooltip`, `axisPointer`, etc, do not need series refresh when `setOption`,\n // and some components like coordinate system, axes, dataZoom, visualMap only\n // need their target series refresh.\n // (1) If we are implementing this feature some day, we should consider these cases:\n // if a data processor depends on a component (e.g., dataZoomProcessor depends\n // on the settings of `dataZoom`), it should be re-performed if the component\n // is modified by `setOption`.\n // (2) If a processor depends on sevral series, speicified by its `getTargetSeries`,\n // it should be re-performed when the result array of `getTargetSeries` changed.\n // We use `dependencies` to cover these issues.\n // (3) How to update target series when coordinate system related components modified.\n\n // TODO: simply the dirty mechanism? Check whether only the case here can set tasks dirty,\n // and this case all of the tasks will be set as dirty.\n\n ecModel.restoreData(payload);\n\n // Theoretically an overall task not only depends on each of its target series, but also\n // depends on all of the series.\n // The overall task is not in pipeline, and `ecModel.restoreData` only set pipeline tasks\n // dirty. If `getTargetSeries` of an overall task returns nothing, we should also ensure\n // that the overall task is set as dirty and to be performed, otherwise it probably cause\n // state chaos. So we have to set dirty of all of the overall tasks manually, otherwise it\n // probably cause state chaos (consider `dataZoomProcessor`).\n this._stageTaskMap.each(function (taskRecord) {\n var overallTask = taskRecord.overallTask;\n overallTask && overallTask.dirty();\n });\n};\n\n// If seriesModel provided, incremental threshold is check by series data.\nproto.getPerformArgs = function (task, isBlock) {\n // For overall task\n if (!task.__pipeline) {\n return;\n }\n\n var pipeline = this._pipelineMap.get(task.__pipeline.id);\n var pCtx = pipeline.context;\n var incremental = !isBlock\n && pipeline.progressiveEnabled\n && (!pCtx || pCtx.progressiveRender)\n && task.__idxInPipeline > pipeline.blockIndex;\n\n var step = incremental ? pipeline.step : null;\n var modDataCount = pCtx && pCtx.modDataCount;\n var modBy = modDataCount != null ? Math.ceil(modDataCount / step) : null;\n\n return {step: step, modBy: modBy, modDataCount: modDataCount};\n};\n\nproto.getPipeline = function (pipelineId) {\n return this._pipelineMap.get(pipelineId);\n};\n\n/**\n * Current, progressive rendering starts from visual and layout.\n * Always detect render mode in the same stage, avoiding that incorrect\n * detection caused by data filtering.\n * Caution:\n * `updateStreamModes` use `seriesModel.getData()`.\n */\nproto.updateStreamModes = function (seriesModel, view) {\n var pipeline = this._pipelineMap.get(seriesModel.uid);\n var data = seriesModel.getData();\n var dataLen = data.count();\n\n // `progressiveRender` means that can render progressively in each\n // animation frame. Note that some types of series do not provide\n // `view.incrementalPrepareRender` but support `chart.appendData`. We\n // use the term `incremental` but not `progressive` to describe the\n // case that `chart.appendData`.\n var progressiveRender = pipeline.progressiveEnabled\n && view.incrementalPrepareRender\n && dataLen >= pipeline.threshold;\n\n var large = seriesModel.get('large') && dataLen >= seriesModel.get('largeThreshold');\n\n // TODO: modDataCount should not updated if `appendData`, otherwise cause whole repaint.\n // see `test/candlestick-large3.html`\n var modDataCount = seriesModel.get('progressiveChunkMode') === 'mod' ? dataLen : null;\n\n seriesModel.pipelineContext = pipeline.context = {\n progressiveRender: progressiveRender,\n modDataCount: modDataCount,\n large: large\n };\n};\n\nproto.restorePipelines = function (ecModel) {\n var scheduler = this;\n var pipelineMap = scheduler._pipelineMap = createHashMap();\n\n ecModel.eachSeries(function (seriesModel) {\n var progressive = seriesModel.getProgressive();\n var pipelineId = seriesModel.uid;\n\n pipelineMap.set(pipelineId, {\n id: pipelineId,\n head: null,\n tail: null,\n threshold: seriesModel.getProgressiveThreshold(),\n progressiveEnabled: progressive\n && !(seriesModel.preventIncremental && seriesModel.preventIncremental()),\n blockIndex: -1,\n step: Math.round(progressive || 700),\n count: 0\n });\n\n pipe(scheduler, seriesModel, seriesModel.dataTask);\n });\n};\n\nproto.prepareStageTasks = function () {\n var stageTaskMap = this._stageTaskMap;\n var ecModel = this.ecInstance.getModel();\n var api = this.api;\n\n each(this._allHandlers, function (handler) {\n var record = stageTaskMap.get(handler.uid) || stageTaskMap.set(handler.uid, []);\n\n handler.reset && createSeriesStageTask(this, handler, record, ecModel, api);\n handler.overallReset && createOverallStageTask(this, handler, record, ecModel, api);\n }, this);\n};\n\nproto.prepareView = function (view, model, ecModel, api) {\n var renderTask = view.renderTask;\n var context = renderTask.context;\n\n context.model = model;\n context.ecModel = ecModel;\n context.api = api;\n\n renderTask.__block = !view.incrementalPrepareRender;\n\n pipe(this, model, renderTask);\n};\n\n\nproto.performDataProcessorTasks = function (ecModel, payload) {\n // If we do not use `block` here, it should be considered when to update modes.\n performStageTasks(this, this._dataProcessorHandlers, ecModel, payload, {block: true});\n};\n\n// opt\n// opt.visualType: 'visual' or 'layout'\n// opt.setDirty\nproto.performVisualTasks = function (ecModel, payload, opt) {\n performStageTasks(this, this._visualHandlers, ecModel, payload, opt);\n};\n\nfunction performStageTasks(scheduler, stageHandlers, ecModel, payload, opt) {\n opt = opt || {};\n var unfinished;\n\n each(stageHandlers, function (stageHandler, idx) {\n if (opt.visualType && opt.visualType !== stageHandler.visualType) {\n return;\n }\n\n var stageHandlerRecord = scheduler._stageTaskMap.get(stageHandler.uid);\n var seriesTaskMap = stageHandlerRecord.seriesTaskMap;\n var overallTask = stageHandlerRecord.overallTask;\n\n if (overallTask) {\n var overallNeedDirty;\n var agentStubMap = overallTask.agentStubMap;\n agentStubMap.each(function (stub) {\n if (needSetDirty(opt, stub)) {\n stub.dirty();\n overallNeedDirty = true;\n }\n });\n overallNeedDirty && overallTask.dirty();\n updatePayload(overallTask, payload);\n var performArgs = scheduler.getPerformArgs(overallTask, opt.block);\n // Execute stubs firstly, which may set the overall task dirty,\n // then execute the overall task. And stub will call seriesModel.setData,\n // which ensures that in the overallTask seriesModel.getData() will not\n // return incorrect data.\n agentStubMap.each(function (stub) {\n stub.perform(performArgs);\n });\n unfinished |= overallTask.perform(performArgs);\n }\n else if (seriesTaskMap) {\n seriesTaskMap.each(function (task, pipelineId) {\n if (needSetDirty(opt, task)) {\n task.dirty();\n }\n var performArgs = scheduler.getPerformArgs(task, opt.block);\n // FIXME\n // if intending to decalare `performRawSeries` in handlers, only\n // stream-independent (specifically, data item independent) operations can be\n // performed. Because is a series is filtered, most of the tasks will not\n // be performed. A stream-dependent operation probably cause wrong biz logic.\n // Perhaps we should not provide a separate callback for this case instead\n // of providing the config `performRawSeries`. The stream-dependent operaions\n // and stream-independent operations should better not be mixed.\n performArgs.skip = !stageHandler.performRawSeries\n && ecModel.isSeriesFiltered(task.context.model);\n updatePayload(task, payload);\n unfinished |= task.perform(performArgs);\n });\n }\n });\n\n function needSetDirty(opt, task) {\n return opt.setDirty && (!opt.dirtyMap || opt.dirtyMap.get(task.__pipeline.id));\n }\n\n scheduler.unfinished |= unfinished;\n}\n\nproto.performSeriesTasks = function (ecModel) {\n var unfinished;\n\n ecModel.eachSeries(function (seriesModel) {\n // Progress to the end for dataInit and dataRestore.\n unfinished |= seriesModel.dataTask.perform();\n });\n\n this.unfinished |= unfinished;\n};\n\nproto.plan = function () {\n // Travel pipelines, check block.\n this._pipelineMap.each(function (pipeline) {\n var task = pipeline.tail;\n do {\n if (task.__block) {\n pipeline.blockIndex = task.__idxInPipeline;\n break;\n }\n task = task.getUpstream();\n }\n while (task);\n });\n};\n\nvar updatePayload = proto.updatePayload = function (task, payload) {\n payload !== 'remain' && (task.context.payload = payload);\n};\n\nfunction createSeriesStageTask(scheduler, stageHandler, stageHandlerRecord, ecModel, api) {\n var seriesTaskMap = stageHandlerRecord.seriesTaskMap\n || (stageHandlerRecord.seriesTaskMap = createHashMap());\n var seriesType = stageHandler.seriesType;\n var getTargetSeries = stageHandler.getTargetSeries;\n\n // If a stageHandler should cover all series, `createOnAllSeries` should be declared mandatorily,\n // to avoid some typo or abuse. Otherwise if an extension do not specify a `seriesType`,\n // it works but it may cause other irrelevant charts blocked.\n if (stageHandler.createOnAllSeries) {\n ecModel.eachRawSeries(create);\n }\n else if (seriesType) {\n ecModel.eachRawSeriesByType(seriesType, create);\n }\n else if (getTargetSeries) {\n getTargetSeries(ecModel, api).each(create);\n }\n\n function create(seriesModel) {\n var pipelineId = seriesModel.uid;\n\n // Init tasks for each seriesModel only once.\n // Reuse original task instance.\n var task = seriesTaskMap.get(pipelineId)\n || seriesTaskMap.set(pipelineId, createTask({\n plan: seriesTaskPlan,\n reset: seriesTaskReset,\n count: seriesTaskCount\n }));\n task.context = {\n model: seriesModel,\n ecModel: ecModel,\n api: api,\n useClearVisual: stageHandler.isVisual && !stageHandler.isLayout,\n plan: stageHandler.plan,\n reset: stageHandler.reset,\n scheduler: scheduler\n };\n pipe(scheduler, seriesModel, task);\n }\n\n // Clear unused series tasks.\n var pipelineMap = scheduler._pipelineMap;\n seriesTaskMap.each(function (task, pipelineId) {\n if (!pipelineMap.get(pipelineId)) {\n task.dispose();\n seriesTaskMap.removeKey(pipelineId);\n }\n });\n}\n\nfunction createOverallStageTask(scheduler, stageHandler, stageHandlerRecord, ecModel, api) {\n var overallTask = stageHandlerRecord.overallTask = stageHandlerRecord.overallTask\n // For overall task, the function only be called on reset stage.\n || createTask({reset: overallTaskReset});\n\n overallTask.context = {\n ecModel: ecModel,\n api: api,\n overallReset: stageHandler.overallReset,\n scheduler: scheduler\n };\n\n // Reuse orignal stubs.\n var agentStubMap = overallTask.agentStubMap = overallTask.agentStubMap || createHashMap();\n\n var seriesType = stageHandler.seriesType;\n var getTargetSeries = stageHandler.getTargetSeries;\n var overallProgress = true;\n var modifyOutputEnd = stageHandler.modifyOutputEnd;\n\n // An overall task with seriesType detected or has `getTargetSeries`, we add\n // stub in each pipelines, it will set the overall task dirty when the pipeline\n // progress. Moreover, to avoid call the overall task each frame (too frequent),\n // we set the pipeline block.\n if (seriesType) {\n ecModel.eachRawSeriesByType(seriesType, createStub);\n }\n else if (getTargetSeries) {\n getTargetSeries(ecModel, api).each(createStub);\n }\n // Otherwise, (usually it is legancy case), the overall task will only be\n // executed when upstream dirty. Otherwise the progressive rendering of all\n // pipelines will be disabled unexpectedly. But it still needs stubs to receive\n // dirty info from upsteam.\n else {\n overallProgress = false;\n each(ecModel.getSeries(), createStub);\n }\n\n function createStub(seriesModel) {\n var pipelineId = seriesModel.uid;\n var stub = agentStubMap.get(pipelineId);\n if (!stub) {\n stub = agentStubMap.set(pipelineId, createTask(\n {reset: stubReset, onDirty: stubOnDirty}\n ));\n // When the result of `getTargetSeries` changed, the overallTask\n // should be set as dirty and re-performed.\n overallTask.dirty();\n }\n stub.context = {\n model: seriesModel,\n overallProgress: overallProgress,\n modifyOutputEnd: modifyOutputEnd\n };\n stub.agent = overallTask;\n stub.__block = overallProgress;\n\n pipe(scheduler, seriesModel, stub);\n }\n\n // Clear unused stubs.\n var pipelineMap = scheduler._pipelineMap;\n agentStubMap.each(function (stub, pipelineId) {\n if (!pipelineMap.get(pipelineId)) {\n stub.dispose();\n // When the result of `getTargetSeries` changed, the overallTask\n // should be set as dirty and re-performed.\n overallTask.dirty();\n agentStubMap.removeKey(pipelineId);\n }\n });\n}\n\nfunction overallTaskReset(context) {\n context.overallReset(\n context.ecModel, context.api, context.payload\n );\n}\n\nfunction stubReset(context, upstreamContext) {\n return context.overallProgress && stubProgress;\n}\n\nfunction stubProgress() {\n this.agent.dirty();\n this.getDownstream().dirty();\n}\n\nfunction stubOnDirty() {\n this.agent && this.agent.dirty();\n}\n\nfunction seriesTaskPlan(context) {\n return context.plan && context.plan(\n context.model, context.ecModel, context.api, context.payload\n );\n}\n\nfunction seriesTaskReset(context) {\n if (context.useClearVisual) {\n context.data.clearAllVisual();\n }\n var resetDefines = context.resetDefines = normalizeToArray(context.reset(\n context.model, context.ecModel, context.api, context.payload\n ));\n return resetDefines.length > 1\n ? map(resetDefines, function (v, idx) {\n return makeSeriesTaskProgress(idx);\n })\n : singleSeriesTaskProgress;\n}\n\nvar singleSeriesTaskProgress = makeSeriesTaskProgress(0);\n\nfunction makeSeriesTaskProgress(resetDefineIdx) {\n return function (params, context) {\n var data = context.data;\n var resetDefine = context.resetDefines[resetDefineIdx];\n\n if (resetDefine && resetDefine.dataEach) {\n for (var i = params.start; i < params.end; i++) {\n resetDefine.dataEach(data, i);\n }\n }\n else if (resetDefine && resetDefine.progress) {\n resetDefine.progress(params, data);\n }\n };\n}\n\nfunction seriesTaskCount(context) {\n return context.data.count();\n}\n\nfunction pipe(scheduler, seriesModel, task) {\n var pipelineId = seriesModel.uid;\n var pipeline = scheduler._pipelineMap.get(pipelineId);\n !pipeline.head && (pipeline.head = task);\n pipeline.tail && pipeline.tail.pipe(task);\n pipeline.tail = task;\n task.__idxInPipeline = pipeline.count++;\n task.__pipeline = pipeline;\n}\n\nScheduler.wrapStageHandler = function (stageHandler, visualType) {\n if (isFunction(stageHandler)) {\n stageHandler = {\n overallReset: stageHandler,\n seriesType: detectSeriseType(stageHandler)\n };\n }\n\n stageHandler.uid = getUID('stageHandler');\n visualType && (stageHandler.visualType = visualType);\n\n return stageHandler;\n};\n\n\n\n/**\n * Only some legacy stage handlers (usually in echarts extensions) are pure function.\n * To ensure that they can work normally, they should work in block mode, that is,\n * they should not be started util the previous tasks finished. So they cause the\n * progressive rendering disabled. We try to detect the series type, to narrow down\n * the block range to only the series type they concern, but not all series.\n */\nfunction detectSeriseType(legacyFunc) {\n seriesType = null;\n try {\n // Assume there is no async when calling `eachSeriesByType`.\n legacyFunc(ecModelMock, apiMock);\n }\n catch (e) {\n }\n return seriesType;\n}\n\nvar ecModelMock = {};\nvar apiMock = {};\nvar seriesType;\n\nmockMethods(ecModelMock, GlobalModel);\nmockMethods(apiMock, ExtensionAPI);\necModelMock.eachSeriesByType = ecModelMock.eachRawSeriesByType = function (type) {\n seriesType = type;\n};\necModelMock.eachComponent = function (cond) {\n if (cond.mainType === 'series' && cond.subType) {\n seriesType = cond.subType;\n }\n};\n\nfunction mockMethods(target, Clz) {\n /* eslint-disable */\n for (var name in Clz.prototype) {\n // Do not use hasOwnProperty\n target[name] = noop;\n }\n /* eslint-enable */\n}\n\nexport default Scheduler;\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nvar colorAll = [\n '#37A2DA', '#32C5E9', '#67E0E3', '#9FE6B8', '#FFDB5C', '#ff9f7f',\n '#fb7293', '#E062AE', '#E690D1', '#e7bcf3', '#9d96f5', '#8378EA', '#96BFFF'\n];\n\nexport default {\n\n color: colorAll,\n\n colorLayer: [\n ['#37A2DA', '#ffd85c', '#fd7b5f'],\n ['#37A2DA', '#67E0E3', '#FFDB5C', '#ff9f7f', '#E062AE', '#9d96f5'],\n ['#37A2DA', '#32C5E9', '#9FE6B8', '#FFDB5C', '#ff9f7f', '#fb7293', '#e7bcf3', '#8378EA', '#96BFFF'],\n colorAll\n ]\n};","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nvar contrastColor = '#eee';\nvar axisCommon = function () {\n return {\n axisLine: {\n lineStyle: {\n color: contrastColor\n }\n },\n axisTick: {\n lineStyle: {\n color: contrastColor\n }\n },\n axisLabel: {\n textStyle: {\n color: contrastColor\n }\n },\n splitLine: {\n lineStyle: {\n type: 'dashed',\n color: '#aaa'\n }\n },\n splitArea: {\n areaStyle: {\n color: contrastColor\n }\n }\n };\n};\n\nvar colorPalette = [\n '#dd6b66', '#759aa0', '#e69d87', '#8dc1a9', '#ea7e53',\n '#eedd78', '#73a373', '#73b9bc', '#7289ab', '#91ca8c', '#f49f42'\n];\nvar theme = {\n color: colorPalette,\n backgroundColor: '#333',\n tooltip: {\n axisPointer: {\n lineStyle: {\n color: contrastColor\n },\n crossStyle: {\n color: contrastColor\n },\n label: {\n color: '#000'\n }\n }\n },\n legend: {\n textStyle: {\n color: contrastColor\n }\n },\n textStyle: {\n color: contrastColor\n },\n title: {\n textStyle: {\n color: contrastColor\n }\n },\n toolbox: {\n iconStyle: {\n normal: {\n borderColor: contrastColor\n }\n }\n },\n dataZoom: {\n textStyle: {\n color: contrastColor\n }\n },\n visualMap: {\n textStyle: {\n color: contrastColor\n }\n },\n timeline: {\n lineStyle: {\n color: contrastColor\n },\n itemStyle: {\n normal: {\n color: colorPalette[1]\n }\n },\n label: {\n normal: {\n textStyle: {\n color: contrastColor\n }\n }\n },\n controlStyle: {\n normal: {\n color: contrastColor,\n borderColor: contrastColor\n }\n }\n },\n timeAxis: axisCommon(),\n logAxis: axisCommon(),\n valueAxis: axisCommon(),\n categoryAxis: axisCommon(),\n\n line: {\n symbol: 'circle'\n },\n graph: {\n color: colorPalette\n },\n gauge: {\n title: {\n textStyle: {\n color: contrastColor\n }\n }\n },\n candlestick: {\n itemStyle: {\n normal: {\n color: '#FD1050',\n color0: '#0CF49B',\n borderColor: '#FD1050',\n borderColor0: '#0CF49B'\n }\n }\n }\n};\ntheme.categoryAxis.splitLine.show = false;\n\nexport default theme;","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\n/**\n * This module is imported by echarts directly.\n *\n * Notice:\n * Always keep this file exists for backward compatibility.\n * Because before 4.1.0, dataset is an optional component,\n * some users may import this module manually.\n */\n\nimport ComponentModel from '../model/Component';\nimport ComponentView from '../view/Component';\nimport {detectSourceFormat} from '../data/helper/sourceHelper';\nimport {SERIES_LAYOUT_BY_COLUMN} from '../data/helper/sourceType';\n\nComponentModel.extend({\n\n type: 'dataset',\n\n /**\n * @protected\n */\n defaultOption: {\n\n // 'row', 'column'\n seriesLayoutBy: SERIES_LAYOUT_BY_COLUMN,\n\n // null/'auto': auto detect header, see \"module:echarts/data/helper/sourceHelper\"\n sourceHeader: null,\n\n dimensions: null,\n\n source: null\n },\n\n optionUpdated: function () {\n detectSourceFormat(this);\n }\n\n});\n\nComponentView.extend({\n\n type: 'dataset'\n\n});\n","/**\n * 椭圆形状\n * @module zrender/graphic/shape/Ellipse\n */\n\nimport Path from '../Path';\n\nexport default Path.extend({\n\n type: 'ellipse',\n\n shape: {\n cx: 0, cy: 0,\n rx: 0, ry: 0\n },\n\n buildPath: function (ctx, shape) {\n var k = 0.5522848;\n var x = shape.cx;\n var y = shape.cy;\n var a = shape.rx;\n var b = shape.ry;\n var ox = a * k; // 水平控制点偏移量\n var oy = b * k; // 垂直控制点偏移量\n // 从椭圆的左端点开始顺时针绘制四条三次贝塞尔曲线\n ctx.moveTo(x - a, y);\n ctx.bezierCurveTo(x - a, y - oy, x - ox, y - b, x, y - b);\n ctx.bezierCurveTo(x + ox, y - b, x + a, y - oy, x + a, y);\n ctx.bezierCurveTo(x + a, y + oy, x + ox, y + b, x, y + b);\n ctx.bezierCurveTo(x - ox, y + b, x - a, y + oy, x - a, y);\n ctx.closePath();\n }\n});","import Group from '../container/Group';\nimport ZImage from '../graphic/Image';\nimport Text from '../graphic/Text';\nimport Circle from '../graphic/shape/Circle';\nimport Rect from '../graphic/shape/Rect';\nimport Ellipse from '../graphic/shape/Ellipse';\nimport Line from '../graphic/shape/Line';\nimport Path from '../graphic/Path';\nimport Polygon from '../graphic/shape/Polygon';\nimport Polyline from '../graphic/shape/Polyline';\nimport LinearGradient from '../graphic/LinearGradient';\n// import RadialGradient from '../graphic/RadialGradient';\n// import Pattern from '../graphic/Pattern';\nimport Style from '../graphic/Style';\n// import * as vector from '../core/vector';\nimport * as matrix from '../core/matrix';\nimport { createFromString } from './path';\nimport { isString, extend, defaults, trim, each } from '../core/util';\n\n// Most of the values can be separated by comma and/or white space.\nvar DILIMITER_REG = /[\\s,]+/;\n\n/**\n * For big svg string, this method might be time consuming.\n *\n * @param {string} svg xml string\n * @return {Object} xml root.\n */\nexport function parseXML(svg) {\n if (isString(svg)) {\n var parser = new DOMParser();\n svg = parser.parseFromString(svg, 'text/xml');\n }\n\n // Document node. If using $.get, doc node may be input.\n if (svg.nodeType === 9) {\n svg = svg.firstChild;\n }\n // nodeName of <!DOCTYPE svg> is also 'svg'.\n while (svg.nodeName.toLowerCase() !== 'svg' || svg.nodeType !== 1) {\n svg = svg.nextSibling;\n }\n\n return svg;\n}\n\nfunction SVGParser() {\n this._defs = {};\n this._root = null;\n\n this._isDefine = false;\n this._isText = false;\n}\n\nSVGParser.prototype.parse = function (xml, opt) {\n opt = opt || {};\n\n var svg = parseXML(xml);\n\n if (!svg) {\n throw new Error('Illegal svg');\n }\n\n var root = new Group();\n this._root = root;\n // parse view port\n var viewBox = svg.getAttribute('viewBox') || '';\n\n // If width/height not specified, means \"100%\" of `opt.width/height`.\n // TODO: Other percent value not supported yet.\n var width = parseFloat(svg.getAttribute('width') || opt.width);\n var height = parseFloat(svg.getAttribute('height') || opt.height);\n // If width/height not specified, set as null for output.\n isNaN(width) && (width = null);\n isNaN(height) && (height = null);\n\n // Apply inline style on svg element.\n parseAttributes(svg, root, null, true);\n\n var child = svg.firstChild;\n while (child) {\n this._parseNode(child, root);\n child = child.nextSibling;\n }\n\n var viewBoxRect;\n var viewBoxTransform;\n\n if (viewBox) {\n var viewBoxArr = trim(viewBox).split(DILIMITER_REG);\n // Some invalid case like viewBox: 'none'.\n if (viewBoxArr.length >= 4) {\n viewBoxRect = {\n x: parseFloat(viewBoxArr[0] || 0),\n y: parseFloat(viewBoxArr[1] || 0),\n width: parseFloat(viewBoxArr[2]),\n height: parseFloat(viewBoxArr[3])\n };\n }\n }\n\n if (viewBoxRect && width != null && height != null) {\n viewBoxTransform = makeViewBoxTransform(viewBoxRect, width, height);\n\n if (!opt.ignoreViewBox) {\n // If set transform on the output group, it probably bring trouble when\n // some users only intend to show the clipped content inside the viewBox,\n // but not intend to transform the output group. So we keep the output\n // group no transform. If the user intend to use the viewBox as a\n // camera, just set `opt.ignoreViewBox` as `true` and set transfrom\n // manually according to the viewBox info in the output of this method.\n var elRoot = root;\n root = new Group();\n root.add(elRoot);\n elRoot.scale = viewBoxTransform.scale.slice();\n elRoot.position = viewBoxTransform.position.slice();\n }\n }\n\n // Some shapes might be overflow the viewport, which should be\n // clipped despite whether the viewBox is used, as the SVG does.\n if (!opt.ignoreRootClip && width != null && height != null) {\n root.setClipPath(new Rect({\n shape: {x: 0, y: 0, width: width, height: height}\n }));\n }\n\n // Set width/height on group just for output the viewport size.\n return {\n root: root,\n width: width,\n height: height,\n viewBoxRect: viewBoxRect,\n viewBoxTransform: viewBoxTransform\n };\n};\n\nSVGParser.prototype._parseNode = function (xmlNode, parentGroup) {\n\n var nodeName = xmlNode.nodeName.toLowerCase();\n\n // TODO\n // support <style>...</style> in svg, where nodeName is 'style',\n // CSS classes is defined globally wherever the style tags are declared.\n\n if (nodeName === 'defs') {\n // define flag\n this._isDefine = true;\n }\n else if (nodeName === 'text') {\n this._isText = true;\n }\n\n var el;\n if (this._isDefine) {\n var parser = defineParsers[nodeName];\n if (parser) {\n var def = parser.call(this, xmlNode);\n var id = xmlNode.getAttribute('id');\n if (id) {\n this._defs[id] = def;\n }\n }\n }\n else {\n var parser = nodeParsers[nodeName];\n if (parser) {\n el = parser.call(this, xmlNode, parentGroup);\n parentGroup.add(el);\n }\n }\n\n var child = xmlNode.firstChild;\n while (child) {\n if (child.nodeType === 1) {\n this._parseNode(child, el);\n }\n // Is text\n if (child.nodeType === 3 && this._isText) {\n this._parseText(child, el);\n }\n child = child.nextSibling;\n }\n\n // Quit define\n if (nodeName === 'defs') {\n this._isDefine = false;\n }\n else if (nodeName === 'text') {\n this._isText = false;\n }\n};\n\nSVGParser.prototype._parseText = function (xmlNode, parentGroup) {\n if (xmlNode.nodeType === 1) {\n var dx = xmlNode.getAttribute('dx') || 0;\n var dy = xmlNode.getAttribute('dy') || 0;\n this._textX += parseFloat(dx);\n this._textY += parseFloat(dy);\n }\n\n var text = new Text({\n style: {\n text: xmlNode.textContent,\n transformText: true\n },\n position: [this._textX || 0, this._textY || 0]\n });\n\n inheritStyle(parentGroup, text);\n parseAttributes(xmlNode, text, this._defs);\n\n var fontSize = text.style.fontSize;\n if (fontSize && fontSize < 9) {\n // PENDING\n text.style.fontSize = 9;\n text.scale = text.scale || [1, 1];\n text.scale[0] *= fontSize / 9;\n text.scale[1] *= fontSize / 9;\n }\n\n var rect = text.getBoundingRect();\n this._textX += rect.width;\n\n parentGroup.add(text);\n\n return text;\n};\n\nvar nodeParsers = {\n 'g': function (xmlNode, parentGroup) {\n var g = new Group();\n inheritStyle(parentGroup, g);\n parseAttributes(xmlNode, g, this._defs);\n\n return g;\n },\n 'rect': function (xmlNode, parentGroup) {\n var rect = new Rect();\n inheritStyle(parentGroup, rect);\n parseAttributes(xmlNode, rect, this._defs);\n\n rect.setShape({\n x: parseFloat(xmlNode.getAttribute('x') || 0),\n y: parseFloat(xmlNode.getAttribute('y') || 0),\n width: parseFloat(xmlNode.getAttribute('width') || 0),\n height: parseFloat(xmlNode.getAttribute('height') || 0)\n });\n\n // console.log(xmlNode.getAttribute('transform'));\n // console.log(rect.transform);\n\n return rect;\n },\n 'circle': function (xmlNode, parentGroup) {\n var circle = new Circle();\n inheritStyle(parentGroup, circle);\n parseAttributes(xmlNode, circle, this._defs);\n\n circle.setShape({\n cx: parseFloat(xmlNode.getAttribute('cx') || 0),\n cy: parseFloat(xmlNode.getAttribute('cy') || 0),\n r: parseFloat(xmlNode.getAttribute('r') || 0)\n });\n\n return circle;\n },\n 'line': function (xmlNode, parentGroup) {\n var line = new Line();\n inheritStyle(parentGroup, line);\n parseAttributes(xmlNode, line, this._defs);\n\n line.setShape({\n x1: parseFloat(xmlNode.getAttribute('x1') || 0),\n y1: parseFloat(xmlNode.getAttribute('y1') || 0),\n x2: parseFloat(xmlNode.getAttribute('x2') || 0),\n y2: parseFloat(xmlNode.getAttribute('y2') || 0)\n });\n\n return line;\n },\n 'ellipse': function (xmlNode, parentGroup) {\n var ellipse = new Ellipse();\n inheritStyle(parentGroup, ellipse);\n parseAttributes(xmlNode, ellipse, this._defs);\n\n ellipse.setShape({\n cx: parseFloat(xmlNode.getAttribute('cx') || 0),\n cy: parseFloat(xmlNode.getAttribute('cy') || 0),\n rx: parseFloat(xmlNode.getAttribute('rx') || 0),\n ry: parseFloat(xmlNode.getAttribute('ry') || 0)\n });\n return ellipse;\n },\n 'polygon': function (xmlNode, parentGroup) {\n var points = xmlNode.getAttribute('points');\n if (points) {\n points = parsePoints(points);\n }\n var polygon = new Polygon({\n shape: {\n points: points || []\n }\n });\n\n inheritStyle(parentGroup, polygon);\n parseAttributes(xmlNode, polygon, this._defs);\n\n return polygon;\n },\n 'polyline': function (xmlNode, parentGroup) {\n var path = new Path();\n inheritStyle(parentGroup, path);\n parseAttributes(xmlNode, path, this._defs);\n\n var points = xmlNode.getAttribute('points');\n if (points) {\n points = parsePoints(points);\n }\n var polyline = new Polyline({\n shape: {\n points: points || []\n }\n });\n\n return polyline;\n },\n 'image': function (xmlNode, parentGroup) {\n var img = new ZImage();\n inheritStyle(parentGroup, img);\n parseAttributes(xmlNode, img, this._defs);\n\n img.setStyle({\n image: xmlNode.getAttribute('xlink:href'),\n x: xmlNode.getAttribute('x'),\n y: xmlNode.getAttribute('y'),\n width: xmlNode.getAttribute('width'),\n height: xmlNode.getAttribute('height')\n });\n\n return img;\n },\n 'text': function (xmlNode, parentGroup) {\n var x = xmlNode.getAttribute('x') || 0;\n var y = xmlNode.getAttribute('y') || 0;\n var dx = xmlNode.getAttribute('dx') || 0;\n var dy = xmlNode.getAttribute('dy') || 0;\n\n this._textX = parseFloat(x) + parseFloat(dx);\n this._textY = parseFloat(y) + parseFloat(dy);\n\n var g = new Group();\n inheritStyle(parentGroup, g);\n parseAttributes(xmlNode, g, this._defs);\n\n return g;\n },\n 'tspan': function (xmlNode, parentGroup) {\n var x = xmlNode.getAttribute('x');\n var y = xmlNode.getAttribute('y');\n if (x != null) {\n // new offset x\n this._textX = parseFloat(x);\n }\n if (y != null) {\n // new offset y\n this._textY = parseFloat(y);\n }\n var dx = xmlNode.getAttribute('dx') || 0;\n var dy = xmlNode.getAttribute('dy') || 0;\n\n var g = new Group();\n\n inheritStyle(parentGroup, g);\n parseAttributes(xmlNode, g, this._defs);\n\n\n this._textX += dx;\n this._textY += dy;\n\n return g;\n },\n 'path': function (xmlNode, parentGroup) {\n // TODO svg fill rule\n // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule\n // path.style.globalCompositeOperation = 'xor';\n var d = xmlNode.getAttribute('d') || '';\n\n // Performance sensitive.\n\n var path = createFromString(d);\n\n inheritStyle(parentGroup, path);\n parseAttributes(xmlNode, path, this._defs);\n\n return path;\n }\n};\n\nvar defineParsers = {\n\n 'lineargradient': function (xmlNode) {\n var x1 = parseInt(xmlNode.getAttribute('x1') || 0, 10);\n var y1 = parseInt(xmlNode.getAttribute('y1') || 0, 10);\n var x2 = parseInt(xmlNode.getAttribute('x2') || 10, 10);\n var y2 = parseInt(xmlNode.getAttribute('y2') || 0, 10);\n\n var gradient = new LinearGradient(x1, y1, x2, y2);\n\n _parseGradientColorStops(xmlNode, gradient);\n\n return gradient;\n },\n\n 'radialgradient': function (xmlNode) {\n\n }\n};\n\nfunction _parseGradientColorStops(xmlNode, gradient) {\n\n var stop = xmlNode.firstChild;\n\n while (stop) {\n if (stop.nodeType === 1) {\n var offset = stop.getAttribute('offset');\n if (offset.indexOf('%') > 0) { // percentage\n offset = parseInt(offset, 10) / 100;\n }\n else if (offset) { // number from 0 to 1\n offset = parseFloat(offset);\n }\n else {\n offset = 0;\n }\n\n var stopColor = stop.getAttribute('stop-color') || '#000000';\n\n gradient.addColorStop(offset, stopColor);\n }\n stop = stop.nextSibling;\n }\n}\n\nfunction inheritStyle(parent, child) {\n if (parent && parent.__inheritedStyle) {\n if (!child.__inheritedStyle) {\n child.__inheritedStyle = {};\n }\n defaults(child.__inheritedStyle, parent.__inheritedStyle);\n }\n}\n\nfunction parsePoints(pointsString) {\n var list = trim(pointsString).split(DILIMITER_REG);\n var points = [];\n\n for (var i = 0; i < list.length; i += 2) {\n var x = parseFloat(list[i]);\n var y = parseFloat(list[i + 1]);\n points.push([x, y]);\n }\n return points;\n}\n\nvar attributesMap = {\n 'fill': 'fill',\n 'stroke': 'stroke',\n 'stroke-width': 'lineWidth',\n 'opacity': 'opacity',\n 'fill-opacity': 'fillOpacity',\n 'stroke-opacity': 'strokeOpacity',\n 'stroke-dasharray': 'lineDash',\n 'stroke-dashoffset': 'lineDashOffset',\n 'stroke-linecap': 'lineCap',\n 'stroke-linejoin': 'lineJoin',\n 'stroke-miterlimit': 'miterLimit',\n 'font-family': 'fontFamily',\n 'font-size': 'fontSize',\n 'font-style': 'fontStyle',\n 'font-weight': 'fontWeight',\n\n 'text-align': 'textAlign',\n 'alignment-baseline': 'textBaseline'\n};\n\nfunction parseAttributes(xmlNode, el, defs, onlyInlineStyle) {\n var zrStyle = el.__inheritedStyle || {};\n var isTextEl = el.type === 'text';\n\n // TODO Shadow\n if (xmlNode.nodeType === 1) {\n parseTransformAttribute(xmlNode, el);\n\n extend(zrStyle, parseStyleAttribute(xmlNode));\n\n if (!onlyInlineStyle) {\n for (var svgAttrName in attributesMap) {\n if (attributesMap.hasOwnProperty(svgAttrName)) {\n var attrValue = xmlNode.getAttribute(svgAttrName);\n if (attrValue != null) {\n zrStyle[attributesMap[svgAttrName]] = attrValue;\n }\n }\n }\n }\n }\n\n var elFillProp = isTextEl ? 'textFill' : 'fill';\n var elStrokeProp = isTextEl ? 'textStroke' : 'stroke';\n\n el.style = el.style || new Style();\n var elStyle = el.style;\n\n zrStyle.fill != null && elStyle.set(elFillProp, getPaint(zrStyle.fill, defs));\n zrStyle.stroke != null && elStyle.set(elStrokeProp, getPaint(zrStyle.stroke, defs));\n\n each([\n 'lineWidth', 'opacity', 'fillOpacity', 'strokeOpacity', 'miterLimit', 'fontSize'\n ], function (propName) {\n var elPropName = (propName === 'lineWidth' && isTextEl) ? 'textStrokeWidth' : propName;\n zrStyle[propName] != null && elStyle.set(elPropName, parseFloat(zrStyle[propName]));\n });\n\n if (!zrStyle.textBaseline || zrStyle.textBaseline === 'auto') {\n zrStyle.textBaseline = 'alphabetic';\n }\n if (zrStyle.textBaseline === 'alphabetic') {\n zrStyle.textBaseline = 'bottom';\n }\n if (zrStyle.textAlign === 'start') {\n zrStyle.textAlign = 'left';\n }\n if (zrStyle.textAlign === 'end') {\n zrStyle.textAlign = 'right';\n }\n\n each(['lineDashOffset', 'lineCap', 'lineJoin',\n 'fontWeight', 'fontFamily', 'fontStyle', 'textAlign', 'textBaseline'\n ], function (propName) {\n zrStyle[propName] != null && elStyle.set(propName, zrStyle[propName]);\n });\n\n if (zrStyle.lineDash) {\n el.style.lineDash = trim(zrStyle.lineDash).split(DILIMITER_REG);\n }\n\n if (elStyle[elStrokeProp] && elStyle[elStrokeProp] !== 'none') {\n // enable stroke\n el[elStrokeProp] = true;\n }\n\n el.__inheritedStyle = zrStyle;\n}\n\n\nvar urlRegex = /url\\(\\s*#(.*?)\\)/;\nfunction getPaint(str, defs) {\n // if (str === 'none') {\n // return;\n // }\n var urlMatch = defs && str && str.match(urlRegex);\n if (urlMatch) {\n var url = trim(urlMatch[1]);\n var def = defs[url];\n return def;\n }\n return str;\n}\n\nvar transformRegex = /(translate|scale|rotate|skewX|skewY|matrix)\\(([\\-\\s0-9\\.e,]*)\\)/g;\n\nfunction parseTransformAttribute(xmlNode, node) {\n var transform = xmlNode.getAttribute('transform');\n if (transform) {\n transform = transform.replace(/,/g, ' ');\n var m = null;\n var transformOps = [];\n transform.replace(transformRegex, function (str, type, value) {\n transformOps.push(type, value);\n });\n for (var i = transformOps.length - 1; i > 0; i -= 2) {\n var value = transformOps[i];\n var type = transformOps[i - 1];\n m = m || matrix.create();\n switch (type) {\n case 'translate':\n value = trim(value).split(DILIMITER_REG);\n matrix.translate(m, m, [parseFloat(value[0]), parseFloat(value[1] || 0)]);\n break;\n case 'scale':\n value = trim(value).split(DILIMITER_REG);\n matrix.scale(m, m, [parseFloat(value[0]), parseFloat(value[1] || value[0])]);\n break;\n case 'rotate':\n value = trim(value).split(DILIMITER_REG);\n matrix.rotate(m, m, parseFloat(value[0]));\n break;\n case 'skew':\n value = trim(value).split(DILIMITER_REG);\n console.warn('Skew transform is not supported yet');\n break;\n case 'matrix':\n var value = trim(value).split(DILIMITER_REG);\n m[0] = parseFloat(value[0]);\n m[1] = parseFloat(value[1]);\n m[2] = parseFloat(value[2]);\n m[3] = parseFloat(value[3]);\n m[4] = parseFloat(value[4]);\n m[5] = parseFloat(value[5]);\n break;\n }\n }\n node.setLocalTransform(m);\n }\n}\n\n// Value may contain space.\nvar styleRegex = /([^\\s:;]+)\\s*:\\s*([^:;]+)/g;\nfunction parseStyleAttribute(xmlNode) {\n var style = xmlNode.getAttribute('style');\n var result = {};\n\n if (!style) {\n return result;\n }\n\n var styleList = {};\n styleRegex.lastIndex = 0;\n var styleRegResult;\n while ((styleRegResult = styleRegex.exec(style)) != null) {\n styleList[styleRegResult[1]] = styleRegResult[2];\n }\n\n for (var svgAttrName in attributesMap) {\n if (attributesMap.hasOwnProperty(svgAttrName) && styleList[svgAttrName] != null) {\n result[attributesMap[svgAttrName]] = styleList[svgAttrName];\n }\n }\n\n return result;\n}\n\n/**\n * @param {Array.<number>} viewBoxRect\n * @param {number} width\n * @param {number} height\n * @return {Object} {scale, position}\n */\nexport function makeViewBoxTransform(viewBoxRect, width, height) {\n var scaleX = width / viewBoxRect.width;\n var scaleY = height / viewBoxRect.height;\n var scale = Math.min(scaleX, scaleY);\n // preserveAspectRatio 'xMidYMid'\n var viewBoxScale = [scale, scale];\n var viewBoxPosition = [\n -(viewBoxRect.x + viewBoxRect.width / 2) * scale + width / 2,\n -(viewBoxRect.y + viewBoxRect.height / 2) * scale + height / 2\n ];\n\n return {\n scale: viewBoxScale,\n position: viewBoxPosition\n };\n}\n\n/**\n * @param {string|XMLElement} xml\n * @param {Object} [opt]\n * @param {number} [opt.width] Default width if svg width not specified or is a percent value.\n * @param {number} [opt.height] Default height if svg height not specified or is a percent value.\n * @param {boolean} [opt.ignoreViewBox]\n * @param {boolean} [opt.ignoreRootClip]\n * @return {Object} result:\n * {\n * root: Group, The root of the the result tree of zrender shapes,\n * width: number, the viewport width of the SVG,\n * height: number, the viewport height of the SVG,\n * viewBoxRect: {x, y, width, height}, the declared viewBox rect of the SVG, if exists,\n * viewBoxTransform: the {scale, position} calculated by viewBox and viewport, is exists.\n * }\n */\nexport function parseSVG(xml, opt) {\n var parser = new SVGParser();\n return parser.parse(xml, opt);\n}","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport {__DEV__} from '../../config';\nimport {createHashMap, isString, isArray, each, assert} from 'zrender/src/core/util';\nimport {parseXML} from 'zrender/src/tool/parseSVG';\n\n\nvar storage = createHashMap();\n\n// For minimize the code size of common echarts package,\n// do not put too much logic in this module.\n\nexport default {\n\n // The format of record: see `echarts.registerMap`.\n // Compatible with previous `echarts.registerMap`.\n registerMap: function (mapName, rawGeoJson, rawSpecialAreas) {\n\n var records;\n\n if (isArray(rawGeoJson)) {\n records = rawGeoJson;\n }\n else if (rawGeoJson.svg) {\n records = [{\n type: 'svg',\n source: rawGeoJson.svg,\n specialAreas: rawGeoJson.specialAreas\n }];\n }\n else {\n // Backward compatibility.\n if (rawGeoJson.geoJson && !rawGeoJson.features) {\n rawSpecialAreas = rawGeoJson.specialAreas;\n rawGeoJson = rawGeoJson.geoJson;\n }\n records = [{\n type: 'geoJSON',\n source: rawGeoJson,\n specialAreas: rawSpecialAreas\n }];\n }\n\n each(records, function (record) {\n var type = record.type;\n type === 'geoJson' && (type = record.type = 'geoJSON');\n\n var parse = parsers[type];\n\n if (__DEV__) {\n assert(parse, 'Illegal map type: ' + type);\n }\n\n parse(record);\n });\n\n return storage.set(mapName, records);\n },\n\n retrieveMap: function (mapName) {\n return storage.get(mapName);\n }\n\n};\n\nvar parsers = {\n\n geoJSON: function (record) {\n var source = record.source;\n record.geoJSON = !isString(source)\n ? source\n : (typeof JSON !== 'undefined' && JSON.parse)\n ? JSON.parse(source)\n : (new Function('return (' + source + ');'))();\n },\n\n // Only perform parse to XML object here, which might be time\n // consiming for large SVG.\n // Although convert XML to zrender element is also time consiming,\n // if we do it here, the clone of zrender elements has to be\n // required. So we do it once for each geo instance, util real\n // performance issues call for optimizing it.\n svg: function (record) {\n record.svgXML = parseXML(record.source);\n }\n\n};\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\nimport {__DEV__} from './config';\nimport * as zrender from 'zrender/src/zrender';\nimport * as zrUtil from 'zrender/src/core/util';\nimport * as colorTool from 'zrender/src/tool/color';\nimport env from 'zrender/src/core/env';\nimport timsort from 'zrender/src/core/timsort';\nimport Eventful from 'zrender/src/mixin/Eventful';\nimport GlobalModel from './model/Global';\nimport ExtensionAPI from './ExtensionAPI';\nimport CoordinateSystemManager from './CoordinateSystem';\nimport OptionManager from './model/OptionManager';\nimport backwardCompat from './preprocessor/backwardCompat';\nimport dataStack from './processor/dataStack';\nimport ComponentModel from './model/Component';\nimport SeriesModel from './model/Series';\nimport ComponentView from './view/Component';\nimport ChartView from './view/Chart';\nimport * as graphic from './util/graphic';\nimport * as modelUtil from './util/model';\nimport {throttle} from './util/throttle';\nimport seriesColor from './visual/seriesColor';\nimport aria from './visual/aria';\nimport loadingDefault from './loading/default';\nimport Scheduler from './stream/Scheduler';\nimport lightTheme from './theme/light';\nimport darkTheme from './theme/dark';\nimport './component/dataset';\nimport mapDataStorage from './coord/geo/mapDataStorage';\n\nvar assert = zrUtil.assert;\nvar each = zrUtil.each;\nvar isFunction = zrUtil.isFunction;\nvar isObject = zrUtil.isObject;\nvar parseClassType = ComponentModel.parseClassType;\n\nexport var version = '4.9.0';\n\nexport var dependencies = {\n zrender: '4.3.2'\n};\n\nvar TEST_FRAME_REMAIN_TIME = 1;\n\nvar PRIORITY_PROCESSOR_FILTER = 1000;\nvar PRIORITY_PROCESSOR_SERIES_FILTER = 800;\nvar PRIORITY_PROCESSOR_DATASTACK = 900;\nvar PRIORITY_PROCESSOR_STATISTIC = 5000;\n\nvar PRIORITY_VISUAL_LAYOUT = 1000;\nvar PRIORITY_VISUAL_PROGRESSIVE_LAYOUT = 1100;\nvar PRIORITY_VISUAL_GLOBAL = 2000;\nvar PRIORITY_VISUAL_CHART = 3000;\nvar PRIORITY_VISUAL_POST_CHART_LAYOUT = 3500;\nvar PRIORITY_VISUAL_COMPONENT = 4000;\n// FIXME\n// necessary?\nvar PRIORITY_VISUAL_BRUSH = 5000;\n\nexport var PRIORITY = {\n PROCESSOR: {\n FILTER: PRIORITY_PROCESSOR_FILTER,\n SERIES_FILTER: PRIORITY_PROCESSOR_SERIES_FILTER,\n STATISTIC: PRIORITY_PROCESSOR_STATISTIC\n },\n VISUAL: {\n LAYOUT: PRIORITY_VISUAL_LAYOUT,\n PROGRESSIVE_LAYOUT: PRIORITY_VISUAL_PROGRESSIVE_LAYOUT,\n GLOBAL: PRIORITY_VISUAL_GLOBAL,\n CHART: PRIORITY_VISUAL_CHART,\n POST_CHART_LAYOUT: PRIORITY_VISUAL_POST_CHART_LAYOUT,\n COMPONENT: PRIORITY_VISUAL_COMPONENT,\n BRUSH: PRIORITY_VISUAL_BRUSH\n }\n};\n\n// Main process have three entries: `setOption`, `dispatchAction` and `resize`,\n// where they must not be invoked nestedly, except the only case: invoke\n// dispatchAction with updateMethod \"none\" in main process.\n// This flag is used to carry out this rule.\n// All events will be triggered out side main process (i.e. when !this[IN_MAIN_PROCESS]).\nvar IN_MAIN_PROCESS = '__flagInMainProcess';\nvar OPTION_UPDATED = '__optionUpdated';\nvar ACTION_REG = /^[a-zA-Z0-9_]+$/;\n\n\nfunction createRegisterEventWithLowercaseName(method, ignoreDisposed) {\n return function (eventName, handler, context) {\n if (!ignoreDisposed && this._disposed) {\n disposedWarning(this.id);\n return;\n }\n\n // Event name is all lowercase\n eventName = eventName && eventName.toLowerCase();\n Eventful.prototype[method].call(this, eventName, handler, context);\n };\n}\n\n/**\n * @module echarts~MessageCenter\n */\nfunction MessageCenter() {\n Eventful.call(this);\n}\nMessageCenter.prototype.on = createRegisterEventWithLowercaseName('on', true);\nMessageCenter.prototype.off = createRegisterEventWithLowercaseName('off', true);\nMessageCenter.prototype.one = createRegisterEventWithLowercaseName('one', true);\nzrUtil.mixin(MessageCenter, Eventful);\n\n/**\n * @module echarts~ECharts\n */\nfunction ECharts(dom, theme, opts) {\n opts = opts || {};\n\n // Get theme by name\n if (typeof theme === 'string') {\n theme = themeStorage[theme];\n }\n\n /**\n * @type {string}\n */\n this.id;\n\n /**\n * Group id\n * @type {string}\n */\n this.group;\n\n /**\n * @type {HTMLElement}\n * @private\n */\n this._dom = dom;\n\n var defaultRenderer = 'canvas';\n if (__DEV__) {\n defaultRenderer = (\n typeof window === 'undefined' ? global : window\n ).__ECHARTS__DEFAULT__RENDERER__ || defaultRenderer;\n }\n\n /**\n * @type {module:zrender/ZRender}\n * @private\n */\n var zr = this._zr = zrender.init(dom, {\n renderer: opts.renderer || defaultRenderer,\n devicePixelRatio: opts.devicePixelRatio,\n width: opts.width,\n height: opts.height\n });\n\n /**\n * Expect 60 fps.\n * @type {Function}\n * @private\n */\n this._throttledZrFlush = throttle(zrUtil.bind(zr.flush, zr), 17);\n\n var theme = zrUtil.clone(theme);\n theme && backwardCompat(theme, true);\n /**\n * @type {Object}\n * @private\n */\n this._theme = theme;\n\n /**\n * @type {Array.<module:echarts/view/Chart>}\n * @private\n */\n this._chartsViews = [];\n\n /**\n * @type {Object.<string, module:echarts/view/Chart>}\n * @private\n */\n this._chartsMap = {};\n\n /**\n * @type {Array.<module:echarts/view/Component>}\n * @private\n */\n this._componentsViews = [];\n\n /**\n * @type {Object.<string, module:echarts/view/Component>}\n * @private\n */\n this._componentsMap = {};\n\n /**\n * @type {module:echarts/CoordinateSystem}\n * @private\n */\n this._coordSysMgr = new CoordinateSystemManager();\n\n /**\n * @type {module:echarts/ExtensionAPI}\n * @private\n */\n var api = this._api = createExtensionAPI(this);\n\n // Sort on demand\n function prioritySortFunc(a, b) {\n return a.__prio - b.__prio;\n }\n timsort(visualFuncs, prioritySortFunc);\n timsort(dataProcessorFuncs, prioritySortFunc);\n\n /**\n * @type {module:echarts/stream/Scheduler}\n */\n this._scheduler = new Scheduler(this, api, dataProcessorFuncs, visualFuncs);\n\n Eventful.call(this, this._ecEventProcessor = new EventProcessor());\n\n /**\n * @type {module:echarts~MessageCenter}\n * @private\n */\n this._messageCenter = new MessageCenter();\n\n // Init mouse events\n this._initEvents();\n\n // In case some people write `window.onresize = chart.resize`\n this.resize = zrUtil.bind(this.resize, this);\n\n // Can't dispatch action during rendering procedure\n this._pendingActions = [];\n\n zr.animation.on('frame', this._onframe, this);\n\n bindRenderedEvent(zr, this);\n\n // ECharts instance can be used as value.\n zrUtil.setAsPrimitive(this);\n}\n\nvar echartsProto = ECharts.prototype;\n\nechartsProto._onframe = function () {\n if (this._disposed) {\n return;\n }\n\n var scheduler = this._scheduler;\n\n // Lazy update\n if (this[OPTION_UPDATED]) {\n var silent = this[OPTION_UPDATED].silent;\n\n this[IN_MAIN_PROCESS] = true;\n\n prepare(this);\n updateMethods.update.call(this);\n\n this[IN_MAIN_PROCESS] = false;\n\n this[OPTION_UPDATED] = false;\n\n flushPendingActions.call(this, silent);\n\n triggerUpdatedEvent.call(this, silent);\n }\n // Avoid do both lazy update and progress in one frame.\n else if (scheduler.unfinished) {\n // Stream progress.\n var remainTime = TEST_FRAME_REMAIN_TIME;\n var ecModel = this._model;\n var api = this._api;\n scheduler.unfinished = false;\n do {\n var startTime = +new Date();\n\n scheduler.performSeriesTasks(ecModel);\n\n // Currently dataProcessorFuncs do not check threshold.\n scheduler.performDataProcessorTasks(ecModel);\n\n updateStreamModes(this, ecModel);\n\n // Do not update coordinate system here. Because that coord system update in\n // each frame is not a good user experience. So we follow the rule that\n // the extent of the coordinate system is determin in the first frame (the\n // frame is executed immedietely after task reset.\n // this._coordSysMgr.update(ecModel, api);\n\n // console.log('--- ec frame visual ---', remainTime);\n scheduler.performVisualTasks(ecModel);\n\n renderSeries(this, this._model, api, 'remain');\n\n remainTime -= (+new Date() - startTime);\n }\n while (remainTime > 0 && scheduler.unfinished);\n\n // Call flush explicitly for trigger finished event.\n if (!scheduler.unfinished) {\n this._zr.flush();\n }\n // Else, zr flushing be ensue within the same frame,\n // because zr flushing is after onframe event.\n }\n};\n\n/**\n * @return {HTMLElement}\n */\nechartsProto.getDom = function () {\n return this._dom;\n};\n\n/**\n * @return {module:zrender~ZRender}\n */\nechartsProto.getZr = function () {\n return this._zr;\n};\n\n/**\n * Usage:\n * chart.setOption(option, notMerge, lazyUpdate);\n * chart.setOption(option, {\n * notMerge: ...,\n * lazyUpdate: ...,\n * silent: ...\n * });\n *\n * @param {Object} option\n * @param {Object|boolean} [opts] opts or notMerge.\n * @param {boolean} [opts.notMerge=false]\n * @param {boolean} [opts.lazyUpdate=false] Useful when setOption frequently.\n */\nechartsProto.setOption = function (option, notMerge, lazyUpdate) {\n if (__DEV__) {\n assert(!this[IN_MAIN_PROCESS], '`setOption` should not be called during main process.');\n }\n if (this._disposed) {\n disposedWarning(this.id);\n return;\n }\n\n var silent;\n if (isObject(notMerge)) {\n lazyUpdate = notMerge.lazyUpdate;\n silent = notMerge.silent;\n notMerge = notMerge.notMerge;\n }\n\n this[IN_MAIN_PROCESS] = true;\n\n if (!this._model || notMerge) {\n var optionManager = new OptionManager(this._api);\n var theme = this._theme;\n var ecModel = this._model = new GlobalModel();\n ecModel.scheduler = this._scheduler;\n ecModel.init(null, null, theme, optionManager);\n }\n\n this._model.setOption(option, optionPreprocessorFuncs);\n\n if (lazyUpdate) {\n this[OPTION_UPDATED] = {silent: silent};\n this[IN_MAIN_PROCESS] = false;\n }\n else {\n prepare(this);\n\n updateMethods.update.call(this);\n\n // Ensure zr refresh sychronously, and then pixel in canvas can be\n // fetched after `setOption`.\n this._zr.flush();\n\n this[OPTION_UPDATED] = false;\n this[IN_MAIN_PROCESS] = false;\n\n flushPendingActions.call(this, silent);\n triggerUpdatedEvent.call(this, silent);\n }\n};\n\n/**\n * @DEPRECATED\n */\nechartsProto.setTheme = function () {\n console.error('ECharts#setTheme() is DEPRECATED in ECharts 3.0');\n};\n\n/**\n * @return {module:echarts/model/Global}\n */\nechartsProto.getModel = function () {\n return this._model;\n};\n\n/**\n * @return {Object}\n */\nechartsProto.getOption = function () {\n return this._model && this._model.getOption();\n};\n\n/**\n * @return {number}\n */\nechartsProto.getWidth = function () {\n return this._zr.getWidth();\n};\n\n/**\n * @return {number}\n */\nechartsProto.getHeight = function () {\n return this._zr.getHeight();\n};\n\n/**\n * @return {number}\n */\nechartsProto.getDevicePixelRatio = function () {\n return this._zr.painter.dpr || window.devicePixelRatio || 1;\n};\n\n/**\n * Get canvas which has all thing rendered\n * @param {Object} opts\n * @param {string} [opts.backgroundColor]\n * @return {string}\n */\nechartsProto.getRenderedCanvas = function (opts) {\n if (!env.canvasSupported) {\n return;\n }\n opts = opts || {};\n opts.pixelRatio = opts.pixelRatio || 1;\n opts.backgroundColor = opts.backgroundColor\n || this._model.get('backgroundColor');\n var zr = this._zr;\n // var list = zr.storage.getDisplayList();\n // Stop animations\n // Never works before in init animation, so remove it.\n // zrUtil.each(list, function (el) {\n // el.stopAnimation(true);\n // });\n return zr.painter.getRenderedCanvas(opts);\n};\n\n/**\n * Get svg data url\n * @return {string}\n */\nechartsProto.getSvgDataURL = function () {\n if (!env.svgSupported) {\n return;\n }\n\n var zr = this._zr;\n var list = zr.storage.getDisplayList();\n // Stop animations\n zrUtil.each(list, function (el) {\n el.stopAnimation(true);\n });\n\n return zr.painter.toDataURL();\n};\n\n/**\n * @return {string}\n * @param {Object} opts\n * @param {string} [opts.type='png']\n * @param {string} [opts.pixelRatio=1]\n * @param {string} [opts.backgroundColor]\n * @param {string} [opts.excludeComponents]\n */\nechartsProto.getDataURL = function (opts) {\n if (this._disposed) {\n disposedWarning(this.id);\n return;\n }\n\n opts = opts || {};\n var excludeComponents = opts.excludeComponents;\n var ecModel = this._model;\n var excludesComponentViews = [];\n var self = this;\n\n each(excludeComponents, function (componentType) {\n ecModel.eachComponent({\n mainType: componentType\n }, function (component) {\n var view = self._componentsMap[component.__viewId];\n if (!view.group.ignore) {\n excludesComponentViews.push(view);\n view.group.ignore = true;\n }\n });\n });\n\n var url = this._zr.painter.getType() === 'svg'\n ? this.getSvgDataURL()\n : this.getRenderedCanvas(opts).toDataURL(\n 'image/' + (opts && opts.type || 'png')\n );\n\n each(excludesComponentViews, function (view) {\n view.group.ignore = false;\n });\n\n return url;\n};\n\n\n/**\n * @return {string}\n * @param {Object} opts\n * @param {string} [opts.type='png']\n * @param {string} [opts.pixelRatio=1]\n * @param {string} [opts.backgroundColor]\n */\nechartsProto.getConnectedDataURL = function (opts) {\n if (this._disposed) {\n disposedWarning(this.id);\n return;\n }\n\n if (!env.canvasSupported) {\n return;\n }\n var isSvg = opts.type === 'svg';\n var groupId = this.group;\n var mathMin = Math.min;\n var mathMax = Math.max;\n var MAX_NUMBER = Infinity;\n if (connectedGroups[groupId]) {\n var left = MAX_NUMBER;\n var top = MAX_NUMBER;\n var right = -MAX_NUMBER;\n var bottom = -MAX_NUMBER;\n var canvasList = [];\n var dpr = (opts && opts.pixelRatio) || 1;\n\n zrUtil.each(instances, function (chart, id) {\n if (chart.group === groupId) {\n var canvas = isSvg\n ? chart.getZr().painter.getSvgDom().innerHTML\n : chart.getRenderedCanvas(zrUtil.clone(opts));\n var boundingRect = chart.getDom().getBoundingClientRect();\n left = mathMin(boundingRect.left, left);\n top = mathMin(boundingRect.top, top);\n right = mathMax(boundingRect.right, right);\n bottom = mathMax(boundingRect.bottom, bottom);\n canvasList.push({\n dom: canvas,\n left: boundingRect.left,\n top: boundingRect.top\n });\n }\n });\n\n left *= dpr;\n top *= dpr;\n right *= dpr;\n bottom *= dpr;\n var width = right - left;\n var height = bottom - top;\n var targetCanvas = zrUtil.createCanvas();\n var zr = zrender.init(targetCanvas, {\n renderer: isSvg ? 'svg' : 'canvas'\n });\n zr.resize({\n width: width,\n height: height\n });\n\n if (isSvg) {\n var content = '';\n each(canvasList, function (item) {\n var x = item.left - left;\n var y = item.top - top;\n content += '<g transform=\"translate(' + x + ','\n + y + ')\">' + item.dom + '</g>';\n });\n zr.painter.getSvgRoot().innerHTML = content;\n\n if (opts.connectedBackgroundColor) {\n zr.painter.setBackgroundColor(opts.connectedBackgroundColor);\n }\n\n zr.refreshImmediately();\n return zr.painter.toDataURL();\n }\n else {\n // Background between the charts\n if (opts.connectedBackgroundColor) {\n zr.add(new graphic.Rect({\n shape: {\n x: 0,\n y: 0,\n width: width,\n height: height\n },\n style: {\n fill: opts.connectedBackgroundColor\n }\n }));\n }\n\n each(canvasList, function (item) {\n var img = new graphic.Image({\n style: {\n x: item.left * dpr - left,\n y: item.top * dpr - top,\n image: item.dom\n }\n });\n zr.add(img);\n });\n\n zr.refreshImmediately();\n return targetCanvas.toDataURL('image/' + (opts && opts.type || 'png'));\n }\n }\n else {\n return this.getDataURL(opts);\n }\n};\n\n/**\n * Convert from logical coordinate system to pixel coordinate system.\n * See CoordinateSystem#convertToPixel.\n * @param {string|Object} finder\n * If string, e.g., 'geo', means {geoIndex: 0}.\n * If Object, could contain some of these properties below:\n * {\n * seriesIndex / seriesId / seriesName,\n * geoIndex / geoId, geoName,\n * bmapIndex / bmapId / bmapName,\n * xAxisIndex / xAxisId / xAxisName,\n * yAxisIndex / yAxisId / yAxisName,\n * gridIndex / gridId / gridName,\n * ... (can be extended)\n * }\n * @param {Array|number} value\n * @return {Array|number} result\n */\nechartsProto.convertToPixel = zrUtil.curry(doConvertPixel, 'convertToPixel');\n\n/**\n * Convert from pixel coordinate system to logical coordinate system.\n * See CoordinateSystem#convertFromPixel.\n * @param {string|Object} finder\n * If string, e.g., 'geo', means {geoIndex: 0}.\n * If Object, could contain some of these properties below:\n * {\n * seriesIndex / seriesId / seriesName,\n * geoIndex / geoId / geoName,\n * bmapIndex / bmapId / bmapName,\n * xAxisIndex / xAxisId / xAxisName,\n * yAxisIndex / yAxisId / yAxisName\n * gridIndex / gridId / gridName,\n * ... (can be extended)\n * }\n * @param {Array|number} value\n * @return {Array|number} result\n */\nechartsProto.convertFromPixel = zrUtil.curry(doConvertPixel, 'convertFromPixel');\n\nfunction doConvertPixel(methodName, finder, value) {\n if (this._disposed) {\n disposedWarning(this.id);\n return;\n }\n\n var ecModel = this._model;\n var coordSysList = this._coordSysMgr.getCoordinateSystems();\n var result;\n\n finder = modelUtil.parseFinder(ecModel, finder);\n\n for (var i = 0; i < coordSysList.length; i++) {\n var coordSys = coordSysList[i];\n if (coordSys[methodName]\n && (result = coordSys[methodName](ecModel, finder, value)) != null\n ) {\n return result;\n }\n }\n\n if (__DEV__) {\n console.warn(\n 'No coordinate system that supports ' + methodName + ' found by the given finder.'\n );\n }\n}\n\n/**\n * Is the specified coordinate systems or components contain the given pixel point.\n * @param {string|Object} finder\n * If string, e.g., 'geo', means {geoIndex: 0}.\n * If Object, could contain some of these properties below:\n * {\n * seriesIndex / seriesId / seriesName,\n * geoIndex / geoId / geoName,\n * bmapIndex / bmapId / bmapName,\n * xAxisIndex / xAxisId / xAxisName,\n * yAxisIndex / yAxisId / yAxisName,\n * gridIndex / gridId / gridName,\n * ... (can be extended)\n * }\n * @param {Array|number} value\n * @return {boolean} result\n */\nechartsProto.containPixel = function (finder, value) {\n if (this._disposed) {\n disposedWarning(this.id);\n return;\n }\n\n var ecModel = this._model;\n var result;\n\n finder = modelUtil.parseFinder(ecModel, finder);\n\n zrUtil.each(finder, function (models, key) {\n key.indexOf('Models') >= 0 && zrUtil.each(models, function (model) {\n var coordSys = model.coordinateSystem;\n if (coordSys && coordSys.containPoint) {\n result |= !!coordSys.containPoint(value);\n }\n else if (key === 'seriesModels') {\n var view = this._chartsMap[model.__viewId];\n if (view && view.containPoint) {\n result |= view.containPoint(value, model);\n }\n else {\n if (__DEV__) {\n console.warn(key + ': ' + (view\n ? 'The found component do not support containPoint.'\n : 'No view mapping to the found component.'\n ));\n }\n }\n }\n else {\n if (__DEV__) {\n console.warn(key + ': containPoint is not supported');\n }\n }\n }, this);\n }, this);\n\n return !!result;\n};\n\n/**\n * Get visual from series or data.\n * @param {string|Object} finder\n * If string, e.g., 'series', means {seriesIndex: 0}.\n * If Object, could contain some of these properties below:\n * {\n * seriesIndex / seriesId / seriesName,\n * dataIndex / dataIndexInside\n * }\n * If dataIndex is not specified, series visual will be fetched,\n * but not data item visual.\n * If all of seriesIndex, seriesId, seriesName are not specified,\n * visual will be fetched from first series.\n * @param {string} visualType 'color', 'symbol', 'symbolSize'\n */\nechartsProto.getVisual = function (finder, visualType) {\n var ecModel = this._model;\n\n finder = modelUtil.parseFinder(ecModel, finder, {defaultMainType: 'series'});\n\n var seriesModel = finder.seriesModel;\n\n if (__DEV__) {\n if (!seriesModel) {\n console.warn('There is no specified seires model');\n }\n }\n\n var data = seriesModel.getData();\n\n var dataIndexInside = finder.hasOwnProperty('dataIndexInside')\n ? finder.dataIndexInside\n : finder.hasOwnProperty('dataIndex')\n ? data.indexOfRawIndex(finder.dataIndex)\n : null;\n\n return dataIndexInside != null\n ? data.getItemVisual(dataIndexInside, visualType)\n : data.getVisual(visualType);\n};\n\n/**\n * Get view of corresponding component model\n * @param {module:echarts/model/Component} componentModel\n * @return {module:echarts/view/Component}\n */\nechartsProto.getViewOfComponentModel = function (componentModel) {\n return this._componentsMap[componentModel.__viewId];\n};\n\n/**\n * Get view of corresponding series model\n * @param {module:echarts/model/Series} seriesModel\n * @return {module:echarts/view/Chart}\n */\nechartsProto.getViewOfSeriesModel = function (seriesModel) {\n return this._chartsMap[seriesModel.__viewId];\n};\n\nvar updateMethods = {\n\n prepareAndUpdate: function (payload) {\n prepare(this);\n updateMethods.update.call(this, payload);\n },\n\n /**\n * @param {Object} payload\n * @private\n */\n update: function (payload) {\n // console.profile && console.profile('update');\n\n var ecModel = this._model;\n var api = this._api;\n var zr = this._zr;\n var coordSysMgr = this._coordSysMgr;\n var scheduler = this._scheduler;\n\n // update before setOption\n if (!ecModel) {\n return;\n }\n\n scheduler.restoreData(ecModel, payload);\n\n scheduler.performSeriesTasks(ecModel);\n\n // TODO\n // Save total ecModel here for undo/redo (after restoring data and before processing data).\n // Undo (restoration of total ecModel) can be carried out in 'action' or outside API call.\n\n // Create new coordinate system each update\n // In LineView may save the old coordinate system and use it to get the orignal point\n coordSysMgr.create(ecModel, api);\n\n scheduler.performDataProcessorTasks(ecModel, payload);\n\n // Current stream render is not supported in data process. So we can update\n // stream modes after data processing, where the filtered data is used to\n // deteming whether use progressive rendering.\n updateStreamModes(this, ecModel);\n\n // We update stream modes before coordinate system updated, then the modes info\n // can be fetched when coord sys updating (consider the barGrid extent fix). But\n // the drawback is the full coord info can not be fetched. Fortunately this full\n // coord is not requied in stream mode updater currently.\n coordSysMgr.update(ecModel, api);\n\n clearColorPalette(ecModel);\n scheduler.performVisualTasks(ecModel, payload);\n\n render(this, ecModel, api, payload);\n\n // Set background\n var backgroundColor = ecModel.get('backgroundColor') || 'transparent';\n\n // In IE8\n if (!env.canvasSupported) {\n var colorArr = colorTool.parse(backgroundColor);\n backgroundColor = colorTool.stringify(colorArr, 'rgb');\n if (colorArr[3] === 0) {\n backgroundColor = 'transparent';\n }\n }\n else {\n zr.setBackgroundColor(backgroundColor);\n }\n\n performPostUpdateFuncs(ecModel, api);\n\n // console.profile && console.profileEnd('update');\n },\n\n /**\n * @param {Object} payload\n * @private\n */\n updateTransform: function (payload) {\n var ecModel = this._model;\n var ecIns = this;\n var api = this._api;\n\n // update before setOption\n if (!ecModel) {\n return;\n }\n\n // ChartView.markUpdateMethod(payload, 'updateTransform');\n\n var componentDirtyList = [];\n ecModel.eachComponent(function (componentType, componentModel) {\n var componentView = ecIns.getViewOfComponentModel(componentModel);\n if (componentView && componentView.__alive) {\n if (componentView.updateTransform) {\n var result = componentView.updateTransform(componentModel, ecModel, api, payload);\n result && result.update && componentDirtyList.push(componentView);\n }\n else {\n componentDirtyList.push(componentView);\n }\n }\n });\n\n var seriesDirtyMap = zrUtil.createHashMap();\n ecModel.eachSeries(function (seriesModel) {\n var chartView = ecIns._chartsMap[seriesModel.__viewId];\n if (chartView.updateTransform) {\n var result = chartView.updateTransform(seriesModel, ecModel, api, payload);\n result && result.update && seriesDirtyMap.set(seriesModel.uid, 1);\n }\n else {\n seriesDirtyMap.set(seriesModel.uid, 1);\n }\n });\n\n clearColorPalette(ecModel);\n // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.\n // this._scheduler.performVisualTasks(ecModel, payload, 'layout', true);\n this._scheduler.performVisualTasks(\n ecModel, payload, {setDirty: true, dirtyMap: seriesDirtyMap}\n );\n\n // Currently, not call render of components. Geo render cost a lot.\n // renderComponents(ecIns, ecModel, api, payload, componentDirtyList);\n renderSeries(ecIns, ecModel, api, payload, seriesDirtyMap);\n\n performPostUpdateFuncs(ecModel, this._api);\n },\n\n /**\n * @param {Object} payload\n * @private\n */\n updateView: function (payload) {\n var ecModel = this._model;\n\n // update before setOption\n if (!ecModel) {\n return;\n }\n\n ChartView.markUpdateMethod(payload, 'updateView');\n\n clearColorPalette(ecModel);\n\n // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.\n this._scheduler.performVisualTasks(ecModel, payload, {setDirty: true});\n\n render(this, this._model, this._api, payload);\n\n performPostUpdateFuncs(ecModel, this._api);\n },\n\n /**\n * @param {Object} payload\n * @private\n */\n updateVisual: function (payload) {\n updateMethods.update.call(this, payload);\n\n // var ecModel = this._model;\n\n // // update before setOption\n // if (!ecModel) {\n // return;\n // }\n\n // ChartView.markUpdateMethod(payload, 'updateVisual');\n\n // clearColorPalette(ecModel);\n\n // // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.\n // this._scheduler.performVisualTasks(ecModel, payload, {visualType: 'visual', setDirty: true});\n\n // render(this, this._model, this._api, payload);\n\n // performPostUpdateFuncs(ecModel, this._api);\n },\n\n /**\n * @param {Object} payload\n * @private\n */\n updateLayout: function (payload) {\n updateMethods.update.call(this, payload);\n\n // var ecModel = this._model;\n\n // // update before setOption\n // if (!ecModel) {\n // return;\n // }\n\n // ChartView.markUpdateMethod(payload, 'updateLayout');\n\n // // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.\n // // this._scheduler.performVisualTasks(ecModel, payload, 'layout', true);\n // this._scheduler.performVisualTasks(ecModel, payload, {setDirty: true});\n\n // render(this, this._model, this._api, payload);\n\n // performPostUpdateFuncs(ecModel, this._api);\n }\n};\n\nfunction prepare(ecIns) {\n var ecModel = ecIns._model;\n var scheduler = ecIns._scheduler;\n\n scheduler.restorePipelines(ecModel);\n\n scheduler.prepareStageTasks();\n\n prepareView(ecIns, 'component', ecModel, scheduler);\n\n prepareView(ecIns, 'chart', ecModel, scheduler);\n\n scheduler.plan();\n}\n\n/**\n * @private\n */\nfunction updateDirectly(ecIns, method, payload, mainType, subType) {\n var ecModel = ecIns._model;\n\n // broadcast\n if (!mainType) {\n // FIXME\n // Chart will not be update directly here, except set dirty.\n // But there is no such scenario now.\n each(ecIns._componentsViews.concat(ecIns._chartsViews), callView);\n return;\n }\n\n var query = {};\n query[mainType + 'Id'] = payload[mainType + 'Id'];\n query[mainType + 'Index'] = payload[mainType + 'Index'];\n query[mainType + 'Name'] = payload[mainType + 'Name'];\n\n var condition = {mainType: mainType, query: query};\n subType && (condition.subType = subType); // subType may be '' by parseClassType;\n\n var excludeSeriesId = payload.excludeSeriesId;\n if (excludeSeriesId != null) {\n excludeSeriesId = zrUtil.createHashMap(modelUtil.normalizeToArray(excludeSeriesId));\n }\n\n // If dispatchAction before setOption, do nothing.\n ecModel && ecModel.eachComponent(condition, function (model) {\n if (!excludeSeriesId || excludeSeriesId.get(model.id) == null) {\n callView(ecIns[\n mainType === 'series' ? '_chartsMap' : '_componentsMap'\n ][model.__viewId]);\n }\n }, ecIns);\n\n function callView(view) {\n view && view.__alive && view[method] && view[method](\n view.__model, ecModel, ecIns._api, payload\n );\n }\n}\n\n/**\n * Resize the chart\n * @param {Object} opts\n * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)\n * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)\n * @param {boolean} [opts.silent=false]\n */\nechartsProto.resize = function (opts) {\n if (__DEV__) {\n assert(!this[IN_MAIN_PROCESS], '`resize` should not be called during main process.');\n }\n if (this._disposed) {\n disposedWarning(this.id);\n return;\n }\n\n this._zr.resize(opts);\n\n var ecModel = this._model;\n\n // Resize loading effect\n this._loadingFX && this._loadingFX.resize();\n\n if (!ecModel) {\n return;\n }\n\n var optionChanged = ecModel.resetOption('media');\n\n var silent = opts && opts.silent;\n\n this[IN_MAIN_PROCESS] = true;\n\n optionChanged && prepare(this);\n updateMethods.update.call(this);\n\n this[IN_MAIN_PROCESS] = false;\n\n flushPendingActions.call(this, silent);\n\n triggerUpdatedEvent.call(this, silent);\n};\n\nfunction updateStreamModes(ecIns, ecModel) {\n var chartsMap = ecIns._chartsMap;\n var scheduler = ecIns._scheduler;\n ecModel.eachSeries(function (seriesModel) {\n scheduler.updateStreamModes(seriesModel, chartsMap[seriesModel.__viewId]);\n });\n}\n\n/**\n * Show loading effect\n * @param {string} [name='default']\n * @param {Object} [cfg]\n */\nechartsProto.showLoading = function (name, cfg) {\n if (this._disposed) {\n disposedWarning(this.id);\n return;\n }\n\n if (isObject(name)) {\n cfg = name;\n name = '';\n }\n name = name || 'default';\n\n this.hideLoading();\n if (!loadingEffects[name]) {\n if (__DEV__) {\n console.warn('Loading effects ' + name + ' not exists.');\n }\n return;\n }\n var el = loadingEffects[name](this._api, cfg);\n var zr = this._zr;\n this._loadingFX = el;\n\n zr.add(el);\n};\n\n/**\n * Hide loading effect\n */\nechartsProto.hideLoading = function () {\n if (this._disposed) {\n disposedWarning(this.id);\n return;\n }\n\n this._loadingFX && this._zr.remove(this._loadingFX);\n this._loadingFX = null;\n};\n\n/**\n * @param {Object} eventObj\n * @return {Object}\n */\nechartsProto.makeActionFromEvent = function (eventObj) {\n var payload = zrUtil.extend({}, eventObj);\n payload.type = eventActionMap[eventObj.type];\n return payload;\n};\n\n/**\n * @pubilc\n * @param {Object} payload\n * @param {string} [payload.type] Action type\n * @param {Object|boolean} [opt] If pass boolean, means opt.silent\n * @param {boolean} [opt.silent=false] Whether trigger events.\n * @param {boolean} [opt.flush=undefined]\n * true: Flush immediately, and then pixel in canvas can be fetched\n * immediately. Caution: it might affect performance.\n * false: Not flush.\n * undefined: Auto decide whether perform flush.\n */\nechartsProto.dispatchAction = function (payload, opt) {\n if (this._disposed) {\n disposedWarning(this.id);\n return;\n }\n\n if (!isObject(opt)) {\n opt = {silent: !!opt};\n }\n\n if (!actions[payload.type]) {\n return;\n }\n\n // Avoid dispatch action before setOption. Especially in `connect`.\n if (!this._model) {\n return;\n }\n\n // May dispatchAction in rendering procedure\n if (this[IN_MAIN_PROCESS]) {\n this._pendingActions.push(payload);\n return;\n }\n\n doDispatchAction.call(this, payload, opt.silent);\n\n if (opt.flush) {\n this._zr.flush(true);\n }\n else if (opt.flush !== false && env.browser.weChat) {\n // In WeChat embeded browser, `requestAnimationFrame` and `setInterval`\n // hang when sliding page (on touch event), which cause that zr does not\n // refresh util user interaction finished, which is not expected.\n // But `dispatchAction` may be called too frequently when pan on touch\n // screen, which impacts performance if do not throttle them.\n this._throttledZrFlush();\n }\n\n flushPendingActions.call(this, opt.silent);\n\n triggerUpdatedEvent.call(this, opt.silent);\n};\n\nfunction doDispatchAction(payload, silent) {\n var payloadType = payload.type;\n var escapeConnect = payload.escapeConnect;\n var actionWrap = actions[payloadType];\n var actionInfo = actionWrap.actionInfo;\n\n var cptType = (actionInfo.update || 'update').split(':');\n var updateMethod = cptType.pop();\n cptType = cptType[0] != null && parseClassType(cptType[0]);\n\n this[IN_MAIN_PROCESS] = true;\n\n var payloads = [payload];\n var batched = false;\n // Batch action\n if (payload.batch) {\n batched = true;\n payloads = zrUtil.map(payload.batch, function (item) {\n item = zrUtil.defaults(zrUtil.extend({}, item), payload);\n item.batch = null;\n return item;\n });\n }\n\n var eventObjBatch = [];\n var eventObj;\n var isHighDown = payloadType === 'highlight' || payloadType === 'downplay';\n\n each(payloads, function (batchItem) {\n // Action can specify the event by return it.\n eventObj = actionWrap.action(batchItem, this._model, this._api);\n // Emit event outside\n eventObj = eventObj || zrUtil.extend({}, batchItem);\n // Convert type to eventType\n eventObj.type = actionInfo.event || eventObj.type;\n eventObjBatch.push(eventObj);\n\n // light update does not perform data process, layout and visual.\n if (isHighDown) {\n // method, payload, mainType, subType\n updateDirectly(this, updateMethod, batchItem, 'series');\n }\n else if (cptType) {\n updateDirectly(this, updateMethod, batchItem, cptType.main, cptType.sub);\n }\n }, this);\n\n if (updateMethod !== 'none' && !isHighDown && !cptType) {\n // Still dirty\n if (this[OPTION_UPDATED]) {\n // FIXME Pass payload ?\n prepare(this);\n updateMethods.update.call(this, payload);\n this[OPTION_UPDATED] = false;\n }\n else {\n updateMethods[updateMethod].call(this, payload);\n }\n }\n\n // Follow the rule of action batch\n if (batched) {\n eventObj = {\n type: actionInfo.event || payloadType,\n escapeConnect: escapeConnect,\n batch: eventObjBatch\n };\n }\n else {\n eventObj = eventObjBatch[0];\n }\n\n this[IN_MAIN_PROCESS] = false;\n\n !silent && this._messageCenter.trigger(eventObj.type, eventObj);\n}\n\nfunction flushPendingActions(silent) {\n var pendingActions = this._pendingActions;\n while (pendingActions.length) {\n var payload = pendingActions.shift();\n doDispatchAction.call(this, payload, silent);\n }\n}\n\nfunction triggerUpdatedEvent(silent) {\n !silent && this.trigger('updated');\n}\n\n/**\n * Event `rendered` is triggered when zr\n * rendered. It is useful for realtime\n * snapshot (reflect animation).\n *\n * Event `finished` is triggered when:\n * (1) zrender rendering finished.\n * (2) initial animation finished.\n * (3) progressive rendering finished.\n * (4) no pending action.\n * (5) no delayed setOption needs to be processed.\n */\nfunction bindRenderedEvent(zr, ecIns) {\n zr.on('rendered', function () {\n\n ecIns.trigger('rendered');\n\n // The `finished` event should not be triggered repeatly,\n // so it should only be triggered when rendering indeed happend\n // in zrender. (Consider the case that dipatchAction is keep\n // triggering when mouse move).\n if (\n // Although zr is dirty if initial animation is not finished\n // and this checking is called on frame, we also check\n // animation finished for robustness.\n zr.animation.isFinished()\n && !ecIns[OPTION_UPDATED]\n && !ecIns._scheduler.unfinished\n && !ecIns._pendingActions.length\n ) {\n ecIns.trigger('finished');\n }\n });\n}\n\n/**\n * @param {Object} params\n * @param {number} params.seriesIndex\n * @param {Array|TypedArray} params.data\n */\nechartsProto.appendData = function (params) {\n if (this._disposed) {\n disposedWarning(this.id);\n return;\n }\n\n var seriesIndex = params.seriesIndex;\n var ecModel = this.getModel();\n var seriesModel = ecModel.getSeriesByIndex(seriesIndex);\n\n if (__DEV__) {\n assert(params.data && seriesModel);\n }\n\n seriesModel.appendData(params);\n\n // Note: `appendData` does not support that update extent of coordinate\n // system, util some scenario require that. In the expected usage of\n // `appendData`, the initial extent of coordinate system should better\n // be fixed by axis `min`/`max` setting or initial data, otherwise if\n // the extent changed while `appendData`, the location of the painted\n // graphic elements have to be changed, which make the usage of\n // `appendData` meaningless.\n\n this._scheduler.unfinished = true;\n};\n\n/**\n * Register event\n * @method\n */\nechartsProto.on = createRegisterEventWithLowercaseName('on', false);\nechartsProto.off = createRegisterEventWithLowercaseName('off', false);\nechartsProto.one = createRegisterEventWithLowercaseName('one', false);\n\n/**\n * Prepare view instances of charts and components\n * @param {module:echarts/model/Global} ecModel\n * @private\n */\nfunction prepareView(ecIns, type, ecModel, scheduler) {\n var isComponent = type === 'component';\n var viewList = isComponent ? ecIns._componentsViews : ecIns._chartsViews;\n var viewMap = isComponent ? ecIns._componentsMap : ecIns._chartsMap;\n var zr = ecIns._zr;\n var api = ecIns._api;\n\n for (var i = 0; i < viewList.length; i++) {\n viewList[i].__alive = false;\n }\n\n isComponent\n ? ecModel.eachComponent(function (componentType, model) {\n componentType !== 'series' && doPrepare(model);\n })\n : ecModel.eachSeries(doPrepare);\n\n function doPrepare(model) {\n // Consider: id same and type changed.\n var viewId = '_ec_' + model.id + '_' + model.type;\n var view = viewMap[viewId];\n if (!view) {\n var classType = parseClassType(model.type);\n var Clazz = isComponent\n ? ComponentView.getClass(classType.main, classType.sub)\n : ChartView.getClass(classType.sub);\n\n if (__DEV__) {\n assert(Clazz, classType.sub + ' does not exist.');\n }\n\n view = new Clazz();\n view.init(ecModel, api);\n viewMap[viewId] = view;\n viewList.push(view);\n zr.add(view.group);\n }\n\n model.__viewId = view.__id = viewId;\n view.__alive = true;\n view.__model = model;\n view.group.__ecComponentInfo = {\n mainType: model.mainType,\n index: model.componentIndex\n };\n !isComponent && scheduler.prepareView(view, model, ecModel, api);\n }\n\n for (var i = 0; i < viewList.length;) {\n var view = viewList[i];\n if (!view.__alive) {\n !isComponent && view.renderTask.dispose();\n zr.remove(view.group);\n view.dispose(ecModel, api);\n viewList.splice(i, 1);\n delete viewMap[view.__id];\n view.__id = view.group.__ecComponentInfo = null;\n }\n else {\n i++;\n }\n }\n}\n\n// /**\n// * Encode visual infomation from data after data processing\n// *\n// * @param {module:echarts/model/Global} ecModel\n// * @param {object} layout\n// * @param {boolean} [layoutFilter] `true`: only layout,\n// * `false`: only not layout,\n// * `null`/`undefined`: all.\n// * @param {string} taskBaseTag\n// * @private\n// */\n// function startVisualEncoding(ecIns, ecModel, api, payload, layoutFilter) {\n// each(visualFuncs, function (visual, index) {\n// var isLayout = visual.isLayout;\n// if (layoutFilter == null\n// || (layoutFilter === false && !isLayout)\n// || (layoutFilter === true && isLayout)\n// ) {\n// visual.func(ecModel, api, payload);\n// }\n// });\n// }\n\nfunction clearColorPalette(ecModel) {\n ecModel.clearColorPalette();\n ecModel.eachSeries(function (seriesModel) {\n seriesModel.clearColorPalette();\n });\n}\n\nfunction render(ecIns, ecModel, api, payload) {\n\n renderComponents(ecIns, ecModel, api, payload);\n\n each(ecIns._chartsViews, function (chart) {\n chart.__alive = false;\n });\n\n renderSeries(ecIns, ecModel, api, payload);\n\n // Remove groups of unrendered charts\n each(ecIns._chartsViews, function (chart) {\n if (!chart.__alive) {\n chart.remove(ecModel, api);\n }\n });\n}\n\nfunction renderComponents(ecIns, ecModel, api, payload, dirtyList) {\n each(dirtyList || ecIns._componentsViews, function (componentView) {\n var componentModel = componentView.__model;\n componentView.render(componentModel, ecModel, api, payload);\n\n updateZ(componentModel, componentView);\n });\n}\n\n/**\n * Render each chart and component\n * @private\n */\nfunction renderSeries(ecIns, ecModel, api, payload, dirtyMap) {\n // Render all charts\n var scheduler = ecIns._scheduler;\n var unfinished;\n ecModel.eachSeries(function (seriesModel) {\n var chartView = ecIns._chartsMap[seriesModel.__viewId];\n chartView.__alive = true;\n\n var renderTask = chartView.renderTask;\n scheduler.updatePayload(renderTask, payload);\n\n if (dirtyMap && dirtyMap.get(seriesModel.uid)) {\n renderTask.dirty();\n }\n\n unfinished |= renderTask.perform(scheduler.getPerformArgs(renderTask));\n\n chartView.group.silent = !!seriesModel.get('silent');\n\n updateZ(seriesModel, chartView);\n\n updateBlend(seriesModel, chartView);\n });\n scheduler.unfinished |= unfinished;\n\n // If use hover layer\n updateHoverLayerStatus(ecIns, ecModel);\n\n // Add aria\n aria(ecIns._zr.dom, ecModel);\n}\n\nfunction performPostUpdateFuncs(ecModel, api) {\n each(postUpdateFuncs, function (func) {\n func(ecModel, api);\n });\n}\n\n\nvar MOUSE_EVENT_NAMES = [\n 'click', 'dblclick', 'mouseover', 'mouseout', 'mousemove',\n 'mousedown', 'mouseup', 'globalout', 'contextmenu'\n];\n\n/**\n * @private\n */\nechartsProto._initEvents = function () {\n each(MOUSE_EVENT_NAMES, function (eveName) {\n var handler = function (e) {\n var ecModel = this.getModel();\n var el = e.target;\n var params;\n var isGlobalOut = eveName === 'globalout';\n\n // no e.target when 'globalout'.\n if (isGlobalOut) {\n params = {};\n }\n else if (el && el.dataIndex != null) {\n var dataModel = el.dataModel || ecModel.getSeriesByIndex(el.seriesIndex);\n params = dataModel && dataModel.getDataParams(el.dataIndex, el.dataType, el) || {};\n }\n // If element has custom eventData of components\n else if (el && el.eventData) {\n params = zrUtil.extend({}, el.eventData);\n }\n\n // Contract: if params prepared in mouse event,\n // these properties must be specified:\n // {\n // componentType: string (component main type)\n // componentIndex: number\n // }\n // Otherwise event query can not work.\n\n if (params) {\n var componentType = params.componentType;\n var componentIndex = params.componentIndex;\n // Special handling for historic reason: when trigger by\n // markLine/markPoint/markArea, the componentType is\n // 'markLine'/'markPoint'/'markArea', but we should better\n // enable them to be queried by seriesIndex, since their\n // option is set in each series.\n if (componentType === 'markLine'\n || componentType === 'markPoint'\n || componentType === 'markArea'\n ) {\n componentType = 'series';\n componentIndex = params.seriesIndex;\n }\n var model = componentType && componentIndex != null\n && ecModel.getComponent(componentType, componentIndex);\n var view = model && this[\n model.mainType === 'series' ? '_chartsMap' : '_componentsMap'\n ][model.__viewId];\n\n if (__DEV__) {\n // `event.componentType` and `event[componentTpype + 'Index']` must not\n // be missed, otherwise there is no way to distinguish source component.\n // See `dataFormat.getDataParams`.\n if (!isGlobalOut && !(model && view)) {\n console.warn('model or view can not be found by params');\n }\n }\n\n params.event = e;\n params.type = eveName;\n\n this._ecEventProcessor.eventInfo = {\n targetEl: el,\n packedEvent: params,\n model: model,\n view: view\n };\n\n this.trigger(eveName, params);\n }\n };\n // Consider that some component (like tooltip, brush, ...)\n // register zr event handler, but user event handler might\n // do anything, such as call `setOption` or `dispatchAction`,\n // which probably update any of the content and probably\n // cause problem if it is called previous other inner handlers.\n handler.zrEventfulCallAtLast = true;\n this._zr.on(eveName, handler, this);\n }, this);\n\n each(eventActionMap, function (actionType, eventType) {\n this._messageCenter.on(eventType, function (event) {\n this.trigger(eventType, event);\n }, this);\n }, this);\n};\n\n/**\n * @return {boolean}\n */\nechartsProto.isDisposed = function () {\n return this._disposed;\n};\n\n/**\n * Clear\n */\nechartsProto.clear = function () {\n if (this._disposed) {\n disposedWarning(this.id);\n return;\n }\n this.setOption({ series: [] }, true);\n};\n\n/**\n * Dispose instance\n */\nechartsProto.dispose = function () {\n if (this._disposed) {\n disposedWarning(this.id);\n return;\n }\n this._disposed = true;\n\n modelUtil.setAttribute(this.getDom(), DOM_ATTRIBUTE_KEY, '');\n\n var api = this._api;\n var ecModel = this._model;\n\n each(this._componentsViews, function (component) {\n component.dispose(ecModel, api);\n });\n each(this._chartsViews, function (chart) {\n chart.dispose(ecModel, api);\n });\n\n // Dispose after all views disposed\n this._zr.dispose();\n\n delete instances[this.id];\n};\n\nzrUtil.mixin(ECharts, Eventful);\n\nfunction disposedWarning(id) {\n if (__DEV__) {\n console.warn('Instance ' + id + ' has been disposed');\n }\n}\n\nfunction updateHoverLayerStatus(ecIns, ecModel) {\n var zr = ecIns._zr;\n var storage = zr.storage;\n var elCount = 0;\n\n storage.traverse(function (el) {\n elCount++;\n });\n\n if (elCount > ecModel.get('hoverLayerThreshold') && !env.node) {\n ecModel.eachSeries(function (seriesModel) {\n if (seriesModel.preventUsingHoverLayer) {\n return;\n }\n var chartView = ecIns._chartsMap[seriesModel.__viewId];\n if (chartView.__alive) {\n chartView.group.traverse(function (el) {\n // Don't switch back.\n el.useHoverLayer = true;\n });\n }\n });\n }\n}\n\n/**\n * Update chart progressive and blend.\n * @param {module:echarts/model/Series|module:echarts/model/Component} model\n * @param {module:echarts/view/Component|module:echarts/view/Chart} view\n */\nfunction updateBlend(seriesModel, chartView) {\n var blendMode = seriesModel.get('blendMode') || null;\n if (__DEV__) {\n if (!env.canvasSupported && blendMode && blendMode !== 'source-over') {\n console.warn('Only canvas support blendMode');\n }\n }\n chartView.group.traverse(function (el) {\n // FIXME marker and other components\n if (!el.isGroup) {\n // Only set if blendMode is changed. In case element is incremental and don't wan't to rerender.\n if (el.style.blend !== blendMode) {\n el.setStyle('blend', blendMode);\n }\n }\n if (el.eachPendingDisplayable) {\n el.eachPendingDisplayable(function (displayable) {\n displayable.setStyle('blend', blendMode);\n });\n }\n });\n}\n\n/**\n * @param {module:echarts/model/Series|module:echarts/model/Component} model\n * @param {module:echarts/view/Component|module:echarts/view/Chart} view\n */\nfunction updateZ(model, view) {\n var z = model.get('z');\n var zlevel = model.get('zlevel');\n // Set z and zlevel\n view.group.traverse(function (el) {\n if (el.type !== 'group') {\n z != null && (el.z = z);\n zlevel != null && (el.zlevel = zlevel);\n }\n });\n}\n\nfunction createExtensionAPI(ecInstance) {\n var coordSysMgr = ecInstance._coordSysMgr;\n return zrUtil.extend(new ExtensionAPI(ecInstance), {\n // Inject methods\n getCoordinateSystems: zrUtil.bind(\n coordSysMgr.getCoordinateSystems, coordSysMgr\n ),\n getComponentByElement: function (el) {\n while (el) {\n var modelInfo = el.__ecComponentInfo;\n if (modelInfo != null) {\n return ecInstance._model.getComponent(modelInfo.mainType, modelInfo.index);\n }\n el = el.parent;\n }\n }\n });\n}\n\n\n/**\n * @class\n * Usage of query:\n * `chart.on('click', query, handler);`\n * The `query` can be:\n * + The component type query string, only `mainType` or `mainType.subType`,\n * like: 'xAxis', 'series', 'xAxis.category' or 'series.line'.\n * + The component query object, like:\n * `{seriesIndex: 2}`, `{seriesName: 'xx'}`, `{seriesId: 'some'}`,\n * `{xAxisIndex: 2}`, `{xAxisName: 'xx'}`, `{xAxisId: 'some'}`.\n * + The data query object, like:\n * `{dataIndex: 123}`, `{dataType: 'link'}`, `{name: 'some'}`.\n * + The other query object (cmponent customized query), like:\n * `{element: 'some'}` (only available in custom series).\n *\n * Caveat: If a prop in the `query` object is `null/undefined`, it is the\n * same as there is no such prop in the `query` object.\n */\nfunction EventProcessor() {\n // These info required: targetEl, packedEvent, model, view\n this.eventInfo;\n}\nEventProcessor.prototype = {\n constructor: EventProcessor,\n\n normalizeQuery: function (query) {\n var cptQuery = {};\n var dataQuery = {};\n var otherQuery = {};\n\n // `query` is `mainType` or `mainType.subType` of component.\n if (zrUtil.isString(query)) {\n var condCptType = parseClassType(query);\n // `.main` and `.sub` may be ''.\n cptQuery.mainType = condCptType.main || null;\n cptQuery.subType = condCptType.sub || null;\n }\n // `query` is an object, convert to {mainType, index, name, id}.\n else {\n // `xxxIndex`, `xxxName`, `xxxId`, `name`, `dataIndex`, `dataType` is reserved,\n // can not be used in `compomentModel.filterForExposedEvent`.\n var suffixes = ['Index', 'Name', 'Id'];\n var dataKeys = {name: 1, dataIndex: 1, dataType: 1};\n zrUtil.each(query, function (val, key) {\n var reserved = false;\n for (var i = 0; i < suffixes.length; i++) {\n var propSuffix = suffixes[i];\n var suffixPos = key.lastIndexOf(propSuffix);\n if (suffixPos > 0 && suffixPos === key.length - propSuffix.length) {\n var mainType = key.slice(0, suffixPos);\n // Consider `dataIndex`.\n if (mainType !== 'data') {\n cptQuery.mainType = mainType;\n cptQuery[propSuffix.toLowerCase()] = val;\n reserved = true;\n }\n }\n }\n if (dataKeys.hasOwnProperty(key)) {\n dataQuery[key] = val;\n reserved = true;\n }\n if (!reserved) {\n otherQuery[key] = val;\n }\n });\n }\n\n return {\n cptQuery: cptQuery,\n dataQuery: dataQuery,\n otherQuery: otherQuery\n };\n },\n\n filter: function (eventType, query, args) {\n // They should be assigned before each trigger call.\n var eventInfo = this.eventInfo;\n\n if (!eventInfo) {\n return true;\n }\n\n var targetEl = eventInfo.targetEl;\n var packedEvent = eventInfo.packedEvent;\n var model = eventInfo.model;\n var view = eventInfo.view;\n\n // For event like 'globalout'.\n if (!model || !view) {\n return true;\n }\n\n var cptQuery = query.cptQuery;\n var dataQuery = query.dataQuery;\n\n return check(cptQuery, model, 'mainType')\n && check(cptQuery, model, 'subType')\n && check(cptQuery, model, 'index', 'componentIndex')\n && check(cptQuery, model, 'name')\n && check(cptQuery, model, 'id')\n && check(dataQuery, packedEvent, 'name')\n && check(dataQuery, packedEvent, 'dataIndex')\n && check(dataQuery, packedEvent, 'dataType')\n && (!view.filterForExposedEvent || view.filterForExposedEvent(\n eventType, query.otherQuery, targetEl, packedEvent\n ));\n\n function check(query, host, prop, propOnHost) {\n return query[prop] == null || host[propOnHost || prop] === query[prop];\n }\n },\n\n afterTrigger: function () {\n // Make sure the eventInfo wont be used in next trigger.\n this.eventInfo = null;\n }\n};\n\n\n/**\n * @type {Object} key: actionType.\n * @inner\n */\nvar actions = {};\n\n/**\n * Map eventType to actionType\n * @type {Object}\n */\nvar eventActionMap = {};\n\n/**\n * Data processor functions of each stage\n * @type {Array.<Object.<string, Function>>}\n * @inner\n */\nvar dataProcessorFuncs = [];\n\n/**\n * @type {Array.<Function>}\n * @inner\n */\nvar optionPreprocessorFuncs = [];\n\n/**\n * @type {Array.<Function>}\n * @inner\n */\nvar postUpdateFuncs = [];\n\n/**\n * Visual encoding functions of each stage\n * @type {Array.<Object.<string, Function>>}\n */\nvar visualFuncs = [];\n\n/**\n * Theme storage\n * @type {Object.<key, Object>}\n */\nvar themeStorage = {};\n/**\n * Loading effects\n */\nvar loadingEffects = {};\n\nvar instances = {};\nvar connectedGroups = {};\n\nvar idBase = new Date() - 0;\nvar groupIdBase = new Date() - 0;\nvar DOM_ATTRIBUTE_KEY = '_echarts_instance_';\n\nfunction enableConnect(chart) {\n var STATUS_PENDING = 0;\n var STATUS_UPDATING = 1;\n var STATUS_UPDATED = 2;\n var STATUS_KEY = '__connectUpdateStatus';\n\n function updateConnectedChartsStatus(charts, status) {\n for (var i = 0; i < charts.length; i++) {\n var otherChart = charts[i];\n otherChart[STATUS_KEY] = status;\n }\n }\n\n each(eventActionMap, function (actionType, eventType) {\n chart._messageCenter.on(eventType, function (event) {\n if (connectedGroups[chart.group] && chart[STATUS_KEY] !== STATUS_PENDING) {\n if (event && event.escapeConnect) {\n return;\n }\n\n var action = chart.makeActionFromEvent(event);\n var otherCharts = [];\n\n each(instances, function (otherChart) {\n if (otherChart !== chart && otherChart.group === chart.group) {\n otherCharts.push(otherChart);\n }\n });\n\n updateConnectedChartsStatus(otherCharts, STATUS_PENDING);\n each(otherCharts, function (otherChart) {\n if (otherChart[STATUS_KEY] !== STATUS_UPDATING) {\n otherChart.dispatchAction(action);\n }\n });\n updateConnectedChartsStatus(otherCharts, STATUS_UPDATED);\n }\n });\n });\n}\n\n/**\n * @param {HTMLElement} dom\n * @param {Object} [theme]\n * @param {Object} opts\n * @param {number} [opts.devicePixelRatio] Use window.devicePixelRatio by default\n * @param {string} [opts.renderer] Can choose 'canvas' or 'svg' to render the chart.\n * @param {number} [opts.width] Use clientWidth of the input `dom` by default.\n * Can be 'auto' (the same as null/undefined)\n * @param {number} [opts.height] Use clientHeight of the input `dom` by default.\n * Can be 'auto' (the same as null/undefined)\n */\nexport function init(dom, theme, opts) {\n if (__DEV__) {\n // Check version\n if ((zrender.version.replace('.', '') - 0) < (dependencies.zrender.replace('.', '') - 0)) {\n throw new Error(\n 'zrender/src ' + zrender.version\n + ' is too old for ECharts ' + version\n + '. Current version need ZRender '\n + dependencies.zrender + '+'\n );\n }\n\n if (!dom) {\n throw new Error('Initialize failed: invalid dom.');\n }\n }\n\n var existInstance = getInstanceByDom(dom);\n if (existInstance) {\n if (__DEV__) {\n console.warn('There is a chart instance already initialized on the dom.');\n }\n return existInstance;\n }\n\n if (__DEV__) {\n if (zrUtil.isDom(dom)\n && dom.nodeName.toUpperCase() !== 'CANVAS'\n && (\n (!dom.clientWidth && (!opts || opts.width == null))\n || (!dom.clientHeight && (!opts || opts.height == null))\n )\n ) {\n console.warn('Can\\'t get DOM width or height. Please check '\n + 'dom.clientWidth and dom.clientHeight. They should not be 0.'\n + 'For example, you may need to call this in the callback '\n + 'of window.onload.');\n }\n }\n\n var chart = new ECharts(dom, theme, opts);\n chart.id = 'ec_' + idBase++;\n instances[chart.id] = chart;\n\n modelUtil.setAttribute(dom, DOM_ATTRIBUTE_KEY, chart.id);\n\n enableConnect(chart);\n\n return chart;\n}\n\n/**\n * @return {string|Array.<module:echarts~ECharts>} groupId\n */\nexport function connect(groupId) {\n // Is array of charts\n if (zrUtil.isArray(groupId)) {\n var charts = groupId;\n groupId = null;\n // If any chart has group\n each(charts, function (chart) {\n if (chart.group != null) {\n groupId = chart.group;\n }\n });\n groupId = groupId || ('g_' + groupIdBase++);\n each(charts, function (chart) {\n chart.group = groupId;\n });\n }\n connectedGroups[groupId] = true;\n return groupId;\n}\n\n/**\n * @DEPRECATED\n * @return {string} groupId\n */\nexport function disConnect(groupId) {\n connectedGroups[groupId] = false;\n}\n\n/**\n * @return {string} groupId\n */\nexport var disconnect = disConnect;\n\n/**\n * Dispose a chart instance\n * @param {module:echarts~ECharts|HTMLDomElement|string} chart\n */\nexport function dispose(chart) {\n if (typeof chart === 'string') {\n chart = instances[chart];\n }\n else if (!(chart instanceof ECharts)) {\n // Try to treat as dom\n chart = getInstanceByDom(chart);\n }\n if ((chart instanceof ECharts) && !chart.isDisposed()) {\n chart.dispose();\n }\n}\n\n/**\n * @param {HTMLElement} dom\n * @return {echarts~ECharts}\n */\nexport function getInstanceByDom(dom) {\n return instances[modelUtil.getAttribute(dom, DOM_ATTRIBUTE_KEY)];\n}\n\n/**\n * @param {string} key\n * @return {echarts~ECharts}\n */\nexport function getInstanceById(key) {\n return instances[key];\n}\n\n/**\n * Register theme\n */\nexport function registerTheme(name, theme) {\n themeStorage[name] = theme;\n}\n\n/**\n * Register option preprocessor\n * @param {Function} preprocessorFunc\n */\nexport function registerPreprocessor(preprocessorFunc) {\n optionPreprocessorFuncs.push(preprocessorFunc);\n}\n\n/**\n * @param {number} [priority=1000]\n * @param {Object|Function} processor\n */\nexport function registerProcessor(priority, processor) {\n normalizeRegister(dataProcessorFuncs, priority, processor, PRIORITY_PROCESSOR_FILTER);\n}\n\n/**\n * Register postUpdater\n * @param {Function} postUpdateFunc\n */\nexport function registerPostUpdate(postUpdateFunc) {\n postUpdateFuncs.push(postUpdateFunc);\n}\n\n/**\n * Usage:\n * registerAction('someAction', 'someEvent', function () { ... });\n * registerAction('someAction', function () { ... });\n * registerAction(\n * {type: 'someAction', event: 'someEvent', update: 'updateView'},\n * function () { ... }\n * );\n *\n * @param {(string|Object)} actionInfo\n * @param {string} actionInfo.type\n * @param {string} [actionInfo.event]\n * @param {string} [actionInfo.update]\n * @param {string} [eventName]\n * @param {Function} action\n */\nexport function registerAction(actionInfo, eventName, action) {\n if (typeof eventName === 'function') {\n action = eventName;\n eventName = '';\n }\n var actionType = isObject(actionInfo)\n ? actionInfo.type\n : ([actionInfo, actionInfo = {\n event: eventName\n }][0]);\n\n // Event name is all lowercase\n actionInfo.event = (actionInfo.event || actionType).toLowerCase();\n eventName = actionInfo.event;\n\n // Validate action type and event name.\n assert(ACTION_REG.test(actionType) && ACTION_REG.test(eventName));\n\n if (!actions[actionType]) {\n actions[actionType] = {action: action, actionInfo: actionInfo};\n }\n eventActionMap[eventName] = actionType;\n}\n\n/**\n * @param {string} type\n * @param {*} CoordinateSystem\n */\nexport function registerCoordinateSystem(type, CoordinateSystem) {\n CoordinateSystemManager.register(type, CoordinateSystem);\n}\n\n/**\n * Get dimensions of specified coordinate system.\n * @param {string} type\n * @return {Array.<string|Object>}\n */\nexport function getCoordinateSystemDimensions(type) {\n var coordSysCreator = CoordinateSystemManager.get(type);\n if (coordSysCreator) {\n return coordSysCreator.getDimensionsInfo\n ? coordSysCreator.getDimensionsInfo()\n : coordSysCreator.dimensions.slice();\n }\n}\n\n/**\n * Layout is a special stage of visual encoding\n * Most visual encoding like color are common for different chart\n * But each chart has it's own layout algorithm\n *\n * @param {number} [priority=1000]\n * @param {Function} layoutTask\n */\nexport function registerLayout(priority, layoutTask) {\n normalizeRegister(visualFuncs, priority, layoutTask, PRIORITY_VISUAL_LAYOUT, 'layout');\n}\n\n/**\n * @param {number} [priority=3000]\n * @param {module:echarts/stream/Task} visualTask\n */\nexport function registerVisual(priority, visualTask) {\n normalizeRegister(visualFuncs, priority, visualTask, PRIORITY_VISUAL_CHART, 'visual');\n}\n\n/**\n * @param {Object|Function} fn: {seriesType, createOnAllSeries, performRawSeries, reset}\n */\nfunction normalizeRegister(targetList, priority, fn, defaultPriority, visualType) {\n if (isFunction(priority) || isObject(priority)) {\n fn = priority;\n priority = defaultPriority;\n }\n\n if (__DEV__) {\n if (isNaN(priority) || priority == null) {\n throw new Error('Illegal priority');\n }\n // Check duplicate\n each(targetList, function (wrap) {\n assert(wrap.__raw !== fn);\n });\n }\n\n var stageHandler = Scheduler.wrapStageHandler(fn, visualType);\n\n stageHandler.__prio = priority;\n stageHandler.__raw = fn;\n targetList.push(stageHandler);\n\n return stageHandler;\n}\n\n/**\n * @param {string} name\n */\nexport function registerLoading(name, loadingFx) {\n loadingEffects[name] = loadingFx;\n}\n\n/**\n * @param {Object} opts\n * @param {string} [superClass]\n */\nexport function extendComponentModel(opts/*, superClass*/) {\n // var Clazz = ComponentModel;\n // if (superClass) {\n // var classType = parseClassType(superClass);\n // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);\n // }\n return ComponentModel.extend(opts);\n}\n\n/**\n * @param {Object} opts\n * @param {string} [superClass]\n */\nexport function extendComponentView(opts/*, superClass*/) {\n // var Clazz = ComponentView;\n // if (superClass) {\n // var classType = parseClassType(superClass);\n // Clazz = ComponentView.getClass(classType.main, classType.sub, true);\n // }\n return ComponentView.extend(opts);\n}\n\n/**\n * @param {Object} opts\n * @param {string} [superClass]\n */\nexport function extendSeriesModel(opts/*, superClass*/) {\n // var Clazz = SeriesModel;\n // if (superClass) {\n // superClass = 'series.' + superClass.replace('series.', '');\n // var classType = parseClassType(superClass);\n // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);\n // }\n return SeriesModel.extend(opts);\n}\n\n/**\n * @param {Object} opts\n * @param {string} [superClass]\n */\nexport function extendChartView(opts/*, superClass*/) {\n // var Clazz = ChartView;\n // if (superClass) {\n // superClass = superClass.replace('series.', '');\n // var classType = parseClassType(superClass);\n // Clazz = ChartView.getClass(classType.main, true);\n // }\n return ChartView.extend(opts);\n}\n\n/**\n * ZRender need a canvas context to do measureText.\n * But in node environment canvas may be created by node-canvas.\n * So we need to specify how to create a canvas instead of using document.createElement('canvas')\n *\n * Be careful of using it in the browser.\n *\n * @param {Function} creator\n * @example\n * var Canvas = require('canvas');\n * var echarts = require('echarts');\n * echarts.setCanvasCreator(function () {\n * // Small size is enough.\n * return new Canvas(32, 32);\n * });\n */\nexport function setCanvasCreator(creator) {\n zrUtil.$override('createCanvas', creator);\n}\n\n/**\n * @param {string} mapName\n * @param {Array.<Object>|Object|string} geoJson\n * @param {Object} [specialAreas]\n *\n * @example GeoJSON\n * $.get('USA.json', function (geoJson) {\n * echarts.registerMap('USA', geoJson);\n * // Or\n * echarts.registerMap('USA', {\n * geoJson: geoJson,\n * specialAreas: {}\n * })\n * });\n *\n * $.get('airport.svg', function (svg) {\n * echarts.registerMap('airport', {\n * svg: svg\n * }\n * });\n *\n * echarts.registerMap('eu', [\n * {svg: eu-topographic.svg},\n * {geoJSON: eu.json}\n * ])\n */\nexport function registerMap(mapName, geoJson, specialAreas) {\n mapDataStorage.registerMap(mapName, geoJson, specialAreas);\n}\n\n/**\n * @param {string} mapName\n * @return {Object}\n */\nexport function getMap(mapName) {\n // For backward compatibility, only return the first one.\n var records = mapDataStorage.retrieveMap(mapName);\n return records && records[0] && {\n geoJson: records[0].geoJSON,\n specialAreas: records[0].specialAreas\n };\n}\n\nregisterVisual(PRIORITY_VISUAL_GLOBAL, seriesColor);\nregisterPreprocessor(backwardCompat);\nregisterProcessor(PRIORITY_PROCESSOR_DATASTACK, dataStack);\nregisterLoading('default', loadingDefault);\n\n// Default actions\n\nregisterAction({\n type: 'highlight',\n event: 'highlight',\n update: 'highlight'\n}, zrUtil.noop);\n\nregisterAction({\n type: 'downplay',\n event: 'downplay',\n update: 'downplay'\n}, zrUtil.noop);\n\n// Default theme\nregisterTheme('light', lightTheme);\nregisterTheme('dark', darkTheme);\n\n// For backward compatibility, where the namespace `dataTool` will\n// be mounted on `echarts` is the extension `dataTool` is imported.\nexport var dataTool = {};\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\n\nfunction defaultKeyGetter(item) {\n return item;\n}\n\n/**\n * @param {Array} oldArr\n * @param {Array} newArr\n * @param {Function} oldKeyGetter\n * @param {Function} newKeyGetter\n * @param {Object} [context] Can be visited by this.context in callback.\n */\nfunction DataDiffer(oldArr, newArr, oldKeyGetter, newKeyGetter, context) {\n this._old = oldArr;\n this._new = newArr;\n\n this._oldKeyGetter = oldKeyGetter || defaultKeyGetter;\n this._newKeyGetter = newKeyGetter || defaultKeyGetter;\n\n this.context = context;\n}\n\nDataDiffer.prototype = {\n\n constructor: DataDiffer,\n\n /**\n * Callback function when add a data\n */\n add: function (func) {\n this._add = func;\n return this;\n },\n\n /**\n * Callback function when update a data\n */\n update: function (func) {\n this._update = func;\n return this;\n },\n\n /**\n * Callback function when remove a data\n */\n remove: function (func) {\n this._remove = func;\n return this;\n },\n\n execute: function () {\n var oldArr = this._old;\n var newArr = this._new;\n\n var oldDataIndexMap = {};\n var newDataIndexMap = {};\n var oldDataKeyArr = [];\n var newDataKeyArr = [];\n var i;\n\n initIndexMap(oldArr, oldDataIndexMap, oldDataKeyArr, '_oldKeyGetter', this);\n initIndexMap(newArr, newDataIndexMap, newDataKeyArr, '_newKeyGetter', this);\n\n for (i = 0; i < oldArr.length; i++) {\n var key = oldDataKeyArr[i];\n var idx = newDataIndexMap[key];\n\n // idx can never be empty array here. see 'set null' logic below.\n if (idx != null) {\n // Consider there is duplicate key (for example, use dataItem.name as key).\n // We should make sure every item in newArr and oldArr can be visited.\n var len = idx.length;\n if (len) {\n len === 1 && (newDataIndexMap[key] = null);\n idx = idx.shift();\n }\n else {\n newDataIndexMap[key] = null;\n }\n this._update && this._update(idx, i);\n }\n else {\n this._remove && this._remove(i);\n }\n }\n\n for (var i = 0; i < newDataKeyArr.length; i++) {\n var key = newDataKeyArr[i];\n if (newDataIndexMap.hasOwnProperty(key)) {\n var idx = newDataIndexMap[key];\n if (idx == null) {\n continue;\n }\n // idx can never be empty array here. see 'set null' logic above.\n if (!idx.length) {\n this._add && this._add(idx);\n }\n else {\n for (var j = 0, len = idx.length; j < len; j++) {\n this._add && this._add(idx[j]);\n }\n }\n }\n }\n }\n};\n\nfunction initIndexMap(arr, map, keyArr, keyGetterName, dataDiffer) {\n for (var i = 0; i < arr.length; i++) {\n // Add prefix to avoid conflict with Object.prototype.\n var key = '_ec_' + dataDiffer[keyGetterName](arr[i], i);\n var existence = map[key];\n if (existence == null) {\n keyArr.push(key);\n map[key] = i;\n }\n else {\n if (!existence.length) {\n map[key] = existence = [existence];\n }\n existence.push(i);\n }\n }\n}\n\nexport default DataDiffer;","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport {each, createHashMap, assert} from 'zrender/src/core/util';\nimport { __DEV__ } from '../../config';\n\nexport var OTHER_DIMENSIONS = createHashMap([\n 'tooltip', 'label', 'itemName', 'itemId', 'seriesName'\n]);\n\nexport function summarizeDimensions(data) {\n var summary = {};\n var encode = summary.encode = {};\n var notExtraCoordDimMap = createHashMap();\n var defaultedLabel = [];\n var defaultedTooltip = [];\n\n // See the comment of `List.js#userOutput`.\n var userOutput = summary.userOutput = {\n dimensionNames: data.dimensions.slice(),\n encode: {}\n };\n\n each(data.dimensions, function (dimName) {\n var dimItem = data.getDimensionInfo(dimName);\n\n var coordDim = dimItem.coordDim;\n if (coordDim) {\n if (__DEV__) {\n assert(OTHER_DIMENSIONS.get(coordDim) == null);\n }\n\n var coordDimIndex = dimItem.coordDimIndex;\n getOrCreateEncodeArr(encode, coordDim)[coordDimIndex] = dimName;\n\n if (!dimItem.isExtraCoord) {\n notExtraCoordDimMap.set(coordDim, 1);\n\n // Use the last coord dim (and label friendly) as default label,\n // because when dataset is used, it is hard to guess which dimension\n // can be value dimension. If both show x, y on label is not look good,\n // and conventionally y axis is focused more.\n if (mayLabelDimType(dimItem.type)) {\n defaultedLabel[0] = dimName;\n }\n\n // User output encode do not contain generated coords.\n // And it only has index. User can use index to retrieve value from the raw item array.\n getOrCreateEncodeArr(userOutput.encode, coordDim)[coordDimIndex] = dimItem.index;\n }\n if (dimItem.defaultTooltip) {\n defaultedTooltip.push(dimName);\n }\n }\n\n OTHER_DIMENSIONS.each(function (v, otherDim) {\n var encodeArr = getOrCreateEncodeArr(encode, otherDim);\n\n var dimIndex = dimItem.otherDims[otherDim];\n if (dimIndex != null && dimIndex !== false) {\n encodeArr[dimIndex] = dimItem.name;\n }\n });\n });\n\n var dataDimsOnCoord = [];\n var encodeFirstDimNotExtra = {};\n\n notExtraCoordDimMap.each(function (v, coordDim) {\n var dimArr = encode[coordDim];\n // ??? FIXME extra coord should not be set in dataDimsOnCoord.\n // But should fix the case that radar axes: simplify the logic\n // of `completeDimension`, remove `extraPrefix`.\n encodeFirstDimNotExtra[coordDim] = dimArr[0];\n // Not necessary to remove duplicate, because a data\n // dim canot on more than one coordDim.\n dataDimsOnCoord = dataDimsOnCoord.concat(dimArr);\n });\n\n summary.dataDimsOnCoord = dataDimsOnCoord;\n summary.encodeFirstDimNotExtra = encodeFirstDimNotExtra;\n\n var encodeLabel = encode.label;\n // FIXME `encode.label` is not recommanded, because formatter can not be set\n // in this way. Use label.formatter instead. May be remove this approach someday.\n if (encodeLabel && encodeLabel.length) {\n defaultedLabel = encodeLabel.slice();\n }\n\n var encodeTooltip = encode.tooltip;\n if (encodeTooltip && encodeTooltip.length) {\n defaultedTooltip = encodeTooltip.slice();\n }\n else if (!defaultedTooltip.length) {\n defaultedTooltip = defaultedLabel.slice();\n }\n\n encode.defaultedLabel = defaultedLabel;\n encode.defaultedTooltip = defaultedTooltip;\n\n return summary;\n}\n\nfunction getOrCreateEncodeArr(encode, dim) {\n if (!encode.hasOwnProperty(dim)) {\n encode[dim] = [];\n }\n return encode[dim];\n}\n\nexport function getDimensionTypeByAxis(axisType) {\n return axisType === 'category'\n ? 'ordinal'\n : axisType === 'time'\n ? 'time'\n : 'float';\n}\n\nfunction mayLabelDimType(dimType) {\n // In most cases, ordinal and time do not suitable for label.\n // Ordinal info can be displayed on axis. Time is too long.\n return !(dimType === 'ordinal' || dimType === 'time');\n}\n\n// function findTheLastDimMayLabel(data) {\n// // Get last value dim\n// var dimensions = data.dimensions.slice();\n// var valueType;\n// var valueDim;\n// while (dimensions.length && (\n// valueDim = dimensions.pop(),\n// valueType = data.getDimensionInfo(valueDim).type,\n// valueType === 'ordinal' || valueType === 'time'\n// )) {} // jshint ignore:line\n// return valueDim;\n// }\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport * as zrUtil from 'zrender/src/core/util';\n\n/**\n * @class\n * @param {Object|DataDimensionInfo} [opt] All of the fields will be shallow copied.\n */\nfunction DataDimensionInfo(opt) {\n if (opt != null) {\n zrUtil.extend(this, opt);\n }\n\n /**\n * Dimension name.\n * Mandatory.\n * @type {string}\n */\n // this.name;\n\n /**\n * The origin name in dimsDef, see source helper.\n * If displayName given, the tooltip will displayed vertically.\n * Optional.\n * @type {string}\n */\n // this.displayName;\n\n /**\n * Which coordSys dimension this dimension mapped to.\n * A `coordDim` can be a \"coordSysDim\" that the coordSys required\n * (for example, an item in `coordSysDims` of `model/referHelper#CoordSysInfo`),\n * or an generated \"extra coord name\" if does not mapped to any \"coordSysDim\"\n * (That is determined by whether `isExtraCoord` is `true`).\n * Mandatory.\n * @type {string}\n */\n // this.coordDim;\n\n /**\n * The index of this dimension in `series.encode[coordDim]`.\n * Mandatory.\n * @type {number}\n */\n // this.coordDimIndex;\n\n /**\n * Dimension type. The enumerable values are the key of\n * `dataCtors` of `data/List`.\n * Optional.\n * @type {string}\n */\n // this.type;\n\n /**\n * This index of this dimension info in `data/List#_dimensionInfos`.\n * Mandatory after added to `data/List`.\n * @type {number}\n */\n // this.index;\n\n /**\n * The format of `otherDims` is:\n * ```js\n * {\n * tooltip: number optional,\n * label: number optional,\n * itemName: number optional,\n * seriesName: number optional,\n * }\n * ```\n *\n * A `series.encode` can specified these fields:\n * ```js\n * encode: {\n * // \"3, 1, 5\" is the index of data dimension.\n * tooltip: [3, 1, 5],\n * label: [0, 3],\n * ...\n * }\n * ```\n * `otherDims` is the parse result of the `series.encode` above, like:\n * ```js\n * // Suppose the index of this data dimension is `3`.\n * this.otherDims = {\n * // `3` is at the index `0` of the `encode.tooltip`\n * tooltip: 0,\n * // `3` is at the index `1` of the `encode.tooltip`\n * label: 1\n * };\n * ```\n *\n * This prop should never be `null`/`undefined` after initialized.\n * @type {Object}\n */\n this.otherDims = {};\n\n /**\n * Be `true` if this dimension is not mapped to any \"coordSysDim\" that the\n * \"coordSys\" required.\n * Mandatory.\n * @type {boolean}\n */\n // this.isExtraCoord;\n\n /**\n * @type {module:data/OrdinalMeta}\n */\n // this.ordinalMeta;\n\n /**\n * Whether to create inverted indices.\n * @type {boolean}\n */\n // this.createInvertedIndices;\n};\n\nexport default DataDimensionInfo;\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\n/* global Float64Array, Int32Array, Uint32Array, Uint16Array */\n\n/**\n * List for data storage\n * @module echarts/data/List\n */\n\nimport {__DEV__} from '../config';\nimport * as zrUtil from 'zrender/src/core/util';\nimport Model from '../model/Model';\nimport DataDiffer from './DataDiffer';\nimport Source from './Source';\nimport {defaultDimValueGetters, DefaultDataProvider} from './helper/dataProvider';\nimport {summarizeDimensions} from './helper/dimensionHelper';\nimport DataDimensionInfo from './DataDimensionInfo';\n\nvar isObject = zrUtil.isObject;\n\nvar UNDEFINED = 'undefined';\nvar INDEX_NOT_FOUND = -1;\n\n// Use prefix to avoid index to be the same as otherIdList[idx],\n// which will cause weird udpate animation.\nvar ID_PREFIX = 'e\\0\\0';\n\nvar dataCtors = {\n 'float': typeof Float64Array === UNDEFINED\n ? Array : Float64Array,\n 'int': typeof Int32Array === UNDEFINED\n ? Array : Int32Array,\n // Ordinal data type can be string or int\n 'ordinal': Array,\n 'number': Array,\n 'time': Array\n};\n\n// Caution: MUST not use `new CtorUint32Array(arr, 0, len)`, because the Ctor of array is\n// different from the Ctor of typed array.\nvar CtorUint32Array = typeof Uint32Array === UNDEFINED ? Array : Uint32Array;\nvar CtorInt32Array = typeof Int32Array === UNDEFINED ? Array : Int32Array;\nvar CtorUint16Array = typeof Uint16Array === UNDEFINED ? Array : Uint16Array;\n\nfunction getIndicesCtor(list) {\n // The possible max value in this._indicies is always this._rawCount despite of filtering.\n return list._rawCount > 65535 ? CtorUint32Array : CtorUint16Array;\n}\n\nfunction cloneChunk(originalChunk) {\n var Ctor = originalChunk.constructor;\n // Only shallow clone is enough when Array.\n return Ctor === Array ? originalChunk.slice() : new Ctor(originalChunk);\n}\n\nvar TRANSFERABLE_PROPERTIES = [\n 'hasItemOption', '_nameList', '_idList', '_invertedIndicesMap',\n '_rawData', '_chunkSize', '_chunkCount', '_dimValueGetter',\n '_count', '_rawCount', '_nameDimIdx', '_idDimIdx'\n];\nvar CLONE_PROPERTIES = [\n '_extent', '_approximateExtent', '_rawExtent'\n];\n\nfunction transferProperties(target, source) {\n zrUtil.each(TRANSFERABLE_PROPERTIES.concat(source.__wrappedMethods || []), function (propName) {\n if (source.hasOwnProperty(propName)) {\n target[propName] = source[propName];\n }\n });\n\n target.__wrappedMethods = source.__wrappedMethods;\n\n zrUtil.each(CLONE_PROPERTIES, function (propName) {\n target[propName] = zrUtil.clone(source[propName]);\n });\n\n target._calculationInfo = zrUtil.extend(source._calculationInfo);\n}\n\n\n\n\n\n/**\n * @constructor\n * @alias module:echarts/data/List\n *\n * @param {Array.<string|Object|module:data/DataDimensionInfo>} dimensions\n * For example, ['someDimName', {name: 'someDimName', type: 'someDimType'}, ...].\n * Dimensions should be concrete names like x, y, z, lng, lat, angle, radius\n * @param {module:echarts/model/Model} hostModel\n */\nvar List = function (dimensions, hostModel) {\n\n dimensions = dimensions || ['x', 'y'];\n\n var dimensionInfos = {};\n var dimensionNames = [];\n var invertedIndicesMap = {};\n\n for (var i = 0; i < dimensions.length; i++) {\n // Use the original dimensions[i], where other flag props may exists.\n var dimensionInfo = dimensions[i];\n\n if (zrUtil.isString(dimensionInfo)) {\n dimensionInfo = new DataDimensionInfo({name: dimensionInfo});\n }\n else if (!(dimensionInfo instanceof DataDimensionInfo)) {\n dimensionInfo = new DataDimensionInfo(dimensionInfo);\n }\n\n var dimensionName = dimensionInfo.name;\n dimensionInfo.type = dimensionInfo.type || 'float';\n if (!dimensionInfo.coordDim) {\n dimensionInfo.coordDim = dimensionName;\n dimensionInfo.coordDimIndex = 0;\n }\n\n dimensionInfo.otherDims = dimensionInfo.otherDims || {};\n dimensionNames.push(dimensionName);\n dimensionInfos[dimensionName] = dimensionInfo;\n\n dimensionInfo.index = i;\n\n if (dimensionInfo.createInvertedIndices) {\n invertedIndicesMap[dimensionName] = [];\n }\n }\n\n /**\n * @readOnly\n * @type {Array.<string>}\n */\n this.dimensions = dimensionNames;\n\n /**\n * Infomation of each data dimension, like data type.\n * @type {Object}\n */\n this._dimensionInfos = dimensionInfos;\n\n /**\n * @type {module:echarts/model/Model}\n */\n this.hostModel = hostModel;\n\n /**\n * @type {module:echarts/model/Model}\n */\n this.dataType;\n\n /**\n * Indices stores the indices of data subset after filtered.\n * This data subset will be used in chart.\n * @type {Array.<number>}\n * @readOnly\n */\n this._indices = null;\n\n this._count = 0;\n this._rawCount = 0;\n\n /**\n * Data storage\n * @type {Object.<key, Array.<TypedArray|Array>>}\n * @private\n */\n this._storage = {};\n\n /**\n * @type {Array.<string>}\n */\n this._nameList = [];\n /**\n * @type {Array.<string>}\n */\n this._idList = [];\n\n /**\n * Models of data option is stored sparse for optimizing memory cost\n * @type {Array.<module:echarts/model/Model>}\n * @private\n */\n this._optionModels = [];\n\n /**\n * Global visual properties after visual coding\n * @type {Object}\n * @private\n */\n this._visual = {};\n\n /**\n * Globel layout properties.\n * @type {Object}\n * @private\n */\n this._layout = {};\n\n /**\n * Item visual properties after visual coding\n * @type {Array.<Object>}\n * @private\n */\n this._itemVisuals = [];\n\n /**\n * Key: visual type, Value: boolean\n * @type {Object}\n * @readOnly\n */\n this.hasItemVisual = {};\n\n /**\n * Item layout properties after layout\n * @type {Array.<Object>}\n * @private\n */\n this._itemLayouts = [];\n\n /**\n * Graphic elemnents\n * @type {Array.<module:zrender/Element>}\n * @private\n */\n this._graphicEls = [];\n\n /**\n * Max size of each chunk.\n * @type {number}\n * @private\n */\n this._chunkSize = 1e5;\n\n /**\n * @type {number}\n * @private\n */\n this._chunkCount = 0;\n\n /**\n * @type {Array.<Array|Object>}\n * @private\n */\n this._rawData;\n\n /**\n * Raw extent will not be cloned, but only transfered.\n * It will not be calculated util needed.\n * key: dim,\n * value: {end: number, extent: Array.<number>}\n * @type {Object}\n * @private\n */\n this._rawExtent = {};\n\n /**\n * @type {Object}\n * @private\n */\n this._extent = {};\n\n /**\n * key: dim\n * value: extent\n * @type {Object}\n * @private\n */\n this._approximateExtent = {};\n\n /**\n * Cache summary info for fast visit. See \"dimensionHelper\".\n * @type {Object}\n * @private\n */\n this._dimensionsSummary = summarizeDimensions(this);\n\n /**\n * @type {Object.<Array|TypedArray>}\n * @private\n */\n this._invertedIndicesMap = invertedIndicesMap;\n\n /**\n * @type {Object}\n * @private\n */\n this._calculationInfo = {};\n\n /**\n * User output info of this data.\n * DO NOT use it in other places!\n *\n * When preparing user params for user callbacks, we have\n * to clone these inner data structures to prevent users\n * from modifying them to effect built-in logic. And for\n * performance consideration we make this `userOutput` to\n * avoid clone them too many times.\n *\n * @type {Object}\n * @readOnly\n */\n this.userOutput = this._dimensionsSummary.userOutput;\n};\n\nvar listProto = List.prototype;\n\nlistProto.type = 'list';\n\n/**\n * If each data item has it's own option\n * @type {boolean}\n */\nlistProto.hasItemOption = true;\n\n/**\n * The meanings of the input parameter `dim`:\n *\n * + If dim is a number (e.g., `1`), it means the index of the dimension.\n * For example, `getDimension(0)` will return 'x' or 'lng' or 'radius'.\n * + If dim is a number-like string (e.g., `\"1\"`):\n * + If there is the same concrete dim name defined in `this.dimensions`, it means that concrete name.\n * + If not, it will be converted to a number, which means the index of the dimension.\n * (why? because of the backward compatbility. We have been tolerating number-like string in\n * dimension setting, although now it seems that it is not a good idea.)\n * For example, `visualMap[i].dimension: \"1\"` is the same meaning as `visualMap[i].dimension: 1`,\n * if no dimension name is defined as `\"1\"`.\n * + If dim is a not-number-like string, it means the concrete dim name.\n * For example, it can be be default name `\"x\"`, `\"y\"`, `\"z\"`, `\"lng\"`, `\"lat\"`, `\"angle\"`, `\"radius\"`,\n * or customized in `dimensions` property of option like `\"age\"`.\n *\n * Get dimension name\n * @param {string|number} dim See above.\n * @return {string} Concrete dim name.\n */\nlistProto.getDimension = function (dim) {\n if (typeof dim === 'number'\n // If being a number-like string but not being defined a dimension name.\n || (!isNaN(dim) && !this._dimensionInfos.hasOwnProperty(dim))\n ) {\n dim = this.dimensions[dim];\n }\n return dim;\n};\n\n/**\n * Get type and calculation info of particular dimension\n * @param {string|number} dim\n * Dimension can be concrete names like x, y, z, lng, lat, angle, radius\n * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'\n */\nlistProto.getDimensionInfo = function (dim) {\n // Do not clone, because there may be categories in dimInfo.\n return this._dimensionInfos[this.getDimension(dim)];\n};\n\n/**\n * @return {Array.<string>} concrete dimension name list on coord.\n */\nlistProto.getDimensionsOnCoord = function () {\n return this._dimensionsSummary.dataDimsOnCoord.slice();\n};\n\n/**\n * @param {string} coordDim\n * @param {number} [idx] A coordDim may map to more than one data dim.\n * If idx is `true`, return a array of all mapped dims.\n * If idx is not specified, return the first dim not extra.\n * @return {string|Array.<string>} concrete data dim.\n * If idx is number, and not found, return null/undefined.\n * If idx is `true`, and not found, return empty array (always return array).\n */\nlistProto.mapDimension = function (coordDim, idx) {\n var dimensionsSummary = this._dimensionsSummary;\n\n if (idx == null) {\n return dimensionsSummary.encodeFirstDimNotExtra[coordDim];\n }\n\n var dims = dimensionsSummary.encode[coordDim];\n return idx === true\n // always return array if idx is `true`\n ? (dims || []).slice()\n : (dims && dims[idx]);\n};\n\n/**\n * Initialize from data\n * @param {Array.<Object|number|Array>} data source or data or data provider.\n * @param {Array.<string>} [nameLIst] The name of a datum is used on data diff and\n * default label/tooltip.\n * A name can be specified in encode.itemName,\n * or dataItem.name (only for series option data),\n * or provided in nameList from outside.\n * @param {Function} [dimValueGetter] (dataItem, dimName, dataIndex, dimIndex) => number\n */\nlistProto.initData = function (data, nameList, dimValueGetter) {\n\n var notProvider = Source.isInstance(data) || zrUtil.isArrayLike(data);\n if (notProvider) {\n data = new DefaultDataProvider(data, this.dimensions.length);\n }\n\n if (__DEV__) {\n if (!notProvider && (typeof data.getItem !== 'function' || typeof data.count !== 'function')) {\n throw new Error('Inavlid data provider.');\n }\n }\n\n this._rawData = data;\n\n // Clear\n this._storage = {};\n this._indices = null;\n\n this._nameList = nameList || [];\n\n this._idList = [];\n\n this._nameRepeatCount = {};\n\n if (!dimValueGetter) {\n this.hasItemOption = false;\n }\n\n /**\n * @readOnly\n */\n this.defaultDimValueGetter = defaultDimValueGetters[\n this._rawData.getSource().sourceFormat\n ];\n // Default dim value getter\n this._dimValueGetter = dimValueGetter = dimValueGetter\n || this.defaultDimValueGetter;\n this._dimValueGetterArrayRows = defaultDimValueGetters.arrayRows;\n\n // Reset raw extent.\n this._rawExtent = {};\n\n this._initDataFromProvider(0, data.count());\n\n // If data has no item option.\n if (data.pure) {\n this.hasItemOption = false;\n }\n};\n\nlistProto.getProvider = function () {\n return this._rawData;\n};\n\n/**\n * Caution: Can be only called on raw data (before `this._indices` created).\n */\nlistProto.appendData = function (data) {\n if (__DEV__) {\n zrUtil.assert(!this._indices, 'appendData can only be called on raw data.');\n }\n\n var rawData = this._rawData;\n var start = this.count();\n rawData.appendData(data);\n var end = rawData.count();\n if (!rawData.persistent) {\n end += start;\n }\n this._initDataFromProvider(start, end);\n};\n\n/**\n * Caution: Can be only called on raw data (before `this._indices` created).\n * This method does not modify `rawData` (`dataProvider`), but only\n * add values to storage.\n *\n * The final count will be increased by `Math.max(values.length, names.length)`.\n *\n * @param {Array.<Array.<*>>} values That is the SourceType: 'arrayRows', like\n * [\n * [12, 33, 44],\n * [NaN, 43, 1],\n * ['-', 'asdf', 0]\n * ]\n * Each item is exaclty cooresponding to a dimension.\n * @param {Array.<string>} [names]\n */\nlistProto.appendValues = function (values, names) {\n var chunkSize = this._chunkSize;\n var storage = this._storage;\n var dimensions = this.dimensions;\n var dimLen = dimensions.length;\n var rawExtent = this._rawExtent;\n\n var start = this.count();\n var end = start + Math.max(values.length, names ? names.length : 0);\n var originalChunkCount = this._chunkCount;\n\n for (var i = 0; i < dimLen; i++) {\n var dim = dimensions[i];\n if (!rawExtent[dim]) {\n rawExtent[dim] = getInitialExtent();\n }\n if (!storage[dim]) {\n storage[dim] = [];\n }\n prepareChunks(storage, this._dimensionInfos[dim], chunkSize, originalChunkCount, end);\n this._chunkCount = storage[dim].length;\n }\n\n var emptyDataItem = new Array(dimLen);\n for (var idx = start; idx < end; idx++) {\n var sourceIdx = idx - start;\n var chunkIndex = Math.floor(idx / chunkSize);\n var chunkOffset = idx % chunkSize;\n\n // Store the data by dimensions\n for (var k = 0; k < dimLen; k++) {\n var dim = dimensions[k];\n var val = this._dimValueGetterArrayRows(\n values[sourceIdx] || emptyDataItem, dim, sourceIdx, k\n );\n storage[dim][chunkIndex][chunkOffset] = val;\n\n var dimRawExtent = rawExtent[dim];\n val < dimRawExtent[0] && (dimRawExtent[0] = val);\n val > dimRawExtent[1] && (dimRawExtent[1] = val);\n }\n\n if (names) {\n this._nameList[idx] = names[sourceIdx];\n }\n }\n\n this._rawCount = this._count = end;\n\n // Reset data extent\n this._extent = {};\n\n prepareInvertedIndex(this);\n};\n\nlistProto._initDataFromProvider = function (start, end) {\n // Optimize.\n if (start >= end) {\n return;\n }\n\n var chunkSize = this._chunkSize;\n var rawData = this._rawData;\n var storage = this._storage;\n var dimensions = this.dimensions;\n var dimLen = dimensions.length;\n var dimensionInfoMap = this._dimensionInfos;\n var nameList = this._nameList;\n var idList = this._idList;\n var rawExtent = this._rawExtent;\n var nameRepeatCount = this._nameRepeatCount = {};\n var nameDimIdx;\n\n var originalChunkCount = this._chunkCount;\n for (var i = 0; i < dimLen; i++) {\n var dim = dimensions[i];\n if (!rawExtent[dim]) {\n rawExtent[dim] = getInitialExtent();\n }\n\n var dimInfo = dimensionInfoMap[dim];\n if (dimInfo.otherDims.itemName === 0) {\n nameDimIdx = this._nameDimIdx = i;\n }\n if (dimInfo.otherDims.itemId === 0) {\n this._idDimIdx = i;\n }\n\n if (!storage[dim]) {\n storage[dim] = [];\n }\n\n prepareChunks(storage, dimInfo, chunkSize, originalChunkCount, end);\n\n this._chunkCount = storage[dim].length;\n }\n\n var dataItem = new Array(dimLen);\n for (var idx = start; idx < end; idx++) {\n // NOTICE: Try not to write things into dataItem\n dataItem = rawData.getItem(idx, dataItem);\n // Each data item is value\n // [1, 2]\n // 2\n // Bar chart, line chart which uses category axis\n // only gives the 'y' value. 'x' value is the indices of category\n // Use a tempValue to normalize the value to be a (x, y) value\n var chunkIndex = Math.floor(idx / chunkSize);\n var chunkOffset = idx % chunkSize;\n\n // Store the data by dimensions\n for (var k = 0; k < dimLen; k++) {\n var dim = dimensions[k];\n var dimStorage = storage[dim][chunkIndex];\n // PENDING NULL is empty or zero\n var val = this._dimValueGetter(dataItem, dim, idx, k);\n dimStorage[chunkOffset] = val;\n\n var dimRawExtent = rawExtent[dim];\n val < dimRawExtent[0] && (dimRawExtent[0] = val);\n val > dimRawExtent[1] && (dimRawExtent[1] = val);\n }\n\n // ??? FIXME not check by pure but sourceFormat?\n // TODO refactor these logic.\n if (!rawData.pure) {\n var name = nameList[idx];\n\n if (dataItem && name == null) {\n // If dataItem is {name: ...}, it has highest priority.\n // That is appropriate for many common cases.\n if (dataItem.name != null) {\n // There is no other place to persistent dataItem.name,\n // so save it to nameList.\n nameList[idx] = name = dataItem.name;\n }\n else if (nameDimIdx != null) {\n var nameDim = dimensions[nameDimIdx];\n var nameDimChunk = storage[nameDim][chunkIndex];\n if (nameDimChunk) {\n name = nameDimChunk[chunkOffset];\n var ordinalMeta = dimensionInfoMap[nameDim].ordinalMeta;\n if (ordinalMeta && ordinalMeta.categories.length) {\n name = ordinalMeta.categories[name];\n }\n }\n }\n }\n\n // Try using the id in option\n // id or name is used on dynamical data, mapping old and new items.\n var id = dataItem == null ? null : dataItem.id;\n\n if (id == null && name != null) {\n // Use name as id and add counter to avoid same name\n nameRepeatCount[name] = nameRepeatCount[name] || 0;\n id = name;\n if (nameRepeatCount[name] > 0) {\n id += '__ec__' + nameRepeatCount[name];\n }\n nameRepeatCount[name]++;\n }\n id != null && (idList[idx] = id);\n }\n }\n\n if (!rawData.persistent && rawData.clean) {\n // Clean unused data if data source is typed array.\n rawData.clean();\n }\n\n this._rawCount = this._count = end;\n\n // Reset data extent\n this._extent = {};\n\n prepareInvertedIndex(this);\n};\n\nfunction prepareChunks(storage, dimInfo, chunkSize, chunkCount, end) {\n var DataCtor = dataCtors[dimInfo.type];\n var lastChunkIndex = chunkCount - 1;\n var dim = dimInfo.name;\n var resizeChunkArray = storage[dim][lastChunkIndex];\n if (resizeChunkArray && resizeChunkArray.length < chunkSize) {\n var newStore = new DataCtor(Math.min(end - lastChunkIndex * chunkSize, chunkSize));\n // The cost of the copy is probably inconsiderable\n // within the initial chunkSize.\n for (var j = 0; j < resizeChunkArray.length; j++) {\n newStore[j] = resizeChunkArray[j];\n }\n storage[dim][lastChunkIndex] = newStore;\n }\n\n // Create new chunks.\n for (var k = chunkCount * chunkSize; k < end; k += chunkSize) {\n storage[dim].push(new DataCtor(Math.min(end - k, chunkSize)));\n }\n}\n\nfunction prepareInvertedIndex(list) {\n var invertedIndicesMap = list._invertedIndicesMap;\n zrUtil.each(invertedIndicesMap, function (invertedIndices, dim) {\n var dimInfo = list._dimensionInfos[dim];\n\n // Currently, only dimensions that has ordinalMeta can create inverted indices.\n var ordinalMeta = dimInfo.ordinalMeta;\n if (ordinalMeta) {\n invertedIndices = invertedIndicesMap[dim] = new CtorInt32Array(\n ordinalMeta.categories.length\n );\n // The default value of TypedArray is 0. To avoid miss\n // mapping to 0, we should set it as INDEX_NOT_FOUND.\n for (var i = 0; i < invertedIndices.length; i++) {\n invertedIndices[i] = INDEX_NOT_FOUND;\n }\n for (var i = 0; i < list._count; i++) {\n // Only support the case that all values are distinct.\n invertedIndices[list.get(dim, i)] = i;\n }\n }\n });\n}\n\nfunction getRawValueFromStore(list, dimIndex, rawIndex) {\n var val;\n if (dimIndex != null) {\n var chunkSize = list._chunkSize;\n var chunkIndex = Math.floor(rawIndex / chunkSize);\n var chunkOffset = rawIndex % chunkSize;\n var dim = list.dimensions[dimIndex];\n var chunk = list._storage[dim][chunkIndex];\n if (chunk) {\n val = chunk[chunkOffset];\n var ordinalMeta = list._dimensionInfos[dim].ordinalMeta;\n if (ordinalMeta && ordinalMeta.categories.length) {\n val = ordinalMeta.categories[val];\n }\n }\n }\n return val;\n}\n\n/**\n * @return {number}\n */\nlistProto.count = function () {\n return this._count;\n};\n\nlistProto.getIndices = function () {\n var newIndices;\n\n var indices = this._indices;\n if (indices) {\n var Ctor = indices.constructor;\n var thisCount = this._count;\n // `new Array(a, b, c)` is different from `new Uint32Array(a, b, c)`.\n if (Ctor === Array) {\n newIndices = new Ctor(thisCount);\n for (var i = 0; i < thisCount; i++) {\n newIndices[i] = indices[i];\n }\n }\n else {\n newIndices = new Ctor(indices.buffer, 0, thisCount);\n }\n }\n else {\n var Ctor = getIndicesCtor(this);\n var newIndices = new Ctor(this.count());\n for (var i = 0; i < newIndices.length; i++) {\n newIndices[i] = i;\n }\n }\n\n return newIndices;\n};\n\n/**\n * Get value. Return NaN if idx is out of range.\n * @param {string} dim Dim must be concrete name.\n * @param {number} idx\n * @param {boolean} stack\n * @return {number}\n */\nlistProto.get = function (dim, idx /*, stack */) {\n if (!(idx >= 0 && idx < this._count)) {\n return NaN;\n }\n var storage = this._storage;\n if (!storage[dim]) {\n // TODO Warn ?\n return NaN;\n }\n\n idx = this.getRawIndex(idx);\n\n var chunkIndex = Math.floor(idx / this._chunkSize);\n var chunkOffset = idx % this._chunkSize;\n\n var chunkStore = storage[dim][chunkIndex];\n var value = chunkStore[chunkOffset];\n // FIXME ordinal data type is not stackable\n // if (stack) {\n // var dimensionInfo = this._dimensionInfos[dim];\n // if (dimensionInfo && dimensionInfo.stackable) {\n // var stackedOn = this.stackedOn;\n // while (stackedOn) {\n // // Get no stacked data of stacked on\n // var stackedValue = stackedOn.get(dim, idx);\n // // Considering positive stack, negative stack and empty data\n // if ((value >= 0 && stackedValue > 0) // Positive stack\n // || (value <= 0 && stackedValue < 0) // Negative stack\n // ) {\n // value += stackedValue;\n // }\n // stackedOn = stackedOn.stackedOn;\n // }\n // }\n // }\n\n return value;\n};\n\n/**\n * @param {string} dim concrete dim\n * @param {number} rawIndex\n * @return {number|string}\n */\nlistProto.getByRawIndex = function (dim, rawIdx) {\n if (!(rawIdx >= 0 && rawIdx < this._rawCount)) {\n return NaN;\n }\n var dimStore = this._storage[dim];\n if (!dimStore) {\n // TODO Warn ?\n return NaN;\n }\n\n var chunkIndex = Math.floor(rawIdx / this._chunkSize);\n var chunkOffset = rawIdx % this._chunkSize;\n var chunkStore = dimStore[chunkIndex];\n return chunkStore[chunkOffset];\n};\n\n/**\n * FIXME Use `get` on chrome maybe slow(in filterSelf and selectRange).\n * Hack a much simpler _getFast\n * @private\n */\nlistProto._getFast = function (dim, rawIdx) {\n var chunkIndex = Math.floor(rawIdx / this._chunkSize);\n var chunkOffset = rawIdx % this._chunkSize;\n var chunkStore = this._storage[dim][chunkIndex];\n return chunkStore[chunkOffset];\n};\n\n/**\n * Get value for multi dimensions.\n * @param {Array.<string>} [dimensions] If ignored, using all dimensions.\n * @param {number} idx\n * @return {number}\n */\nlistProto.getValues = function (dimensions, idx /*, stack */) {\n var values = [];\n\n if (!zrUtil.isArray(dimensions)) {\n // stack = idx;\n idx = dimensions;\n dimensions = this.dimensions;\n }\n\n for (var i = 0, len = dimensions.length; i < len; i++) {\n values.push(this.get(dimensions[i], idx /*, stack */));\n }\n\n return values;\n};\n\n/**\n * If value is NaN. Inlcuding '-'\n * Only check the coord dimensions.\n * @param {string} dim\n * @param {number} idx\n * @return {number}\n */\nlistProto.hasValue = function (idx) {\n var dataDimsOnCoord = this._dimensionsSummary.dataDimsOnCoord;\n for (var i = 0, len = dataDimsOnCoord.length; i < len; i++) {\n // Ordinal type originally can be string or number.\n // But when an ordinal type is used on coord, it can\n // not be string but only number. So we can also use isNaN.\n if (isNaN(this.get(dataDimsOnCoord[i], idx))) {\n return false;\n }\n }\n return true;\n};\n\n/**\n * Get extent of data in one dimension\n * @param {string} dim\n * @param {boolean} stack\n */\nlistProto.getDataExtent = function (dim /*, stack */) {\n // Make sure use concrete dim as cache name.\n dim = this.getDimension(dim);\n var dimData = this._storage[dim];\n var initialExtent = getInitialExtent();\n\n // stack = !!((stack || false) && this.getCalculationInfo(dim));\n\n if (!dimData) {\n return initialExtent;\n }\n\n // Make more strict checkings to ensure hitting cache.\n var currEnd = this.count();\n // var cacheName = [dim, !!stack].join('_');\n // var cacheName = dim;\n\n // Consider the most cases when using data zoom, `getDataExtent`\n // happened before filtering. We cache raw extent, which is not\n // necessary to be cleared and recalculated when restore data.\n var useRaw = !this._indices; // && !stack;\n var dimExtent;\n\n if (useRaw) {\n return this._rawExtent[dim].slice();\n }\n dimExtent = this._extent[dim];\n if (dimExtent) {\n return dimExtent.slice();\n }\n dimExtent = initialExtent;\n\n var min = dimExtent[0];\n var max = dimExtent[1];\n\n for (var i = 0; i < currEnd; i++) {\n // var value = stack ? this.get(dim, i, true) : this._getFast(dim, this.getRawIndex(i));\n var value = this._getFast(dim, this.getRawIndex(i));\n value < min && (min = value);\n value > max && (max = value);\n }\n\n dimExtent = [min, max];\n\n this._extent[dim] = dimExtent;\n\n return dimExtent;\n};\n\n/**\n * Optimize for the scenario that data is filtered by a given extent.\n * Consider that if data amount is more than hundreds of thousand,\n * extent calculation will cost more than 10ms and the cache will\n * be erased because of the filtering.\n */\nlistProto.getApproximateExtent = function (dim /*, stack */) {\n dim = this.getDimension(dim);\n return this._approximateExtent[dim] || this.getDataExtent(dim /*, stack */);\n};\n\nlistProto.setApproximateExtent = function (extent, dim /*, stack */) {\n dim = this.getDimension(dim);\n this._approximateExtent[dim] = extent.slice();\n};\n\n/**\n * @param {string} key\n * @return {*}\n */\nlistProto.getCalculationInfo = function (key) {\n return this._calculationInfo[key];\n};\n\n/**\n * @param {string|Object} key or k-v object\n * @param {*} [value]\n */\nlistProto.setCalculationInfo = function (key, value) {\n isObject(key)\n ? zrUtil.extend(this._calculationInfo, key)\n : (this._calculationInfo[key] = value);\n};\n\n/**\n * Get sum of data in one dimension\n * @param {string} dim\n */\nlistProto.getSum = function (dim /*, stack */) {\n var dimData = this._storage[dim];\n var sum = 0;\n if (dimData) {\n for (var i = 0, len = this.count(); i < len; i++) {\n var value = this.get(dim, i /*, stack */);\n if (!isNaN(value)) {\n sum += value;\n }\n }\n }\n return sum;\n};\n\n/**\n * Get median of data in one dimension\n * @param {string} dim\n */\nlistProto.getMedian = function (dim /*, stack */) {\n var dimDataArray = [];\n // map all data of one dimension\n this.each(dim, function (val, idx) {\n if (!isNaN(val)) {\n dimDataArray.push(val);\n }\n });\n\n // TODO\n // Use quick select?\n\n // immutability & sort\n var sortedDimDataArray = [].concat(dimDataArray).sort(function (a, b) {\n return a - b;\n });\n var len = this.count();\n // calculate median\n return len === 0\n ? 0\n : len % 2 === 1\n ? sortedDimDataArray[(len - 1) / 2]\n : (sortedDimDataArray[len / 2] + sortedDimDataArray[len / 2 - 1]) / 2;\n};\n\n// /**\n// * Retreive the index with given value\n// * @param {string} dim Concrete dimension.\n// * @param {number} value\n// * @return {number}\n// */\n// Currently incorrect: should return dataIndex but not rawIndex.\n// Do not fix it until this method is to be used somewhere.\n// FIXME Precision of float value\n// listProto.indexOf = function (dim, value) {\n// var storage = this._storage;\n// var dimData = storage[dim];\n// var chunkSize = this._chunkSize;\n// if (dimData) {\n// for (var i = 0, len = this.count(); i < len; i++) {\n// var chunkIndex = Math.floor(i / chunkSize);\n// var chunkOffset = i % chunkSize;\n// if (dimData[chunkIndex][chunkOffset] === value) {\n// return i;\n// }\n// }\n// }\n// return -1;\n// };\n\n/**\n * Only support the dimension which inverted index created.\n * Do not support other cases until required.\n * @param {string} concrete dim\n * @param {number|string} value\n * @return {number} rawIndex\n */\nlistProto.ra