| 6dd74de | | | 1 | import { imgSnapshotTest, renderGraph } from '../../helpers/util.ts'; |
| 6dd74de | | | 2 | |
| 6dd74de | | | 3 | describe('Sankey Diagram', () => { |
| 6dd74de | | | 4 | it('should render a simple example', () => { |
| 6dd74de | | | 5 | imgSnapshotTest( |
| 6dd74de | | | 6 | ` |
| 6dd74de | | | 7 | sankey-beta |
| 6dd74de | | | 8 | |
| 6dd74de | | | 9 | sourceNode,targetNode,10 |
| 6dd74de | | | 10 | `, |
| 6dd74de | | | 11 | {} |
| 6dd74de | | | 12 | ); |
| 6dd74de | | | 13 | }); |
| 6dd74de | | | 14 | |
| 6dd74de | | | 15 | describe('when given a linkColor', function () { |
| 6dd74de | | | 16 | this.beforeAll(() => { |
| 6dd74de | | | 17 | cy.wrap( |
| 6dd74de | | | 18 | `sankey |
| 6dd74de | | | 19 | a,b,10 |
| 6dd74de | | | 20 | ` |
| 6dd74de | | | 21 | ).as('graph'); |
| 6dd74de | | | 22 | }); |
| 6dd74de | | | 23 | |
| 6dd74de | | | 24 | it('links should use hex color', function () { |
| 6dd74de | | | 25 | renderGraph(this.graph, { sankey: { linkColor: '#636465' } }); |
| 6dd74de | | | 26 | |
| 6dd74de | | | 27 | cy.get('.link path').should((link) => { |
| 6dd74de | | | 28 | expect(link.attr('stroke')).to.equal('#636465'); |
| 6dd74de | | | 29 | }); |
| 6dd74de | | | 30 | }); |
| 6dd74de | | | 31 | |
| 6dd74de | | | 32 | it('links should be the same color as source node', function () { |
| 6dd74de | | | 33 | renderGraph(this.graph, { sankey: { linkColor: 'source' } }); |
| 6dd74de | | | 34 | |
| 6dd74de | | | 35 | cy.get('.link path').then((link) => { |
| 6dd74de | | | 36 | cy.get('.node[id="node-1"] rect').should((node) => |
| 6dd74de | | | 37 | expect(link.attr('stroke')).to.equal(node.attr('fill')) |
| 6dd74de | | | 38 | ); |
| 6dd74de | | | 39 | }); |
| 6dd74de | | | 40 | }); |
| 6dd74de | | | 41 | |
| 6dd74de | | | 42 | it('links should be the same color as target node', function () { |
| 6dd74de | | | 43 | renderGraph(this.graph, { sankey: { linkColor: 'target' } }); |
| 6dd74de | | | 44 | |
| 6dd74de | | | 45 | cy.get('.link path').then((link) => { |
| 6dd74de | | | 46 | cy.get('.node[id="node-2"] rect').should((node) => |
| 6dd74de | | | 47 | expect(link.attr('stroke')).to.equal(node.attr('fill')) |
| 6dd74de | | | 48 | ); |
| 6dd74de | | | 49 | }); |
| 6dd74de | | | 50 | }); |
| 6dd74de | | | 51 | |
| 6dd74de | | | 52 | it('links must be gradient', function () { |
| 6dd74de | | | 53 | renderGraph(this.graph, { sankey: { linkColor: 'gradient' } }); |
| 6dd74de | | | 54 | |
| 6dd74de | | | 55 | cy.get('.link path').should((link) => { |
| 6dd74de | | | 56 | expect(link.attr('stroke')).to.equal('url(#linearGradient-3)'); |
| 6dd74de | | | 57 | }); |
| 6dd74de | | | 58 | }); |
| 6dd74de | | | 59 | }); |
| 6dd74de | | | 60 | |
| 6dd74de | | | 61 | describe('when given a nodeAlignment', function () { |
| 6dd74de | | | 62 | this.beforeAll(() => { |
| 6dd74de | | | 63 | cy.wrap( |
| 6dd74de | | | 64 | ` |
| 6dd74de | | | 65 | sankey |
| 6dd74de | | | 66 | |
| 6dd74de | | | 67 | a,b,8 |
| 6dd74de | | | 68 | b,c,8 |
| 6dd74de | | | 69 | c,d,8 |
| 6dd74de | | | 70 | d,e,8 |
| 6dd74de | | | 71 | |
| 6dd74de | | | 72 | x,c,4 |
| 6dd74de | | | 73 | c,y,4 |
| 6dd74de | | | 74 | ` |
| 6dd74de | | | 75 | ).as('graph'); |
| 6dd74de | | | 76 | }); |
| 6dd74de | | | 77 | |
| 6dd74de | | | 78 | this.afterEach(() => { |
| 6dd74de | | | 79 | cy.get('.node[id="node-1"]').should((node) => { |
| 6dd74de | | | 80 | expect(node.attr('x')).to.equal('0'); |
| 6dd74de | | | 81 | }); |
| 6dd74de | | | 82 | cy.get('.node[id="node-2"]').should((node) => { |
| 6dd74de | | | 83 | expect(node.attr('x')).to.equal('100'); |
| 6dd74de | | | 84 | }); |
| 6dd74de | | | 85 | cy.get('.node[id="node-3"]').should((node) => { |
| 6dd74de | | | 86 | expect(node.attr('x')).to.equal('200'); |
| 6dd74de | | | 87 | }); |
| 6dd74de | | | 88 | cy.get('.node[id="node-4"]').should((node) => { |
| 6dd74de | | | 89 | expect(node.attr('x')).to.equal('300'); |
| 6dd74de | | | 90 | }); |
| 6dd74de | | | 91 | cy.get('.node[id="node-5"]').should((node) => { |
| 6dd74de | | | 92 | expect(node.attr('x')).to.equal('400'); |
| 6dd74de | | | 93 | }); |
| 6dd74de | | | 94 | }); |
| 6dd74de | | | 95 | |
| 6dd74de | | | 96 | it('should justify nodes', function () { |
| 6dd74de | | | 97 | renderGraph(this.graph, { |
| 6dd74de | | | 98 | sankey: { nodeAlignment: 'justify', width: 410, useMaxWidth: false }, |
| 6dd74de | | | 99 | }); |
| 6dd74de | | | 100 | cy.get('.node[id="node-6"]').should((node) => { |
| 6dd74de | | | 101 | expect(node.attr('x')).to.equal('0'); |
| 6dd74de | | | 102 | }); |
| 6dd74de | | | 103 | cy.get('.node[id="node-7"]').should((node) => { |
| 6dd74de | | | 104 | expect(node.attr('x')).to.equal('400'); |
| 6dd74de | | | 105 | }); |
| 6dd74de | | | 106 | }); |
| 6dd74de | | | 107 | |
| 6dd74de | | | 108 | it('should align nodes left', function () { |
| 6dd74de | | | 109 | renderGraph(this.graph, { |
| 6dd74de | | | 110 | sankey: { nodeAlignment: 'left', width: 410, useMaxWidth: false }, |
| 6dd74de | | | 111 | }); |
| 6dd74de | | | 112 | cy.get('.node[id="node-6"]').should((node) => { |
| 6dd74de | | | 113 | expect(node.attr('x')).to.equal('0'); |
| 6dd74de | | | 114 | }); |
| 6dd74de | | | 115 | cy.get('.node[id="node-7"]').should((node) => { |
| 6dd74de | | | 116 | expect(node.attr('x')).to.equal('300'); |
| 6dd74de | | | 117 | }); |
| 6dd74de | | | 118 | }); |
| 6dd74de | | | 119 | |
| 6dd74de | | | 120 | it('should align nodes right', function () { |
| 6dd74de | | | 121 | renderGraph(this.graph, { |
| 6dd74de | | | 122 | sankey: { nodeAlignment: 'right', width: 410, useMaxWidth: false }, |
| 6dd74de | | | 123 | }); |
| 6dd74de | | | 124 | cy.get('.node[id="node-6"]').should((node) => { |
| 6dd74de | | | 125 | expect(node.attr('x')).to.equal('100'); |
| 6dd74de | | | 126 | }); |
| 6dd74de | | | 127 | cy.get('.node[id="node-7"]').should((node) => { |
| 6dd74de | | | 128 | expect(node.attr('x')).to.equal('400'); |
| 6dd74de | | | 129 | }); |
| 6dd74de | | | 130 | }); |
| 6dd74de | | | 131 | |
| 6dd74de | | | 132 | it('should center nodes', function () { |
| 6dd74de | | | 133 | renderGraph(this.graph, { |
| 6dd74de | | | 134 | sankey: { nodeAlignment: 'center', width: 410, useMaxWidth: false }, |
| 6dd74de | | | 135 | }); |
| 6dd74de | | | 136 | cy.get('.node[id="node-6"]').should((node) => { |
| 6dd74de | | | 137 | expect(node.attr('x')).to.equal('100'); |
| 6dd74de | | | 138 | }); |
| 6dd74de | | | 139 | cy.get('.node[id="node-7"]').should((node) => { |
| 6dd74de | | | 140 | expect(node.attr('x')).to.equal('300'); |
| 6dd74de | | | 141 | }); |
| 6dd74de | | | 142 | }); |
| 6dd74de | | | 143 | }); |
| 6dd74de | | | 144 | }); |