symbol.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 _util = require("zrender/lib/core/util");
  20. var isFunction = _util.isFunction;
  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. function _default(seriesType, defaultSymbolType, legendSymbol) {
  40. // Encoding visual for all series include which is filtered for legend drawing
  41. return {
  42. seriesType: seriesType,
  43. // For legend.
  44. performRawSeries: true,
  45. reset: function (seriesModel, ecModel, api) {
  46. var data = seriesModel.getData();
  47. var symbolType = seriesModel.get('symbol');
  48. var symbolSize = seriesModel.get('symbolSize');
  49. var keepAspect = seriesModel.get('symbolKeepAspect');
  50. var symbolRotate = seriesModel.get('symbolRotate');
  51. var hasSymbolTypeCallback = isFunction(symbolType);
  52. var hasSymbolSizeCallback = isFunction(symbolSize);
  53. var hasSymbolRotateCallback = isFunction(symbolRotate);
  54. var hasCallback = hasSymbolTypeCallback || hasSymbolSizeCallback || hasSymbolRotateCallback;
  55. var seriesSymbol = !hasSymbolTypeCallback && symbolType ? symbolType : defaultSymbolType;
  56. var seriesSymbolSize = !hasSymbolSizeCallback ? symbolSize : null;
  57. var seriesSymbolRotate = !hasSymbolRotateCallback ? seriesSymbolRotate : null;
  58. data.setVisual({
  59. legendSymbol: legendSymbol || seriesSymbol,
  60. // If seting callback functions on `symbol` or `symbolSize`, for simplicity and avoiding
  61. // to bring trouble, we do not pick a reuslt from one of its calling on data item here,
  62. // but just use the default value. Callback on `symbol` or `symbolSize` is convenient in
  63. // some cases but generally it is not recommanded.
  64. symbol: seriesSymbol,
  65. symbolSize: seriesSymbolSize,
  66. symbolKeepAspect: keepAspect,
  67. symbolRotate: symbolRotate
  68. }); // Only visible series has each data be visual encoded
  69. if (ecModel.isSeriesFiltered(seriesModel)) {
  70. return;
  71. }
  72. function dataEach(data, idx) {
  73. if (hasCallback) {
  74. var rawValue = seriesModel.getRawValue(idx);
  75. var params = seriesModel.getDataParams(idx);
  76. hasSymbolTypeCallback && data.setItemVisual(idx, 'symbol', symbolType(rawValue, params));
  77. hasSymbolSizeCallback && data.setItemVisual(idx, 'symbolSize', symbolSize(rawValue, params));
  78. hasSymbolRotateCallback && data.setItemVisual(idx, 'symbolRotate', symbolRotate(rawValue, params));
  79. }
  80. if (data.hasItemOption) {
  81. var itemModel = data.getItemModel(idx);
  82. var itemSymbolType = itemModel.getShallow('symbol', true);
  83. var itemSymbolSize = itemModel.getShallow('symbolSize', true);
  84. var itemSymbolRotate = itemModel.getShallow('symbolRotate', true);
  85. var itemSymbolKeepAspect = itemModel.getShallow('symbolKeepAspect', true); // If has item symbol
  86. if (itemSymbolType != null) {
  87. data.setItemVisual(idx, 'symbol', itemSymbolType);
  88. }
  89. if (itemSymbolSize != null) {
  90. // PENDING Transform symbolSize ?
  91. data.setItemVisual(idx, 'symbolSize', itemSymbolSize);
  92. }
  93. if (itemSymbolRotate != null) {
  94. data.setItemVisual(idx, 'symbolRotate', itemSymbolRotate);
  95. }
  96. if (itemSymbolKeepAspect != null) {
  97. data.setItemVisual(idx, 'symbolKeepAspect', itemSymbolKeepAspect);
  98. }
  99. }
  100. }
  101. return {
  102. dataEach: data.hasItemOption || hasCallback ? dataEach : null
  103. };
  104. }
  105. };
  106. }
  107. module.exports = _default;