summaryrefslogtreecommitdiffstats
path: root/src/options/renderer.php
blob: e7da6e5b9c3326200a763e0fa647fad3ca282d71 (plain)
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
<?php
/**
 * File containing the ezcGraphRenderer2dOptions class
 *
 * 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 //autogentag//
 * @copyright Copyright (C) 2005-2010 eZ Systems AS. All rights reserved.
 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
 */
/**
 * Class containing the basic options for renderers.
 *
 * Renderer options are used to define the general appearance of charts beside
 * the palettes. The renderer transforms chart primitives (like the legend, or
 * one pie slice) into image primitives, which are then rendered by the
 * drivers. The way this transformation is done, and which effects are also
 * rendered is specified by the values in this option class. 
 *
 * The example below shows some basic bar rendering options, which are
 * available in all renderers. You mya want to check the tutorial sections
 * about the renderer, which show example output for more renderer options.
 *
 * <code>
 *   $wikidata = include 'tutorial_wikipedia_data.php';
 *   
 *   $graph = new ezcGraphBarChart();
 *   $graph->title = 'Wikipedia articles';
 *   
 *   // Add data
 *   foreach ( $wikidata as $language => $data )
 *   {
 *       $graph->data[$language] = new ezcGraphArrayDataSet( $data );
 *   }
 *   
 *   // $graph->renderer = new ezcGraphRenderer2d();
 *   
 *   $graph->renderer->options->barMargin = .2;
 *   $graph->renderer->options->barPadding = .2;
 *   
 *   $graph->renderer->options->dataBorder = 0;
 *   
 *   $graph->render( 400, 150, 'tutorial_bar_chart_options.svg' );
 * </code>
 *
 * For additional options, which are special to some chart type you may
 * also want to check the option classes for the repective chart type you
 * are using and the elements of the chart. The chart type dependant option
 * classes are:
 *
 * - ezcGraphLineChartOptions
 * - ezcGraphPieChartOptions
 * - ezcGraphRadarChartOptions
 *
 * There may be additional options dependant on the renderer you are using.
 * You may want to check the extensions of this class:
 *
 * - ezcGraphRenderer2dOptions
 * - ezcGraphRenderer3dOptions
 *
 * @property float $maxLabelHeight
 *           Percent of chart height used as maximum height for pie chart 
 *           labels.
 * @property bool $showSymbol
 *           Indicates wheather to show the line between pie elements and 
 *           labels.
 * @property float $symbolSize
 *           Size of symbols used to connect a label with a pie.
 * @property float $moveOut
 *           Percent to move pie chart elements out of the middle on highlight.
 * @property int $titlePosition
 *           Position of title in a box.
 * @property int $titleAlignement
 *           Alignement of box titles.
 * @property float $dataBorder
 *           Factor to darken border of data elements, like lines, bars and 
 *           pie segments.
 * @property float $barMargin
 *           Percentual distance between bar blocks.
 * @property float $barPadding
 *           Percentual distance between bars.
 * @property float $pieChartOffset
 *           Offset for starting with first pie chart segment in degrees.
 * @property float $legendSymbolGleam
 *           Opacity of gleam in legend symbols
 * @property float $legendSymbolGleamSize
 *           Size of gleam in legend symbols
 * @property float $legendSymbolGleamColor
 *           Color of gleam in legend symbols
 * @property float $pieVerticalSize
 *           Percent of vertical space used for maximum pie chart size.
 * @property float $pieHorizontalSize
 *           Percent of horizontal space used for maximum pie chart size.
 * @property float $pieChartSymbolColor
 *           Color of pie chart symbols
 * @property float $pieChartGleam
 *           Enhance pie chart with gleam on top.
 * @property float $pieChartGleamColor
 *           Color used for gleam on pie charts.
 * @property float $pieChartGleamBorder
 *           Do not draw gleam on an outer border of this size.
 * @property bool $syncAxisFonts
 *           Synchronize fonts of axis. With the defaut true value, the only
 *           the fonts of the yAxis will be used.
 * @property bool $axisEndStyle
 *           Style of axis end markers. Defauls to arrow heads, but you may
 *           also use all symbol constants defined ein the ezcGraph class,
 *           especially ezcGraph::NO_SYMBOL.
 * @property bool $shortAxis
 *           Defines wheather to render the axis extending the chart boundings
 *           or stop them at the chart boundings. Deafults to false.
 * 
 * @version //autogentag//
 * @package Graph
 */
class ezcGraphRendererOptions extends ezcGraphChartOptions
{
    /**
     * Constructor
     * 
     * @param array $options Default option array
     * @return void
     * @ignore
     */
    public function __construct( array $options = array() )
    {
        $this->properties['maxLabelHeight'] = .10;
        $this->properties['showSymbol'] = true;
        $this->properties['symbolSize'] = 6;
        $this->properties['moveOut'] = .1;
        $this->properties['titlePosition'] = ezcGraph::TOP;
        $this->properties['titleAlignement'] = ezcGraph::MIDDLE | ezcGraph::CENTER;
        $this->properties['dataBorder'] = .5;
        $this->properties['barMargin'] = .1;
        $this->properties['barPadding'] = .05;
        $this->properties['pieChartOffset'] = 0;
        $this->properties['pieChartSymbolColor'] = ezcGraphColor::fromHex( '#000000' );
        $this->properties['pieChartGleam'] = false;
        $this->properties['pieChartGleamColor'] = ezcGraphColor::fromHex( '#FFFFFF' );
        $this->properties['pieChartGleamBorder'] = 0;
        $this->properties['legendSymbolGleam'] = false;
        $this->properties['legendSymbolGleamSize'] = .9;
        $this->properties['legendSymbolGleamColor'] = ezcGraphColor::fromHex( '#FFFFFF' );
        $this->properties['pieVerticalSize'] = .5;
        $this->properties['pieHorizontalSize'] = .25;
        $this->properties['syncAxisFonts'] = true;
        $this->properties['axisEndStyle'] = ezcGraph::ARROW;
        $this->properties['shortAxis'] = false;

        parent::__construct( $options );
    }


    /**
     * Set an option value
     * 
     * @param string $propertyName 
     * @param mixed $propertyValue 
     * @throws ezcBasePropertyNotFoundException
     *          If a property is not defined in this class
     * @return void
     * @ignore
     */
    public function __set( $propertyName, $propertyValue )
    {
        switch ( $propertyName )
        {
            case 'dataBorder':
            case 'pieChartGleam':
            case 'legendSymbolGleam':
                if ( $propertyValue !== false &&
                     !is_numeric( $propertyValue ) ||
                     ( $propertyValue < 0 ) || 
                     ( $propertyValue > 1 ) )
                {
                    throw new ezcBaseValueException( $propertyName, $propertyValue, 'false OR 0 <= float <= 1' );
                }

                $this->properties[$propertyName] = ( 
                    $propertyValue === false
                    ? false
                    : (float) $propertyValue );
                break;

            case 'maxLabelHeight':
            case 'moveOut':
            case 'barMargin':
            case 'barPadding':
            case 'legendSymbolGleamSize':
            case 'pieVerticalSize':
            case 'pieHorizontalSize':
                if ( !is_numeric( $propertyValue ) ||
                     ( $propertyValue < 0 ) ||
                     ( $propertyValue > 1 ) )
                {
                    throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= float <= 1' );
                }

                $this->properties[$propertyName] = (float) $propertyValue;
                break;

            case 'symbolSize':
            case 'titlePosition':
            case 'titleAlignement':
            case 'pieChartGleamBorder':
            case 'axisEndStyle':
                if ( !is_numeric( $propertyValue ) ||
                     ( $propertyValue < 0 ) )
                {
                    throw new ezcBaseValueException( $propertyName, $propertyValue, 'int >= 0' );
                }

                $this->properties[$propertyName] = (int) $propertyValue;
                break;

            case 'showSymbol':
            case 'syncAxisFonts':
            case 'shortAxis':
                if ( !is_bool( $propertyValue ) )
                {
                    throw new ezcBaseValueException( $propertyName, $propertyValue, 'bool' );
                }
                $this->properties[$propertyName] = (bool) $propertyValue;
                break;

            case 'pieChartOffset':
                if ( !is_numeric( $propertyValue ) ||
                     ( $propertyValue < 0 ) ||
                     ( $propertyValue > 360 ) )
                {
                    throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= float <= 360' );
                }

                $this->properties[$propertyName] = (float) $propertyValue;
                break;

            case 'pieChartSymbolColor':
            case 'pieChartGleamColor':
            case 'legendSymbolGleamColor':
                $this->properties[$propertyName] = ezcGraphColor::create( $propertyValue );
                break;

            default:
                return parent::__set( $propertyName, $propertyValue );
        }
    }
}

?>
OpenPOWER on IntegriCloud