visualEncoding.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 echarts = require("../../echarts");
  20. var zrUtil = require("zrender/lib/core/util");
  21. var visualSolution = require("../../visual/visualSolution");
  22. var VisualMapping = require("../../visual/VisualMapping");
  23. /*
  24. * Licensed to the Apache Software Foundation (ASF) under one
  25. * or more contributor license agreements. See the NOTICE file
  26. * distributed with this work for additional information
  27. * regarding copyright ownership. The ASF licenses this file
  28. * to you under the Apache License, Version 2.0 (the
  29. * "License"); you may not use this file except in compliance
  30. * with the License. You may obtain a copy of the License at
  31. *
  32. * http://www.apache.org/licenses/LICENSE-2.0
  33. *
  34. * Unless required by applicable law or agreed to in writing,
  35. * software distributed under the License is distributed on an
  36. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37. * KIND, either express or implied. See the License for the
  38. * specific language governing permissions and limitations
  39. * under the License.
  40. */
  41. var VISUAL_PRIORITY = echarts.PRIORITY.VISUAL.COMPONENT;
  42. echarts.registerVisual(VISUAL_PRIORITY, {
  43. createOnAllSeries: true,
  44. reset: function (seriesModel, ecModel) {
  45. var resetDefines = [];
  46. ecModel.eachComponent('visualMap', function (visualMapModel) {
  47. var pipelineContext = seriesModel.pipelineContext;
  48. if (!visualMapModel.isTargetSeries(seriesModel) || pipelineContext && pipelineContext.large) {
  49. return;
  50. }
  51. resetDefines.push(visualSolution.incrementalApplyVisual(visualMapModel.stateList, visualMapModel.targetVisuals, zrUtil.bind(visualMapModel.getValueState, visualMapModel), visualMapModel.getDataDimension(seriesModel.getData())));
  52. });
  53. return resetDefines;
  54. }
  55. }); // Only support color.
  56. echarts.registerVisual(VISUAL_PRIORITY, {
  57. createOnAllSeries: true,
  58. reset: function (seriesModel, ecModel) {
  59. var data = seriesModel.getData();
  60. var visualMetaList = [];
  61. ecModel.eachComponent('visualMap', function (visualMapModel) {
  62. if (visualMapModel.isTargetSeries(seriesModel)) {
  63. var visualMeta = visualMapModel.getVisualMeta(zrUtil.bind(getColorVisual, null, seriesModel, visualMapModel)) || {
  64. stops: [],
  65. outerColors: []
  66. };
  67. var concreteDim = visualMapModel.getDataDimension(data);
  68. var dimInfo = data.getDimensionInfo(concreteDim);
  69. if (dimInfo != null) {
  70. // visualMeta.dimension should be dimension index, but not concrete dimension.
  71. visualMeta.dimension = dimInfo.index;
  72. visualMetaList.push(visualMeta);
  73. }
  74. }
  75. }); // console.log(JSON.stringify(visualMetaList.map(a => a.stops)));
  76. seriesModel.getData().setVisual('visualMeta', visualMetaList);
  77. }
  78. }); // FIXME
  79. // performance and export for heatmap?
  80. // value can be Infinity or -Infinity
  81. function getColorVisual(seriesModel, visualMapModel, value, valueState) {
  82. var mappings = visualMapModel.targetVisuals[valueState];
  83. var visualTypes = VisualMapping.prepareVisualTypes(mappings);
  84. var resultVisual = {
  85. color: seriesModel.getData().getVisual('color') // default color.
  86. };
  87. for (var i = 0, len = visualTypes.length; i < len; i++) {
  88. var type = visualTypes[i];
  89. var mapping = mappings[type === 'opacity' ? '__alphaForOpacity' : type];
  90. mapping && mapping.applyVisual(value, getVisual, setVisual);
  91. }
  92. return resultVisual.color;
  93. function getVisual(key) {
  94. return resultVisual[key];
  95. }
  96. function setVisual(key, value) {
  97. resultVisual[key] = value;
  98. }
  99. }