dataZoomProcessor.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var echarts = require("../../echarts");
  2. echarts.registerProcessor(function (ecModel, api) {
  3. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  4. // We calculate window and reset axis here but not in model
  5. // init stage and not after action dispatch handler, because
  6. // reset should be called after seriesData.restoreData.
  7. dataZoomModel.eachTargetAxis(resetSingleAxis); // Caution: data zoom filtering is order sensitive when using
  8. // percent range and no min/max/scale set on axis.
  9. // For example, we have dataZoom definition:
  10. // [
  11. // {xAxisIndex: 0, start: 30, end: 70},
  12. // {yAxisIndex: 0, start: 20, end: 80}
  13. // ]
  14. // In this case, [20, 80] of y-dataZoom should be based on data
  15. // that have filtered by x-dataZoom using range of [30, 70],
  16. // but should not be based on full raw data. Thus sliding
  17. // x-dataZoom will change both ranges of xAxis and yAxis,
  18. // while sliding y-dataZoom will only change the range of yAxis.
  19. // So we should filter x-axis after reset x-axis immediately,
  20. // and then reset y-axis and filter y-axis.
  21. dataZoomModel.eachTargetAxis(filterSingleAxis);
  22. });
  23. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  24. // Fullfill all of the range props so that user
  25. // is able to get them from chart.getOption().
  26. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  27. var percentRange = axisProxy.getDataPercentWindow();
  28. var valueRange = axisProxy.getDataValueWindow();
  29. dataZoomModel.setRawRange({
  30. start: percentRange[0],
  31. end: percentRange[1],
  32. startValue: valueRange[0],
  33. endValue: valueRange[1]
  34. }, true);
  35. });
  36. });
  37. function resetSingleAxis(dimNames, axisIndex, dataZoomModel) {
  38. dataZoomModel.getAxisProxy(dimNames.name, axisIndex).reset(dataZoomModel);
  39. }
  40. function filterSingleAxis(dimNames, axisIndex, dataZoomModel) {
  41. dataZoomModel.getAxisProxy(dimNames.name, axisIndex).filterData(dataZoomModel);
  42. }