symbol.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 { extend, isFunction, keys } from 'zrender/lib/core/util.js';
  41. var SYMBOL_PROPS_WITH_CB = ['symbol', 'symbolSize', 'symbolRotate', 'symbolOffset'];
  42. var SYMBOL_PROPS = SYMBOL_PROPS_WITH_CB.concat(['symbolKeepAspect']);
  43. // Encoding visual for all series include which is filtered for legend drawing
  44. var seriesSymbolTask = {
  45. createOnAllSeries: true,
  46. // For legend.
  47. performRawSeries: true,
  48. reset: function (seriesModel, ecModel) {
  49. var data = seriesModel.getData();
  50. if (seriesModel.legendIcon) {
  51. data.setVisual('legendIcon', seriesModel.legendIcon);
  52. }
  53. if (!seriesModel.hasSymbolVisual) {
  54. return;
  55. }
  56. var symbolOptions = {};
  57. var symbolOptionsCb = {};
  58. var hasCallback = false;
  59. for (var i = 0; i < SYMBOL_PROPS_WITH_CB.length; i++) {
  60. var symbolPropName = SYMBOL_PROPS_WITH_CB[i];
  61. var val = seriesModel.get(symbolPropName);
  62. if (isFunction(val)) {
  63. hasCallback = true;
  64. symbolOptionsCb[symbolPropName] = val;
  65. } else {
  66. symbolOptions[symbolPropName] = val;
  67. }
  68. }
  69. symbolOptions.symbol = symbolOptions.symbol || seriesModel.defaultSymbol;
  70. data.setVisual(extend({
  71. legendIcon: seriesModel.legendIcon || symbolOptions.symbol,
  72. symbolKeepAspect: seriesModel.get('symbolKeepAspect')
  73. }, symbolOptions));
  74. // Only visible series has each data be visual encoded
  75. if (ecModel.isSeriesFiltered(seriesModel)) {
  76. return;
  77. }
  78. var symbolPropsCb = keys(symbolOptionsCb);
  79. function dataEach(data, idx) {
  80. var rawValue = seriesModel.getRawValue(idx);
  81. var params = seriesModel.getDataParams(idx);
  82. for (var i = 0; i < symbolPropsCb.length; i++) {
  83. var symbolPropName = symbolPropsCb[i];
  84. data.setItemVisual(idx, symbolPropName, symbolOptionsCb[symbolPropName](rawValue, params));
  85. }
  86. }
  87. return {
  88. dataEach: hasCallback ? dataEach : null
  89. };
  90. }
  91. };
  92. var dataSymbolTask = {
  93. createOnAllSeries: true,
  94. // For legend.
  95. performRawSeries: true,
  96. reset: function (seriesModel, ecModel) {
  97. if (!seriesModel.hasSymbolVisual) {
  98. return;
  99. }
  100. // Only visible series has each data be visual encoded
  101. if (ecModel.isSeriesFiltered(seriesModel)) {
  102. return;
  103. }
  104. var data = seriesModel.getData();
  105. function dataEach(data, idx) {
  106. var itemModel = data.getItemModel(idx);
  107. for (var i = 0; i < SYMBOL_PROPS.length; i++) {
  108. var symbolPropName = SYMBOL_PROPS[i];
  109. var val = itemModel.getShallow(symbolPropName, true);
  110. if (val != null) {
  111. data.setItemVisual(idx, symbolPropName, val);
  112. }
  113. }
  114. }
  115. return {
  116. dataEach: data.hasItemOption ? dataEach : null
  117. };
  118. }
  119. };
  120. export { seriesSymbolTask, dataSymbolTask };