symbol.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 { isFunction } from 'zrender/lib/core/util'; // Encoding visual for all series include which is filtered for legend drawing
  41. var seriesSymbolTask = {
  42. createOnAllSeries: true,
  43. // For legend.
  44. performRawSeries: true,
  45. reset: function (seriesModel, ecModel) {
  46. var data = seriesModel.getData();
  47. if (seriesModel.legendIcon) {
  48. data.setVisual('legendIcon', seriesModel.legendIcon);
  49. }
  50. if (!seriesModel.hasSymbolVisual) {
  51. return;
  52. }
  53. var symbolType = seriesModel.get('symbol');
  54. var symbolSize = seriesModel.get('symbolSize');
  55. var keepAspect = seriesModel.get('symbolKeepAspect');
  56. var symbolRotate = seriesModel.get('symbolRotate');
  57. var symbolOffset = seriesModel.get('symbolOffset');
  58. var hasSymbolTypeCallback = isFunction(symbolType);
  59. var hasSymbolSizeCallback = isFunction(symbolSize);
  60. var hasSymbolRotateCallback = isFunction(symbolRotate);
  61. var hasSymbolOffsetCallback = isFunction(symbolOffset);
  62. var hasCallback = hasSymbolTypeCallback || hasSymbolSizeCallback || hasSymbolRotateCallback || hasSymbolOffsetCallback;
  63. var seriesSymbol = !hasSymbolTypeCallback && symbolType ? symbolType : seriesModel.defaultSymbol;
  64. var seriesSymbolSize = !hasSymbolSizeCallback ? symbolSize : null;
  65. var seriesSymbolRotate = !hasSymbolRotateCallback ? symbolRotate : null;
  66. var seriesSymbolOffset = !hasSymbolOffsetCallback ? symbolOffset : null;
  67. data.setVisual({
  68. legendIcon: seriesModel.legendIcon || seriesSymbol,
  69. // If seting callback functions on `symbol` or `symbolSize`, for simplicity and avoiding
  70. // to bring trouble, we do not pick a reuslt from one of its calling on data item here,
  71. // but just use the default value. Callback on `symbol` or `symbolSize` is convenient in
  72. // some cases but generally it is not recommanded.
  73. symbol: seriesSymbol,
  74. symbolSize: seriesSymbolSize,
  75. symbolKeepAspect: keepAspect,
  76. symbolRotate: seriesSymbolRotate,
  77. symbolOffset: seriesSymbolOffset
  78. }); // Only visible series has each data be visual encoded
  79. if (ecModel.isSeriesFiltered(seriesModel)) {
  80. return;
  81. }
  82. function dataEach(data, idx) {
  83. var rawValue = seriesModel.getRawValue(idx);
  84. var params = seriesModel.getDataParams(idx);
  85. hasSymbolTypeCallback && data.setItemVisual(idx, 'symbol', symbolType(rawValue, params));
  86. hasSymbolSizeCallback && data.setItemVisual(idx, 'symbolSize', symbolSize(rawValue, params));
  87. hasSymbolRotateCallback && data.setItemVisual(idx, 'symbolRotate', symbolRotate(rawValue, params));
  88. hasSymbolOffsetCallback && data.setItemVisual(idx, 'symbolOffset', symbolOffset(rawValue, params));
  89. }
  90. return {
  91. dataEach: hasCallback ? dataEach : null
  92. };
  93. }
  94. };
  95. var dataSymbolTask = {
  96. createOnAllSeries: true,
  97. // For legend.
  98. performRawSeries: true,
  99. reset: function (seriesModel, ecModel) {
  100. if (!seriesModel.hasSymbolVisual) {
  101. return;
  102. } // Only visible series has each data be visual encoded
  103. if (ecModel.isSeriesFiltered(seriesModel)) {
  104. return;
  105. }
  106. var data = seriesModel.getData();
  107. function dataEach(data, idx) {
  108. var itemModel = data.getItemModel(idx);
  109. var itemSymbolType = itemModel.getShallow('symbol', true);
  110. var itemSymbolSize = itemModel.getShallow('symbolSize', true);
  111. var itemSymbolRotate = itemModel.getShallow('symbolRotate', true);
  112. var itemSymbolOffset = itemModel.getShallow('symbolOffset', true);
  113. var itemSymbolKeepAspect = itemModel.getShallow('symbolKeepAspect', true); // If has item symbol
  114. if (itemSymbolType != null) {
  115. data.setItemVisual(idx, 'symbol', itemSymbolType);
  116. }
  117. if (itemSymbolSize != null) {
  118. // PENDING Transform symbolSize ?
  119. data.setItemVisual(idx, 'symbolSize', itemSymbolSize);
  120. }
  121. if (itemSymbolRotate != null) {
  122. data.setItemVisual(idx, 'symbolRotate', itemSymbolRotate);
  123. }
  124. if (itemSymbolOffset != null) {
  125. data.setItemVisual(idx, 'symbolOffset', itemSymbolOffset);
  126. }
  127. if (itemSymbolKeepAspect != null) {
  128. data.setItemVisual(idx, 'symbolKeepAspect', itemSymbolKeepAspect);
  129. }
  130. }
  131. return {
  132. dataEach: data.hasItemOption ? dataEach : null
  133. };
  134. }
  135. };
  136. export { seriesSymbolTask, dataSymbolTask };