前端初始化
This commit is contained in:
+303
@@ -0,0 +1,303 @@
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* AUTO-GENERATED FILE. DO NOT MODIFY.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { __extends } from "tslib";
|
||||
import * as zrUtil from 'zrender/lib/core/util.js';
|
||||
import createSeriesDataSimply from '../helper/createSeriesDataSimply.js';
|
||||
import SeriesModel from '../../model/Series.js';
|
||||
import geoSourceManager from '../../coord/geo/geoSourceManager.js';
|
||||
import { makeSeriesEncodeForNameBased } from '../../data/helper/sourceHelper.js';
|
||||
import { createTooltipMarkup } from '../../component/tooltip/tooltipMarkup.js';
|
||||
import { createSymbol } from '../../util/symbol.js';
|
||||
import { COORD_SYS_USAGE_KIND_BOX, decideCoordSysUsageKind } from '../../core/CoordinateSystem.js';
|
||||
import tokens from '../../visual/tokens.js';
|
||||
export var SERIES_TYPE_MAP = 'map';
|
||||
var MapSeries = /** @class */function (_super) {
|
||||
__extends(MapSeries, _super);
|
||||
function MapSeries() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.type = MapSeries.type;
|
||||
_this.getTooltipPosition = function (dataIndex) {
|
||||
if (dataIndex != null) {
|
||||
var name_1 = this.getData().getName(dataIndex);
|
||||
var geo = this.coordinateSystem;
|
||||
var region = geo.getRegion(name_1);
|
||||
return region && geo.dataToPoint(region.getCenter());
|
||||
}
|
||||
};
|
||||
return _this;
|
||||
}
|
||||
MapSeries.prototype.getInitialData = function (option) {
|
||||
var data = createSeriesDataSimply(this, {
|
||||
coordDimensions: ['value'],
|
||||
encodeDefaulter: zrUtil.curry(makeSeriesEncodeForNameBased, this)
|
||||
});
|
||||
var dataNameIndexMap = zrUtil.createHashMap();
|
||||
var toAppendItems = [];
|
||||
for (var i = 0, len = data.count(); i < len; i++) {
|
||||
var name_2 = data.getName(i);
|
||||
dataNameIndexMap.set(name_2, i);
|
||||
}
|
||||
var geoSource = geoSourceManager.load(this.getMapType(), this.option.nameMap, this.option.nameProperty);
|
||||
zrUtil.each(geoSource.regions, function (region) {
|
||||
var name = region.name;
|
||||
var dataNameIdx = dataNameIndexMap.get(name);
|
||||
// apply specified echarts style in GeoJSON data
|
||||
var specifiedGeoJSONRegionStyle = region.properties && region.properties.echartsStyle;
|
||||
var dataItem;
|
||||
if (dataNameIdx == null) {
|
||||
dataItem = {
|
||||
name: name
|
||||
};
|
||||
toAppendItems.push(dataItem);
|
||||
} else {
|
||||
dataItem = data.getRawDataItem(dataNameIdx);
|
||||
}
|
||||
specifiedGeoJSONRegionStyle && zrUtil.merge(dataItem, specifiedGeoJSONRegionStyle);
|
||||
});
|
||||
// Complete data with missing regions. The consequent processes (like visual
|
||||
// map and render) can not be performed without a "full data". For example,
|
||||
// find `dataIndex` by name.
|
||||
data.appendData(toAppendItems);
|
||||
return data;
|
||||
};
|
||||
/**
|
||||
* If no host geo model, return null, which means using a
|
||||
* inner exclusive geo model.
|
||||
*/
|
||||
MapSeries.prototype.getHostGeoModel = function () {
|
||||
if (decideCoordSysUsageKind(this).kind === COORD_SYS_USAGE_KIND_BOX) {
|
||||
// Always use an internal geo if specify as `COORD_SYS_USAGE_KIND_BOX`.
|
||||
// Notice that currently we do not support laying out a geo based on
|
||||
// another geo, but preserve the possibility.
|
||||
return;
|
||||
}
|
||||
return this.getReferringComponents('geo', {
|
||||
useDefault: false,
|
||||
enableAll: false,
|
||||
enableNone: false
|
||||
}).models[0];
|
||||
};
|
||||
MapSeries.prototype.getMapType = function () {
|
||||
return (this.getHostGeoModel() || this).option.map;
|
||||
};
|
||||
// _fillOption(option, mapName) {
|
||||
// Shallow clone
|
||||
// option = zrUtil.extend({}, option);
|
||||
// option.data = geoCreator.getFilledRegions(option.data, mapName, option.nameMap);
|
||||
// return option;
|
||||
// }
|
||||
MapSeries.prototype.getRawValue = function (dataIndex) {
|
||||
// Use value stored in data instead because it is calculated from multiple series
|
||||
// FIXME Provide all value of multiple series ?
|
||||
var data = this.getData();
|
||||
return data.get(data.mapDimension('value'), dataIndex);
|
||||
};
|
||||
/**
|
||||
* Get model of region
|
||||
*/
|
||||
MapSeries.prototype.getRegionModel = function (regionName) {
|
||||
var data = this.getData();
|
||||
return data.getItemModel(data.indexOfName(regionName));
|
||||
};
|
||||
/**
|
||||
* Map tooltip formatter
|
||||
*/
|
||||
MapSeries.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
|
||||
// FIXME originalData and data is a bit confusing
|
||||
var data = this.getData();
|
||||
var value = this.getRawValue(dataIndex);
|
||||
var name = data.getName(dataIndex);
|
||||
var seriesNames = [];
|
||||
zrUtil.each(this.seriesGroup.f, function (mapSeries) {
|
||||
var otherIndex = mapSeries.originalData.indexOfName(name);
|
||||
var valueDim = data.mapDimension('value');
|
||||
if (!isNaN(mapSeries.originalData.get(valueDim, otherIndex))) {
|
||||
seriesNames.push(mapSeries.name);
|
||||
}
|
||||
});
|
||||
return createTooltipMarkup('section', {
|
||||
header: seriesNames.join(', '),
|
||||
noHeader: !seriesNames.length,
|
||||
blocks: [createTooltipMarkup('nameValue', {
|
||||
name: name,
|
||||
value: value
|
||||
})]
|
||||
});
|
||||
};
|
||||
MapSeries.prototype.getLegendIcon = function (opt) {
|
||||
var iconType = opt.icon || 'roundRect';
|
||||
var icon = createSymbol(iconType, 0, 0, opt.itemWidth, opt.itemHeight, opt.itemStyle.fill);
|
||||
icon.setStyle(opt.itemStyle);
|
||||
// Map do not use itemStyle.borderWidth as border width
|
||||
icon.style.stroke = 'none';
|
||||
// No rotation because no series visual symbol for map
|
||||
if (iconType.indexOf('empty') > -1) {
|
||||
icon.style.stroke = icon.style.fill;
|
||||
icon.style.fill = tokens.color.neutral00;
|
||||
icon.style.lineWidth = 2;
|
||||
}
|
||||
return icon;
|
||||
};
|
||||
MapSeries.prototype.__ownRoamView = function () {
|
||||
return mapSeriesNeedsDrawMap(this) ? this.coordinateSystem.view : null;
|
||||
};
|
||||
MapSeries.type = 'series.' + SERIES_TYPE_MAP;
|
||||
MapSeries.dependencies = ['geo'];
|
||||
MapSeries.layoutMode = 'box';
|
||||
MapSeries.defaultOption = {
|
||||
// 一级层叠
|
||||
// zlevel: 0,
|
||||
// 二级层叠
|
||||
z: 2,
|
||||
coordinateSystem: 'geo',
|
||||
// map should be explicitly specified since ec3.
|
||||
map: '',
|
||||
// If `geoIndex` is not specified, a exclusive geo will be
|
||||
// created. Otherwise use the specified geo component, and
|
||||
// `map` and `mapType` are ignored.
|
||||
// geoIndex: 0,
|
||||
// 'center' | 'left' | 'right' | 'x%' | {number}
|
||||
left: 'center',
|
||||
// 'center' | 'top' | 'bottom' | 'x%' | {number}
|
||||
top: 'center',
|
||||
// right
|
||||
// bottom
|
||||
// width:
|
||||
// height
|
||||
// Aspect is width / height. Inited to be geoJson bbox aspect
|
||||
// This parameter is used for scale this aspect
|
||||
// Default value:
|
||||
// for geoSVG source: 1,
|
||||
// for geoJSON source: 0.75.
|
||||
aspectScale: null,
|
||||
// Layout with center and size
|
||||
// If you want to put map in a fixed size box with right aspect ratio
|
||||
// This two properties may be more convenient.
|
||||
// layoutCenter: [50%, 50%]
|
||||
// layoutSize: 100
|
||||
showLegendSymbol: true,
|
||||
// Define left-top, right-bottom coords to control view
|
||||
// For example, [ [180, 90], [-180, -90] ],
|
||||
// higher priority than center and zoom
|
||||
boundingCoords: null,
|
||||
// Default on center of map
|
||||
center: null,
|
||||
zoom: 1,
|
||||
scaleLimit: null,
|
||||
selectedMode: true,
|
||||
label: {
|
||||
show: false,
|
||||
color: tokens.color.tertiary
|
||||
},
|
||||
// scaleLimit: null,
|
||||
itemStyle: {
|
||||
borderWidth: 0.5,
|
||||
borderColor: tokens.color.border,
|
||||
areaColor: tokens.color.background
|
||||
},
|
||||
emphasis: {
|
||||
label: {
|
||||
show: true,
|
||||
color: tokens.color.primary
|
||||
},
|
||||
itemStyle: {
|
||||
areaColor: tokens.color.highlight
|
||||
}
|
||||
},
|
||||
select: {
|
||||
label: {
|
||||
show: true,
|
||||
color: tokens.color.primary
|
||||
},
|
||||
itemStyle: {
|
||||
color: tokens.color.highlight
|
||||
}
|
||||
},
|
||||
nameProperty: 'name'
|
||||
};
|
||||
return MapSeries;
|
||||
}(SeriesModel);
|
||||
/**
|
||||
* Has exclusive geo, rahter than depends on a separate geo componet.
|
||||
*/
|
||||
export function mapSeriesGroupHasOwnGeo(groupKey) {
|
||||
return groupKey.indexOf('i') === 0;
|
||||
}
|
||||
export function mapSeriesNeedsDrawMap(mapSeries) {
|
||||
// Within a MAP_SERIES_GROUP, only `mainSeries` has `needsDrawMap: true`.
|
||||
return getMainMapSeries(mapSeries.seriesGroup) === mapSeries && !mapSeries.getHostGeoModel();
|
||||
}
|
||||
export function getMainMapSeries(mapSeriesGroup) {
|
||||
// The first series after filtering in a MAP_SERIES_GROUP.
|
||||
return mapSeriesGroup.f[0];
|
||||
}
|
||||
/**
|
||||
* @tutorial [MAP_SERIES_GROUP]
|
||||
* - For map series that reference external geo components (typically via `geoIndex` or `geoId` in ec option),
|
||||
* a map series group is all map series that reference to the same geo component.
|
||||
* - For other map series,
|
||||
* a map series group is all map series that use the same `map` in ec option.
|
||||
* NOTICE: series filtering (typically by legend) matters:
|
||||
* If this method is executed before series filtering, all series are included,
|
||||
* otherwise, series filtered out are excluded.
|
||||
* When legend disables the original first series, the original second series takes the responsibility
|
||||
* to render map (via its `MapDraw`).
|
||||
*/
|
||||
export function buildAllMapSeriesGroups(ecModel, beforeSeriesFiltering) {
|
||||
var allMapSeriesGroups = {};
|
||||
ecModel.eachRawSeriesByType(SERIES_TYPE_MAP, function (seriesModel) {
|
||||
var hostGeoModel = seriesModel.getHostGeoModel();
|
||||
var key = hostGeoModel ? 'o' + hostGeoModel.id : 'i' + seriesModel.getMapType();
|
||||
var group = allMapSeriesGroups[key] = allMapSeriesGroups[key] || {
|
||||
f: [],
|
||||
r: []
|
||||
};
|
||||
if (!ecModel.isSeriesFiltered(seriesModel) && !beforeSeriesFiltering) {
|
||||
group.f.push(seriesModel);
|
||||
}
|
||||
group.r.push(seriesModel);
|
||||
});
|
||||
return allMapSeriesGroups;
|
||||
}
|
||||
export default MapSeries;
|
||||
+187
@@ -0,0 +1,187 @@
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* AUTO-GENERATED FILE. DO NOT MODIFY.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { __extends } from "tslib";
|
||||
import * as graphic from '../../util/graphic.js';
|
||||
import MapDraw from '../../component/helper/MapDraw.js';
|
||||
import ChartView from '../../view/Chart.js';
|
||||
import { getMainMapSeries, mapSeriesNeedsDrawMap, SERIES_TYPE_MAP } from './MapSeries.js';
|
||||
import { setLabelStyle, getLabelStatesModels } from '../../label/labelStyle.js';
|
||||
import { setStatesFlag, Z2_EMPHASIS_LIFT } from '../../util/states.js';
|
||||
var MapView = /** @class */function (_super) {
|
||||
__extends(MapView, _super);
|
||||
function MapView() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.type = SERIES_TYPE_MAP;
|
||||
return _this;
|
||||
}
|
||||
MapView.prototype.render = function (mapModel, ecModel, api, payload) {
|
||||
// Not render if it is an toggleSelect action from self
|
||||
if (payload && payload.type === 'mapToggleSelect' && payload.from === this.uid) {
|
||||
return;
|
||||
}
|
||||
var group = this.group;
|
||||
group.removeAll();
|
||||
if (mapModel.getHostGeoModel()) {
|
||||
return;
|
||||
}
|
||||
var mapDraw = this._mapDraw;
|
||||
if (mapDraw && payload && payload.type === 'geoRoam') {
|
||||
mapDraw.resetForLabelLayout();
|
||||
}
|
||||
// Not update map if it is an roam action from self
|
||||
if (!(payload && payload.type === 'geoRoam' && payload.componentType === 'series' && payload.seriesId === mapModel.id)) {
|
||||
if (mapSeriesNeedsDrawMap(mapModel)) {
|
||||
mapDraw = mapDraw || (this._mapDraw = new MapDraw(api));
|
||||
group.add(mapDraw.group);
|
||||
mapDraw.draw(mapModel, ecModel, api, this, payload);
|
||||
} else {
|
||||
this._clearMapDraw();
|
||||
}
|
||||
} else {
|
||||
mapDraw && group.add(mapDraw.group);
|
||||
}
|
||||
mapModel.get('showLegendSymbol') && ecModel.getComponent('legend') && this._renderSymbols(mapModel);
|
||||
};
|
||||
/**
|
||||
* @implements RoamHostView['__updateOnOwnRoam']
|
||||
*/
|
||||
MapView.prototype.__updateOnOwnRoam = function (payload, model, api) {
|
||||
var mapDraw = this._mapDraw;
|
||||
if (mapSeriesNeedsDrawMap(model) && mapDraw) {
|
||||
mapDraw.__updateOnOwnRoam(model);
|
||||
}
|
||||
};
|
||||
MapView.prototype.remove = function () {
|
||||
this._clearMapDraw();
|
||||
this.group.removeAll();
|
||||
};
|
||||
MapView.prototype.dispose = function () {
|
||||
this._clearMapDraw();
|
||||
};
|
||||
MapView.prototype._clearMapDraw = function () {
|
||||
this._mapDraw && this._mapDraw.remove();
|
||||
this._mapDraw = null;
|
||||
};
|
||||
MapView.prototype._renderSymbols = function (mapModel) {
|
||||
var originalData = mapModel.originalData;
|
||||
var group = this.group;
|
||||
originalData.each(originalData.mapDimension('value'), function (value, originalDataIndex) {
|
||||
if (isNaN(value)) {
|
||||
return;
|
||||
}
|
||||
var layout = originalData.getItemLayout(originalDataIndex);
|
||||
if (!layout || !layout.point) {
|
||||
// Not exists in map
|
||||
return;
|
||||
}
|
||||
var point = layout.point;
|
||||
var offset = layout.offset;
|
||||
var circle = new graphic.Circle({
|
||||
style: {
|
||||
// Because the special of map draw.
|
||||
// Which needs statistic of multiple series and draw on one map.
|
||||
// And each series also need a symbol with legend color
|
||||
//
|
||||
// Layout and visual are put one the different data
|
||||
// TODO
|
||||
fill: mapModel.getData().getVisual('style').fill
|
||||
},
|
||||
shape: {
|
||||
cx: point[0] + offset * 9,
|
||||
cy: point[1],
|
||||
r: 3
|
||||
},
|
||||
silent: true,
|
||||
// Do not overlap the first series, on which labels are displayed.
|
||||
z2: 8 + (!offset ? Z2_EMPHASIS_LIFT + 1 : 0)
|
||||
});
|
||||
// Only the series that has the first value on the same region is in charge of rendering the label.
|
||||
// But consider the case:
|
||||
// series: [
|
||||
// {id: 'X', type: 'map', map: 'm', {data: [{name: 'A', value: 11}, {name: 'B', {value: 22}]},
|
||||
// {id: 'Y', type: 'map', map: 'm', {data: [{name: 'A', value: 21}, {name: 'C', {value: 33}]}
|
||||
// ]
|
||||
// The offset `0` of item `A` is at series `X`, but of item `C` is at series `Y`.
|
||||
// For backward compatibility, we follow the rule that render label `A` by the
|
||||
// settings on series `X` but render label `C` by the settings on series `Y`.
|
||||
if (!offset) {
|
||||
// `mapModel.seriesGroup.f` must not be empty here.
|
||||
var fullData = getMainMapSeries(mapModel.seriesGroup).getData();
|
||||
var name_1 = originalData.getName(originalDataIndex);
|
||||
var fullIndex_1 = fullData.indexOfName(name_1);
|
||||
var itemModel = originalData.getItemModel(originalDataIndex);
|
||||
var labelModel = itemModel.getModel('label');
|
||||
var regionGroup = fullData.getItemGraphicEl(fullIndex_1);
|
||||
// `getFormattedLabel` needs to use `getData` inside. Here
|
||||
// `mapModel.getData()` is shallow cloned from `mainSeries.getData()`.
|
||||
// FIXME
|
||||
// If this is not the `mainSeries`, the item model (like label formatter)
|
||||
// set on original data item will never get. But it has been working
|
||||
// like that from the beginning, and this scenario is rarely encountered.
|
||||
// So it won't be fixed until we have to.
|
||||
setLabelStyle(circle, getLabelStatesModels(itemModel), {
|
||||
labelFetcher: {
|
||||
getFormattedLabel: function (idx, state) {
|
||||
return mapModel.getFormattedLabel(fullIndex_1, state);
|
||||
}
|
||||
},
|
||||
defaultText: name_1
|
||||
});
|
||||
circle.disableLabelAnimation = true;
|
||||
if (!labelModel.get('position')) {
|
||||
circle.setTextConfig({
|
||||
position: 'bottom'
|
||||
});
|
||||
}
|
||||
regionGroup.onHoverStateChange = function (toState) {
|
||||
setStatesFlag(circle, toState);
|
||||
};
|
||||
}
|
||||
group.add(circle);
|
||||
});
|
||||
};
|
||||
MapView.type = SERIES_TYPE_MAP;
|
||||
return MapView;
|
||||
}(ChartView);
|
||||
export default MapView;
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* AUTO-GENERATED FILE. DO NOT MODIFY.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { use } from '../../extension.js';
|
||||
import MapView from './MapView.js';
|
||||
import MapSeries from './MapSeries.js';
|
||||
import { createLegacyDataSelectAction } from '../../legacy/dataSelectAction.js';
|
||||
import { install as installGeo } from '../../component/geo/install.js';
|
||||
import { mapSymbolLayoutStageHandler } from './mapSymbolLayout.js';
|
||||
import { mapDataStatisticStageHandler } from './mapDataStatistic.js';
|
||||
export function install(registers) {
|
||||
use(installGeo);
|
||||
registers.registerChartView(MapView);
|
||||
registers.registerSeriesModel(MapSeries);
|
||||
registers.registerLayout(mapSymbolLayoutStageHandler);
|
||||
registers.registerProcessor(registers.PRIORITY.PROCESSOR.STATISTIC, mapDataStatisticStageHandler);
|
||||
createLegacyDataSelectAction('map', registers.registerAction);
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* AUTO-GENERATED FILE. DO NOT MODIFY.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import * as zrUtil from 'zrender/lib/core/util.js';
|
||||
import { buildAllMapSeriesGroups, getMainMapSeries, SERIES_TYPE_MAP } from './MapSeries.js';
|
||||
import { createSimpleOverallStageHandler } from '../../util/model.js';
|
||||
// FIXME 公用?
|
||||
function dataStatistics(datas, statisticType) {
|
||||
var dataNameMap = {};
|
||||
zrUtil.each(datas, function (data) {
|
||||
data.each(data.mapDimension('value'), function (value, idx) {
|
||||
// Add prefix to avoid conflict with Object.prototype.
|
||||
var mapKey = 'ec-' + data.getName(idx);
|
||||
dataNameMap[mapKey] = dataNameMap[mapKey] || [];
|
||||
if (!isNaN(value)) {
|
||||
dataNameMap[mapKey].push(value);
|
||||
}
|
||||
});
|
||||
});
|
||||
return datas[0].map(datas[0].mapDimension('value'), function (value, idx) {
|
||||
var mapKey = 'ec-' + datas[0].getName(idx);
|
||||
var sum = 0;
|
||||
var min = Infinity;
|
||||
var max = -Infinity;
|
||||
var len = dataNameMap[mapKey].length;
|
||||
for (var i = 0; i < len; i++) {
|
||||
min = Math.min(min, dataNameMap[mapKey][i]);
|
||||
max = Math.max(max, dataNameMap[mapKey][i]);
|
||||
sum += dataNameMap[mapKey][i];
|
||||
}
|
||||
var result;
|
||||
if (statisticType === 'min') {
|
||||
result = min;
|
||||
} else if (statisticType === 'max') {
|
||||
result = max;
|
||||
} else if (statisticType === 'average') {
|
||||
result = sum / len;
|
||||
} else {
|
||||
result = sum;
|
||||
}
|
||||
return len === 0 ? NaN : result;
|
||||
});
|
||||
}
|
||||
export var mapDataStatisticStageHandler = createSimpleOverallStageHandler(SERIES_TYPE_MAP, mapDataStatistic);
|
||||
function mapDataStatistic(ecModel) {
|
||||
zrUtil.each(buildAllMapSeriesGroups(ecModel), function (seriesGroup) {
|
||||
var mainSeries = getMainMapSeries(seriesGroup);
|
||||
if (!mainSeries) {
|
||||
return;
|
||||
}
|
||||
var data = dataStatistics(zrUtil.map(seriesGroup.f, function (seriesModel) {
|
||||
return seriesModel.getData();
|
||||
}),
|
||||
// PENDING: It has long been using `seriesGroup[0]` here, but if the first map series
|
||||
// is filtered out by legend, `seriesGroup[0]` is the second series in ec option, therefore,
|
||||
// this definition is not reasonable enough for users.
|
||||
mainSeries.get('mapValueCalculation'));
|
||||
zrUtil.each(seriesGroup.f, function (series) {
|
||||
series.seriesGroup = seriesGroup;
|
||||
series.originalData = series.getData();
|
||||
series.setData(data.cloneShallow());
|
||||
});
|
||||
});
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* AUTO-GENERATED FILE. DO NOT MODIFY.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { buildAllMapSeriesGroups, getMainMapSeries, mapSeriesGroupHasOwnGeo, SERIES_TYPE_MAP } from './MapSeries.js';
|
||||
import { createSimpleOverallStageHandler } from '../../util/model.js';
|
||||
import { each } from 'zrender/lib/core/util.js';
|
||||
export var mapSymbolLayoutStageHandler = createSimpleOverallStageHandler(SERIES_TYPE_MAP, mapSymbolLayout);
|
||||
function mapSymbolLayout(ecModel) {
|
||||
each(buildAllMapSeriesGroups(ecModel), function (mapSeriesGroup, groupKey) {
|
||||
if (!getMainMapSeries(mapSeriesGroup) || !mapSeriesGroupHasOwnGeo(groupKey)) {
|
||||
// map series on separate geo components only provide "choropleth map", but symbols are ignored.
|
||||
return;
|
||||
}
|
||||
var mapSymbolOffsets = {};
|
||||
each(mapSeriesGroup.f, function (subMapSeries) {
|
||||
var geo = subMapSeries.coordinateSystem;
|
||||
var data = subMapSeries.originalData;
|
||||
if (subMapSeries.get('showLegendSymbol') && ecModel.getComponent('legend')) {
|
||||
data.each(data.mapDimension('value'), function (value, idx) {
|
||||
var name = data.getName(idx);
|
||||
var region = geo.getRegion(name);
|
||||
// If input series.data is [11, 22, '-'/null/undefined, 44],
|
||||
// it will be filled with NaN: [11, 22, NaN, 44] and NaN will
|
||||
// not be drawn. So here must validate if value is NaN.
|
||||
if (!region || isNaN(value)) {
|
||||
return;
|
||||
}
|
||||
var offset = mapSymbolOffsets[name] || 0;
|
||||
var point = geo.dataToPoint(region.getCenter());
|
||||
mapSymbolOffsets[name] = offset + 1;
|
||||
data.setItemLayout(idx, {
|
||||
point: point,
|
||||
offset: offset
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
// Show label of those region not has legendIcon (which is offset 0)
|
||||
var data = getMainMapSeries(mapSeriesGroup).getData();
|
||||
data.each(function (idx) {
|
||||
var name = data.getName(idx);
|
||||
var layout = data.getItemLayout(idx) || {};
|
||||
layout.showLabel = !mapSymbolOffsets[name];
|
||||
data.setItemLayout(idx, layout);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user