tests/run-tests.html: move noscript into body
[git-browser.git] / tests / test-diagram.html
blobb70d8a9ca64d34c3dc0d18f10ad199a0468cb097
1 <!DOCTYPE html>
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta charset="utf-8" />
5 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6 <title>test for Diagram.add_node</title>
7 <script type="text/javascript" src="../js.lib/DomTemplate.js"></script>
8 <script type="text/javascript" src="../js.lib/Motion.js"></script>
9 <script type="text/javascript" src="../GitDiagram.js"></script>
10 <script type="text/javascript" src="make-sample-trees.js"></script>
11 <script type="text/javascript">
12 /* <![CDATA[ */
14 function test_determine_branch_offset( t )
16 t.plan( 7 );
17 var diagram=new GitDiagram( { container_element: document.getElementById( "diagram" ) } );
18 var trunk_shape=[ { x: {date:0,offset:0}, y: 0 }, { x: {date:1,offset:0}, y: 4 }, { x: {date:2,offset:0}, y: 0 }, { x: {date:5,offset:0}, y: 3 }, { x: {date:6,offset:0}, y: 0 }, { x: {date:8,offset:0}, y: 0 } ];
19 var branch_shape=[ { x: {date:0,offset:0}, y: 0 }, { x: {date:1,offset:0}, y: -1 }, { x: {date:2,offset:0}, y: 0 }, { x: {date:3,offset:0}, y: -3 }, { x: {date:4,offset:0}, y: 0 }, { x: {date:6,offset:0}, y: 0 } ];
20 t.eq( GitDiagram._determine_branch_offset( 5, 1, branch_shape, trunk_shape ), 6, "branch 1 offset 5" );
21 t.eq( GitDiagram._determine_branch_offset( 4, 1, branch_shape, trunk_shape ), 6, "branch 1 offset 4" );
22 var branch2_shape=[ { x: {date:1,offset:0}, y: 0 }, { x: {date:3,offset:0}, y: -3 }, { x: {date:4,offset:0}, y: 0 }, { x: {date:6,offset:0}, y: 0 } ];
23 t.eq( GitDiagram._determine_branch_offset( 4, 1, branch2_shape, trunk_shape ), 5, "branch 2 offset 4" );
24 var trunk2_shape=[ { x: {date:0,offset:0}, y: 0 }, { x: {date:2,offset:0}, y: 4 }, { x: {date:2,offset:0}, y: 0 }, { x: {date:5,offset:0}, y: 3 }, { x: {date:6,offset:0}, y: 0 }, { x: {date:8,offset:0}, y: 0 } ];
25 t.eq( GitDiagram._determine_branch_offset( 5, 1, branch_shape, trunk2_shape ), 6, "trunk 2 branch 1 offset 5" );
26 t.eq( GitDiagram._determine_branch_offset( 4, 1, branch_shape, trunk2_shape ), 6, "trunk 2 branch 1 offset 4" );
27 var trunk3_shape=[ { x: {date:0,offset:0}, y: 0 }, { x: {date:1,offset:0}, y: -4 }, { x: {date:2,offset:0}, y: 0 }, { x: {date:5,offset:0}, y: -3 }, { x: {date:6,offset:0}, y: 0 }, { x: {date:8,offset:0}, y: 0 } ];
28 var branch3_shape=[ { x: {date:0,offset:0}, y: 0 }, { x: {date:1,offset:0}, y: 1 }, { x: {date:2,offset:0}, y: 0 }, { x: {date:3,offset:0}, y: 3 }, { x: {date:4,offset:0}, y: 0 }, { x: {date:6,offset:0}, y: 0 } ];
29 t.eq( GitDiagram._determine_branch_offset( 1, -1, branch3_shape, trunk3_shape ), -6, "trunk 3 branch 3 offset -1" );
31 var trunk4_shape=[ {x: {date:0,offset:0}, y: 0}, { x: {date:5,offset:0}, y: 0 } ];
32 var branch4_shape=[ {x: {date:0,offset:0}, y: 0}, {x: {date:2,offset:0}, y: -2}, {x: {date:3,offset:0}, y: -2} ];
33 t.eq( GitDiagram._determine_branch_offset( 0, 1, branch4_shape, trunk4_shape ), 3, "trunk 4 branch 4 offset 1" );
36 function test_expand_branch( t )
38 t.plan( 10 );
39 var trunk_shape=[ { x: {date:0,offset:0}, y: 0 }, { x: {date:2,offset:0}, y: 1 }, { x: {date:5,offset:0}, y: 0 }, { x: {date:8,offset:0}, y: 0 } ];
40 t.eq( GitDiagram._expand_shape( 0, trunk_shape, trunk_shape ), trunk_shape, "trunk 1 expanded with itself offset 0" );
41 t.eq( GitDiagram._expand_shape( 1, trunk_shape, trunk_shape ), [ { x: {date:0,offset:0}, y: 1 }, { x: {date:2,offset:0}, y: 2 }, { x: {date:5,offset:0}, y: 1 }, { x: {date:8,offset:0}, y: 1 } ], "trunk 1 expanded with itself offset 1" );
42 var branch_shape=[ { x: {date:1,offset:0}, y: 1 }, { x: {date:1,offset:0}, y: 0 }, { x: {date:2,offset:0}, y: 5 }, { x: {date:4,offset:0}, y: 5 } ];
43 t.eq( GitDiagram._expand_shape( 0, branch_shape, branch_shape ), branch_shape, "branch 1 expanded with itself offset 0" );
44 t.eq( GitDiagram._expand_shape( 1, branch_shape, branch_shape ), [ { x: {date:1,offset:0}, y: 2 }, { x: {date:1,offset:0}, y: 1 }, { x: {date:2,offset:0}, y: 6 }, { x: {date:4,offset:0}, y: 6 } ], "branch 1 expanded with itself offset 1" );
45 t.eq( GitDiagram._expand_shape( 0, branch_shape, trunk_shape ), [ { x: {date:0,offset:0}, y: 0 }, { x: {date:1,offset:0}, y: 1 }, { x: {date:1,offset:0}, y: 0 }, { x: {date:2,offset:0}, y: 5 }, { x: {date:4,offset:0}, y: 1 }, { x: {date:5,offset:0}, y: 0 }, { x: {date:8,offset:0}, y: 0 } ], "trunk 1 branch 1 offset 0" );
46 t.eq( GitDiagram._expand_shape( 0, trunk_shape, branch_shape ), [ { x: {date:0,offset:0}, y: 0 }, { x: {date:1,offset:0}, y: 1 }, { x: {date:1,offset:0}, y: 0 }, { x: {date:2,offset:0}, y: 5 }, { x: {date:4,offset:0}, y: 1 }, { x: {date:5,offset:0}, y: 0 }, { x: {date:8,offset:0}, y: 0 } ], "trunk 1 branch 1 offset 0 in reverse" );
47 var trunk2_shape=[ { x: {date:0,offset:0}, y: 0 }, { x: {date:2,offset:0}, y: -1 }, { x: {date:5,offset:0}, y: 0 }, { x: {date:8,offset:0}, y: 0 } ];
48 t.eq( GitDiagram._expand_shape( 0, trunk2_shape, trunk2_shape ), trunk2_shape, "trunk 2 expanded with itself offset 0" );
49 t.eq( GitDiagram._expand_shape( -1, trunk2_shape, trunk2_shape ), [ { x: {date:0,offset:0}, y: -1 }, { x: {date:2,offset:0}, y: -2 }, { x: {date:5,offset:0}, y: -1 }, { x: {date:8,offset:0}, y: -1 } ], "trunk 2 expanded with itself offset -1" );
50 var branch2_shape=[ { x: {date:1,offset:0}, y: -1 }, { x: {date:1,offset:0}, y: 0 }, { x: {date:2,offset:0}, y: -5 }, { x: {date:4,offset:0}, y: -5 } ];
51 t.eq( GitDiagram._expand_shape( 0, branch2_shape, trunk2_shape ), [ { x: {date:0,offset:0}, y: 0 }, { x: {date:1,offset:0}, y: -1 }, { x: {date:1,offset:0}, y: 0 }, { x: {date:2,offset:0}, y: -5 }, { x: {date:4,offset:0}, y: -1 }, { x: {date:5,offset:0}, y: 0 }, { x: {date:8,offset:0}, y: 0 } ], "trunk 2 branch 2 offset 0" );
52 var trunk3_shape=[ { x: {date:0,offset:0}, y: 0 }, { x: {date:10,offset:0}, y: 0 } ];
53 var branch3_shape=[ { x: {date:2,offset:0}, y: 2 } ];
54 t.eq( GitDiagram._expand_shape( 1, branch3_shape, trunk3_shape ), [ { x: {date:0,offset:0}, y: 0 }, { x: {date:2,offset:0}, y: 3 }, { x: {date:2,offset:0}, y: 0 }, { x: {date:10,offset:0}, y: 0 } ], "trunk 3 branch 3 offset 1" );
58 function get_all_nodes_something( diagram, something )
60 var result={};
61 for( var id in diagram.m_nodes ) {
62 result[id]=diagram.m_nodes[id][something];
64 return result;
66 function get_date_columns_something( diagram, something )
68 var values=[];
69 for( var i=0; i<diagram.m_date_columns.length; ++i ) {
70 var value=diagram.m_date_columns[i][something];
71 if( something=="date" ) {
72 value=date_to_offset( value )
74 values.push( value );
76 return values;
79 function test_place_node_subtree( t )
81 t.plan( 8 );
82 var diagram=new GitDiagram( { container_element: document.getElementById( "diagram" ) } );
83 GitDiagram._g_step_x[diagram.m_style]=0.8;
84 GitDiagram._g_branch_angle=0.2;
85 make_sample_tree1( diagram );
87 // now, _place_node_subtree does not work outside place_nodes (it depends on first pass setting node dates)
88 // diagram._place_node_subtree( diagram.m_nodes[8], diagram.m_nodes[8].date );
89 // t.eq( get_date_columns_something( diagram, "date" ), [0, 1, 2, 3], "date_columns 1" );
90 // t.eq( get_all_nodes_something( diagram, "offset_y" ), { 1: 0, 2: 0, 3: -1, 4: -1, 5: -2, 6: 0, 7: 0, 8: null, 9: null }, "offset_y for every node. 1." );
92 make_sample_tree1a( diagram );
94 diagram.place_nodes();
95 t.eq( get_date_columns_something( diagram, "date" ), [0, 1, 2, 3, 4, 5, 7], "date_columns 1" );
96 t.eq( get_all_nodes_something( diagram, "absolute_y" ), { 1: -3, 2: -3, 3: -3, 4: -4, 5: -5, 6: 0, 7: 0, 8: 0, 9: null, 10: 0, 11: -1, 12: -2, 13: 1, 14: null, 15: 0 }, "absolute_y for every node. 2." );
97 t.eq( get_all_nodes_something( diagram, "offset_x" ), { 1: 0.4, 2: 0.4, 3: 0.4, 4: 0.4, 5: 0.4, 6: 0.4, 7: 0.4, 8: 0.4, 9: null, 10: 0.4, 11: 0.4, 12: 0.4, 13: 0.4, 14: null, 15: 0.4 }, "offset_x for every node 2" );
99 var diagram2=new GitDiagram( { container_element: document.getElementById( "diagram" ) } );
100 make_sample_tree2( diagram2 );
102 diagram2.place_nodes();
103 t.eq( get_all_nodes_something( diagram2, "offset_y" ), { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: null, 8: -1, 9: -1, 10: -1, 11: -1, 12: -1, 13: 1, 14: 2, 15: 0, 100: null }, "offset_y for every node for diagram2" );
104 t.eq( get_all_nodes_something( diagram2, "offset_x" ), { 1: 0.4, 2: 0.4*3, 3: 0.4, 4: 0.4, 5: 0.4, 6: 0.4, 7: 0.4, 8: 0.4*3+0.2, 9: 0.4+0.2, 10: 0.4, 11: 0.4+0.2, 12: 0.4+0.2, 13: 0.4, 14: 0.4, 15: 0.4, 100: null }, "offset_x for every node for diagram2" );
105 t.eq( get_date_columns_something( diagram2, "date" ), [1, 2, 3, 5, 7, 8, 9, 10, 11], "date column dates for diagram2" );
106 t.eq( get_date_columns_something( diagram2, "width" ), [ 0.8, 0.8, 0.4+0.2+0.4, 1, 0.8, 0.8, 0.4*3+0.2+0.4, 0.8, 0.8 ], "date column widths for diagram2" );
107 t.eq( get_date_columns_something( diagram2, "absolute_x" ), [ 0, 0.8, 2*0.8, 2*0.8+1, 2*0.8+2, 3*0.8+2, 4*0.8+2, 5*0.8+3, 5*0.8+3+0.8 ], "date column absolute_x for diagram2" );
113 /* ]]> */
114 </script>
115 </head>
116 <body>
117 <div id="diagram"></div>
118 </body>
119 </html>