~smagoun/whoopsie/whoopsie-lp1017637

« back to all changes in this revision

Viewing changes to backend/stats/static/js/yui/tests/charts/tests/pielegend.html

  • Committer: Evan Dandrea
  • Date: 2012-05-09 05:53:45 UTC
  • Revision ID: evan.dandrea@canonical.com-20120509055345-z2j41tmcbf4as5uf
The backend now lives in lp:daisy and the website (errors.ubuntu.com) now lives in lp:errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
 
<html>
3
 
    <head>
4
 
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
5
 
        <style>
6
 
            /*Supplemental: CSS for the YUI distribution*/
7
 
            #custom-doc { width: 95%; min-width: 950px; }
8
 
            #pagetitle {background-image: url(../../assets/bg_hd.gif);}
9
 
            #mychart {
10
 
                padding:10px 10px 10px 10px;
11
 
            }
12
 
        </style>
13
 
        <link rel="stylesheet" type="text/css" href="../../../build/cssfonts/fonts-min.css">
14
 
    </head>             
15
 
<body class="yui3-skin-sam">
16
 
<h3>Unit Tests</h3>
17
 
<div id="mychart"></div>
18
 
<script type="text/javascript" src="../../../build/yui/yui-min.js"></script>
19
 
<script>            
20
 
YUI({
21
 
    allowRollup: false,
22
 
    filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'min'
23
 
}).use('charts-legend', 'test', 'console', function (Y) 
24
 
25
 
    Y.namespace("example.test");
26
 
 
27
 
    var suite = new Y.Test.Suite("Y.Charts.Legend"),
28
 
 
29
 
    LegendTestTemplate = function(cfg, globalCfg)
30
 
    {
31
 
        var i;
32
 
        LegendTestTemplate.superclass.constructor.apply(this);
33
 
        cfg.width = cfg.width || 400;
34
 
        cfg.height = cfg.height || 300;
35
 
        cfg.categoryKey = "date";
36
 
        this.attrCfg = cfg;
37
 
        for(i in globalCfg)
38
 
        {
39
 
            if(globalCfg.hasOwnProperty(i))
40
 
            {
41
 
                this[i] = globalCfg[i];
42
 
            }
43
 
        }
44
 
    };
45
 
 
46
 
    Y.extend(LegendTestTemplate, Y.Test.Case, {
47
 
        setUp: function() {
48
 
            this.chart = new Y.Chart(this.attrCfg);
49
 
        },
50
 
        
51
 
        tearDown: function() {
52
 
            this.chart.destroy(true);
53
 
        }
54
 
    });
55
 
 
56
 
    var basicDataValues = [ 
57
 
            {date:"5/1/2010", miscellaneous:2000, expenses:3700, revenue:2200}, 
58
 
            {date:"5/2/2010", miscellaneous:50, expenses:9100, revenue:100}, 
59
 
            {date:"5/3/2010", miscellaneous:400, expenses:1100, revenue:1500}, 
60
 
            {date:"5/4/2010", miscellaneous:200, expenses:1900, revenue:2800}, 
61
 
            {date:"5/5/2010", miscellaneous:5000, expenses:5000, revenue:2650}
62
 
    ],
63
 
    
64
 
    pieDataValues = [ 
65
 
            {date:"5/1/2010", miscellaneous:2000}, 
66
 
            {date:"5/2/2010", miscellaneous:50}, 
67
 
            {date:"5/3/2010", miscellaneous:400}, 
68
 
            {date:"5/4/2010", miscellaneous:200}, 
69
 
            {date:"5/5/2010", miscellaneous:5000}
70
 
    ],
71
 
    topLegend = function()
72
 
    {
73
 
        return {
74
 
            position: "top",
75
 
            styles: {
76
 
                hAlign: "center"
77
 
            }
78
 
        };
79
 
    },
80
 
    
81
 
    bottomLegend = function()
82
 
    {
83
 
        return {
84
 
            position: "bottom",
85
 
            styles: {
86
 
                hAlign: "center"
87
 
            }
88
 
        };
89
 
    },
90
 
 
91
 
    leftLegend = function()
92
 
    {
93
 
        return {
94
 
            position: "left",
95
 
            styles: {
96
 
                vAlign: "middle"
97
 
            }
98
 
        };
99
 
    },
100
 
 
101
 
    rightLegend = function()
102
 
    {
103
 
        return {
104
 
            position: "right",
105
 
            styles: {
106
 
                vAlign: "middle"
107
 
            }
108
 
        };
109
 
    },
110
 
 
111
 
    testLegend = function()
112
 
    {
113
 
        var assert = Y.Assert,
114
 
            chart = this.chart,
115
 
            legend = chart.get("legend");
116
 
        assert.isTrue(legend instanceof Y.ChartLegend);
117
 
    },
118
 
 
119
 
    testLegendPosition = function()
120
 
    {
121
 
        var assert = Y.Assert,
122
 
            chart = this.chart,
123
 
            legend = chart.get("legend");
124
 
        assert.areEqual(legend.get("position"), this.legendPosition);
125
 
    },
126
 
 
127
 
    testLegendItemsLength = function()
128
 
    {
129
 
        var assert = Y.Assert,
130
 
            chart = this.chart,
131
 
            legend = chart.get("legend"),
132
 
            chartSC = chart.get("seriesCollection"),
133
 
            legendItems = legend.get("items");
134
 
        assert.areEqual(chartSC.length, legendItems.length);
135
 
    },
136
 
 
137
 
    testPieLegendItemsLength = function()
138
 
    {
139
 
        var assert = Y.Assert,
140
 
            chart = this.chart,
141
 
            legend = chart.get("legend"),
142
 
            chartSC = chart.get("seriesCollection")[0].get("markers"),
143
 
            legendItems = legend.get("items");
144
 
        assert.areEqual(chartSC.length, legendItems.length);
145
 
    },
146
 
 
147
 
    testLegendItemsText = function()
148
 
    {
149
 
        var assert = Y.Assert,
150
 
            chart = this.chart,
151
 
            legend = chart.get("legend"),
152
 
            chartSC = chart.get("seriesCollection"),
153
 
            legendItems = legend.get("items"),
154
 
            i = 0,
155
 
            len = chartSC.length;
156
 
        for(; i < len; ++i)
157
 
        {
158
 
            assert.areEqual(chartSC[i].get("displayName"), legendItems.text);
159
 
        }
160
 
    },
161
 
 
162
 
    testPieLegendItemsText = function()
163
 
    {
164
 
        var assert = Y.Assert,
165
 
            chart = this.chart,
166
 
            legend = chart.get("legend"),
167
 
            series = chart.get("seriesCollection")[0],
168
 
            displayName,
169
 
            legendItems = legend.get("items"),
170
 
            i = 0,
171
 
            len = legendItems.length;
172
 
        for(; i < len; ++i)
173
 
        {
174
 
            displayName = chart.getSeriesItems(series, i).category.value;
175
 
            assert.areEqual(displayName, legendItems[i].text);
176
 
        }
177
 
    },
178
 
    
179
 
    PieNoLegendTest = new LegendTestTemplate({
180
 
        type: "pie",
181
 
        dataProvider: pieDataValues,
182
 
        render: "#mychart"
183
 
    }, {
184
 
        name: "Pie No Legend Tests",
185
 
 
186
 
        testNoLegend: function()
187
 
        {
188
 
            var assert = Y.Assert,
189
 
                chart = this.chart,
190
 
                legend = chart.get("legend");
191
 
            assert.isUndefined(legend);
192
 
        }
193
 
    }),
194
 
    
195
 
    PieTopLegendTest = new LegendTestTemplate({
196
 
        type: "pie",
197
 
        dataProvider: pieDataValues,
198
 
        render: "#mychart",
199
 
        legend: topLegend()
200
 
    }, {
201
 
        name: "Top Legend Test",
202
 
 
203
 
        testLegend: testLegend
204
 
    }),
205
 
    
206
 
    PieRightLegendTest = new LegendTestTemplate({
207
 
        type: "pie",
208
 
        dataProvider: pieDataValues,
209
 
        render: "#mychart",
210
 
        legend: rightLegend()
211
 
    }, {
212
 
        name: "Pie Right Legend Test",
213
 
 
214
 
        testLegend: testLegend
215
 
    }),
216
 
    
217
 
    PieBottomLegendTest = new LegendTestTemplate({
218
 
        type: "pie",
219
 
        dataProvider: pieDataValues,
220
 
        render: "#mychart",
221
 
        legend: bottomLegend()
222
 
    }, {
223
 
        name: "Pie Bottom Legend Test",
224
 
 
225
 
        testLegend: testLegend
226
 
    }),
227
 
    
228
 
    PieLeftLegendTest = new LegendTestTemplate({
229
 
        type: "pie",
230
 
        dataProvider: pieDataValues,
231
 
        render: "#mychart",
232
 
        legend: leftLegend()
233
 
    }, {
234
 
        name: "Pie Left Legend Test",
235
 
 
236
 
        testLegend: testLegend
237
 
    }),
238
 
    
239
 
    PieTopLegendPositionTest = new LegendTestTemplate({
240
 
        type: "pie",
241
 
        dataProvider: pieDataValues,
242
 
        render: "#mychart",
243
 
        legend: topLegend()
244
 
    }, {
245
 
        name: "Pie Top Legend Position Test",
246
 
 
247
 
        legendPosition: "top",
248
 
 
249
 
        testLegendPosition: testLegendPosition
250
 
    }),
251
 
    
252
 
    PieRightLegendPositionTest = new LegendTestTemplate({
253
 
        type: "pie",
254
 
        dataProvider: pieDataValues,
255
 
        render: "#mychart",
256
 
        legend: rightLegend()
257
 
    }, {
258
 
        name: "Pie Right Legend Position Test",
259
 
 
260
 
        legendPosition: "right",
261
 
 
262
 
        testLegend: testLegendPosition
263
 
    }),
264
 
    
265
 
    PieBottomLegendPositionTest = new LegendTestTemplate({
266
 
        type: "pie",
267
 
        dataProvider: pieDataValues,
268
 
        render: "#mychart",
269
 
        legend: bottomLegend()
270
 
    }, {
271
 
        name: "Pie Bottom Legend Position Test",
272
 
 
273
 
        legendPosition: "bottom",
274
 
 
275
 
        testLegend: testLegendPosition
276
 
    }),
277
 
    
278
 
    PieLeftLegendPositionTest = new LegendTestTemplate({
279
 
        type: "pie",
280
 
        dataProvider: pieDataValues,
281
 
        render: "#mychart",
282
 
        legend: leftLegend()
283
 
    }, {
284
 
        name: "Pie Left Legend Position Test",
285
 
        
286
 
        legendPosition: "left",
287
 
 
288
 
        testLegend: testLegendPosition
289
 
    }),
290
 
 
291
 
    PieTopLegendItemsLengthTest = new LegendTestTemplate({
292
 
        type: "pie",
293
 
        dataProvider: pieDataValues,
294
 
        render: "#mychart",
295
 
        legend: topLegend()
296
 
    }, {
297
 
        name: "Pie Top Legend Items Length Test",
298
 
 
299
 
        testLegend: testPieLegendItemsLength
300
 
    }),
301
 
    
302
 
    PieRightLegendItemsLengthTest = new LegendTestTemplate({
303
 
        type: "pie",
304
 
        dataProvider: pieDataValues,
305
 
        render: "#mychart",
306
 
        legend: rightLegend()
307
 
    }, {
308
 
        name: "Pie Right Legend Items Length Test",
309
 
 
310
 
        testLegend: testPieLegendItemsLength
311
 
    }),
312
 
    
313
 
    PieBottomLegendItemsLengthTest = new LegendTestTemplate({
314
 
        type: "pie",
315
 
        dataProvider: pieDataValues,
316
 
        render: "#mychart",
317
 
        legend: bottomLegend()
318
 
    }, {
319
 
        name: "Pie Bottom Legend Items Length Test",
320
 
 
321
 
        testLegend: testPieLegendItemsLength
322
 
    }),
323
 
    
324
 
    PieLeftLegendItemsLengthTest = new LegendTestTemplate({
325
 
        type: "pie",
326
 
        dataProvider: pieDataValues,
327
 
        render: "#mychart",
328
 
        legend: leftLegend()
329
 
    }, {
330
 
        name: "Pie Left Legend Items Length Test",
331
 
 
332
 
        testLegend: testPieLegendItemsLength
333
 
    }),
334
 
    
335
 
    PieTopLegendItemsTextTest = new LegendTestTemplate({
336
 
        type: "pie",
337
 
        dataProvider: pieDataValues,
338
 
        render: "#mychart",
339
 
        legend: topLegend()
340
 
    }, {
341
 
        name: "Pie Top Legend Items Text Test",
342
 
 
343
 
        testLegend: testPieLegendItemsText
344
 
    }),
345
 
    
346
 
    PieRightLegendItemsTextTest = new LegendTestTemplate({
347
 
        type: "pie",
348
 
        dataProvider: pieDataValues,
349
 
        render: "#mychart",
350
 
        legend: rightLegend()
351
 
    }, {
352
 
        name: "Pie Right Legend Items Text Test",
353
 
 
354
 
        testLegend: testPieLegendItemsText
355
 
    }),
356
 
    
357
 
    PieBottomLegendItemsTextTest = new LegendTestTemplate({
358
 
        type: "pie",
359
 
        dataProvider: pieDataValues,
360
 
        render: "#mychart",
361
 
        legend: bottomLegend()
362
 
    }, {
363
 
        name: "Pie Bottom Legend Items Text Test",
364
 
 
365
 
        testLegend: testPieLegendItemsText
366
 
    }),
367
 
    
368
 
    PieLeftLegendItemsTextTest = new LegendTestTemplate({
369
 
        type: "pie",
370
 
        dataProvider: pieDataValues,
371
 
        render: "#mychart",
372
 
        legend: leftLegend()
373
 
    }, {
374
 
        name: "Pie Left Legend Items Text Test",
375
 
 
376
 
        testLegend: testPieLegendItemsText
377
 
    });
378
 
    
379
 
    suite.add(PieNoLegendTest);
380
 
    suite.add(PieTopLegendTest);
381
 
    suite.add(PieRightLegendTest);
382
 
    suite.add(PieBottomLegendTest);
383
 
    suite.add(PieLeftLegendTest);
384
 
    suite.add(PieTopLegendPositionTest);
385
 
    suite.add(PieRightLegendPositionTest);
386
 
    suite.add(PieBottomLegendPositionTest);
387
 
    suite.add(PieLeftLegendPositionTest);
388
 
    suite.add(PieTopLegendItemsLengthTest);
389
 
    suite.add(PieRightLegendItemsLengthTest);
390
 
    suite.add(PieBottomLegendItemsLengthTest);
391
 
    suite.add(PieLeftLegendItemsLengthTest);
392
 
    suite.add(PieTopLegendItemsTextTest);
393
 
    suite.add(PieRightLegendItemsTextTest);
394
 
    suite.add(PieBottomLegendItemsTextTest);
395
 
    suite.add(PieLeftLegendItemsTextTest);
396
 
 
397
 
    //create the console
398
 
    var r = new Y.Console({
399
 
        newestOnTop : false,
400
 
        style: 'block' // to anchor in the example content
401
 
    });
402
 
    
403
 
    r.render('#testLogger');
404
 
 
405
 
    //run the tests
406
 
    Y.Test.Runner.setName("Y.Charts.Legend");
407
 
    Y.Test.Runner.add(suite);
408
 
    Y.Test.Runner.run();
409
 
});
410
 
</script>
411
 
</body>
412
 
</html>