123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543 |
- var echarts = require("../../echarts");
- var zrUtil = require("zrender/lib/core/util");
- var env = require("zrender/lib/core/env");
- var visualDefault = require("../../visual/visualDefault");
- var VisualMapping = require("../../visual/VisualMapping");
- var visualSolution = require("../../visual/visualSolution");
- var modelUtil = require("../../util/model");
- var numberUtil = require("../../util/number");
- var mapVisual = VisualMapping.mapVisual;
- var eachVisual = VisualMapping.eachVisual;
- var isArray = zrUtil.isArray;
- var each = zrUtil.each;
- var asc = numberUtil.asc;
- var linearMap = numberUtil.linearMap;
- var noop = zrUtil.noop;
- var VisualMapModel = echarts.extendComponentModel({
- type: 'visualMap',
- dependencies: ['series'],
-
- stateList: ['inRange', 'outOfRange'],
-
- replacableOptionKeys: ['inRange', 'outOfRange', 'target', 'controller', 'color'],
-
- dataBound: [-Infinity, Infinity],
-
- layoutMode: {
- type: 'box',
- ignoreSize: true
- },
-
- defaultOption: {
- show: true,
- zlevel: 0,
- z: 4,
- seriesIndex: 'all',
-
-
-
-
- min: 0,
-
- max: 200,
-
- dimension: null,
- inRange: null,
-
-
- outOfRange: null,
-
-
-
- left: 0,
-
- right: null,
-
- top: null,
-
- bottom: 0,
-
- itemWidth: null,
- itemHeight: null,
- inverse: false,
- orient: 'vertical',
-
- backgroundColor: 'rgba(0,0,0,0)',
- borderColor: '#ccc',
-
- contentColor: '#5793f3',
- inactiveColor: '#aaa',
- borderWidth: 0,
-
- padding: 5,
-
-
- textGap: 10,
-
- precision: 0,
-
- color: null,
-
- formatter: null,
- text: null,
-
- textStyle: {
- color: '#333'
- }
- },
-
- init: function (option, parentModel, ecModel) {
-
- this._dataExtent;
-
- this.targetVisuals = {};
-
- this.controllerVisuals = {};
-
- this.textStyleModel;
-
- this.itemSize;
- this.mergeDefaultAndTheme(option, ecModel);
- },
-
- optionUpdated: function (newOption, isInit) {
- var thisOption = this.option;
-
-
- if (!env.canvasSupported) {
- thisOption.realtime = false;
- }
- !isInit && visualSolution.replaceVisualOption(thisOption, newOption, this.replacableOptionKeys);
- this.textStyleModel = this.getModel('textStyle');
- this.resetItemSize();
- this.completeVisualOption();
- },
-
- resetVisual: function (supplementVisualOption) {
- var stateList = this.stateList;
- supplementVisualOption = zrUtil.bind(supplementVisualOption, this);
- this.controllerVisuals = visualSolution.createVisualMappings(this.option.controller, stateList, supplementVisualOption);
- this.targetVisuals = visualSolution.createVisualMappings(this.option.target, stateList, supplementVisualOption);
- },
-
- getTargetSeriesIndices: function () {
- var optionSeriesIndex = this.option.seriesIndex;
- var seriesIndices = [];
- if (optionSeriesIndex == null || optionSeriesIndex === 'all') {
- this.ecModel.eachSeries(function (seriesModel, index) {
- seriesIndices.push(index);
- });
- } else {
- seriesIndices = modelUtil.normalizeToArray(optionSeriesIndex);
- }
- return seriesIndices;
- },
-
- eachTargetSeries: function (callback, context) {
- zrUtil.each(this.getTargetSeriesIndices(), function (seriesIndex) {
- callback.call(context, this.ecModel.getSeriesByIndex(seriesIndex));
- }, this);
- },
-
- isTargetSeries: function (seriesModel) {
- var is = false;
- this.eachTargetSeries(function (model) {
- model === seriesModel && (is = true);
- });
- return is;
- },
-
- formatValueText: function (value, isCategory, edgeSymbols) {
- var option = this.option;
- var precision = option.precision;
- var dataBound = this.dataBound;
- var formatter = option.formatter;
- var isMinMax;
- var textValue;
- edgeSymbols = edgeSymbols || ['<', '>'];
- if (zrUtil.isArray(value)) {
- value = value.slice();
- isMinMax = true;
- }
- textValue = isCategory ? value : isMinMax ? [toFixed(value[0]), toFixed(value[1])] : toFixed(value);
- if (zrUtil.isString(formatter)) {
- return formatter.replace('{value}', isMinMax ? textValue[0] : textValue).replace('{value2}', isMinMax ? textValue[1] : textValue);
- } else if (zrUtil.isFunction(formatter)) {
- return isMinMax ? formatter(value[0], value[1]) : formatter(value);
- }
- if (isMinMax) {
- if (value[0] === dataBound[0]) {
- return edgeSymbols[0] + ' ' + textValue[1];
- } else if (value[1] === dataBound[1]) {
- return edgeSymbols[1] + ' ' + textValue[0];
- } else {
- return textValue[0] + ' - ' + textValue[1];
- }
- } else {
-
- return textValue;
- }
- function toFixed(val) {
- return val === dataBound[0] ? 'min' : val === dataBound[1] ? 'max' : (+val).toFixed(Math.min(precision, 20));
- }
- },
-
- resetExtent: function () {
- var thisOption = this.option;
-
-
- var extent = asc([thisOption.min, thisOption.max]);
- this._dataExtent = extent;
- },
-
- getDataDimension: function (list) {
- var optDim = this.option.dimension;
- var listDimensions = list.dimensions;
- if (optDim == null && !listDimensions.length) {
- return;
- }
- if (optDim != null) {
- return list.getDimension(optDim);
- }
- var dimNames = list.dimensions;
- for (var i = dimNames.length - 1; i >= 0; i--) {
- var dimName = dimNames[i];
- var dimInfo = list.getDimensionInfo(dimName);
- if (!dimInfo.isCalculationCoord) {
- return dimName;
- }
- }
- },
-
- getExtent: function () {
- return this._dataExtent.slice();
- },
-
- completeVisualOption: function () {
- var ecModel = this.ecModel;
- var thisOption = this.option;
- var base = {
- inRange: thisOption.inRange,
- outOfRange: thisOption.outOfRange
- };
- var target = thisOption.target || (thisOption.target = {});
- var controller = thisOption.controller || (thisOption.controller = {});
- zrUtil.merge(target, base);
- zrUtil.merge(controller, base);
- var isCategory = this.isCategory();
- completeSingle.call(this, target);
- completeSingle.call(this, controller);
- completeInactive.call(this, target, 'inRange', 'outOfRange');
- completeController.call(this, controller);
- function completeSingle(base) {
-
-
-
-
- if (isArray(thisOption.color)
-
- && !base.inRange) {
- base.inRange = {
- color: thisOption.color.slice().reverse()
- };
- }
-
-
-
-
-
- base.inRange = base.inRange || {
- color: ecModel.get('gradientColor')
- };
- each(this.stateList, function (state) {
- var visualType = base[state];
- if (zrUtil.isString(visualType)) {
- var defa = visualDefault.get(visualType, 'active', isCategory);
- if (defa) {
- base[state] = {};
- base[state][visualType] = defa;
- } else {
-
- delete base[state];
- }
- }
- }, this);
- }
- function completeInactive(base, stateExist, stateAbsent) {
- var optExist = base[stateExist];
- var optAbsent = base[stateAbsent];
- if (optExist && !optAbsent) {
- optAbsent = base[stateAbsent] = {};
- each(optExist, function (visualData, visualType) {
- if (!VisualMapping.isValidType(visualType)) {
- return;
- }
- var defa = visualDefault.get(visualType, 'inactive', isCategory);
- if (defa != null) {
- optAbsent[visualType] = defa;
-
-
- if (visualType === 'color' && !optAbsent.hasOwnProperty('opacity') && !optAbsent.hasOwnProperty('colorAlpha')) {
- optAbsent.opacity = [0, 0];
- }
- }
- });
- }
- }
- function completeController(controller) {
- var symbolExists = (controller.inRange || {}).symbol || (controller.outOfRange || {}).symbol;
- var symbolSizeExists = (controller.inRange || {}).symbolSize || (controller.outOfRange || {}).symbolSize;
- var inactiveColor = this.get('inactiveColor');
- each(this.stateList, function (state) {
- var itemSize = this.itemSize;
- var visuals = controller[state];
-
- if (!visuals) {
- visuals = controller[state] = {
- color: isCategory ? inactiveColor : [inactiveColor]
- };
- }
- if (visuals.symbol == null) {
- visuals.symbol = symbolExists && zrUtil.clone(symbolExists) || (isCategory ? 'roundRect' : ['roundRect']);
- }
- if (visuals.symbolSize == null) {
- visuals.symbolSize = symbolSizeExists && zrUtil.clone(symbolSizeExists) || (isCategory ? itemSize[0] : [itemSize[0], itemSize[0]]);
- }
- visuals.symbol = mapVisual(visuals.symbol, function (symbol) {
- return symbol === 'none' || symbol === 'square' ? 'roundRect' : symbol;
- });
- var symbolSize = visuals.symbolSize;
- if (symbolSize != null) {
- var max = -Infinity;
- eachVisual(symbolSize, function (value) {
- value > max && (max = value);
- });
- visuals.symbolSize = mapVisual(symbolSize, function (value) {
- return linearMap(value, [0, max], [0, itemSize[0]], true);
- });
- }
- }, this);
- }
- },
-
- resetItemSize: function () {
- this.itemSize = [parseFloat(this.get('itemWidth')), parseFloat(this.get('itemHeight'))];
- },
-
- isCategory: function () {
- return !!this.option.categories;
- },
-
- setSelected: noop,
-
- getValueState: noop,
-
- getVisualMeta: noop
- });
- var _default = VisualMapModel;
- module.exports = _default;
|