dataZoomProcessor.js 5.5 KB

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