1: <?php
2: /**
3: * LICENSE (BSD)
4: *
5: * Copyright (c) 2013, Gerd Christian Kunze
6: * All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions are
10: * met:
11: *
12: * * Redistributions of source code must retain the above copyright
13: * notice, this list of conditions and the following disclaimer.
14: *
15: * * Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: *
19: * * Neither the name of Gerd Christian Kunze nor the names of the
20: * contributors may be used to endorse or promote products derived from
21: * this software without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24: * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34: *
35: * Y
36: * 27.03.2013 09:27
37: */
38: namespace MOC\Module\Office\Chart\Axis;
39: use MOC\Api;
40: use MOC\Generic\Device\Module;
41:
42: /**
43: *
44: */
45: class Y implements Module {
46:
47: /**
48: * Get Dependencies
49: *
50: * @static
51: * @return \MOC\Core\Depending
52: */
53: public static function InterfaceDepending() {
54: return Api::Core()->Depending();
55: }
56:
57: /**
58: * Get Singleton/Instance
59: *
60: * @static
61: * @return Y
62: */
63: public static function InterfaceInstance() {
64: return new Y();
65: }
66:
67: /**
68: * Get Changelog
69: *
70: * @static
71: * @return \MOC\Core\Changelog
72: */
73: public static function InterfaceChangelog() {
74: return Api::Core()->Changelog()->Create( __CLASS__ );
75: }
76:
77: /*
78: xaxis, yaxis: {
79: mode: null or "time" ("time" requires jquery.flot.time.js plugin)
80: timezone: null, "browser" or timezone (only makes sense for mode: "time")
81:
82: autoscaleMargin: null or number
83:
84: ticks: null or number or ticks array or (fn: axis -> ticks array)
85: tickSize: number or array
86: minTickSize: number or array
87: tickFormatter: (fn: number, object -> string) or string
88: tickDecimals: null or number
89:
90: labelWidth: null or number
91: labelHeight: null or number
92: reserveSpace: null or true
93:
94: tickLength: null or number
95:
96: alignTicksWithAxis: null or number
97: }
98: */
99: private $Configuration = array(
100: 'show' => true,
101: 'alignTicksWithAxis' => false,
102: 'axisLabelFontFamily' => 'sans-serif',
103: 'axisLabelUseCanvas' => true,
104: // 'axisLabelUseHtml' => true,
105: 'axisLabelFontSizePixels' => 11
106: );
107:
108: /**
109: * @param string $Position 'left','right'
110: *
111: * @return Y
112: */
113: public function Position( $Position = 'left' ) {
114: $this->Configuration['position'] = $Position;
115: return $this;
116: }
117:
118: /**
119: * @param string $Label
120: *
121: * @return Y
122: */
123: public function Label( $Label = 'Y-Axis' ) {
124: $this->Configuration['axisLabel'] = $Label;
125: return $this;
126: }
127:
128: /**
129: * @param string $HexColor
130: *
131: * @return Y
132: */
133: public function Color( $HexColor = '#333333' ) {
134: $this->Configuration['color'] = $HexColor;
135: return $this;
136: }
137:
138: /**
139: * @param int $Size
140: *
141: * @return Y
142: */
143: public function FontSize( $Size = 11 ) {
144: //$this->Configuration['axisLabelFontSizePixels'] = $Size;
145: $this->Configuration['font']['size'] = $Size;
146: return $this;
147: }
148:
149: /**
150: * @param string $Style
151: *
152: * @return Y
153: */
154: public function FontStyle( $Style = 'italic' ) {
155: $this->Configuration['font']['style'] = $Style;
156: return $this;
157: }
158:
159: /**
160: * @param string $Weight
161: *
162: * @return Y
163: */
164: public function FontWeight( $Weight = 'bold' ) {
165: $this->Configuration['font']['weight'] = $Weight;
166: return $this;
167: }
168:
169: /**
170: * @param string $Family
171: *
172: * @return Y
173: */
174: public function FontFamily( $Family = 'sans-serif' ) {
175: //$this->Configuration['axisLabelFontFamily'] = $Family;
176: $this->Configuration['font']['family'] = $Family;
177: return $this;
178: }
179:
180: /**
181: * @param string $Variant
182: *
183: * @return Y
184: */
185: public function FontVariant( $Variant = 'small-caps' ) {
186: $this->Configuration['font']['variant'] = $Variant;
187: return $this;
188: }
189:
190: /**
191: * @param string $HexColor
192: *
193: * @return Y
194: */
195: public function FontColor( $HexColor = '#333333' ) {
196: $this->Configuration['font']['color'] = $HexColor;
197: return $this;
198: }
199:
200: /**
201: * @return Y
202: */
203: public function ScaleToLog() {
204: $this->Configuration['transform'] = 'function (v) { return Math.log(v); }';
205: $this->Configuration['inverseTransform'] = 'function (v) { return Math.exp(v); }';
206: return $this;
207: }
208:
209: /**
210: * @return Y
211: */
212: public function ScaleToCategory() {
213: $this->Configuration['mode'] = "categories";
214: $this->Configuration['tickLength'] = 0;
215: return $this;
216: }
217:
218:
219: /**
220: * @param null|int|float $Minimum
221: *
222: * @return Y
223: */
224: public function ScaleMinimum( $Minimum = null ) {
225: $this->Configuration['min'] = $Minimum;
226: return $this;
227: }
228:
229: /**
230: * @param null|int|float $Maximum
231: *
232: * @return Y
233: */
234: public function ScaleMaximum( $Maximum = null ) {
235: $this->Configuration['max'] = $Maximum;
236: return $this;
237: }
238:
239: /**
240: * @param string $HexColor
241: *
242: * @return Y
243: */
244: public function TickColor( $HexColor = '#333333' ) {
245: $this->Configuration['tickColor'] = $HexColor;
246: return $this;
247: }
248:
249: /**
250: * @param int $Precision
251: *
252: * @return Y
253: */
254: public function TickFormatDecimal( $Precision = 2 ) {
255: $this->Configuration['tickDecimals'] = $Precision;
256: $this->Configuration['tickFormatter'] = 'function formatter( val, axis ) { return val.toFixed( axis.tickDecimals ); }';
257: return $this;
258: }
259:
260: /**
261: * @param int|float $Tick
262: * @param string $Label
263: *
264: * @return $this
265: */
266: public function TickFormatLabel( $Tick, $Label ) {
267: $this->Configuration['ticks'][$Tick] = $Label;
268: return $this;
269: }
270:
271: /**
272: * @return string
273: */
274: public function _getConfiguration() {
275:
276: // Fix: ticks object => array
277: if( isset( $this->Configuration['ticks'] ) && is_array( $this->Configuration['ticks'] ) ) {
278: $this->Configuration['ticks'] = json_encode(
279: array_map(
280: function($key, $value) { return array($key, $value); },
281: array_keys( $this->Configuration['ticks'] ),
282: array_values( $this->Configuration['ticks'] )
283: )
284: );
285: }
286:
287: $Data = json_encode( $this->Configuration, JSON_FORCE_OBJECT );
288:
289: // Fix: string is function
290: $Data = preg_replace( '!"(function[^{]+{.*?})"(,|})!is', '${1}${2}', $Data );
291:
292: return $Data;
293: }
294: }
295: