symbol.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 hasSymbolTypeCallback = isFunction(symbolType);
  51. var hasSymbolSizeCallback = isFunction(symbolSize);
  52. var hasCallback = hasSymbolTypeCallback || hasSymbolSizeCallback;
  53. var seriesSymbol = !hasSymbolTypeCallback && symbolType ? symbolType : defaultSymbolType;
  54. var seriesSymbolSize = !hasSymbolSizeCallback ? symbolSize : null;
  55. data.setVisual({
  56. legendSymbol: legendSymbol || seriesSymbol,
  57. // If seting callback functions on `symbol` or `symbolSize`, for simplicity and avoiding
  58. // to bring trouble, we do not pick a reuslt from one of its calling on data item here,
  59. // but just use the default value. Callback on `symbol` or `symbolSize` is convenient in
  60. // some cases but generally it is not recommanded.
  61. symbol: seriesSymbol,
  62. symbolSize: seriesSymbolSize,
  63. symbolKeepAspect: keepAspect
  64. }); // Only visible series has each data be visual encoded
  65. if (ecModel.isSeriesFiltered(seriesModel)) {
  66. return;
  67. }
  68. function dataEach(data, idx) {
  69. if (hasCallback) {
  70. var rawValue = seriesModel.getRawValue(idx);
  71. var params = seriesModel.getDataParams(idx);
  72. hasSymbolTypeCallback && data.setItemVisual(idx, 'symbol', symbolType(rawValue, params));
  73. hasSymbolSizeCallback && data.setItemVisual(idx, 'symbolSize', symbolSize(rawValue, params));
  74. }
  75. if (data.hasItemOption) {
  76. var itemModel = data.getItemModel(idx);
  77. var itemSymbolType = itemModel.getShallow('symbol', true);
  78. var itemSymbolSize = itemModel.getShallow('symbolSize', true);
  79. var itemSymbolKeepAspect = itemModel.getShallow('symbolKeepAspect', true); // If has item symbol
  80. if (itemSymbolType != null) {
  81. data.setItemVisual(idx, 'symbol', itemSymbolType);
  82. }
  83. if (itemSymbolSize != null) {
  84. // PENDING Transform symbolSize ?
  85. data.setItemVisual(idx, 'symbolSize', itemSymbolSize);
  86. }
  87. if (itemSymbolKeepAspect != null) {
  88. data.setItemVisual(idx, 'symbolKeepAspect', itemSymbolKeepAspect);
  89. }
  90. }
  91. }
  92. return {
  93. dataEach: data.hasItemOption || hasCallback ? dataEach : null
  94. };
  95. }
  96. };
  97. }
  98. module.exports = _default;