symbol.js 4.3 KB

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