visualEncoding.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. },
  58. // Only support color.
  59. {
  60. createOnAllSeries: true,
  61. reset: function (seriesModel, ecModel) {
  62. var data = seriesModel.getData();
  63. var visualMetaList = [];
  64. ecModel.eachComponent('visualMap', function (visualMapModel) {
  65. if (visualMapModel.isTargetSeries(seriesModel)) {
  66. var visualMeta = visualMapModel.getVisualMeta(zrUtil.bind(getColorVisual, null, seriesModel, visualMapModel)) || {
  67. stops: [],
  68. outerColors: []
  69. };
  70. var dimIdx = visualMapModel.getDataDimensionIndex(data);
  71. if (dimIdx >= 0) {
  72. // visualMeta.dimension should be dimension index, but not concrete dimension.
  73. visualMeta.dimension = dimIdx;
  74. visualMetaList.push(visualMeta);
  75. }
  76. }
  77. });
  78. // console.log(JSON.stringify(visualMetaList.map(a => a.stops)));
  79. seriesModel.getData().setVisual('visualMeta', visualMetaList);
  80. }
  81. }];
  82. // FIXME
  83. // performance and export for heatmap?
  84. // value can be Infinity or -Infinity
  85. function getColorVisual(seriesModel, visualMapModel, value, valueState) {
  86. var mappings = visualMapModel.targetVisuals[valueState];
  87. var visualTypes = VisualMapping.prepareVisualTypes(mappings);
  88. var resultVisual = {
  89. color: getVisualFromData(seriesModel.getData(), 'color') // default color.
  90. };
  91. for (var i = 0, len = visualTypes.length; i < len; i++) {
  92. var type = visualTypes[i];
  93. var mapping = mappings[type === 'opacity' ? '__alphaForOpacity' : type];
  94. mapping && mapping.applyVisual(value, getVisual, setVisual);
  95. }
  96. return resultVisual.color;
  97. function getVisual(key) {
  98. return resultVisual[key];
  99. }
  100. function setVisual(key, value) {
  101. resultVisual[key] = value;
  102. }
  103. }