1: <?php
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: namespace MOC\Module\Office;
39: use MOC\Api;
40: use MOC\Generic\Device\Module;
41:
42: 43: 44:
45: class Chart implements Module{
46: 47: 48: 49: 50: 51:
52: public static function InterfaceInstance() {
53: return new Chart();
54: }
55:
56: 57: 58: 59: 60: 61:
62: public static function InterfaceChangelog() {
63: return Api::Core()->Changelog()->Create( __CLASS__ );
64: }
65:
66: 67: 68: 69: 70: 71:
72: public static function InterfaceDepending() {
73: return Api::Core()->Depending();
74: }
75:
76: 77: 78: 79: 80: 81:
82: public function Setup( $ExCanvas = true, $jQuery = false ) {
83: $Script = '';
84: if( $ExCanvas ) {
85: $Script .= '<script type="text/javascript" src="'.
86: Api::Core()->Proxy()->Url(
87: Api::Core()->Drive()->File()->Handle( __DIR__.'/../../Extension/Flot/3rdParty/excanvas.min.js' )
88: ).'"></script>';
89: }
90: if( $jQuery ) {
91: $Script .= '<script type="text/javascript" src="'.
92: Api::Core()->Proxy()->Url(
93: Api::Core()->Drive()->File()->Handle( __DIR__.'/../../Extension/Flot/3rdParty/jquery.js' )
94: ).'"></script>';
95: }
96: $Script .= '<script type="text/javascript" src="'.Api::Core()->Proxy()->Url( Api::Core()->Drive()->File()->Handle(
97: __DIR__.'/../../Extension/Flot/3rdParty/jquery.flot.js'
98: )).'"></script>';
99:
100: $Script .= '<script type="text/javascript" src="'.Api::Core()->Proxy()->Url( Api::Core()->Drive()->File()->Handle(
101: __DIR__.'/../../Extension/Flot/3rdParty/jquery.flot.categories.js'
102: )).'"></script>';
103: $Script .= '<script type="text/javascript" src="'.Api::Core()->Proxy()->Url( Api::Core()->Drive()->File()->Handle(
104: __DIR__.'/../../Extension/Flot/3rdParty/jquery.flot.navigate.js'
105: )).'"></script>';
106: $Script .= '<script type="text/javascript" src="'.Api::Core()->Proxy()->Url( Api::Core()->Drive()->File()->Handle(
107: __DIR__.'/../../Extension/Flot/3rdParty/jquery.flot.threshold.js'
108: )).'"></script>';
109:
110: $Script .= '<script type="text/javascript" src="'.Api::Core()->Proxy()->Url( Api::Core()->Drive()->File()->Handle(
111: __DIR__.'/../../Extension/Flot/3rdParty/Plugins/flot.axislabels/jquery.flot.axislabels.js'
112: )).'"></script>';
113: return $Script;
114: }
115:
116:
117: private static $Container = null;
118:
119: private static $Grid = null;
120:
121: private static $Axis = null;
122:
123: private static $Data = null;
124:
125: private static $Legend = null;
126:
127: 128: 129:
130: public function Container() {
131: if( self::$Container === null ) {
132: self::$Container = Chart\Container::InterfaceInstance();
133: }
134: return self::$Container;
135: }
136:
137: 138: 139:
140: public function Grid() {
141: if( self::$Grid === null ) {
142: self::$Grid = Chart\Grid::InterfaceInstance();
143: }
144: return self::$Grid;
145: }
146:
147: 148: 149:
150: public function Data() {
151: if( self::$Data === null ) {
152: self::$Data = Chart\Data::InterfaceInstance();
153: }
154: return self::$Data;
155: }
156:
157: 158: 159:
160: public function Axis() {
161: if( self::$Axis === null ) {
162: self::$Axis = Chart\Axis::InterfaceInstance();
163: }
164: return self::$Axis;
165: }
166:
167: public function Legend() {
168:
169: }
170:
171: 172: 173:
174: public function Render() {
175:
176: $SeriesList = Api::Module()->Office()->Chart()->Data()->_getSeries();
177: $DataList = array();
178:
179: foreach( (array)$SeriesList as $Label => $Data ) {
180:
181: $Data = json_encode( $Data, JSON_FORCE_OBJECT );
182: $Data = str_replace( ',', "],[", $Data );
183: $Data = str_replace( ":", ",", $Data );
184: $Data = str_replace( '{', '[[', $Data );
185: $Data = str_replace( '}', ']]', $Data );
186: $Data = str_replace( '"', '', $Data );
187:
188: $Data = array( 'label' => $Label, 'data' => $Data );
189:
190: $Data = array_merge( $Data, Api::Module()->Office()->Chart()->Data()->Config( $Label )->_getConfiguration() );
191:
192: $DataList[] = $Data;
193:
194: }
195:
196: $DataList = json_encode( $DataList );
197: $DataList = str_replace( '"[', "[", $DataList );
198: $DataList = str_replace( ']"', "]", $DataList );
199:
200:
201:
202: $Script = '<script type="text/javascript">'.
203: "jQuery('#".$this->Container()->_getIdentifier()."').css({'width':'".$this->Container()->_getWidth()."','height':'".$this->Container()->_getHeight()."'});".
204: "jQuery.plot('#".$this->Container()->_getIdentifier()."', ".$DataList.", {"
205: .$this->Grid()->_getConfiguration().', '
206: .$this->Axis()->_getConfiguration()
207:
208: ."});".
209: '</script>';
210:
211: $this->_doReset();
212:
213: return $Script;
214: }
215:
216: 217: 218: 219: 220:
221: public function _doReset() {
222:
223: self::$Container = null;
224: self::$Grid = null;
225:
226: if( self::$Axis !== null ) {
227: self::$Axis->_doReset();
228: self::$Axis = null;
229: }
230:
231: self::$Data = null;
232: self::$Legend = null;
233:
234: return $this;
235: }
236: }
237: