1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
|
<?php
/**
* ezcGraphPieChartTest
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* @package Graph
* @version //autogen//
* @subpackage Tests
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
*/
require_once dirname( __FILE__ ) . '/test_case.php';
/**
* Tests for ezcGraph class.
*
* @package Graph
* @subpackage Tests
*/
class ezcGraphPieChartTest extends ezcGraphTestCase
{
protected $basePath;
protected $tempDir;
public static function suite()
{
return new PHPUnit_Framework_TestSuite( "ezcGraphPieChartTest" );
}
protected function setUp()
{
static $i = 0;
if ( version_compare( phpversion(), '5.1.3', '<' ) )
{
$this->markTestSkipped( "These tests required atleast PHP 5.1.3" );
}
$this->tempDir = $this->createTempDir( __CLASS__ . sprintf( '_%03d_', ++$i ) ) . '/';
$this->basePath = dirname( __FILE__ ) . '/data/';
}
protected function tearDown()
{
if ( !$this->hasFailed() )
{
$this->removeTempDir();
}
}
public function testPieChartOptionsPropertyLabel()
{
$options = new ezcGraphPieChartOptions();
$this->assertSame(
'%1$s: %2$d (%3$.1f%%)',
$options->label,
'Wrong default value for property label in class ezcGraphPieChartOptions'
);
$options->label = '%1$s';
$this->assertSame(
'%1$s',
$options->label,
'Setting property value did not work for property label in class ezcGraphPieChartOptions'
);
}
public function testPieChartOptionsPropertyLabelCallback()
{
$options = new ezcGraphPieChartOptions();
$this->assertSame(
null,
$options->labelCallback,
'Wrong default value for property labelCallback in class ezcGraphPieChartOptions'
);
$options->labelCallback = 'printf';
$this->assertSame(
'printf',
$options->labelCallback,
'Setting property value did not work for property labelCallback in class ezcGraphPieChartOptions'
);
$options->labelCallback = array( $this, __METHOD__ );
$this->assertSame(
array( $this, __METHOD__ ),
$options->labelCallback,
'Setting property value did not work for property labelCallback in class ezcGraphPieChartOptions'
);
try
{
$options->labelCallback = 'undefined_function';
}
catch ( ezcBasevalueException $e )
{
return true;
}
$this->fail( 'ezcBasevalueException expected.' );
}
public function testPieChartOptionsPropertySum()
{
$options = new ezcGraphPieChartOptions();
$this->assertSame(
false,
$options->sum,
'Wrong default value for property sum in class ezcGraphPieChartOptions'
);
$options->sum = 100;
$this->assertSame(
100.,
$options->sum,
'Setting property value did not work for property sum in class ezcGraphPieChartOptions'
);
}
public function testPieChartOptionsPropertyPercentThreshold()
{
$options = new ezcGraphPieChartOptions();
$this->assertSame(
0.,
$options->percentThreshold,
'Wrong default value for property percentThreshold in class ezcGraphPieChartOptions'
);
$options->percentThreshold = .5;
$this->assertSame(
.5,
$options->percentThreshold,
'Setting property value did not work for property percentThreshold in class ezcGraphPieChartOptions'
);
}
public function testPieChartOptionsPropertyAbsoluteThreshold()
{
$options = new ezcGraphPieChartOptions();
$this->assertSame(
0.,
$options->absoluteThreshold,
'Wrong default value for property absoluteThreshold in class ezcGraphPieChartOptions'
);
$options->absoluteThreshold = 5;
$this->assertSame(
5.,
$options->absoluteThreshold,
'Setting property value did not work for property absoluteThreshold in class ezcGraphPieChartOptions'
);
}
public function testPieChartOptionsPropertySummarizeCaption()
{
$options = new ezcGraphPieChartOptions();
$this->assertSame(
'Misc',
$options->summarizeCaption,
'Wrong default value for property summarizeCaption in class ezcGraphPieChartOptions'
);
$options->summarizeCaption = 'Others';
$this->assertSame(
'Others',
$options->summarizeCaption,
'Setting property value did not work for property summarizeCaption in class ezcGraphPieChartOptions'
);
}
public function testElementGenerationLegend()
{
$chart = new ezcGraphPieChart();
$chart->data['sampleData'] = new ezcGraphArrayDataSet( array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1 ) );
$chart->render( 500, 200 );
$legend = $this->readAttribute( $chart->legend, 'labels' );
$this->assertEquals(
5,
count( $legend ),
'Count of legends items should be <5>'
);
$this->assertEquals(
'sample 1',
$legend[0]['label'],
'Label of first legend item should be <sample 1>.'
);
$this->assertEquals(
ezcGraphColor::fromHex( '#4E9A06' ),
$legend[1]['color'],
'Default color for single label is wrong.'
);
$this->assertEquals(
ezcGraphColor::fromHex( '#CC0000' ),
$legend[2]['color'],
'Special color for single label is wrong.'
);
}
public function testInvalidDisplayType()
{
$chart = new ezcGraphPieChart();
$chart->data['sampleData'] = new ezcGraphArrayDataSet( array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1 ) );
$chart->data['sampleData']->displayType = ezcGraph::LINE;
try
{
$chart->render( 500, 200 );
}
catch ( ezcGraphInvalidDisplayTypeException $e )
{
return true;
}
$this->fail( 'Expected ezcGraphInvalidDisplayTypeException.' );
}
public function testPieRenderPieSegments()
{
$chart = new ezcGraphPieChart();
$chart->data['sample'] = new ezcGraphArrayDataSet( array(
'Mozilla' => 4375,
'IE' => 345,
'Opera' => 1204,
'wget' => 231,
'Safari' => 987,
) );
$chart->data['sample']->highlight['wget'] = true;
$mockedRenderer = $this->getMock( 'ezcGraphRenderer2d', array(
'drawPieSegment',
) );
$mockedRenderer
->expects( $this->at( 0 ) )
->method( 'drawPieSegment' )
->with(
$this->equalTo( new ezcGraphBoundings( 80, 0, 400, 200 ) ),
$this->equalTo( new ezcGraphContext( 'sample', 'Mozilla' ) ),
$this->equalTo( ezcGraphColor::fromHex( '#3465A4' ) ),
$this->equalTo( 0., 1. ),
$this->equalTo( 220.5, .1 ),
$this->equalTo( 'Mozilla: 4375 (61.3%)' ),
$this->equalTo( false )
);
$mockedRenderer
->expects( $this->at( 1 ) )
->method( 'drawPieSegment' )
->with(
$this->equalTo( new ezcGraphBoundings( 80, 0, 400, 200 ) ),
$this->equalTo( new ezcGraphContext( 'sample', 'IE' ) ),
$this->equalTo( ezcGraphColor::fromHex( '#4E9A06' ) ),
$this->equalTo( 220.5, .1 ),
$this->equalTo( 238., 1. ),
$this->equalTo( 'IE: 345 (4.8%)' ),
$this->equalTo( false )
);
$mockedRenderer
->expects( $this->at( 2 ) )
->method( 'drawPieSegment' )
->with(
$this->equalTo( new ezcGraphBoundings( 80, 0, 400, 200 ) ),
$this->equalTo( new ezcGraphContext( 'sample', 'Opera' ) ),
$this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ),
$this->equalTo( 238., 1. ),
$this->equalTo( 298.6, 1. ),
$this->equalTo( 'Opera: 1204 (16.9%)' ),
$this->equalTo( false )
);
$mockedRenderer
->expects( $this->at( 3 ) )
->method( 'drawPieSegment' )
->with(
$this->equalTo( new ezcGraphBoundings( 80, 0, 400, 200 ) ),
$this->equalTo( new ezcGraphContext( 'sample', 'wget' ) ),
$this->equalTo( ezcGraphColor::fromHex( '#EDD400' ) ),
$this->equalTo( 298.6, 1. ),
$this->equalTo( 310., 1. ),
$this->equalTo( 'wget: 231 (3.2%)' ),
$this->equalTo( true )
);
$mockedRenderer
->expects( $this->at( 4 ) )
->method( 'drawPieSegment' )
->with(
$this->equalTo( new ezcGraphBoundings( 80, 0, 400, 200 ) ),
$this->equalTo( new ezcGraphContext( 'sample', 'Safari' ) ),
$this->equalTo( ezcGraphColor::fromHex( '#75505B' ) ),
$this->equalTo( 310., 1. ),
$this->equalTo( 360., 1. ),
$this->equalTo( 'Safari: 987 (13.8%)' ),
$this->equalTo( false )
);
$chart->renderer = $mockedRenderer;
$chart->render( 400, 200 );
}
public function testPieRenderPieSegmentsWithLabelCallback()
{
$chart = new ezcGraphPieChart();
$chart->data['sample'] = new ezcGraphArrayDataSet( array(
'Mozilla' => 4375,
'IE' => 345,
'Opera' => 1204,
'wget' => 231,
'Safari' => 987,
) );
$chart->data['sample']->highlight['wget'] = true;
$chart->options->labelCallback =
create_function(
'$label, $value, $percent',
"return 'Callback: ' . \$label;"
);
$mockedRenderer = $this->getMock( 'ezcGraphRenderer2d', array(
'drawPieSegment',
) );
$mockedRenderer
->expects( $this->at( 0 ) )
->method( 'drawPieSegment' )
->with(
$this->equalTo( new ezcGraphBoundings( 80, 0, 400, 200 ) ),
$this->equalTo( new ezcGraphContext( 'sample', 'Mozilla' ) ),
$this->equalTo( ezcGraphColor::fromHex( '#3465A4' ) ),
$this->equalTo( 0., 1. ),
$this->equalTo( 220.5, .1 ),
$this->equalTo( 'Callback: Mozilla' ),
$this->equalTo( false )
);
$mockedRenderer
->expects( $this->at( 1 ) )
->method( 'drawPieSegment' )
->with(
$this->equalTo( new ezcGraphBoundings( 80, 0, 400, 200 ) ),
$this->equalTo( new ezcGraphContext( 'sample', 'IE' ) ),
$this->equalTo( ezcGraphColor::fromHex( '#4E9A06' ) ),
$this->equalTo( 220.5, .1 ),
$this->equalTo( 238., 1. ),
$this->equalTo( 'Callback: IE' ),
$this->equalTo( false )
);
$mockedRenderer
->expects( $this->at( 2 ) )
->method( 'drawPieSegment' )
->with(
$this->equalTo( new ezcGraphBoundings( 80, 0, 400, 200 ) ),
$this->equalTo( new ezcGraphContext( 'sample', 'Opera' ) ),
$this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ),
$this->equalTo( 238., 1. ),
$this->equalTo( 298.6, 1. ),
$this->equalTo( 'Callback: Opera' ),
$this->equalTo( false )
);
$mockedRenderer
->expects( $this->at( 3 ) )
->method( 'drawPieSegment' )
->with(
$this->equalTo( new ezcGraphBoundings( 80, 0, 400, 200 ) ),
$this->equalTo( new ezcGraphContext( 'sample', 'wget' ) ),
$this->equalTo( ezcGraphColor::fromHex( '#EDD400' ) ),
$this->equalTo( 298.6, 1. ),
$this->equalTo( 310., 1. ),
$this->equalTo( 'Callback: wget' ),
$this->equalTo( true )
);
$mockedRenderer
->expects( $this->at( 4 ) )
->method( 'drawPieSegment' )
->with(
$this->equalTo( new ezcGraphBoundings( 80, 0, 400, 200 ) ),
$this->equalTo( new ezcGraphContext( 'sample', 'Safari' ) ),
$this->equalTo( ezcGraphColor::fromHex( '#75505B' ) ),
$this->equalTo( 310., 1. ),
$this->equalTo( 360., 1. ),
$this->equalTo( 'Callback: Safari' ),
$this->equalTo( false )
);
$chart->renderer = $mockedRenderer;
$chart->render( 400, 200 );
}
public function testInvalidValues()
{
try
{
$chart = new ezcGraphPieChart();
$chart->data['Skien'] = new ezcGraphArrayDataSet( array( 3, -1, 2 ) );
$chart->render( 500, 200 );
}
catch ( ezcGraphInvalidDataException $e )
{
return true;
}
$this->fail( 'Expected ezcGraphInvalidDataException.' );
}
public function testInvalidValueSum()
{
try
{
$chart = new ezcGraphPieChart();
$chart->data['Skien'] = new ezcGraphArrayDataSet( array( 0, 0 ) );
$chart->render( 500, 200 );
}
catch ( ezcGraphInvalidDataException $e )
{
return true;
}
$this->fail( 'Expected ezcGraphInvalidDataException.' );
}
public function testEmptyDataSet()
{
try
{
$chart = new ezcGraphPieChart();
$chart->data['Skien'] = new ezcGraphArrayDataSet( array() );
$chart->render( 500, 200 );
}
catch ( ezcGraphInvalidDataException $e )
{
return true;
}
$this->fail( 'Expected ezcGraphInvalidDataException.' );
}
public function testRenderSmallPieChart()
{
$filename = $this->tempDir . __FUNCTION__ . '.svg';
$chart = new ezcGraphPieChart();
$chart->data['Skien'] = new ezcGraphArrayDataSet( array( 'Norwegian' => 10, 'Dutch' => 3, 'German' => 2, 'French' => 2, 'Hindi' => 1, 'Taiwanese' => 1, 'Brazilian' => 1, 'Venezuelan' => 1, 'Japanese' => 1, 'Czech' => 1, 'Hungarian' => 1, 'Romanian' => 1 ) );
$chart->data['Skien']->highlight['Norwegian'] = true;
$chart->renderer->options->pieVerticalSize = .2;
$chart->renderer->options->pieHorizontalSize = .2;
$chart->render( 500, 200, $filename );
$this->compare(
$filename,
$this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
);
}
public function testRenderSmallPieChartToOutput()
{
$filename = $this->tempDir . __FUNCTION__ . '.svg';
$chart = new ezcGraphPieChart();
$chart->data['Skien'] = new ezcGraphArrayDataSet( array( 'Norwegian' => 10, 'Dutch' => 3, 'German' => 2, 'French' => 2, 'Hindi' => 1, 'Taiwanese' => 1, 'Brazilian' => 1, 'Venezuelan' => 1, 'Japanese' => 1, 'Czech' => 1, 'Hungarian' => 1, 'Romanian' => 1 ) );
ob_start();
// Suppress header already sent warning
@$chart->renderToOutput( 500, 200 );
file_put_contents( $filename, ob_get_clean() );
$this->compare(
$filename,
$this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
);
}
public function testRenderPieChartWithZeroValues()
{
$filename = $this->tempDir . __FUNCTION__ . '.svg';
$chart = new ezcGraphPieChart();
$chart->data['Skien'] = new ezcGraphArrayDataSet( array( 'Norwegian' => 10, 'Dutch' => 3, 'German' => 2, 'French' => 2, 'Hindi' => 1, 'Taiwanese' => 0, 'Brazilian' => 1, 'Venezuelan' => 0, 'Japanese' => 1, 'Czech' => 0, 'Hungarian' => 1, 'Romanian' => 1 ) );
$chart->data['Skien']->highlight['Norwegian'] = true;
$chart->render( 500, 200, $filename );
$this->compare(
$filename,
$this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
);
}
public function testRenderPieChartWithLotsOfLabels()
{
$filename = $this->tempDir . __FUNCTION__ . '.svg';
$chart = new ezcGraphPieChart();
$chart->data['Skien'] = new ezcGraphArrayDataSet( array( 'Norwegian' => 10, 'Dutch' => 3, 'German' => 2, 'French' => 2, 'Hindi' => 1, 'Taiwanese' => 1, 'Brazilian' => 1, 'Venezuelan' => 1, 'Japanese' => 1, 'Czech' => 1, 'Hungarian' => 1, 'Romanian' => 1 ) );
$chart->data['Skien']->highlight['Norwegian'] = true;
$chart->render( 500, 200, $filename );
$this->compare(
$filename,
$this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
);
}
public function testRenderPortraitPieChartWithLotsOfLabels()
{
$filename = $this->tempDir . __FUNCTION__ . '.svg';
$chart = new ezcGraphPieChart();
$chart->data['Skien'] = new ezcGraphArrayDataSet( array( 'Norwegian' => 10, 'Dutch' => 3, 'German' => 2, 'French' => 2, 'Hindi' => 1, 'Taiwanese' => 1, 'Brazilian' => 1, 'Venezuelan' => 1, 'Japanese' => 1, 'Czech' => 1, 'Hungarian' => 1, 'Romanian' => 1 ) );
$chart->data['Skien']->highlight['Norwegian'] = true;
$chart->render( 500, 500, $filename );
$this->compare(
$filename,
$this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
);
}
public function testRenderPieChartWithCustomSum()
{
$filename = $this->tempDir . __FUNCTION__ . '.svg';
$chart = new ezcGraphPieChart();
$chart->options->sum = 30;
$chart->data['Skien'] = new ezcGraphArrayDataSet( array( 'Norwegian' => 10, 'Dutch' => 3, 'German' => 2, 'French' => 2, 'Hindi' => 1, 'Taiwanese' => 1, 'Brazilian' => 1, 'Venezuelan' => 1, 'Japanese' => 1, 'Czech' => 1, 'Hungarian' => 1, 'Romanian' => 1 ) );
$chart->render( 500, 300, $filename );
$this->compare(
$filename,
$this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
);
try
{
$chart->options->sum = false;
}
catch ( ezcBaseValueException $e )
{
return true;
}
$this->fail( 'Expected ezcBaseValueException.' );
}
public function testRenderPieChartWithAbsoluteThreshold()
{
$filename = $this->tempDir . __FUNCTION__ . '.svg';
$chart = new ezcGraphPieChart();
$chart->options->absoluteThreshold = 1;
$chart->data['Skien'] = new ezcGraphArrayDataSet( array( 'Norwegian' => 10, 'Dutch' => 3, 'German' => 2, 'French' => 2, 'Hindi' => 1, 'Taiwanese' => 1, 'Brazilian' => 1, 'Venezuelan' => 1, 'Japanese' => 1, 'Czech' => 1, 'Hungarian' => 1, 'Romanian' => 1 ) );
$chart->render( 500, 300, $filename );
$this->compare(
$filename,
$this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
);
try
{
$chart->options->absoluteThreshold = false;
}
catch ( ezcBaseValueException $e )
{
return true;
}
$this->fail( 'Expected ezcBaseValueException.' );
}
public function testRenderPieChartWithPercentageThreshold()
{
$filename = $this->tempDir . __FUNCTION__ . '.svg';
$chart = new ezcGraphPieChart();
$chart->options->percentThreshold = .05;
$chart->options->summarizeCaption = 'Others';
$chart->data['Skien'] = new ezcGraphArrayDataSet( array( 'Norwegian' => 10, 'Dutch' => 3, 'German' => 2, 'French' => 2, 'Hindi' => 1, 'Taiwanese' => 1, 'Brazilian' => 1, 'Venezuelan' => 1, 'Japanese' => 1, 'Czech' => 1, 'Hungarian' => 1, 'Romanian' => 1 ) );
$chart->render( 500, 300, $filename );
$this->compare(
$filename,
$this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
);
try
{
$chart->options->percentThreshold = false;
}
catch ( ezcBaseValueException $e )
{
return true;
}
$this->fail( 'Expected ezcBaseValueException.' );
}
public function testRenderPieChartWithLowAbsoluteThreshold()
{
$filename = $this->tempDir . __FUNCTION__ . '.svg';
$chart = new ezcGraphPieChart();
$chart->options->absoluteThreshold = 1;
$chart->data['Skien'] = new ezcGraphArrayDataSet( array( 'Norwegian' => 10, 'Dutch' => 3, 'German' => 2, 'French' => 2, 'Hindi' => 1 ) );
$chart->render( 500, 300, $filename );
$this->compare(
$filename,
$this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
);
try
{
$chart->options->absoluteThreshold = false;
}
catch ( ezcBaseValueException $e )
{
return true;
}
$this->fail( 'Expected ezcBaseValueException.' );
}
public function testRenderPieChartWithLowPercentageThreshold()
{
$filename = $this->tempDir . __FUNCTION__ . '.svg';
$chart = new ezcGraphPieChart();
$chart->options->percentThreshold = .06;
$chart->options->summarizeCaption = 'Others';
$chart->data['Skien'] = new ezcGraphArrayDataSet( array( 'Norwegian' => 10, 'Dutch' => 3, 'German' => 2, 'French' => 2, 'Hindi' => 1 ) );
$chart->render( 500, 300, $filename );
$this->compare(
$filename,
$this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
);
try
{
$chart->options->percentThreshold = false;
}
catch ( ezcBaseValueException $e )
{
return true;
}
$this->fail( 'Expected ezcBaseValueException.' );
}
public function testRenderPieChartWithPercentageThresholdAndCustomSum()
{
$filename = $this->tempDir . __FUNCTION__ . '.svg';
$chart = new ezcGraphPieChart();
$chart->options->sum = 30;
$chart->options->percentThreshold = .05;
$chart->options->summarizeCaption = 'Others';
$chart->data['Skien'] = new ezcGraphArrayDataSet( array( 'Norwegian' => 10, 'Dutch' => 3, 'German' => 2, 'French' => 2, 'Hindi' => 1, 'Taiwanese' => 1, 'Brazilian' => 1, 'Venezuelan' => 1, 'Japanese' => 1, 'Czech' => 1, 'Hungarian' => 1, 'Romanian' => 1 ) );
$chart->render( 500, 300, $filename );
$this->compare(
$filename,
$this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
);
}
public function testRenderPieChartWithOneDataPoint()
{
$filename = $this->tempDir . __FUNCTION__ . '.svg';
$chart = new ezcGraphPieChart();
$chart->data['Skien'] = new ezcGraphArrayDataSet( array( 'Norwegian' => 10 ) );
$chart->render( 500, 300, $filename );
$this->compare(
$filename,
$this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
);
}
public function testRender3dPieChartWithOneDataPoint()
{
$filename = $this->tempDir . __FUNCTION__ . '.svg';
$chart = new ezcGraphPieChart();
$chart->data['Skien'] = new ezcGraphArrayDataSet( array( 'Norwegian' => 10 ) );
$chart->renderer = new ezcGraphRenderer3d();
$chart->renderer->options->dataBorder = false;
$chart->render( 500, 300, $filename );
$this->compare(
$filename,
$this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
);
}
}
?>
|