MapSeries.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. var zrUtil = require("zrender/lib/core/util");
  2. var List = require("../../data/List");
  3. var SeriesModel = require("../../model/Series");
  4. var completeDimensions = require("../../data/helper/completeDimensions");
  5. var _format = require("../../util/format");
  6. var encodeHTML = _format.encodeHTML;
  7. var addCommas = _format.addCommas;
  8. var dataSelectableMixin = require("../../component/helper/selectableMixin");
  9. var geoCreator = require("../../coord/geo/geoCreator");
  10. var MapSeries = SeriesModel.extend({
  11. type: 'series.map',
  12. dependencies: ['geo'],
  13. layoutMode: 'box',
  14. /**
  15. * Only first map series of same mapType will drawMap
  16. * @type {boolean}
  17. */
  18. needsDrawMap: false,
  19. /**
  20. * Group of all map series with same mapType
  21. * @type {boolean}
  22. */
  23. seriesGroup: [],
  24. init: function (option) {
  25. this._fillOption(option, this.getMapType()); // this.option = option;
  26. MapSeries.superApply(this, 'init', arguments);
  27. this.updateSelectedMap(option.data);
  28. },
  29. getInitialData: function (option) {
  30. var dimensions = completeDimensions(['value'], option.data || []);
  31. var list = new List(dimensions, this);
  32. list.initData(option.data);
  33. return list;
  34. },
  35. mergeOption: function (newOption) {
  36. this._fillOption(newOption, this.getMapType());
  37. MapSeries.superApply(this, 'mergeOption', arguments);
  38. this.updateSelectedMap(this.option.data);
  39. },
  40. /**
  41. * If no host geo model, return null, which means using a
  42. * inner exclusive geo model.
  43. */
  44. getHostGeoModel: function () {
  45. var geoIndex = this.option.geoIndex;
  46. return geoIndex != null ? this.dependentModels.geo[geoIndex] : null;
  47. },
  48. getMapType: function () {
  49. return (this.getHostGeoModel() || this).option.map;
  50. },
  51. _fillOption: function (option, mapName) {
  52. // Shallow clone
  53. // option = zrUtil.extend({}, option);
  54. option.data = geoCreator.getFilledRegions(option.data, mapName, option.nameMap); // return option;
  55. },
  56. getRawValue: function (dataIndex) {
  57. // Use value stored in data instead because it is calculated from multiple series
  58. // FIXME Provide all value of multiple series ?
  59. return this.getData().get('value', dataIndex);
  60. },
  61. /**
  62. * Get model of region
  63. * @param {string} name
  64. * @return {module:echarts/model/Model}
  65. */
  66. getRegionModel: function (regionName) {
  67. var data = this.getData();
  68. return data.getItemModel(data.indexOfName(regionName));
  69. },
  70. /**
  71. * Map tooltip formatter
  72. *
  73. * @param {number} dataIndex
  74. */
  75. formatTooltip: function (dataIndex) {
  76. // FIXME orignalData and data is a bit confusing
  77. var data = this.getData();
  78. var formattedValue = addCommas(this.getRawValue(dataIndex));
  79. var name = data.getName(dataIndex);
  80. var seriesGroup = this.seriesGroup;
  81. var seriesNames = [];
  82. for (var i = 0; i < seriesGroup.length; i++) {
  83. var otherIndex = seriesGroup[i].originalData.indexOfName(name);
  84. if (!isNaN(seriesGroup[i].originalData.get('value', otherIndex))) {
  85. seriesNames.push(encodeHTML(seriesGroup[i].name));
  86. }
  87. }
  88. return seriesNames.join(', ') + '<br />' + encodeHTML(name + ' : ' + formattedValue);
  89. },
  90. /**
  91. * @implement
  92. */
  93. getTooltipPosition: function (dataIndex) {
  94. if (dataIndex != null) {
  95. var name = this.getData().getName(dataIndex);
  96. var geo = this.coordinateSystem;
  97. var region = geo.getRegion(name);
  98. return region && geo.dataToPoint(region.center);
  99. }
  100. },
  101. setZoom: function (zoom) {
  102. this.option.zoom = zoom;
  103. },
  104. setCenter: function (center) {
  105. this.option.center = center;
  106. },
  107. defaultOption: {
  108. // 一级层叠
  109. zlevel: 0,
  110. // 二级层叠
  111. z: 2,
  112. coordinateSystem: 'geo',
  113. // map should be explicitly specified since ec3.
  114. map: '',
  115. // If `geoIndex` is not specified, a exclusive geo will be
  116. // created. Otherwise use the specified geo component, and
  117. // `map` and `mapType` are ignored.
  118. // geoIndex: 0,
  119. // 'center' | 'left' | 'right' | 'x%' | {number}
  120. left: 'center',
  121. // 'center' | 'top' | 'bottom' | 'x%' | {number}
  122. top: 'center',
  123. // right
  124. // bottom
  125. // width:
  126. // height
  127. // Aspect is width / height. Inited to be geoJson bbox aspect
  128. // This parameter is used for scale this aspect
  129. aspectScale: 0.75,
  130. ///// Layout with center and size
  131. // If you wan't to put map in a fixed size box with right aspect ratio
  132. // This two properties may more conveninet
  133. // layoutCenter: [50%, 50%]
  134. // layoutSize: 100
  135. // 数值合并方式,默认加和,可选为:
  136. // 'sum' | 'average' | 'max' | 'min'
  137. // mapValueCalculation: 'sum',
  138. // 地图数值计算结果小数精度
  139. // mapValuePrecision: 0,
  140. // 显示图例颜色标识(系列标识的小圆点),图例开启时有效
  141. showLegendSymbol: true,
  142. // 选择模式,默认关闭,可选single,multiple
  143. // selectedMode: false,
  144. dataRangeHoverLink: true,
  145. // 是否开启缩放及漫游模式
  146. // roam: false,
  147. // Define left-top, right-bottom coords to control view
  148. // For example, [ [180, 90], [-180, -90] ],
  149. // higher priority than center and zoom
  150. boundingCoords: null,
  151. // Default on center of map
  152. center: null,
  153. zoom: 1,
  154. scaleLimit: null,
  155. label: {
  156. normal: {
  157. show: false,
  158. color: '#000'
  159. },
  160. emphasis: {
  161. show: true,
  162. color: 'rgb(100,0,0)'
  163. }
  164. },
  165. // scaleLimit: null,
  166. itemStyle: {
  167. normal: {
  168. // color: 各异,
  169. borderWidth: 0.5,
  170. borderColor: '#444',
  171. areaColor: '#eee'
  172. },
  173. // 也是选中样式
  174. emphasis: {
  175. areaColor: 'rgba(255,215,0,0.8)'
  176. }
  177. }
  178. }
  179. });
  180. zrUtil.mixin(MapSeries, dataSelectableMixin);
  181. var _default = MapSeries;
  182. module.exports = _default;