dataZoomProcessor.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 { createHashMap, each } from 'zrender/lib/core/util.js';
  41. import { getAxisMainType } from './helper.js';
  42. import AxisProxy from './AxisProxy.js';
  43. var dataZoomProcessor = {
  44. // `dataZoomProcessor` will only be performed in needed series. Consider if
  45. // there is a line series and a pie series, it is better not to update the
  46. // line series if only pie series is needed to be updated.
  47. getTargetSeries: function (ecModel) {
  48. function eachAxisModel(cb) {
  49. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  50. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  51. var axisModel = ecModel.getComponent(getAxisMainType(axisDim), axisIndex);
  52. cb(axisDim, axisIndex, axisModel, dataZoomModel);
  53. });
  54. });
  55. }
  56. // FIXME: it brings side-effect to `getTargetSeries`.
  57. // Prepare axis proxies.
  58. eachAxisModel(function (axisDim, axisIndex, axisModel, dataZoomModel) {
  59. // dispose all last axis proxy, in case that some axis are deleted.
  60. axisModel.__dzAxisProxy = null;
  61. });
  62. var proxyList = [];
  63. eachAxisModel(function (axisDim, axisIndex, axisModel, dataZoomModel) {
  64. // Different dataZooms may constrol the same axis. In that case,
  65. // an axisProxy serves both of them.
  66. if (!axisModel.__dzAxisProxy) {
  67. // Use the first dataZoomModel as the main model of axisProxy.
  68. axisModel.__dzAxisProxy = new AxisProxy(axisDim, axisIndex, dataZoomModel, ecModel);
  69. proxyList.push(axisModel.__dzAxisProxy);
  70. }
  71. });
  72. var seriesModelMap = createHashMap();
  73. each(proxyList, function (axisProxy) {
  74. each(axisProxy.getTargetSeriesModels(), function (seriesModel) {
  75. seriesModelMap.set(seriesModel.uid, seriesModel);
  76. });
  77. });
  78. return seriesModelMap;
  79. },
  80. // Consider appendData, where filter should be performed. Because data process is
  81. // in block mode currently, it is not need to worry about that the overallProgress
  82. // execute every frame.
  83. overallReset: function (ecModel, api) {
  84. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  85. // We calculate window and reset axis here but not in model
  86. // init stage and not after action dispatch handler, because
  87. // reset should be called after seriesData.restoreData.
  88. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  89. dataZoomModel.getAxisProxy(axisDim, axisIndex).reset(dataZoomModel);
  90. });
  91. // Caution: data zoom filtering is order sensitive when using
  92. // percent range and no min/max/scale set on axis.
  93. // For example, we have dataZoom definition:
  94. // [
  95. // {xAxisIndex: 0, start: 30, end: 70},
  96. // {yAxisIndex: 0, start: 20, end: 80}
  97. // ]
  98. // In this case, [20, 80] of y-dataZoom should be based on data
  99. // that have filtered by x-dataZoom using range of [30, 70],
  100. // but should not be based on full raw data. Thus sliding
  101. // x-dataZoom will change both ranges of xAxis and yAxis,
  102. // while sliding y-dataZoom will only change the range of yAxis.
  103. // So we should filter x-axis after reset x-axis immediately,
  104. // and then reset y-axis and filter y-axis.
  105. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  106. dataZoomModel.getAxisProxy(axisDim, axisIndex).filterData(dataZoomModel, api);
  107. });
  108. });
  109. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  110. // Fullfill all of the range props so that user
  111. // is able to get them from chart.getOption().
  112. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  113. if (axisProxy) {
  114. var percentRange = axisProxy.getDataPercentWindow();
  115. var valueRange = axisProxy.getDataValueWindow();
  116. dataZoomModel.setCalculatedRange({
  117. start: percentRange[0],
  118. end: percentRange[1],
  119. startValue: valueRange[0],
  120. endValue: valueRange[1]
  121. });
  122. }
  123. });
  124. }
  125. };
  126. export default dataZoomProcessor;