visualEncoding.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 * as zrUtil from 'zrender/lib/core/util.js';
  41. import * as visualSolution from '../../visual/visualSolution.js';
  42. import VisualMapping from '../../visual/VisualMapping.js';
  43. import { getVisualFromData } from '../../visual/helper.js';
  44. export var visualMapEncodingHandlers = [{
  45. createOnAllSeries: true,
  46. reset: function (seriesModel, ecModel) {
  47. var resetDefines = [];
  48. ecModel.eachComponent('visualMap', function (visualMapModel) {
  49. var pipelineContext = seriesModel.pipelineContext;
  50. if (!visualMapModel.isTargetSeries(seriesModel) || pipelineContext && pipelineContext.large) {
  51. return;
  52. }
  53. resetDefines.push(visualSolution.incrementalApplyVisual(visualMapModel.stateList, visualMapModel.targetVisuals, zrUtil.bind(visualMapModel.getValueState, visualMapModel), visualMapModel.getDataDimensionIndex(seriesModel.getData())));
  54. });
  55. return resetDefines;
  56. }
  57. }, // Only support color.
  58. {
  59. createOnAllSeries: true,
  60. reset: function (seriesModel, ecModel) {
  61. var data = seriesModel.getData();
  62. var visualMetaList = [];
  63. ecModel.eachComponent('visualMap', function (visualMapModel) {
  64. if (visualMapModel.isTargetSeries(seriesModel)) {
  65. var visualMeta = visualMapModel.getVisualMeta(zrUtil.bind(getColorVisual, null, seriesModel, visualMapModel)) || {
  66. stops: [],
  67. outerColors: []
  68. };
  69. var dimIdx = visualMapModel.getDataDimensionIndex(data);
  70. if (dimIdx >= 0) {
  71. // visualMeta.dimension should be dimension index, but not concrete dimension.
  72. visualMeta.dimension = dimIdx;
  73. visualMetaList.push(visualMeta);
  74. }
  75. }
  76. }); // console.log(JSON.stringify(visualMetaList.map(a => a.stops)));
  77. seriesModel.getData().setVisual('visualMeta', visualMetaList);
  78. }
  79. }]; // FIXME
  80. // performance and export for heatmap?
  81. // value can be Infinity or -Infinity
  82. function getColorVisual(seriesModel, visualMapModel, value, valueState) {
  83. var mappings = visualMapModel.targetVisuals[valueState];
  84. var visualTypes = VisualMapping.prepareVisualTypes(mappings);
  85. var resultVisual = {
  86. color: getVisualFromData(seriesModel.getData(), 'color') // default color.
  87. };
  88. for (var i = 0, len = visualTypes.length; i < len; i++) {
  89. var type = visualTypes[i];
  90. var mapping = mappings[type === 'opacity' ? '__alphaForOpacity' : type];
  91. mapping && mapping.applyVisual(value, getVisual, setVisual);
  92. }
  93. return resultVisual.color;
  94. function getVisual(key) {
  95. return resultVisual[key];
  96. }
  97. function setVisual(key, value) {
  98. resultVisual[key] = value;
  99. }
  100. }