sankeyVisual.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. var VisualMapping = require("../../visual/VisualMapping");
  2. var zrUtil = require("zrender/lib/core/util");
  3. /**
  4. * @file Visual encoding for sankey view
  5. * @author Deqing Li(annong035@gmail.com)
  6. */
  7. function _default(ecModel, payload) {
  8. ecModel.eachSeriesByType('sankey', function (seriesModel) {
  9. var graph = seriesModel.getGraph();
  10. var nodes = graph.nodes;
  11. nodes.sort(function (a, b) {
  12. return a.getLayout().value - b.getLayout().value;
  13. });
  14. var minValue = nodes[0].getLayout().value;
  15. var maxValue = nodes[nodes.length - 1].getLayout().value;
  16. zrUtil.each(nodes, function (node) {
  17. var mapping = new VisualMapping({
  18. type: 'color',
  19. mappingMethod: 'linear',
  20. dataExtent: [minValue, maxValue],
  21. visual: seriesModel.get('color')
  22. });
  23. var mapValueToColor = mapping.mapValueToVisual(node.getLayout().value);
  24. node.setVisual('color', mapValueToColor); // If set itemStyle.normal.color
  25. var itemModel = node.getModel();
  26. var customColor = itemModel.get('itemStyle.normal.color');
  27. if (customColor != null) {
  28. node.setVisual('color', customColor);
  29. }
  30. });
  31. });
  32. }
  33. module.exports = _default;