dataZoomProcessor.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. var echarts = require("../../echarts");
  20. var _util = require("zrender/lib/core/util");
  21. var createHashMap = _util.createHashMap;
  22. var each = _util.each;
  23. /*
  24. * Licensed to the Apache Software Foundation (ASF) under one
  25. * or more contributor license agreements. See the NOTICE file
  26. * distributed with this work for additional information
  27. * regarding copyright ownership. The ASF licenses this file
  28. * to you under the Apache License, Version 2.0 (the
  29. * "License"); you may not use this file except in compliance
  30. * with the License. You may obtain a copy of the License at
  31. *
  32. * http://www.apache.org/licenses/LICENSE-2.0
  33. *
  34. * Unless required by applicable law or agreed to in writing,
  35. * software distributed under the License is distributed on an
  36. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37. * KIND, either express or implied. See the License for the
  38. * specific language governing permissions and limitations
  39. * under the License.
  40. */
  41. echarts.registerProcessor({
  42. // `dataZoomProcessor` will only be performed in needed series. Consider if
  43. // there is a line series and a pie series, it is better not to update the
  44. // line series if only pie series is needed to be updated.
  45. getTargetSeries: function (ecModel) {
  46. var seriesModelMap = createHashMap();
  47. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  48. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel) {
  49. var axisProxy = dataZoomModel.getAxisProxy(dimNames.name, axisIndex);
  50. each(axisProxy.getTargetSeriesModels(), function (seriesModel) {
  51. seriesModelMap.set(seriesModel.uid, seriesModel);
  52. });
  53. });
  54. });
  55. return seriesModelMap;
  56. },
  57. modifyOutputEnd: true,
  58. // Consider appendData, where filter should be performed. Because data process is
  59. // in block mode currently, it is not need to worry about that the overallProgress
  60. // execute every frame.
  61. overallReset: function (ecModel, api) {
  62. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  63. // We calculate window and reset axis here but not in model
  64. // init stage and not after action dispatch handler, because
  65. // reset should be called after seriesData.restoreData.
  66. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel) {
  67. dataZoomModel.getAxisProxy(dimNames.name, axisIndex).reset(dataZoomModel, api);
  68. }); // Caution: data zoom filtering is order sensitive when using
  69. // percent range and no min/max/scale set on axis.
  70. // For example, we have dataZoom definition:
  71. // [
  72. // {xAxisIndex: 0, start: 30, end: 70},
  73. // {yAxisIndex: 0, start: 20, end: 80}
  74. // ]
  75. // In this case, [20, 80] of y-dataZoom should be based on data
  76. // that have filtered by x-dataZoom using range of [30, 70],
  77. // but should not be based on full raw data. Thus sliding
  78. // x-dataZoom will change both ranges of xAxis and yAxis,
  79. // while sliding y-dataZoom will only change the range of yAxis.
  80. // So we should filter x-axis after reset x-axis immediately,
  81. // and then reset y-axis and filter y-axis.
  82. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel) {
  83. dataZoomModel.getAxisProxy(dimNames.name, axisIndex).filterData(dataZoomModel, api);
  84. });
  85. });
  86. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  87. // Fullfill all of the range props so that user
  88. // is able to get them from chart.getOption().
  89. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  90. var percentRange = axisProxy.getDataPercentWindow();
  91. var valueRange = axisProxy.getDataValueWindow();
  92. dataZoomModel.setCalculatedRange({
  93. start: percentRange[0],
  94. end: percentRange[1],
  95. startValue: valueRange[0],
  96. endValue: valueRange[1]
  97. });
  98. });
  99. }
  100. });