MapSeries.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import { __extends } from "tslib";
  41. import * as zrUtil from 'zrender/lib/core/util.js';
  42. import createSeriesDataSimply from '../helper/createSeriesDataSimply.js';
  43. import SeriesModel from '../../model/Series.js';
  44. import geoSourceManager from '../../coord/geo/geoSourceManager.js';
  45. import { makeSeriesEncodeForNameBased } from '../../data/helper/sourceHelper.js';
  46. import { createTooltipMarkup } from '../../component/tooltip/tooltipMarkup.js';
  47. import { createSymbol } from '../../util/symbol.js';
  48. import { COORD_SYS_USAGE_KIND_BOX, decideCoordSysUsageKind } from '../../core/CoordinateSystem.js';
  49. import tokens from '../../visual/tokens.js';
  50. export var SERIES_TYPE_MAP = 'map';
  51. var MapSeries = /** @class */function (_super) {
  52. __extends(MapSeries, _super);
  53. function MapSeries() {
  54. var _this = _super !== null && _super.apply(this, arguments) || this;
  55. _this.type = MapSeries.type;
  56. _this.getTooltipPosition = function (dataIndex) {
  57. if (dataIndex != null) {
  58. var name_1 = this.getData().getName(dataIndex);
  59. var geo = this.coordinateSystem;
  60. var region = geo.getRegion(name_1);
  61. return region && geo.dataToPoint(region.getCenter());
  62. }
  63. };
  64. return _this;
  65. }
  66. MapSeries.prototype.getInitialData = function (option) {
  67. var data = createSeriesDataSimply(this, {
  68. coordDimensions: ['value'],
  69. encodeDefaulter: zrUtil.curry(makeSeriesEncodeForNameBased, this)
  70. });
  71. var dataNameIndexMap = zrUtil.createHashMap();
  72. var toAppendItems = [];
  73. for (var i = 0, len = data.count(); i < len; i++) {
  74. var name_2 = data.getName(i);
  75. dataNameIndexMap.set(name_2, i);
  76. }
  77. var geoSource = geoSourceManager.load(this.getMapType(), this.option.nameMap, this.option.nameProperty);
  78. zrUtil.each(geoSource.regions, function (region) {
  79. var name = region.name;
  80. var dataNameIdx = dataNameIndexMap.get(name);
  81. // apply specified echarts style in GeoJSON data
  82. var specifiedGeoJSONRegionStyle = region.properties && region.properties.echartsStyle;
  83. var dataItem;
  84. if (dataNameIdx == null) {
  85. dataItem = {
  86. name: name
  87. };
  88. toAppendItems.push(dataItem);
  89. } else {
  90. dataItem = data.getRawDataItem(dataNameIdx);
  91. }
  92. specifiedGeoJSONRegionStyle && zrUtil.merge(dataItem, specifiedGeoJSONRegionStyle);
  93. });
  94. // Complete data with missing regions. The consequent processes (like visual
  95. // map and render) can not be performed without a "full data". For example,
  96. // find `dataIndex` by name.
  97. data.appendData(toAppendItems);
  98. return data;
  99. };
  100. /**
  101. * If no host geo model, return null, which means using a
  102. * inner exclusive geo model.
  103. */
  104. MapSeries.prototype.getHostGeoModel = function () {
  105. if (decideCoordSysUsageKind(this).kind === COORD_SYS_USAGE_KIND_BOX) {
  106. // Always use an internal geo if specify as `COORD_SYS_USAGE_KIND_BOX`.
  107. // Notice that currently we do not support laying out a geo based on
  108. // another geo, but preserve the possibility.
  109. return;
  110. }
  111. return this.getReferringComponents('geo', {
  112. useDefault: false,
  113. enableAll: false,
  114. enableNone: false
  115. }).models[0];
  116. };
  117. MapSeries.prototype.getMapType = function () {
  118. return (this.getHostGeoModel() || this).option.map;
  119. };
  120. // _fillOption(option, mapName) {
  121. // Shallow clone
  122. // option = zrUtil.extend({}, option);
  123. // option.data = geoCreator.getFilledRegions(option.data, mapName, option.nameMap);
  124. // return option;
  125. // }
  126. MapSeries.prototype.getRawValue = function (dataIndex) {
  127. // Use value stored in data instead because it is calculated from multiple series
  128. // FIXME Provide all value of multiple series ?
  129. var data = this.getData();
  130. return data.get(data.mapDimension('value'), dataIndex);
  131. };
  132. /**
  133. * Get model of region
  134. */
  135. MapSeries.prototype.getRegionModel = function (regionName) {
  136. var data = this.getData();
  137. return data.getItemModel(data.indexOfName(regionName));
  138. };
  139. /**
  140. * Map tooltip formatter
  141. */
  142. MapSeries.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  143. // FIXME originalData and data is a bit confusing
  144. var data = this.getData();
  145. var value = this.getRawValue(dataIndex);
  146. var name = data.getName(dataIndex);
  147. var seriesNames = [];
  148. zrUtil.each(this.seriesGroup.f, function (mapSeries) {
  149. var otherIndex = mapSeries.originalData.indexOfName(name);
  150. var valueDim = data.mapDimension('value');
  151. if (!isNaN(mapSeries.originalData.get(valueDim, otherIndex))) {
  152. seriesNames.push(mapSeries.name);
  153. }
  154. });
  155. return createTooltipMarkup('section', {
  156. header: seriesNames.join(', '),
  157. noHeader: !seriesNames.length,
  158. blocks: [createTooltipMarkup('nameValue', {
  159. name: name,
  160. value: value
  161. })]
  162. });
  163. };
  164. MapSeries.prototype.getLegendIcon = function (opt) {
  165. var iconType = opt.icon || 'roundRect';
  166. var icon = createSymbol(iconType, 0, 0, opt.itemWidth, opt.itemHeight, opt.itemStyle.fill);
  167. icon.setStyle(opt.itemStyle);
  168. // Map do not use itemStyle.borderWidth as border width
  169. icon.style.stroke = 'none';
  170. // No rotation because no series visual symbol for map
  171. if (iconType.indexOf('empty') > -1) {
  172. icon.style.stroke = icon.style.fill;
  173. icon.style.fill = tokens.color.neutral00;
  174. icon.style.lineWidth = 2;
  175. }
  176. return icon;
  177. };
  178. MapSeries.prototype.__ownRoamView = function () {
  179. return mapSeriesNeedsDrawMap(this) ? this.coordinateSystem.view : null;
  180. };
  181. MapSeries.type = 'series.' + SERIES_TYPE_MAP;
  182. MapSeries.dependencies = ['geo'];
  183. MapSeries.layoutMode = 'box';
  184. MapSeries.defaultOption = {
  185. // 一级层叠
  186. // zlevel: 0,
  187. // 二级层叠
  188. z: 2,
  189. coordinateSystem: 'geo',
  190. // map should be explicitly specified since ec3.
  191. map: '',
  192. // If `geoIndex` is not specified, a exclusive geo will be
  193. // created. Otherwise use the specified geo component, and
  194. // `map` and `mapType` are ignored.
  195. // geoIndex: 0,
  196. // 'center' | 'left' | 'right' | 'x%' | {number}
  197. left: 'center',
  198. // 'center' | 'top' | 'bottom' | 'x%' | {number}
  199. top: 'center',
  200. // right
  201. // bottom
  202. // width:
  203. // height
  204. // Aspect is width / height. Inited to be geoJson bbox aspect
  205. // This parameter is used for scale this aspect
  206. // Default value:
  207. // for geoSVG source: 1,
  208. // for geoJSON source: 0.75.
  209. aspectScale: null,
  210. // Layout with center and size
  211. // If you want to put map in a fixed size box with right aspect ratio
  212. // This two properties may be more convenient.
  213. // layoutCenter: [50%, 50%]
  214. // layoutSize: 100
  215. showLegendSymbol: true,
  216. // Define left-top, right-bottom coords to control view
  217. // For example, [ [180, 90], [-180, -90] ],
  218. // higher priority than center and zoom
  219. boundingCoords: null,
  220. // Default on center of map
  221. center: null,
  222. zoom: 1,
  223. scaleLimit: null,
  224. selectedMode: true,
  225. label: {
  226. show: false,
  227. color: tokens.color.tertiary
  228. },
  229. // scaleLimit: null,
  230. itemStyle: {
  231. borderWidth: 0.5,
  232. borderColor: tokens.color.border,
  233. areaColor: tokens.color.background
  234. },
  235. emphasis: {
  236. label: {
  237. show: true,
  238. color: tokens.color.primary
  239. },
  240. itemStyle: {
  241. areaColor: tokens.color.highlight
  242. }
  243. },
  244. select: {
  245. label: {
  246. show: true,
  247. color: tokens.color.primary
  248. },
  249. itemStyle: {
  250. color: tokens.color.highlight
  251. }
  252. },
  253. nameProperty: 'name'
  254. };
  255. return MapSeries;
  256. }(SeriesModel);
  257. /**
  258. * Has exclusive geo, rahter than depends on a separate geo componet.
  259. */
  260. export function mapSeriesGroupHasOwnGeo(groupKey) {
  261. return groupKey.indexOf('i') === 0;
  262. }
  263. export function mapSeriesNeedsDrawMap(mapSeries) {
  264. // Within a MAP_SERIES_GROUP, only `mainSeries` has `needsDrawMap: true`.
  265. return getMainMapSeries(mapSeries.seriesGroup) === mapSeries && !mapSeries.getHostGeoModel();
  266. }
  267. export function getMainMapSeries(mapSeriesGroup) {
  268. // The first series after filtering in a MAP_SERIES_GROUP.
  269. return mapSeriesGroup.f[0];
  270. }
  271. /**
  272. * @tutorial [MAP_SERIES_GROUP]
  273. * - For map series that reference external geo components (typically via `geoIndex` or `geoId` in ec option),
  274. * a map series group is all map series that reference to the same geo component.
  275. * - For other map series,
  276. * a map series group is all map series that use the same `map` in ec option.
  277. * NOTICE: series filtering (typically by legend) matters:
  278. * If this method is executed before series filtering, all series are included,
  279. * otherwise, series filtered out are excluded.
  280. * When legend disables the original first series, the original second series takes the responsibility
  281. * to render map (via its `MapDraw`).
  282. */
  283. export function buildAllMapSeriesGroups(ecModel, beforeSeriesFiltering) {
  284. var allMapSeriesGroups = {};
  285. ecModel.eachRawSeriesByType(SERIES_TYPE_MAP, function (seriesModel) {
  286. var hostGeoModel = seriesModel.getHostGeoModel();
  287. var key = hostGeoModel ? 'o' + hostGeoModel.id : 'i' + seriesModel.getMapType();
  288. var group = allMapSeriesGroups[key] = allMapSeriesGroups[key] || {
  289. f: [],
  290. r: []
  291. };
  292. if (!ecModel.isSeriesFiltered(seriesModel) && !beforeSeriesFiltering) {
  293. group.f.push(seriesModel);
  294. }
  295. group.r.push(seriesModel);
  296. });
  297. return allMapSeriesGroups;
  298. }
  299. export default MapSeries;