move custom_rhino out of plotkit
[dygraphs.git] / plotkit_v091 / tests / svg.js
CommitLineData
6a1aa64f
DV
1/* actual tests */
2
3var options = {
4 "axisLineWidth": 2.0,
5 "axisLabelColor": Color.grayColor(),
6 "axisLineColor": Color.blackColor(),
7 "padding": {top: 5, bottom: 20, left: 40, right: 10},
8 "backgroundColor": Color.whiteColor(),
9 "strokeColor": null,
10 "axisLabelUseDiv": false
11};
12
13function genericTest(num, plotStyle) {
14 var l = new PlotKit.Layout(plotStyle, {});
15 var success = l.addDatasetFromTable("data" + num, $("test" + num));
16 l.evaluate();
17 var c = $("test" + num + "canvas");
18 var g = new PlotKit.SVGRenderer(c, l, options);
19 g.render();
20}
21
22function genericTestAndClear(num, plotStyle) {
23 var l = new PlotKit.Layout(plotStyle, {});
24 l.addDatasetFromTable("data" + num, $("test" + num));
25 l.evaluate();
26 var c = $("test" + num + "canvas");
27 var g = new PlotKit.SVGRenderer(c, l, {});
28 g.render();
29 g.clear();
30}
31
32function dualDataSet(num, plotStyle) {
33 var l = new PlotKit.Layout(plotStyle, {});
34 l.addDatasetFromTable("data1." + num, $("test" + num), 0, 1);
35 l.addDatasetFromTable("data2." + num, $("test" + num), 0, 2);
36 l.evaluate();
37 var c = $("test" + num + "canvas");
38 var g = new PlotKit.SVGRenderer(c, l, options);
39 g.render();
40}
41
42
43/* create HTML for tests */
44
45function makeTableRow(list) {
46 return TR({}, map(partial(TD, null), list));
47}
48
49function generateTestTable(num, data) {
50 var tableid = "test" + num;
51 var tablehead = THEAD(null, map(makeTableRow, [["x", "y"]]));
52 var tablebody = TBODY(null, map(makeTableRow, data));
53
54 var table = TABLE({"class": "data", "id": tableid}, [tablehead, tablebody]);
55 return table;
56}
57
58function generateCanvas(num) {
59 var canvasid = "test" + num + "canvas";
60 var canvasopts = {
61 "id": canvasid,
62 "width": 400,
63 "height": 200,
64 "version": "1.1",
65 "baseProfile": "full"
66 };
67
68 var canvas = PlotKit.SVGRenderer.SVG(canvasopts, "");
69 return canvas
70}
71
72function generateUnitTest(num, func, data, type, desc) {
73 var table = DIV({"class": "data"}, generateTestTable(num, data));
74 var canvas = DIV({"class": "canvas"}, generateCanvas(num));
75 var ending = DIV({"class":"ending"}, desc);
76
77 addLoadEvent(partial(func, num, type));
78
79 return DIV({"class": "unit"}, [table, canvas, ending]);
80 return DIV({"class": "unit"}, [table, ending]);
81}
82
83function generateTests() {
84 var tests = $('tests');
85
86 // datasets
87 var simpleData1 = [[0, 0], [1, 1], [2, 2], [3, 3]];
88 var simpleData2 = [[1, 2], [2, 3], [3, 4], [4, 5]];
89 var singleData = [[1, 1]];
90
91 var ninety = [[1, 9], [2, 1]];
92
93 var floatData1 = [[0, 0.5], [1, 0.4], [2, 0.3]];
94 var missingData = [[0, 1], [1, 4], [3, 16], [5, 17]];
95
96 var dualData = [[0,0,0], [1,2,1], [2,4,4], [3,8,9], [4,16,16], [5,32,25], [6, 64, 36], [7, 128, 49]];
97
98 tests.appendChild(H2(null, "Simple Tests"));
99
100 tests.appendChild(generateUnitTest(1, genericTest, simpleData1, "bar", ""));
101
102 tests.appendChild(generateUnitTest(2, genericTest, simpleData1,
103 "line", ""));
104 tests.appendChild(generateUnitTest(3, genericTest, simpleData2,
105 "pie", ""));
106
107 tests.appendChild(H2(null, "One Value Set"));
108
109 tests.appendChild(generateUnitTest(4, genericTest, singleData,
110 "bar", ""));
111 tests.appendChild(generateUnitTest(5, genericTest, singleData,
112 "line", ""));
113 tests.appendChild(generateUnitTest(6, genericTest, singleData,
114 "pie", ""));
115
116 tests.appendChild(H2(null, "Float Values Set"));
117 tests.appendChild(generateUnitTest(7, genericTest, floatData1,
118 "bar", ""));
119 tests.appendChild(generateUnitTest(8, genericTest, floatData1,
120 "line", ""));
121 tests.appendChild(generateUnitTest(9, genericTest, floatData1,
122 "pie", ""));
123
124 tests.appendChild(H2(null, "Dual Value Set"));
125 tests.appendChild(generateUnitTest(10, dualDataSet, dualData,
126 "bar", ""));
127 tests.appendChild(generateUnitTest(11, dualDataSet, dualData,
128 "line", ""));
129
130 tests.appendChild(H2(null, "Drawing and Clearing"));
131 tests.appendChild(generateUnitTest(12, genericTest, floatData1,
132 "bar", ""));
133 tests.appendChild(generateUnitTest(13, genericTestAndClear, floatData1,
134 "bar", ""));
135 tests.appendChild(generateUnitTest(14, genericTest, floatData1,
136 "pie", ""));
137 tests.appendChild(generateUnitTest(15, genericTestAndClear, floatData1,
138 "pie", ""));
139
140 tests.appendChild(H2(null, "Testing Circle Drawing"));
141
142 tests.appendChild(generateUnitTest(16, genericTest, ninety,
143 "pie", ""));
144
145}
146
147addLoadEvent(generateTests);