|
| 1 | +// var Plotly = require('@lib/index'); |
| 2 | +// var attributes = require('@src/traces/sankey/attributes'); |
| 3 | + |
| 4 | +var d3SankeyCircular = require('d3-sankey-circular'); |
| 5 | +var mockCircular = require('@mocks/sankey_circular.json'); |
| 6 | +var convertToD3Sankey = require('@src/traces/sankey/convert-to-d3-sankey'); |
| 7 | + |
| 8 | +describe('d3-sankey-ciruclar', function() { |
| 9 | + var data, sankey, graph; |
| 10 | + |
| 11 | + beforeEach(function() { |
| 12 | + data = convertToD3Sankey(mockCircular.data[0]); |
| 13 | + sankey = d3SankeyCircular |
| 14 | + .sankeyCircular() |
| 15 | + .iterations(32) |
| 16 | + .circularLinkGap(2) |
| 17 | + .nodePadding(10) |
| 18 | + .size([500, 500]) |
| 19 | + .nodeId(function(d) { |
| 20 | + return d.pointNumber; |
| 21 | + }) |
| 22 | + .nodes(data.nodes) |
| 23 | + .links(data.links); |
| 24 | + |
| 25 | + graph = sankey(); |
| 26 | + }); |
| 27 | + |
| 28 | + function checkArray(key, result) { |
| 29 | + var value = graph.nodes.map(function(obj) { |
| 30 | + return obj[key]; |
| 31 | + }); |
| 32 | + expect(value).toEqual(result, 'invalid property named ' + key); |
| 33 | + } |
| 34 | + |
| 35 | + function checkRoundedArray(key, result, msg) { |
| 36 | + var value = graph.nodes.map(function(obj) { |
| 37 | + return Math.round(obj[key]); |
| 38 | + }); |
| 39 | + expect(value).toEqual(result, msg); |
| 40 | + } |
| 41 | + |
| 42 | + it('creates a graph with circular links', function() { |
| 43 | + expect(graph.nodes.length).toEqual(6, 'there are 6 nodes'); |
| 44 | + var circularLinks = graph.links.filter(function(link) { |
| 45 | + return link.circular; |
| 46 | + }); |
| 47 | + expect(circularLinks.length).toEqual(2, 'there are two circular links'); |
| 48 | + }); |
| 49 | + |
| 50 | + it('keep a list of nodes with positions in integer (col, height)', function() { |
| 51 | + checkArray('column', [0, 0, 2, 3, 1, 1]); |
| 52 | + checkArray('height', [1, 3, 1, 0, 2, 0]); |
| 53 | + }); |
| 54 | + |
| 55 | + it('keep a list of nodes with positions in x and y', function() { |
| 56 | + checkRoundedArray('x0', [72, 72, 267, 365, 169, 169]); |
| 57 | + checkRoundedArray('y0', [303, 86, 72, 109, 86, 359]); |
| 58 | + }); |
| 59 | + |
| 60 | + it('supports column reordering', function() { |
| 61 | + var reorder = [ 2, 2, 1, 1, 0, 0 ]; |
| 62 | + |
| 63 | + var a = graph.nodes[0].x0; |
| 64 | + sankey.nodeAlign(function(node) { |
| 65 | + return reorder[node.pointNumber]; |
| 66 | + }); |
| 67 | + graph = sankey(); |
| 68 | + checkArray('column', [2, 2, 1, 1, 0, 0]); |
| 69 | + checkArray('height', [1, 3, 1, 0, 2, 0]); |
| 70 | + var b = graph.nodes[0].x0; |
| 71 | + expect(a).not.toEqual(b); |
| 72 | + }); |
| 73 | + |
| 74 | +}); |
0 commit comments