mapDataStatistic.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 * as zrUtil from 'zrender/lib/core/util.js';
  41. // FIXME 公用?
  42. function dataStatistics(datas, statisticType) {
  43. var dataNameMap = {};
  44. zrUtil.each(datas, function (data) {
  45. data.each(data.mapDimension('value'), function (value, idx) {
  46. // Add prefix to avoid conflict with Object.prototype.
  47. var mapKey = 'ec-' + data.getName(idx);
  48. dataNameMap[mapKey] = dataNameMap[mapKey] || [];
  49. if (!isNaN(value)) {
  50. dataNameMap[mapKey].push(value);
  51. }
  52. });
  53. });
  54. return datas[0].map(datas[0].mapDimension('value'), function (value, idx) {
  55. var mapKey = 'ec-' + datas[0].getName(idx);
  56. var sum = 0;
  57. var min = Infinity;
  58. var max = -Infinity;
  59. var len = dataNameMap[mapKey].length;
  60. for (var i = 0; i < len; i++) {
  61. min = Math.min(min, dataNameMap[mapKey][i]);
  62. max = Math.max(max, dataNameMap[mapKey][i]);
  63. sum += dataNameMap[mapKey][i];
  64. }
  65. var result;
  66. if (statisticType === 'min') {
  67. result = min;
  68. } else if (statisticType === 'max') {
  69. result = max;
  70. } else if (statisticType === 'average') {
  71. result = sum / len;
  72. } else {
  73. result = sum;
  74. }
  75. return len === 0 ? NaN : result;
  76. });
  77. }
  78. export default function mapDataStatistic(ecModel) {
  79. var seriesGroups = {};
  80. ecModel.eachSeriesByType('map', function (seriesModel) {
  81. var hostGeoModel = seriesModel.getHostGeoModel();
  82. var key = hostGeoModel ? 'o' + hostGeoModel.id : 'i' + seriesModel.getMapType();
  83. (seriesGroups[key] = seriesGroups[key] || []).push(seriesModel);
  84. });
  85. zrUtil.each(seriesGroups, function (seriesList, key) {
  86. var data = dataStatistics(zrUtil.map(seriesList, function (seriesModel) {
  87. return seriesModel.getData();
  88. }), seriesList[0].get('mapValueCalculation'));
  89. for (var i = 0; i < seriesList.length; i++) {
  90. seriesList[i].originalData = seriesList[i].getData();
  91. }
  92. // FIXME Put where?
  93. for (var i = 0; i < seriesList.length; i++) {
  94. seriesList[i].seriesGroup = seriesList;
  95. seriesList[i].needsDrawMap = i === 0 && !seriesList[i].getHostGeoModel();
  96. seriesList[i].setData(data.cloneShallow());
  97. seriesList[i].mainSeries = seriesList[0];
  98. }
  99. });
  100. }