MapSeries.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 { CoordinateSystemUsageKind, decideCoordSysUsageKind } from '../../core/CoordinateSystem.js';
  49. import tokens from '../../visual/tokens.js';
  50. var MapSeries = /** @class */function (_super) {
  51. __extends(MapSeries, _super);
  52. function MapSeries() {
  53. var _this = _super !== null && _super.apply(this, arguments) || this;
  54. _this.type = MapSeries.type;
  55. // Only first map series of same mapType will drawMap.
  56. _this.needsDrawMap = false;
  57. // Group of all map series with same mapType
  58. _this.seriesGroup = [];
  59. _this.getTooltipPosition = function (dataIndex) {
  60. if (dataIndex != null) {
  61. var name_1 = this.getData().getName(dataIndex);
  62. var geo = this.coordinateSystem;
  63. var region = geo.getRegion(name_1);
  64. return region && geo.dataToPoint(region.getCenter());
  65. }
  66. };
  67. return _this;
  68. }
  69. MapSeries.prototype.getInitialData = function (option) {
  70. var data = createSeriesDataSimply(this, {
  71. coordDimensions: ['value'],
  72. encodeDefaulter: zrUtil.curry(makeSeriesEncodeForNameBased, this)
  73. });
  74. var dataNameIndexMap = zrUtil.createHashMap();
  75. var toAppendItems = [];
  76. for (var i = 0, len = data.count(); i < len; i++) {
  77. var name_2 = data.getName(i);
  78. dataNameIndexMap.set(name_2, i);
  79. }
  80. var geoSource = geoSourceManager.load(this.getMapType(), this.option.nameMap, this.option.nameProperty);
  81. zrUtil.each(geoSource.regions, function (region) {
  82. var name = region.name;
  83. var dataNameIdx = dataNameIndexMap.get(name);
  84. // apply specified echarts style in GeoJSON data
  85. var specifiedGeoJSONRegionStyle = region.properties && region.properties.echartsStyle;
  86. var dataItem;
  87. if (dataNameIdx == null) {
  88. dataItem = {
  89. name: name
  90. };
  91. toAppendItems.push(dataItem);
  92. } else {
  93. dataItem = data.getRawDataItem(dataNameIdx);
  94. }
  95. specifiedGeoJSONRegionStyle && zrUtil.merge(dataItem, specifiedGeoJSONRegionStyle);
  96. });
  97. // Complete data with missing regions. The consequent processes (like visual
  98. // map and render) can not be performed without a "full data". For example,
  99. // find `dataIndex` by name.
  100. data.appendData(toAppendItems);
  101. return data;
  102. };
  103. /**
  104. * If no host geo model, return null, which means using a
  105. * inner exclusive geo model.
  106. */
  107. MapSeries.prototype.getHostGeoModel = function () {
  108. if (decideCoordSysUsageKind(this).kind === CoordinateSystemUsageKind.boxCoordSys) {
  109. // Always use an internal geo if specify a boxCoordSys.
  110. // Notice that currently we do not support laying out a geo based on
  111. // another geo, but preserve the possibility.
  112. return;
  113. }
  114. return this.getReferringComponents('geo', {
  115. useDefault: false,
  116. enableAll: false,
  117. enableNone: false
  118. }).models[0];
  119. };
  120. MapSeries.prototype.getMapType = function () {
  121. return (this.getHostGeoModel() || this).option.map;
  122. };
  123. // _fillOption(option, mapName) {
  124. // Shallow clone
  125. // option = zrUtil.extend({}, option);
  126. // option.data = geoCreator.getFilledRegions(option.data, mapName, option.nameMap);
  127. // return option;
  128. // }
  129. MapSeries.prototype.getRawValue = function (dataIndex) {
  130. // Use value stored in data instead because it is calculated from multiple series
  131. // FIXME Provide all value of multiple series ?
  132. var data = this.getData();
  133. return data.get(data.mapDimension('value'), dataIndex);
  134. };
  135. /**
  136. * Get model of region
  137. */
  138. MapSeries.prototype.getRegionModel = function (regionName) {
  139. var data = this.getData();
  140. return data.getItemModel(data.indexOfName(regionName));
  141. };
  142. /**
  143. * Map tooltip formatter
  144. */
  145. MapSeries.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  146. // FIXME orignalData and data is a bit confusing
  147. var data = this.getData();
  148. var value = this.getRawValue(dataIndex);
  149. var name = data.getName(dataIndex);
  150. var seriesGroup = this.seriesGroup;
  151. var seriesNames = [];
  152. for (var i = 0; i < seriesGroup.length; i++) {
  153. var otherIndex = seriesGroup[i].originalData.indexOfName(name);
  154. var valueDim = data.mapDimension('value');
  155. if (!isNaN(seriesGroup[i].originalData.get(valueDim, otherIndex))) {
  156. seriesNames.push(seriesGroup[i].name);
  157. }
  158. }
  159. return createTooltipMarkup('section', {
  160. header: seriesNames.join(', '),
  161. noHeader: !seriesNames.length,
  162. blocks: [createTooltipMarkup('nameValue', {
  163. name: name,
  164. value: value
  165. })]
  166. });
  167. };
  168. MapSeries.prototype.setZoom = function (zoom) {
  169. this.option.zoom = zoom;
  170. };
  171. MapSeries.prototype.setCenter = function (center) {
  172. this.option.center = center;
  173. };
  174. MapSeries.prototype.getLegendIcon = function (opt) {
  175. var iconType = opt.icon || 'roundRect';
  176. var icon = createSymbol(iconType, 0, 0, opt.itemWidth, opt.itemHeight, opt.itemStyle.fill);
  177. icon.setStyle(opt.itemStyle);
  178. // Map do not use itemStyle.borderWidth as border width
  179. icon.style.stroke = 'none';
  180. // No rotation because no series visual symbol for map
  181. if (iconType.indexOf('empty') > -1) {
  182. icon.style.stroke = icon.style.fill;
  183. icon.style.fill = tokens.color.neutral00;
  184. icon.style.lineWidth = 2;
  185. }
  186. return icon;
  187. };
  188. MapSeries.type = 'series.map';
  189. MapSeries.dependencies = ['geo'];
  190. MapSeries.layoutMode = 'box';
  191. MapSeries.defaultOption = {
  192. // 一级层叠
  193. // zlevel: 0,
  194. // 二级层叠
  195. z: 2,
  196. coordinateSystem: 'geo',
  197. // map should be explicitly specified since ec3.
  198. map: '',
  199. // If `geoIndex` is not specified, a exclusive geo will be
  200. // created. Otherwise use the specified geo component, and
  201. // `map` and `mapType` are ignored.
  202. // geoIndex: 0,
  203. // 'center' | 'left' | 'right' | 'x%' | {number}
  204. left: 'center',
  205. // 'center' | 'top' | 'bottom' | 'x%' | {number}
  206. top: 'center',
  207. // right
  208. // bottom
  209. // width:
  210. // height
  211. // Aspect is width / height. Inited to be geoJson bbox aspect
  212. // This parameter is used for scale this aspect
  213. // Default value:
  214. // for geoSVG source: 1,
  215. // for geoJSON source: 0.75.
  216. aspectScale: null,
  217. // Layout with center and size
  218. // If you want to put map in a fixed size box with right aspect ratio
  219. // This two properties may be more convenient.
  220. // layoutCenter: [50%, 50%]
  221. // layoutSize: 100
  222. showLegendSymbol: true,
  223. // Define left-top, right-bottom coords to control view
  224. // For example, [ [180, 90], [-180, -90] ],
  225. // higher priority than center and zoom
  226. boundingCoords: null,
  227. // Default on center of map
  228. center: null,
  229. zoom: 1,
  230. scaleLimit: null,
  231. selectedMode: true,
  232. label: {
  233. show: false,
  234. color: tokens.color.tertiary
  235. },
  236. // scaleLimit: null,
  237. itemStyle: {
  238. borderWidth: 0.5,
  239. borderColor: tokens.color.border,
  240. areaColor: tokens.color.background
  241. },
  242. emphasis: {
  243. label: {
  244. show: true,
  245. color: tokens.color.primary
  246. },
  247. itemStyle: {
  248. areaColor: tokens.color.highlight
  249. }
  250. },
  251. select: {
  252. label: {
  253. show: true,
  254. color: tokens.color.primary
  255. },
  256. itemStyle: {
  257. color: tokens.color.highlight
  258. }
  259. },
  260. nameProperty: 'name'
  261. };
  262. return MapSeries;
  263. }(SeriesModel);
  264. export default MapSeries;