sunburstAction.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 helper = require("../helper/treeHelper");
  21. /*
  22. * Licensed to the Apache Software Foundation (ASF) under one
  23. * or more contributor license agreements. See the NOTICE file
  24. * distributed with this work for additional information
  25. * regarding copyright ownership. The ASF licenses this file
  26. * to you under the Apache License, Version 2.0 (the
  27. * "License"); you may not use this file except in compliance
  28. * with the License. You may obtain a copy of the License at
  29. *
  30. * http://www.apache.org/licenses/LICENSE-2.0
  31. *
  32. * Unless required by applicable law or agreed to in writing,
  33. * software distributed under the License is distributed on an
  34. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35. * KIND, either express or implied. See the License for the
  36. * specific language governing permissions and limitations
  37. * under the License.
  38. */
  39. /**
  40. * @file Sunburst action
  41. */
  42. var ROOT_TO_NODE_ACTION = 'sunburstRootToNode';
  43. echarts.registerAction({
  44. type: ROOT_TO_NODE_ACTION,
  45. update: 'updateView'
  46. }, function (payload, ecModel) {
  47. ecModel.eachComponent({
  48. mainType: 'series',
  49. subType: 'sunburst',
  50. query: payload
  51. }, handleRootToNode);
  52. function handleRootToNode(model, index) {
  53. var targetInfo = helper.retrieveTargetInfo(payload, [ROOT_TO_NODE_ACTION], model);
  54. if (targetInfo) {
  55. var originViewRoot = model.getViewRoot();
  56. if (originViewRoot) {
  57. payload.direction = helper.aboveViewRoot(originViewRoot, targetInfo.node) ? 'rollUp' : 'drillDown';
  58. }
  59. model.resetViewRoot(targetInfo.node);
  60. }
  61. }
  62. });
  63. var HIGHLIGHT_ACTION = 'sunburstHighlight';
  64. echarts.registerAction({
  65. type: HIGHLIGHT_ACTION,
  66. update: 'updateView'
  67. }, function (payload, ecModel) {
  68. ecModel.eachComponent({
  69. mainType: 'series',
  70. subType: 'sunburst',
  71. query: payload
  72. }, handleHighlight);
  73. function handleHighlight(model, index) {
  74. var targetInfo = helper.retrieveTargetInfo(payload, [HIGHLIGHT_ACTION], model);
  75. if (targetInfo) {
  76. payload.highlight = targetInfo.node;
  77. }
  78. }
  79. });
  80. var UNHIGHLIGHT_ACTION = 'sunburstUnhighlight';
  81. echarts.registerAction({
  82. type: UNHIGHLIGHT_ACTION,
  83. update: 'updateView'
  84. }, function (payload, ecModel) {
  85. ecModel.eachComponent({
  86. mainType: 'series',
  87. subType: 'sunburst',
  88. query: payload
  89. }, handleUnhighlight);
  90. function handleUnhighlight(model, index) {
  91. payload.unhighlight = true;
  92. }
  93. });