100pah commented on a change in pull request #10084: Update sankey diagram with
levels setting, reducing code size and so on.
URL:
https://github.com/apache/incubator-echarts/pull/10084#discussion_r264235234
##########
File path: src/chart/sankey/sankeyLayout.js
##########
@@ -368,73 +340,44 @@ function initializeNodeDepth(nodes, nodesByBreadth,
edges, height, width, nodeGa
* @param {number} height the whole height of the area to draw the view
*/
function resolveCollisions(nodesByBreadth, nodeGap, height, width, orient) {
+ var keyAttr = orient === 'vertical' ? 'x' : 'y';
zrUtil.each(nodesByBreadth, function (nodes) {
+ nodes.sort(function (a, b) {
+ return a.getLayout()[keyAttr] - b.getLayout()[keyAttr];
+ });
+ var nodeX;
var node;
var dy;
var y0 = 0;
var n = nodes.length;
- var i;
-
- if (orient === 'vertical') {
- var nodeX;
- nodes.sort(function (a, b) {
- return a.getLayout().x - b.getLayout().x;
- });
- for (i = 0; i < n; i++) {
- node = nodes[i];
- dy = y0 - node.getLayout().x;
- if (dy > 0) {
- nodeX = node.getLayout().x + dy;
- node.setLayout({x: nodeX}, true);
- }
- y0 = node.getLayout().x + node.getLayout().dx + nodeGap;
- }
- // If the bottommost node goes outside the bounds, push it back up
- dy = y0 - nodeGap - width;
+ var nodeDyAttr = orient === 'vertical' ? 'dx' : 'dy';
+ for (var i = 0; i < n; i++) {
+ node = nodes[i];
+ dy = y0 - node.getLayout()[keyAttr];
if (dy > 0) {
- nodeX = node.getLayout().x - dy;
- node.setLayout({x: nodeX}, true);
- y0 = nodeX;
- for (i = n - 2; i >= 0; --i) {
- node = nodes[i];
- dy = node.getLayout().x + node.getLayout().dx + nodeGap -
y0;
- if (dy > 0) {
- nodeX = node.getLayout().x - dy;
- node.setLayout({x: nodeX}, true);
- }
- y0 = node.getLayout().x;
- }
+ nodeX = node.getLayout()[keyAttr] + dy;
+ orient === 'vertical' ? node.setLayout({x: nodeX}, true)
+ : node.setLayout({y: nodeX}, true);
Review comment:
indent
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]