MapSeries.js 8.4 KB

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