style.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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, extend, createHashMap } from 'zrender/lib/core/util.js';
  41. import makeStyleMapper from '../model/mixin/makeStyleMapper.js';
  42. import { ITEM_STYLE_KEY_MAP } from '../model/mixin/itemStyle.js';
  43. import { LINE_STYLE_KEY_MAP } from '../model/mixin/lineStyle.js';
  44. import Model from '../model/Model.js';
  45. import { makeInner } from '../util/model.js';
  46. var inner = makeInner();
  47. var defaultStyleMappers = {
  48. itemStyle: makeStyleMapper(ITEM_STYLE_KEY_MAP, true),
  49. lineStyle: makeStyleMapper(LINE_STYLE_KEY_MAP, true)
  50. };
  51. var defaultColorKey = {
  52. lineStyle: 'stroke',
  53. itemStyle: 'fill'
  54. };
  55. function getStyleMapper(seriesModel, stylePath) {
  56. var styleMapper = seriesModel.visualStyleMapper || defaultStyleMappers[stylePath];
  57. if (!styleMapper) {
  58. console.warn("Unknown style type '" + stylePath + "'.");
  59. return defaultStyleMappers.itemStyle;
  60. }
  61. return styleMapper;
  62. }
  63. function getDefaultColorKey(seriesModel, stylePath) {
  64. // return defaultColorKey[stylePath] ||
  65. var colorKey = seriesModel.visualDrawType || defaultColorKey[stylePath];
  66. if (!colorKey) {
  67. console.warn("Unknown style type '" + stylePath + "'.");
  68. return 'fill';
  69. }
  70. return colorKey;
  71. }
  72. var seriesStyleTask = {
  73. createOnAllSeries: true,
  74. performRawSeries: true,
  75. reset: function (seriesModel, ecModel) {
  76. var data = seriesModel.getData();
  77. var stylePath = seriesModel.visualStyleAccessPath || 'itemStyle'; // Set in itemStyle
  78. var styleModel = seriesModel.getModel(stylePath);
  79. var getStyle = getStyleMapper(seriesModel, stylePath);
  80. var globalStyle = getStyle(styleModel);
  81. var decalOption = styleModel.getShallow('decal');
  82. if (decalOption) {
  83. data.setVisual('decal', decalOption);
  84. decalOption.dirty = true;
  85. } // TODO
  86. var colorKey = getDefaultColorKey(seriesModel, stylePath);
  87. var color = globalStyle[colorKey]; // TODO style callback
  88. var colorCallback = isFunction(color) ? color : null;
  89. var hasAutoColor = globalStyle.fill === 'auto' || globalStyle.stroke === 'auto'; // Get from color palette by default.
  90. if (!globalStyle[colorKey] || colorCallback || hasAutoColor) {
  91. // Note: If some series has color specified (e.g., by itemStyle.color), we DO NOT
  92. // make it effect palette. Because some scenarios users need to make some series
  93. // transparent or as background, which should better not effect the palette.
  94. var colorPalette = seriesModel.getColorFromPalette( // TODO series count changed.
  95. seriesModel.name, null, ecModel.getSeriesCount());
  96. if (!globalStyle[colorKey]) {
  97. globalStyle[colorKey] = colorPalette;
  98. data.setVisual('colorFromPalette', true);
  99. }
  100. globalStyle.fill = globalStyle.fill === 'auto' || isFunction(globalStyle.fill) ? colorPalette : globalStyle.fill;
  101. globalStyle.stroke = globalStyle.stroke === 'auto' || isFunction(globalStyle.stroke) ? colorPalette : globalStyle.stroke;
  102. }
  103. data.setVisual('style', globalStyle);
  104. data.setVisual('drawType', colorKey); // Only visible series has each data be visual encoded
  105. if (!ecModel.isSeriesFiltered(seriesModel) && colorCallback) {
  106. data.setVisual('colorFromPalette', false);
  107. return {
  108. dataEach: function (data, idx) {
  109. var dataParams = seriesModel.getDataParams(idx);
  110. var itemStyle = extend({}, globalStyle);
  111. itemStyle[colorKey] = colorCallback(dataParams);
  112. data.setItemVisual(idx, 'style', itemStyle);
  113. }
  114. };
  115. }
  116. }
  117. };
  118. var sharedModel = new Model();
  119. var dataStyleTask = {
  120. createOnAllSeries: true,
  121. performRawSeries: true,
  122. reset: function (seriesModel, ecModel) {
  123. if (seriesModel.ignoreStyleOnData || ecModel.isSeriesFiltered(seriesModel)) {
  124. return;
  125. }
  126. var data = seriesModel.getData();
  127. var stylePath = seriesModel.visualStyleAccessPath || 'itemStyle'; // Set in itemStyle
  128. var getStyle = getStyleMapper(seriesModel, stylePath);
  129. var colorKey = data.getVisual('drawType');
  130. return {
  131. dataEach: data.hasItemOption ? function (data, idx) {
  132. // Not use getItemModel for performance considuration
  133. var rawItem = data.getRawDataItem(idx);
  134. if (rawItem && rawItem[stylePath]) {
  135. sharedModel.option = rawItem[stylePath];
  136. var style = getStyle(sharedModel);
  137. var existsStyle = data.ensureUniqueItemVisual(idx, 'style');
  138. extend(existsStyle, style);
  139. if (sharedModel.option.decal) {
  140. data.setItemVisual(idx, 'decal', sharedModel.option.decal);
  141. sharedModel.option.decal.dirty = true;
  142. }
  143. if (colorKey in style) {
  144. data.setItemVisual(idx, 'colorFromPalette', false);
  145. }
  146. }
  147. } : null
  148. };
  149. }
  150. }; // Pick color from palette for the data which has not been set with color yet.
  151. // Note: do not support stream rendering. No such cases yet.
  152. var dataColorPaletteTask = {
  153. performRawSeries: true,
  154. overallReset: function (ecModel) {
  155. // Each type of series uses one scope.
  156. // Pie and funnel are using different scopes.
  157. var paletteScopeGroupByType = createHashMap();
  158. ecModel.eachSeries(function (seriesModel) {
  159. var colorBy = seriesModel.getColorBy();
  160. if (seriesModel.isColorBySeries()) {
  161. return;
  162. }
  163. var key = seriesModel.type + '-' + colorBy;
  164. var colorScope = paletteScopeGroupByType.get(key);
  165. if (!colorScope) {
  166. colorScope = {};
  167. paletteScopeGroupByType.set(key, colorScope);
  168. }
  169. inner(seriesModel).scope = colorScope;
  170. });
  171. ecModel.eachSeries(function (seriesModel) {
  172. if (seriesModel.isColorBySeries() || ecModel.isSeriesFiltered(seriesModel)) {
  173. return;
  174. }
  175. var dataAll = seriesModel.getRawData();
  176. var idxMap = {};
  177. var data = seriesModel.getData();
  178. var colorScope = inner(seriesModel).scope;
  179. var stylePath = seriesModel.visualStyleAccessPath || 'itemStyle';
  180. var colorKey = getDefaultColorKey(seriesModel, stylePath);
  181. data.each(function (idx) {
  182. var rawIdx = data.getRawIndex(idx);
  183. idxMap[rawIdx] = idx;
  184. }); // Iterate on data before filtered. To make sure color from palette can be
  185. // Consistent when toggling legend.
  186. dataAll.each(function (rawIdx) {
  187. var idx = idxMap[rawIdx];
  188. var fromPalette = data.getItemVisual(idx, 'colorFromPalette'); // Get color from palette for each data only when the color is inherited from series color, which is
  189. // also picked from color palette. So following situation is not in the case:
  190. // 1. series.itemStyle.color is set
  191. // 2. color is encoded by visualMap
  192. if (fromPalette) {
  193. var itemStyle = data.ensureUniqueItemVisual(idx, 'style');
  194. var name_1 = dataAll.getName(rawIdx) || rawIdx + '';
  195. var dataCount = dataAll.count();
  196. itemStyle[colorKey] = seriesModel.getColorFromPalette(name_1, colorScope, dataCount);
  197. }
  198. });
  199. });
  200. }
  201. };
  202. export { seriesStyleTask, dataStyleTask, dataColorPaletteTask };