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
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
|
<?php
/**
* File containing the ezcGraphSVGDriver class
*
* @package Graph
* @version //autogentag//
* @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Extension of the basic Driver package to utilize the SVGlib.
*
* @package Graph
*/
class ezcGraphSvgDriver extends ezcGraphDriver
{
/**
* DOM tree of the svg document
*
* @var DOMDocument
*/
protected $dom;
/**
* DOMElement containing all svg style definitions
*
* @var DOMElement
*/
protected $defs;
/**
* DOMElement containing all svg objects
*
* @var DOMElement
*/
protected $elements;
/**
* List of strings to draw
* array ( array(
* 'text' => array( 'strings' ),
* 'options' => ezcGraphFontOptions,
* )
*
* @var array
*/
protected $strings = array();
/**
* List of already created gradients
*
* @var array
*/
protected $drawnGradients = array();
/**
* Numeric unique element id
*
* @var int
*/
protected $elementID = 0;
public function __construct( array $options = array() )
{
$this->options = new ezcGraphSvgDriverOptions( $options );
}
protected function createDocument()
{
if ( $this->dom === null )
{
if ( $this->options->templateDocument !== false )
{
$this->dom = new DOMDocument();
// @TODO: Add $this->dom->format
$this->dom->load( $this->options->templateDocument );
$this->defs = $this->dom->getElementsByTagName( 'defs' )->item( 0 );
$svg = $this->dom->getElementsByTagName( 'svg' )->item( 0 );
}
else
{
$this->dom = new DOMDocument();
$svg = $this->dom->createElementNS( 'http://www.w3.org/2000/svg', 'svg' );
$this->dom->appendChild( $svg );
$svg->setAttribute( 'width', $this->options->width );
$svg->setAttribute( 'height', $this->options->height );
$svg->setAttribute( 'version', '1.0' );
$svg->setAttribute( 'id', $this->options->idPrefix );
$this->defs = $this->dom->createElement( 'defs' );
$this->defs = $svg->appendChild( $this->defs );
}
if ( $this->options->insertIntoGroup !== false )
{
// getElementById only works for Documents validated against a certain
// schema, so that the use of XPath should be faster in most cases.
$xpath = new DomXPath( $this->dom );
$this->elements = $xpath->query( '//*[@id = \'' . $this->options->insertIntoGroup . '\']' )->item( 0 );
if ( !$this->elements )
{
throw new ezcGraphSvgDriverInvalidIdException( $this->options->insertIntoGroup );
}
}
else
{
$this->elements = $this->dom->createElement( 'g' );
$this->elements->setAttribute( 'id', $this->options->idPrefix . 'Chart' );
$this->elements->setAttribute( 'color-rendering', $this->options->colorRendering );
$this->elements->setAttribute( 'shape-rendering', $this->options->shapeRendering );
$this->elements->setAttribute( 'text-rendering', $this->options->textRendering );
$this->elements = $svg->appendChild( $this->elements );
}
}
}
protected function getGradientUrl( ezcGraphColor $color )
{
switch ( true )
{
case ( $color instanceof ezcGraphLinearGradient ):
if ( !in_array( $color->__toString(), $this->drawnGradients, true ) )
{
$gradient = $this->dom->createElement( 'linearGradient' );
$gradient->setAttribute( 'id', 'Definition_' . $color->__toString() );
$this->defs->appendChild( $gradient );
// Start of linear gradient
$stop = $this->dom->createElement( 'stop' );
$stop->setAttribute( 'offset', 0 );
$stop->setAttribute( 'style', sprintf( 'stop-color: #%02x%02x%02x; stop-opacity: %.2f;',
$color->startColor->red,
$color->startColor->green,
$color->startColor->blue,
1 - ( $color->startColor->alpha / 255 )
)
);
$gradient->appendChild( $stop );
// End of linear gradient
$stop = $this->dom->createElement( 'stop' );
$stop->setAttribute( 'offset', 1 );
$stop->setAttribute( 'style', sprintf( 'stop-color: #%02x%02x%02x; stop-opacity: %.2f;',
$color->endColor->red,
$color->endColor->green,
$color->endColor->blue,
1 - ( $color->endColor->alpha / 255 )
)
);
$gradient->appendChild( $stop );
$gradient = $this->dom->createElement( 'linearGradient' );
$gradient->setAttribute( 'id', $color->__toString() );
$gradient->setAttribute( 'x1', $color->startPoint->x );
$gradient->setAttribute( 'y1', $color->startPoint->y );
$gradient->setAttribute( 'x2', $color->endPoint->x );
$gradient->setAttribute( 'y2', $color->endPoint->y );
$gradient->setAttribute( 'gradientUnits', 'userSpaceOnUse' );
$gradient->setAttributeNS(
'http://www.w3.org/1999/xlink',
'xlink:href',
'#Definition_' . $color->__toString()
);
$this->defs->appendChild( $gradient );
$this->drawnGradients[] = $color->__toString();
}
return sprintf( 'url(#%s)',
$color->__toString()
);
case ( $color instanceof ezcGraphRadialGradient ):
if ( !in_array( $color->__toString(), $this->drawnGradients, true ) )
{
$gradient = $this->dom->createElement( 'linearGradient' );
$gradient->setAttribute( 'id', 'Definition_' . $color->__toString() );
$this->defs->appendChild( $gradient );
// Start of linear gradient
$stop = $this->dom->createElement( 'stop' );
$stop->setAttribute( 'offset', 0 );
$stop->setAttribute( 'style', sprintf( 'stop-color: #%02x%02x%02x; stop-opacity: %.2f;',
$color->startColor->red,
$color->startColor->green,
$color->startColor->blue,
1 - ( $color->startColor->alpha / 255 )
)
);
$gradient->appendChild( $stop );
// End of linear gradient
$stop = $this->dom->createElement( 'stop' );
$stop->setAttribute( 'offset', 1 );
$stop->setAttribute( 'style', sprintf( 'stop-color: #%02x%02x%02x; stop-opacity: %.2f;',
$color->endColor->red,
$color->endColor->green,
$color->endColor->blue,
1 - ( $color->endColor->alpha / 255 )
)
);
$gradient->appendChild( $stop );
$gradient = $this->dom->createElement( 'radialGradient' );
$gradient->setAttribute( 'id', $color->__toString() );
$gradient->setAttribute( 'cx', $color->center->x );
$gradient->setAttribute( 'cy', $color->center->y );
$gradient->setAttribute( 'fx', $color->center->x );
$gradient->setAttribute( 'fy', $color->center->y );
$gradient->setAttribute( 'r', max( $color->height, $color->width ) );
$gradient->setAttribute( 'gradientUnits', 'userSpaceOnUse' );
$gradient->setAttributeNS(
'http://www.w3.org/1999/xlink',
'xlink:href',
'#Definition_' . $color->__toString()
);
$this->defs->appendChild( $gradient );
$this->drawnGradients[] = $color->__toString();
}
return sprintf( 'url(#%s)',
$color->__toString()
);
default:
return false;
}
}
protected function getStyle( ezcGraphColor $color, $filled = true, $thickness = 1 )
{
if ( $filled )
{
if ( $url = $this->getGradientUrl( $color ) )
{
return sprintf( 'fill: %s; stroke: none;', $url );
}
else
{
return sprintf( 'fill: #%02x%02x%02x; fill-opacity: %.2f; stroke: none;',
$color->red,
$color->green,
$color->blue,
1 - ( $color->alpha / 255 )
);
}
}
else
{
if ( $url = $this->getGradientUrl( $color ) )
{
return sprintf( 'fill: none; stroke: %s;', $url );
}
else
{
return sprintf( 'fill: none; stroke: #%02x%02x%02x; stroke-width: %d; stroke-opacity: %.2f; stroke-linecap: %s; stroke-linejoin: %s;',
$color->red,
$color->green,
$color->blue,
$thickness,
1 - ( $color->alpha / 255 ),
$this->options->strokeLineCap,
$this->options->strokeLineJoin
);
}
}
}
/**
* Draws a single polygon
*
* @param mixed $points
* @param ezcGraphColor $color
* @param mixed $filled
* @return void
*/
public function drawPolygon( array $points, ezcGraphColor $color, $filled = true, $thickness = 1 )
{
$this->createDocument();
$lastPoint = end( $points );
$pointString = sprintf( ' M %.4f,%.4f',
$lastPoint->x + $this->options->graphOffset->x,
$lastPoint->y + $this->options->graphOffset->y
);
foreach ( $points as $point )
{
$pointString .= sprintf( ' L %.4f,%.4f',
$point->x + $this->options->graphOffset->x,
$point->y + $this->options->graphOffset->y
);
}
$pointString .= ' z ';
$path = $this->dom->createElement( 'path' );
$path->setAttribute( 'd', $pointString );
$path->setAttribute(
'style',
$this->getStyle( $color, $filled, $thickness )
);
$path->setAttribute( 'id', $id = ( $this->options->idPrefix . 'Polygon_' . ++$this->elementID ) );
$this->elements->appendChild( $path );
return $id;
}
/**
* Draws a single line
*
* @param ezcGraphCoordinate $start
* @param ezcGraphCoordinate $end
* @param ezcGraphColor $color
* @return void
*/
public function drawLine( ezcGraphCoordinate $start, ezcGraphCoordinate $end, ezcGraphColor $color, $thickness = 1 )
{
$this->createDocument();
$pointString = sprintf( ' M %.4f,%.4f L %.4f,%.4f',
$start->x + $this->options->graphOffset->x,
$start->y + $this->options->graphOffset->y,
$end->x + $this->options->graphOffset->x,
$end->y + $this->options->graphOffset->y
);
$path = $this->dom->createElement( 'path' );
$path->setAttribute( 'd', $pointString );
$path->setAttribute(
'style',
$this->getStyle( $color, false, $thickness )
);
$path->setAttribute( 'id', $id = ( $this->options->idPrefix . 'Line_' . ++$this->elementID ) );
$this->elements->appendChild( $path );
return $id;
}
protected function testFitStringInTextBox( $string, ezcGraphCoordinate $position, $width, $height, $size )
{
// Tokenize String
$tokens = preg_split( '/\s+/', $string );
$lines = array( array() );
$line = 0;
foreach ( $tokens as $token )
{
// Add token to tested line
$selectedLine = $lines[$line];
$selectedLine[] = $token;
// Assume characters have the same width as height
$strWidth = $size * strlen( implode( ' ', $selectedLine ) ) * $this->options->assumedCharacterWidth;
// Check if line is too long
if ( $strWidth > $width )
{
if ( count( $selectedLine ) == 1 )
{
// Return false if one single word does not fit into one line
return false;
}
else
{
// Put word in next line instead and reduce available height by used space
$lines[++$line][] = $token;
$height -= $size * ( 1 + $this->options->lineSpacing );
}
}
else
{
// Everything is ok - put token in this line
$lines[$line][] = $token;
}
// Return false if text exceeds vertical limit
if ( $size > $height )
{
return false;
}
}
// Check width of last line
$strWidth = $size * strlen( implode( ' ', $selectedLine ) ) * $this->options->assumedCharacterWidth;
if ( $strWidth > $width ) {
return false;
}
// It seems to fit - return line array
return $lines;
}
/**
* Wrties text in a box of desired size
*
* @param mixed $string
* @param ezcGraphCoordinate $position
* @param mixed $width
* @param mixed $height
* @param ezcGraphColor $color
* @return void
*/
public function drawTextBox( $string, ezcGraphCoordinate $position, $width, $height, $align )
{
// Try to get a font size for the text to fit into the box
$maxSize = min( $height, $this->options->font->maxFontSize );
$result = false;
for ( $size = $maxSize; $size >= $this->options->font->minFontSize; --$size )
{
$result = $this->testFitStringInTextBox( $string, $position, $width, $height, $size );
if ( $result !== false )
{
break;
}
}
$this->options->font->minimalUsedFont = $size;
$this->strings[] = array(
'text' => $result,
'id' => $id = ( $this->options->idPrefix . 'TextBox_' . ++$this->elementID ),
'position' => $position,
'width' => $width,
'height' => $height,
'align' => $align,
'options' => $this->options->font,
);
return $id;
}
protected function drawAllTexts()
{
foreach ( $this->strings as $text )
{
$size = $text['options']->minimalUsedFont;
$font = $text['options']->name;
$completeHeight = count( $text['text'] ) * $size + ( count( $text['text'] ) - 1 ) * $this->options->lineSpacing;
// Calculate y offset for vertical alignement
switch ( true )
{
case ( $text['align'] & ezcGraph::BOTTOM ):
$yOffset = $text['height'] - $completeHeight;
break;
case ( $text['align'] & ezcGraph::MIDDLE ):
$yOffset = ( $text['height'] - $completeHeight ) / 2;
break;
case ( $text['align'] & ezcGraph::TOP ):
default:
$yOffset = 0;
break;
}
// Render text with evaluated font size
foreach ( $text['text'] as $line )
{
$string = implode( ' ', $line );
$text['position']->y += $size;
switch ( true )
{
case ( $text['align'] & ezcGraph::LEFT ):
$position = new ezcGraphCoordinate(
$text['position']->x,
$text['position']->y + $yOffset
);
break;
case ( $text['align'] & ezcGraph::RIGHT ):
$position = new ezcGraphCoordinate(
$text['position']->x + ( $text['width'] - $size * strlen( $string ) * $this->options->assumedCharacterWidth ),
$text['position']->y + $yOffset
);
break;
case ( $text['align'] & ezcGraph::CENTER ):
$position = new ezcGraphCoordinate(
$text['position']->x + ( ( $text['width'] - $size * strlen( $string ) * $this->options->assumedCharacterWidth ) / 2 ),
$text['position']->y + $yOffset
);
break;
}
$textNode = $this->dom->createElement( 'text', $string );
$textNode->setAttribute( 'id', $text['id'] );
$textNode->setAttribute( 'x', $position->x + $this->options->graphOffset->x );
$textNode->setAttribute( 'text-length', ( $size * strlen( $string ) * $this->options->assumedCharacterWidth ) . 'px' );
$textNode->setAttribute( 'y', $position->y + $this->options->graphOffset->y );
$textNode->setAttribute(
'style',
sprintf(
'font-size: %dpx; font-family: %s; fill: #%02x%02x%02x; fill-opacity: %.2f; stroke: none;',
$size,
$text['options']->name,
$text['options']->color->red,
$text['options']->color->green,
$text['options']->color->blue,
1 - ( $text['options']->color->alpha / 255 )
)
);
$this->elements->appendChild( $textNode );
$text['position']->y += $size * $this->options->lineSpacing;
}
}
}
/**
* Draws a sector of cirlce
*
* @param ezcGraphCoordinate $center
* @param mixed $width
* @param mixed $height
* @param mixed $startAngle
* @param mixed $endAngle
* @param ezcGraphColor $color
* @return void
*/
public function drawCircleSector( ezcGraphCoordinate $center, $width, $height, $startAngle, $endAngle, ezcGraphColor $color, $filled = true )
{
$this->createDocument();
// Normalize angles
if ( $startAngle > $endAngle )
{
$tmp = $startAngle;
$startAngle = $endAngle;
$endAngle = $tmp;
}
// We need the radius
$width /= 2;
$height /= 2;
$Xstart = $center->x + $this->options->graphOffset->x + $width * cos( ( -$startAngle / 180 ) * M_PI );
$Ystart = $center->y + $this->options->graphOffset->y + $height * sin( ( $startAngle / 180 ) * M_PI );
$Xend = $center->x + $this->options->graphOffset->x + $width * cos( ( -( $endAngle ) / 180 ) * M_PI );
$Yend = $center->y + $this->options->graphOffset->y + $height * sin( ( ( $endAngle ) / 180 ) * M_PI );
$arc = $this->dom->createElement( 'path' );
$arc->setAttribute('d', sprintf('M %.2f,%.2f L %.2f,%.2f A %.2f,%.2f 0 %d,1 %.2f,%.2f z',
// Middle
$center->x + $this->options->graphOffset->x, $center->y + $this->options->graphOffset->y,
// Startpoint
$Xstart, $Ystart,
// Radius
$width, $height,
// SVG-Stuff
( $endAngle - $startAngle ) > 180,
// Endpoint
$Xend, $Yend
)
);
$arc->setAttribute(
'style',
$this->getStyle( $color, $filled, 1 )
);
$arc->setAttribute( 'id', $id = ( $this->options->idPrefix . 'CircleSector_' . ++$this->elementID ) );
$this->elements->appendChild( $arc );
return $id;
}
/**
* Draws a circular arc
*
* @param ezcGraphCoordinate $center Center of ellipse
* @param integer $width Width of ellipse
* @param integer $height Height of ellipse
* @param integer $size Height of border
* @param float $startAngle Starting angle of circle sector
* @param float $endAngle Ending angle of circle sector
* @param ezcGraphColor $color Color of Border
* @return void
*/
public function drawCircularArc( ezcGraphCoordinate $center, $width, $height, $size, $startAngle, $endAngle, ezcGraphColor $color, $filled = true )
{
$this->createDocument();
// Normalize angles
if ( $startAngle > $endAngle )
{
$tmp = $startAngle;
$startAngle = $endAngle;
$endAngle = $tmp;
}
if ( ( $endAngle - $startAngle > 180 ) ||
( ( $startAngle % 180 != 0) && ( $endAngle % 180 != 0) && ( ( $startAngle % 360 > 180 ) XOR ( $endAngle % 360 > 180 ) ) ) )
{
// Border crosses he 180 degrees border
$intersection = floor( $endAngle / 180 ) * 180;
while ( $intersection >= $endAngle )
{
$intersection -= 180;
}
$this->drawCircularArc( $center, $width, $height, $size, $startAngle, $intersection, $color, $filled );
$this->drawCircularArc( $center, $width, $height, $size, $intersection, $endAngle, $color, $filled );
return;
}
// We need the radius
$width /= 2;
$height /= 2;
$Xstart = $center->x + $this->options->graphOffset->x + $width * cos( -( $startAngle / 180 ) * M_PI );
$Ystart = $center->y + $this->options->graphOffset->y + $height * sin( ( $startAngle / 180 ) * M_PI );
$Xend = $center->x + $this->options->graphOffset->x + $width * cos( ( -( $endAngle ) / 180 ) * M_PI );
$Yend = $center->y + $this->options->graphOffset->y + $height * sin( ( ( $endAngle ) / 180 ) * M_PI );
if ( $filled === true )
{
$arc = $this->dom->createElement( 'path' );
$arc->setAttribute('d', sprintf( 'M %.2f,%.2f A %.2f,%.2f 0 %d,0 %.2f,%.2f L %.2f,%.2f A %.2f,%2f 0 %d,1 %.2f,%.2f z',
// Endpoint low
$Xend, $Yend + $size,
// Radius
$width, $height,
// SVG-Stuff
( $endAngle - $startAngle ) > 180,
// Startpoint low
$Xstart, $Ystart + $size,
// Startpoint
$Xstart, $Ystart,
// Radius
$width, $height,
// SVG-Stuff
( $endAngle - $startAngle ) > 180,
// Endpoint
$Xend, $Yend
)
);
}
else
{
$arc = $this->dom->createElement( 'path' );
$arc->setAttribute('d', sprintf( 'M %.2f,%.2f A %.2f,%.2f 0 %d,1 %.2f,%.2f',
// Startpoint
$Xstart, $Ystart,
// Radius
$width, $height,
// SVG-Stuff
( $endAngle - $startAngle ) > 180,
// Endpoint
$Xend, $Yend
)
);
}
$arc->setAttribute(
'style',
$this->getStyle( $color, $filled )
);
$arc->setAttribute( 'id', $id = ( $this->options->idPrefix . 'CircularArc_' . ++$this->elementID ) );
$this->elements->appendChild( $arc );
if ( ( $this->options->shadeCircularArc !== false ) &&
$filled )
{
$gradient = new ezcGraphLinearGradient(
new ezcGraphCoordinate(
$center->x - $width,
$center->y
),
new ezcGraphCoordinate(
$center->x + $width,
$center->y
),
ezcGraphColor::fromHex( '#FFFFFF' )->transparent( $this->options->shadeCircularArc * 1.5 ),
ezcGraphColor::fromHex( '#000000' )->transparent( $this->options->shadeCircularArc )
);
$arc = $this->dom->createElement( 'path' );
$arc->setAttribute('d', sprintf( 'M %.2f,%.2f A %.2f,%.2f 0 %d,0 %.2f,%.2f L %.2f,%.2f A %.2f,%2f 0 %d,1 %.2f,%.2f z',
// Endpoint low
$Xend, $Yend + $size,
// Radius
$width, $height,
// SVG-Stuff
( $endAngle - $startAngle ) > 180,
// Startpoint low
$Xstart, $Ystart + $size,
// Startpoint
$Xstart, $Ystart,
// Radius
$width, $height,
// SVG-Stuff
( $endAngle - $startAngle ) > 180,
// Endpoint
$Xend, $Yend
)
);
$arc->setAttribute(
'style',
$this->getStyle( $gradient, $filled )
);
$this->elements->appendChild( $arc );
}
return $id;
}
/**
* Draws a circle
*
* @param ezcGraphCoordinate $center
* @param mixed $width
* @param mixed $height
* @param ezcGraphColor $color
* @param bool $filled
*
* @return void
*/
public function drawCircle( ezcGraphCoordinate $center, $width, $height, ezcGraphColor $color, $filled = true )
{
$this->createDocument();
$ellipse = $this->dom->createElement('ellipse');
$ellipse->setAttribute( 'cx', $center->x + $this->options->graphOffset->x );
$ellipse->setAttribute( 'cy', $center->y + $this->options->graphOffset->y );
$ellipse->setAttribute( 'rx', $width / 2 );
$ellipse->setAttribute( 'ry', $height / 2 );
$ellipse->setAttribute(
'style',
$this->getStyle( $color, $filled, 1 )
);
$ellipse->setAttribute( 'id', $id = ( $this->options->idPrefix . 'Circle_' . ++$this->elementID ) );
$this->elements->appendChild( $ellipse );
return $id;
}
/**
* Draws a imagemap of desired size
*
* @param mixed $file
* @param ezcGraphCoordinate $position
* @param mixed $width
* @param mixed $height
* @return void
*/
public function drawImage( $file, ezcGraphCoordinate $position, $width, $height )
{
$this->createDocument();
$data = getimagesize( $file );
$image = $this->dom->createElement( 'image' );
$image->setAttribute( 'x', $position->x + $this->options->graphOffset->x );
$image->setAttribute( 'y', $position->y + $this->options->graphOffset->y );
$image->setAttribute( 'width', $width . 'px' );
$image->setAttribute( 'height', $height . 'px' );
$image->setAttributeNS(
'http://www.w3.org/1999/xlink',
'xlink:href',
sprintf( 'data:%s;base64,%s',
$data['mime'],
base64_encode( file_get_contents( $file ) )
)
);
$this->elements->appendChild( $image );
$image->setAttribute( 'id', $id = ( $this->options->idPrefix . 'Image_' . ++$this->elementID ) );
return $id;
}
/**
* Finally save image
*
* @param mixed $file
* @return void
*/
public function render ( $file )
{
$this->createDocument();
$this->drawAllTexts();
$this->dom->save( $file );
}
}
?>
|