GoogleChartIconNote.php
102 lines
| 1 | <?php |
| 2 | |
| 3 | /** @file |
| 4 | * This file is part of Google Chart PHP library. |
| 5 | * |
| 6 | * Copyright (c) 2010 Rémi Lanvin <remi@cloudconnected.fr> |
| 7 | * |
| 8 | * Licensed under the MIT license. |
| 9 | * |
| 10 | * For the full copyright and license information, please view the LICENSE file. |
| 11 | */ |
| 12 | |
| 13 | require_once dirname(__FILE__).'/../GoogleChartIcon.php'; |
| 14 | |
| 15 | /** |
| 16 | * A "Fun style notes with text and optional title". |
| 17 | */ |
| 18 | class GoogleChartIconNote extends GoogleChartIcon |
| 19 | { |
| 20 | const LARGE = 1; |
| 21 | const SMALL = 2; |
| 22 | |
| 23 | const LEFT = 'l'; |
| 24 | const CENTER = 'h'; |
| 25 | const RIGHt = 'r'; |
| 26 | |
| 27 | protected $title = null; |
| 28 | protected $text = null; |
| 29 | protected $type = null; |
| 30 | |
| 31 | protected $size = self::LARGE; |
| 32 | protected $text_color = '000000'; |
| 33 | protected $text_alignment = self::CENTER; |
| 34 | |
| 35 | public function __construct($text, $note_type = 'sticky_y') |
| 36 | { |
| 37 | $this->setText($text); |
| 38 | $this->setType($note_type); |
| 39 | } |
| 40 | |
| 41 | public function setTitle($title) |
| 42 | { |
| 43 | $this->title = $title; |
| 44 | return $this; |
| 45 | } |
| 46 | |
| 47 | public function setText($text) |
| 48 | { |
| 49 | $this->text = $text; |
| 50 | return $this; |
| 51 | } |
| 52 | |
| 53 | public function setType($note_type) |
| 54 | { |
| 55 | $this->type = $note_type; |
| 56 | return $this; |
| 57 | } |
| 58 | |
| 59 | public function setSize($size) |
| 60 | { |
| 61 | $this->size = $size; |
| 62 | return $this; |
| 63 | } |
| 64 | |
| 65 | public function setTextColor($color) |
| 66 | { |
| 67 | $this->text_color = $color; |
| 68 | return $this; |
| 69 | } |
| 70 | |
| 71 | public function setTextAlignment($align) |
| 72 | { |
| 73 | $this->text_alignment = $align; |
| 74 | return $this; |
| 75 | } |
| 76 | |
| 77 | public function computeChst() |
| 78 | { |
| 79 | if ( $this->title === null ) |
| 80 | return 'd_fnote'; |
| 81 | else |
| 82 | return 'd_fnote_title'; |
| 83 | } |
| 84 | |
| 85 | public function computeChld($separator = '|', $eol='|', $escape = '') |
| 86 | { |
| 87 | $str = $this->type |
| 88 | .$separator.$this->size |
| 89 | .$separator.$this->text_color |
| 90 | .$separator.$this->text_alignment |
| 91 | .$separator.($this->title ? $this->title.($this->text?$separator:'') : ''); |
| 92 | |
| 93 | $str .= str_replace( |
| 94 | array("\n","\r", '|','@','=',',',';'), |
| 95 | array($eol, '', $escape.'|', $escape.'@', $escape.'=', $escape.',', $escape.';'), |
| 96 | $this->text |
| 97 | ); |
| 98 | |
| 99 | return $str; |
| 100 | } |
| 101 | } |
| 102 |