PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.5.12
GiveWP – Donation Plugin and Fundraising Platform v2.5.12
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / reports / class-give-graph.php
give / includes / admin / reports Last commit date
class-donor-reports-table.php 7 years ago class-earnings-report.php 7 years ago class-form-reports-table.php 7 years ago class-forms-report.php 7 years ago class-gateways-report.php 7 years ago class-gateways-reports-table.php 7 years ago class-give-graph.php 7 years ago graphing.php 7 years ago reports.php 7 years ago
class-give-graph.php
340 lines
1 <?php
2 /**
3 * Graphs
4 *
5 * This class handles building pretty report graphs
6 *
7 * @package Give
8 * @subpackage Admin/Reports
9 * @copyright Copyright (c) 2012, GiveWP
10 * @license https://opensource.org/licenses/gpl-license GNU Public License
11 * @since 1.0
12 */
13
14 // Exit if accessed directly.
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 /**
20 * Give_Graph Class
21 *
22 * @since 1.0
23 */
24 class Give_Graph {
25
26 /*
27
28 Simple example:
29
30 data format for each point: array( location on x, location on y )
31
32 $data = array(
33
34 'Label' => array(
35 array( 1, 5 ),
36 array( 3, 8 ),
37 array( 10, 2 )
38 ),
39
40 'Second Label' => array(
41 array( 1, 7 ),
42 array( 4, 5 ),
43 array( 12, 8 )
44 )
45 );
46
47 $graph = new Give_Graph( $data );
48 $graph->display();
49
50 */
51
52 /**
53 * Data to graph
54 *
55 * @var array
56 * @since 1.0
57 */
58 private $data;
59
60 /**
61 * Unique ID for the graph
62 *
63 * @var string
64 * @since 1.0
65 */
66 private $id = '';
67
68 /**
69 * Graph options
70 *
71 * @var array
72 * @since 1.0
73 */
74 private $options = array();
75
76 /**
77 * Get things started
78 *
79 * @since 1.0
80 *
81 * @param array $_data
82 * @param array $options
83 */
84 public function __construct( $_data, $options = array() ) {
85
86 $this->data = $_data;
87
88 // Generate unique ID
89 $this->id = md5( rand() );
90
91 // Setup default options;
92 $this->options = apply_filters( 'give_graph_args', array(
93 'y_mode' => null,
94 'x_mode' => null,
95 'y_decimals' => 0,
96 'x_decimals' => 0,
97 'y_position' => 'right',
98 'time_format' => '%d/%b',
99 'ticksize_unit' => 'day',
100 'ticksize_num' => 1,
101 'multiple_y_axes' => false,
102 'bgcolor' => '#f9f9f9',
103 'bordercolor' => '#eee',
104 'color' => '#bbb',
105 'borderwidth' => 1,
106 'bars' => true,
107 'lines' => false,
108 'points' => true,
109 'dataType' => array()
110 ) );
111
112 $this->options = wp_parse_args( $options, $this->options );
113 }
114
115 /**
116 * Set an option
117 *
118 * @param $key The option key to set
119 * @param $value The value to assign to the key
120 *
121 * @since 1.0
122 */
123 public function set( $key, $value ) {
124 $this->options[ $key ] = $value;
125 }
126
127 /**
128 * Get an option
129 *
130 * @param $key The option key to get
131 *
132 * @since 1.0
133 */
134 public function get( $key ) {
135 return isset( $this->options[ $key ] ) ? $this->options[ $key ] : false;
136 }
137
138 /**
139 * Get graph data
140 *
141 * @since 1.0
142 */
143 public function get_data() {
144 return apply_filters( 'give_get_graph_data', $this->data, $this );
145 }
146
147 /**
148 * Load the graphing library script
149 *
150 * @since 1.0
151 */
152 public function load_scripts() {
153 // Use minified libraries if SCRIPT_DEBUG is turned off
154 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
155
156 wp_register_script( 'jquery-flot-orderbars', GIVE_PLUGIN_URL . 'assets/js/plugins/jquery.flot.orderBars' . $suffix . '.js', array('jquery-flot'), GIVE_VERSION );
157 wp_enqueue_script( 'jquery-flot-orderbars' );
158
159 wp_register_script( 'jquery-flot-time', GIVE_PLUGIN_URL . 'assets/js/plugins/jquery.flot.time' . $suffix . '.js', array('jquery-flot'), GIVE_VERSION );
160 wp_enqueue_script( 'jquery-flot-time' );
161
162 wp_register_script( 'jquery-flot-resize', GIVE_PLUGIN_URL . 'assets/js/plugins/jquery.flot.resize' . $suffix . '.js', array('jquery-flot'), GIVE_VERSION );
163 wp_enqueue_script( 'jquery-flot-resize' );
164
165 wp_register_script( 'jquery-flot', GIVE_PLUGIN_URL . 'assets/js/plugins/jquery.flot' . $suffix . '.js', false, GIVE_VERSION );
166 wp_enqueue_script( 'jquery-flot' );
167
168 }
169
170 /**
171 * Build the graph and return it as a string
172 *
173 * @var array
174 * @since 1.0
175 * @return string
176 */
177 public function build_graph() {
178
179 $yaxis_count = 1;
180
181 ob_start();
182 ?>
183 <script type="text/javascript">
184
185 jQuery( document ).ready( function ( $ ) {
186 $.plot(
187 $( "#give-graph-<?php echo $this->id; ?>" ),
188 [
189 <?php
190 $order = 0;
191 foreach( $this->get_data() as $label => $data ) :
192 ?>
193 {
194 label : "<?php echo esc_attr( $label ); ?>",
195 id : "<?php echo sanitize_key( $label ); ?>",
196 dataType : '<?php echo ( ! empty( $this->options['dataType'][$order] ) ? $this->options['dataType'][$order] : 'count' ); ?>',
197 // data format is: [ point on x, value on y ]
198 data : [<?php foreach( $data as $point ) { echo '[' . implode( ',', $point ) . '],'; } ?>],
199 points: {
200 show: <?php echo $this->options['points'] ? 'true' : 'false'; ?>,
201 },
202 bars : {
203 show : <?php echo $this->options['bars'] ? 'true' : 'false'; ?>,
204 barWidth: 100,
205                 order: <?php echo $order++; ?>,
206 align : 'center'
207 },
208 lines : {
209 show : <?php echo $this->options['lines'] ? 'true' : 'false'; ?>,
210 fill : true,
211 fillColor: {colors: [{opacity: 0.4}, {opacity: 0.1}]}
212 },
213 <?php if( $this->options[ 'multiple_y_axes' ] ) : ?>
214 yaxis : <?php echo $yaxis_count; ?>
215 <?php endif; ?>
216
217 },
218
219 <?php $yaxis_count++; endforeach; ?>
220
221 ],
222 {
223 // Options
224 grid: {
225 show : true,
226 aboveData : false,
227 color : "<?php echo $this->options[ 'color' ]; ?>",
228 backgroundColor: "<?php echo $this->options[ 'bgcolor' ]; ?>",
229 borderColor : "<?php echo $this->options[ 'bordercolor' ]; ?>",
230 borderWidth : <?php echo absint( $this->options[ 'borderwidth' ] ); ?>,
231 clickable : false,
232 hoverable : true
233 },
234
235 colors: ["#66bb6a", "#546e7a"], //Give Colors
236
237 xaxis: {
238 mode : "<?php echo $this->options['x_mode']; ?>",
239 timeFormat : "<?php echo $this->options['x_mode'] == 'time' ? $this->options['time_format'] : ''; ?>",
240 tickSize : "<?php echo $this->options['x_mode'] == 'time' ? '' : 1; ?>",
241 <?php if( $this->options['x_mode'] != 'time' ) : ?>
242 tickDecimals: <?php echo $this->options['x_decimals']; ?>
243 <?php endif; ?>
244 },
245 yaxis: {
246 position : 'right',
247 min : 0,
248 mode : "<?php echo $this->options['y_mode']; ?>",
249 timeFormat : "<?php echo $this->options['y_mode'] == 'time' ? $this->options['time_format'] : ''; ?>",
250 <?php if( $this->options['y_mode'] != 'time' ) : ?>
251 tickDecimals: <?php echo $this->options['y_decimals']; ?>,
252 <?php endif; ?>
253 tickFormatter: function(val) {
254 return val.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, give_vars.thousands_separator);
255 },
256 }
257 }
258 );
259
260 function give_flot_tooltip( x, y, contents ) {
261 $( '<div id="give-flot-tooltip">' + contents + '</div>' ).css( {
262 position : 'absolute',
263 display : 'none',
264 top : y + 5,
265 left : x + 5,
266 border : '1px solid #fdd',
267 padding : '2px',
268 'background-color': '#fee',
269 opacity : 0.80
270 } ).appendTo( "body" ).fadeIn( 200 );
271 }
272
273 var previousPoint = null;
274 $( "#give-graph-<?php echo $this->id; ?>" ).bind( "plothover", function ( event, pos, item ) {
275
276 $( "#x" ).text( pos.x.toFixed( 2 ) );
277 $( "#y" ).text( pos.y.toFixed( 2 ) );
278 if ( item ) {
279 if ( previousPoint !== item.dataIndex ) {
280 previousPoint = item.dataIndex;
281 $( "#give-flot-tooltip" ).remove();
282 var x = item.datapoint[0].toFixed( 2 ),
283 y = accounting.formatMoney( item.datapoint[1].toFixed( give_vars.currency_decimals ), '', give_vars.currency_decimals, give_vars.thousands_separator, give_vars.decimal_separator );
284
285 if ( item.series.dataType.length && item.series.dataType === 'amount' ) {
286
287 if ( give_vars.currency_pos === 'before' ) {
288
289 give_flot_tooltip( item.pageX, item.pageY, item.series.label + ' ' + give_vars.currency_sign + y );
290 } else {
291 give_flot_tooltip( item.pageX, item.pageY, item.series.label + ' ' + y + give_vars.currency_sign );
292 }
293 } else {
294 give_flot_tooltip( item.pageX, item.pageY, item.series.label + ' ' + parseInt( y ) );
295 }
296 }
297 } else {
298 $( "#give-flot-tooltip" ).remove();
299 previousPoint = null;
300 }
301 } );
302
303 } );
304
305 </script>
306 <div id="give-graph-<?php echo $this->id; ?>" class="give-graph" style="height: 300px;"></div>
307 <?php
308 return ob_get_clean();
309 }
310
311 /**
312 * Output the final graph
313 *
314 * @since 1.0
315 */
316 public function display() {
317 /**
318 * Fires before displaying the final graph.
319 *
320 * @since 1.0
321 *
322 * @param Give_Graph $this Graph object.
323 */
324 do_action( 'give_before_graph', $this );
325
326 // Build the graph.
327 echo $this->build_graph();
328
329 /**
330 * Fires after displaying the final graph.
331 *
332 * @since 1.0
333 *
334 * @param Give_Graph $this Graph object.
335 */
336 do_action( 'give_after_graph', $this );
337 }
338
339 }
340