class-wc-admin-report.php
1 year ago
class-wc-report-coupon-usage.php
5 years ago
class-wc-report-customer-list.php
9 months ago
class-wc-report-customers.php
9 months ago
class-wc-report-downloads.php
5 years ago
class-wc-report-low-in-stock.php
5 years ago
class-wc-report-most-stocked.php
5 years ago
class-wc-report-out-of-stock.php
5 years ago
class-wc-report-sales-by-category.php
2 years ago
class-wc-report-sales-by-date.php
1 year ago
class-wc-report-sales-by-product.php
3 months ago
class-wc-report-stock.php
1 year ago
class-wc-report-taxes-by-code.php
1 year ago
class-wc-report-taxes-by-date.php
1 year ago
class-wc-report-coupon-usage.php
572 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Coupon usage report functionality |
| 4 | * |
| 5 | * @package WooCommerce\Admin\Reports |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; // Exit if accessed directly. |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * WC_Report_Coupon_Usage |
| 14 | * |
| 15 | * @package WooCommerce\Admin\Reports |
| 16 | * @version 2.1.0 |
| 17 | */ |
| 18 | class WC_Report_Coupon_Usage extends WC_Admin_Report { |
| 19 | |
| 20 | /** |
| 21 | * Chart colors. |
| 22 | * |
| 23 | * @var array |
| 24 | */ |
| 25 | public $chart_colours = array(); |
| 26 | |
| 27 | /** |
| 28 | * Coupon codes. |
| 29 | * |
| 30 | * @var array |
| 31 | */ |
| 32 | public $coupon_codes = array(); |
| 33 | |
| 34 | /** |
| 35 | * Constructor. |
| 36 | */ |
| 37 | public function __construct() { |
| 38 | if ( isset( $_GET['coupon_codes'] ) && is_array( $_GET['coupon_codes'] ) ) { |
| 39 | $this->coupon_codes = array_filter( array_map( 'sanitize_text_field', wp_unslash( $_GET['coupon_codes'] ) ) ); |
| 40 | } elseif ( isset( $_GET['coupon_codes'] ) ) { |
| 41 | $this->coupon_codes = array_filter( array( sanitize_text_field( wp_unslash( $_GET['coupon_codes'] ) ) ) ); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Get the legend for the main chart sidebar. |
| 47 | * |
| 48 | * @return array |
| 49 | */ |
| 50 | public function get_chart_legend() { |
| 51 | $legend = array(); |
| 52 | |
| 53 | $total_discount_query = array( |
| 54 | 'data' => array( |
| 55 | 'discount_amount' => array( |
| 56 | 'type' => 'order_item_meta', |
| 57 | 'order_item_type' => 'coupon', |
| 58 | 'function' => 'SUM', |
| 59 | 'name' => 'discount_amount', |
| 60 | ), |
| 61 | ), |
| 62 | 'where' => array( |
| 63 | array( |
| 64 | 'key' => 'order_item_type', |
| 65 | 'value' => 'coupon', |
| 66 | 'operator' => '=', |
| 67 | ), |
| 68 | ), |
| 69 | 'query_type' => 'get_var', |
| 70 | 'filter_range' => true, |
| 71 | 'order_types' => wc_get_order_types( 'order-count' ), |
| 72 | ); |
| 73 | |
| 74 | $total_coupons_query = array( |
| 75 | 'data' => array( |
| 76 | 'order_item_id' => array( |
| 77 | 'type' => 'order_item', |
| 78 | 'order_item_type' => 'coupon', |
| 79 | 'function' => 'COUNT', |
| 80 | 'name' => 'order_coupon_count', |
| 81 | ), |
| 82 | ), |
| 83 | 'where' => array( |
| 84 | array( |
| 85 | 'key' => 'order_item_type', |
| 86 | 'value' => 'coupon', |
| 87 | 'operator' => '=', |
| 88 | ), |
| 89 | ), |
| 90 | 'query_type' => 'get_var', |
| 91 | 'filter_range' => true, |
| 92 | 'order_types' => wc_get_order_types( 'order-count' ), |
| 93 | ); |
| 94 | |
| 95 | if ( ! empty( $this->coupon_codes ) ) { |
| 96 | $coupon_code_query = array( |
| 97 | 'type' => 'order_item', |
| 98 | 'key' => 'order_item_name', |
| 99 | 'value' => $this->coupon_codes, |
| 100 | 'operator' => 'IN', |
| 101 | ); |
| 102 | |
| 103 | $total_discount_query['where'][] = $coupon_code_query; |
| 104 | $total_coupons_query['where'][] = $coupon_code_query; |
| 105 | } |
| 106 | |
| 107 | $total_discount = $this->get_order_report_data( $total_discount_query ); |
| 108 | $total_coupons = absint( $this->get_order_report_data( $total_coupons_query ) ); |
| 109 | |
| 110 | $legend[] = array( |
| 111 | /* translators: %s: discount amount */ |
| 112 | 'title' => sprintf( __( '%s discounts in total', 'woocommerce' ), '<strong>' . wc_price( $total_discount ) . '</strong>' ), |
| 113 | 'color' => $this->chart_colours['discount_amount'], |
| 114 | 'highlight_series' => 1, |
| 115 | ); |
| 116 | |
| 117 | $legend[] = array( |
| 118 | /* translators: %s: coupons amount */ |
| 119 | 'title' => sprintf( __( '%s coupons used in total', 'woocommerce' ), '<strong>' . $total_coupons . '</strong>' ), |
| 120 | 'color' => $this->chart_colours['coupon_count'], |
| 121 | 'highlight_series' => 0, |
| 122 | ); |
| 123 | |
| 124 | return $legend; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Output the report. |
| 129 | */ |
| 130 | public function output_report() { |
| 131 | |
| 132 | $ranges = array( |
| 133 | 'year' => __( 'Year', 'woocommerce' ), |
| 134 | 'last_month' => __( 'Last month', 'woocommerce' ), |
| 135 | 'month' => __( 'This month', 'woocommerce' ), |
| 136 | '7day' => __( 'Last 7 days', 'woocommerce' ), |
| 137 | ); |
| 138 | |
| 139 | $this->chart_colours = array( |
| 140 | 'discount_amount' => '#3498db', |
| 141 | 'coupon_count' => '#d4d9dc', |
| 142 | ); |
| 143 | |
| 144 | $current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : '7day'; |
| 145 | |
| 146 | if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) ) { |
| 147 | $current_range = '7day'; |
| 148 | } |
| 149 | |
| 150 | $this->check_current_range_nonce( $current_range ); |
| 151 | $this->calculate_current_range( $current_range ); |
| 152 | |
| 153 | include WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php'; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Get chart widgets. |
| 158 | * |
| 159 | * @return array |
| 160 | */ |
| 161 | public function get_chart_widgets() { |
| 162 | $widgets = array(); |
| 163 | |
| 164 | $widgets[] = array( |
| 165 | 'title' => '', |
| 166 | 'callback' => array( $this, 'coupons_widget' ), |
| 167 | ); |
| 168 | |
| 169 | return $widgets; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Output coupons widget. |
| 174 | */ |
| 175 | public function coupons_widget() { |
| 176 | ?> |
| 177 | <h4 class="section_title"><span><?php esc_html_e( 'Filter by coupon', 'woocommerce' ); ?></span></h4> |
| 178 | <div class="section"> |
| 179 | <form method="GET"> |
| 180 | <div> |
| 181 | <?php |
| 182 | $used_coupons = $this->get_order_report_data( |
| 183 | array( |
| 184 | 'data' => array( |
| 185 | 'order_item_name' => array( |
| 186 | 'type' => 'order_item', |
| 187 | 'order_item_type' => 'coupon', |
| 188 | 'function' => '', |
| 189 | 'distinct' => true, |
| 190 | 'name' => 'order_item_name', |
| 191 | ), |
| 192 | ), |
| 193 | 'where' => array( |
| 194 | array( |
| 195 | 'key' => 'order_item_type', |
| 196 | 'value' => 'coupon', |
| 197 | 'operator' => '=', |
| 198 | ), |
| 199 | ), |
| 200 | 'query_type' => 'get_col', |
| 201 | 'filter_range' => false, |
| 202 | ) |
| 203 | ); |
| 204 | |
| 205 | if ( ! empty( $used_coupons ) && is_array( $used_coupons ) ) : |
| 206 | ?> |
| 207 | <select id="coupon_codes" name="coupon_codes" class="wc-enhanced-select" data-placeholder="<?php esc_attr_e( 'Choose coupons…', 'woocommerce' ); ?>" style="width:100%;"> |
| 208 | <option value=""><?php esc_html_e( 'All coupons', 'woocommerce' ); ?></option> |
| 209 | <?php |
| 210 | foreach ( $used_coupons as $coupon ) { |
| 211 | echo '<option value="' . esc_attr( $coupon ) . '"' . wc_selected( $coupon, $this->coupon_codes ) . '>' . esc_html( $coupon ) . '</option>'; |
| 212 | } |
| 213 | ?> |
| 214 | </select> |
| 215 | <?php // @codingStandardsIgnoreStart ?> |
| 216 | <button type="submit" class="submit button" value="<?php esc_attr_e( 'Show', 'woocommerce' ); ?>"><?php esc_html_e( 'Show', 'woocommerce' ); ?></button> |
| 217 | <input type="hidden" name="range" value="<?php echo ( ! empty( $_GET['range'] ) ) ? esc_attr( wp_unslash( $_GET['range'] ) ) : ''; ?>" /> |
| 218 | <input type="hidden" name="start_date" value="<?php echo ( ! empty( $_GET['start_date'] ) ) ? esc_attr( wp_unslash( $_GET['start_date'] ) ) : ''; ?>" /> |
| 219 | <input type="hidden" name="end_date" value="<?php echo ( ! empty( $_GET['end_date'] ) ) ? esc_attr( wp_unslash( $_GET['end_date'] ) ) : ''; ?>" /> |
| 220 | <input type="hidden" name="page" value="<?php echo ( ! empty( $_GET['page'] ) ) ? esc_attr( wp_unslash( $_GET['page'] ) ) : ''; ?>" /> |
| 221 | <input type="hidden" name="tab" value="<?php echo ( ! empty( $_GET['tab'] ) ) ? esc_attr( wp_unslash( $_GET['tab'] ) ) : ''; ?>" /> |
| 222 | <input type="hidden" name="report" value="<?php echo ( ! empty( $_GET['report'] ) ) ? esc_attr( wp_unslash( $_GET['report'] ) ) : ''; ?>" /> |
| 223 | <?php // @codingStandardsIgnoreEnd ?> |
| 224 | <?php else : ?> |
| 225 | <span><?php esc_html_e( 'No used coupons found', 'woocommerce' ); ?></span> |
| 226 | <?php endif; ?> |
| 227 | </div> |
| 228 | </form> |
| 229 | </div> |
| 230 | <h4 class="section_title"><span><?php esc_html_e( 'Most popular', 'woocommerce' ); ?></span></h4> |
| 231 | <div class="section"> |
| 232 | <table cellspacing="0"> |
| 233 | <?php |
| 234 | $most_popular = $this->get_order_report_data( |
| 235 | array( |
| 236 | 'data' => array( |
| 237 | 'order_item_name' => array( |
| 238 | 'type' => 'order_item', |
| 239 | 'order_item_type' => 'coupon', |
| 240 | 'function' => '', |
| 241 | 'name' => 'coupon_code', |
| 242 | ), |
| 243 | 'order_item_id' => array( |
| 244 | 'type' => 'order_item', |
| 245 | 'order_item_type' => 'coupon', |
| 246 | 'function' => 'COUNT', |
| 247 | 'name' => 'coupon_count', |
| 248 | ), |
| 249 | ), |
| 250 | 'where' => array( |
| 251 | array( |
| 252 | 'type' => 'order_item', |
| 253 | 'key' => 'order_item_type', |
| 254 | 'value' => 'coupon', |
| 255 | 'operator' => '=', |
| 256 | ), |
| 257 | ), |
| 258 | 'order_by' => 'coupon_count DESC', |
| 259 | 'group_by' => 'order_item_name', |
| 260 | 'limit' => 12, |
| 261 | 'query_type' => 'get_results', |
| 262 | 'filter_range' => true, |
| 263 | ) |
| 264 | ); |
| 265 | |
| 266 | if ( ! empty( $most_popular ) && is_array( $most_popular ) ) { |
| 267 | foreach ( $most_popular as $coupon ) { |
| 268 | echo '<tr class="' . ( in_array( $coupon->coupon_code, $this->coupon_codes ) ? 'active' : '' ) . '"> |
| 269 | <td class="count" width="1%">' . esc_html( $coupon->coupon_count ) . '</td> |
| 270 | <td class="name"><a href="' . esc_url( add_query_arg( 'coupon_codes', $coupon->coupon_code ) ) . '">' . esc_html( $coupon->coupon_code ) . '</a></td> |
| 271 | </tr>'; |
| 272 | } |
| 273 | } else { |
| 274 | echo '<tr><td colspan="2">' . esc_html__( 'No coupons found in range', 'woocommerce' ) . '</td></tr>'; |
| 275 | } |
| 276 | ?> |
| 277 | </table> |
| 278 | </div> |
| 279 | <h4 class="section_title"><span><?php esc_html_e( 'Most discount', 'woocommerce' ); ?></span></h4> |
| 280 | <div class="section"> |
| 281 | <table cellspacing="0"> |
| 282 | <?php |
| 283 | $most_discount = $this->get_order_report_data( |
| 284 | array( |
| 285 | 'data' => array( |
| 286 | 'order_item_name' => array( |
| 287 | 'type' => 'order_item', |
| 288 | 'order_item_type' => 'coupon', |
| 289 | 'function' => '', |
| 290 | 'name' => 'coupon_code', |
| 291 | ), |
| 292 | 'discount_amount' => array( |
| 293 | 'type' => 'order_item_meta', |
| 294 | 'order_item_type' => 'coupon', |
| 295 | 'function' => 'SUM', |
| 296 | 'name' => 'discount_amount', |
| 297 | ), |
| 298 | ), |
| 299 | 'where' => array( |
| 300 | array( |
| 301 | 'type' => 'order_item', |
| 302 | 'key' => 'order_item_type', |
| 303 | 'value' => 'coupon', |
| 304 | 'operator' => '=', |
| 305 | ), |
| 306 | ), |
| 307 | 'order_by' => 'discount_amount DESC', |
| 308 | 'group_by' => 'order_item_name', |
| 309 | 'limit' => 12, |
| 310 | 'query_type' => 'get_results', |
| 311 | 'filter_range' => true, |
| 312 | ) |
| 313 | ); |
| 314 | |
| 315 | if ( ! empty( $most_discount ) && is_array( $most_discount ) ) { |
| 316 | foreach ( $most_discount as $coupon ) { |
| 317 | // @codingStandardsIgnoreStart |
| 318 | echo '<tr class="' . ( in_array( $coupon->coupon_code, $this->coupon_codes ) ? 'active' : '' ) . '"> |
| 319 | <td class="count" width="1%">' . wc_price( $coupon->discount_amount ) . '</td> |
| 320 | <td class="name"><a href="' . esc_url( add_query_arg( 'coupon_codes', $coupon->coupon_code ) ) . '">' . esc_html( $coupon->coupon_code ) . '</a></td> |
| 321 | </tr>'; |
| 322 | // @codingStandardsIgnoreEnd |
| 323 | } |
| 324 | } else { |
| 325 | echo '<tr><td colspan="3">' . esc_html__( 'No coupons found in range', 'woocommerce' ) . '</td></tr>'; |
| 326 | } |
| 327 | ?> |
| 328 | </table> |
| 329 | </div> |
| 330 | <script type="text/javascript"> |
| 331 | jQuery( '.section_title' ).on( 'click', function() { |
| 332 | var next_section = jQuery( this ).next( '.section' ); |
| 333 | |
| 334 | if ( jQuery( next_section ).is( ':visible' ) ) { |
| 335 | return false; |
| 336 | } |
| 337 | |
| 338 | jQuery( '.section:visible' ).slideUp(); |
| 339 | jQuery( '.section_title' ).removeClass( 'open' ); |
| 340 | jQuery( this ).addClass( 'open' ).next( '.section' ).slideDown(); |
| 341 | |
| 342 | return false; |
| 343 | } ); |
| 344 | jQuery( '.section' ).slideUp( 100, function() { |
| 345 | <?php if ( empty( $this->coupon_codes ) ) : ?> |
| 346 | jQuery( '.section_title:eq(1)' ).trigger( 'click' ); |
| 347 | <?php else : ?> |
| 348 | jQuery( '.section_title:eq(0)' ).trigger( 'click' ); |
| 349 | <?php endif; ?> |
| 350 | } ); |
| 351 | </script> |
| 352 | <?php |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * Output an export link. |
| 357 | */ |
| 358 | public function get_export_button() { |
| 359 | $current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : '7day'; |
| 360 | ?> |
| 361 | <a |
| 362 | href="#" |
| 363 | download="report-<?php echo esc_attr( $current_range ); ?>-<?php echo esc_attr( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) ); ?>.csv" |
| 364 | class="export_csv" |
| 365 | data-export="chart" |
| 366 | data-xaxes="<?php esc_attr_e( 'Date', 'woocommerce' ); ?>" |
| 367 | data-groupby="<?php echo esc_attr( $this->chart_groupby ); ?>" |
| 368 | > |
| 369 | <?php esc_html_e( 'Export CSV', 'woocommerce' ); ?> |
| 370 | </a> |
| 371 | <?php |
| 372 | } |
| 373 | |
| 374 | /** |
| 375 | * Get the main chart. |
| 376 | */ |
| 377 | public function get_main_chart() { |
| 378 | global $wp_locale; |
| 379 | |
| 380 | // Get orders and dates in range - we want the SUM of order totals, COUNT of order items, COUNT of orders, and the date. |
| 381 | $order_coupon_counts_query = array( |
| 382 | 'data' => array( |
| 383 | 'order_item_name' => array( |
| 384 | 'type' => 'order_item', |
| 385 | 'order_item_type' => 'coupon', |
| 386 | 'function' => 'COUNT', |
| 387 | 'name' => 'order_coupon_count', |
| 388 | ), |
| 389 | 'post_date' => array( |
| 390 | 'type' => 'post_data', |
| 391 | 'function' => '', |
| 392 | 'name' => 'post_date', |
| 393 | ), |
| 394 | ), |
| 395 | 'where' => array( |
| 396 | array( |
| 397 | 'key' => 'order_item_type', |
| 398 | 'value' => 'coupon', |
| 399 | 'operator' => '=', |
| 400 | ), |
| 401 | ), |
| 402 | 'group_by' => $this->group_by_query, |
| 403 | 'order_by' => 'post_date ASC', |
| 404 | 'query_type' => 'get_results', |
| 405 | 'filter_range' => true, |
| 406 | 'order_types' => wc_get_order_types( 'order-count' ), |
| 407 | ); |
| 408 | |
| 409 | $order_discount_amounts_query = array( |
| 410 | 'data' => array( |
| 411 | 'discount_amount' => array( |
| 412 | 'type' => 'order_item_meta', |
| 413 | 'order_item_type' => 'coupon', |
| 414 | 'function' => 'SUM', |
| 415 | 'name' => 'discount_amount', |
| 416 | ), |
| 417 | 'post_date' => array( |
| 418 | 'type' => 'post_data', |
| 419 | 'function' => '', |
| 420 | 'name' => 'post_date', |
| 421 | ), |
| 422 | ), |
| 423 | 'where' => array( |
| 424 | array( |
| 425 | 'key' => 'order_item_type', |
| 426 | 'value' => 'coupon', |
| 427 | 'operator' => '=', |
| 428 | ), |
| 429 | ), |
| 430 | 'group_by' => $this->group_by_query . ', order_item_name', |
| 431 | 'order_by' => 'post_date ASC', |
| 432 | 'query_type' => 'get_results', |
| 433 | 'filter_range' => true, |
| 434 | 'order_types' => wc_get_order_types( 'order-count' ), |
| 435 | ); |
| 436 | |
| 437 | if ( ! empty( $this->coupon_codes ) ) { |
| 438 | $coupon_code_query = array( |
| 439 | 'type' => 'order_item', |
| 440 | 'key' => 'order_item_name', |
| 441 | 'value' => $this->coupon_codes, |
| 442 | 'operator' => 'IN', |
| 443 | ); |
| 444 | |
| 445 | $order_coupon_counts_query['where'][] = $coupon_code_query; |
| 446 | $order_discount_amounts_query['where'][] = $coupon_code_query; |
| 447 | } |
| 448 | |
| 449 | $order_coupon_counts = $this->get_order_report_data( $order_coupon_counts_query ); |
| 450 | $order_discount_amounts = $this->get_order_report_data( $order_discount_amounts_query ); |
| 451 | |
| 452 | // Prepare data for report. |
| 453 | $order_coupon_counts = $this->prepare_chart_data( $order_coupon_counts, 'post_date', 'order_coupon_count', $this->chart_interval, $this->start_date, $this->chart_groupby ); |
| 454 | $order_discount_amounts = $this->prepare_chart_data( $order_discount_amounts, 'post_date', 'discount_amount', $this->chart_interval, $this->start_date, $this->chart_groupby ); |
| 455 | |
| 456 | // Encode in json format. |
| 457 | $chart_data = wp_json_encode( |
| 458 | array( |
| 459 | 'order_coupon_counts' => array_values( $order_coupon_counts ), |
| 460 | 'order_discount_amounts' => array_values( $order_discount_amounts ), |
| 461 | ) |
| 462 | ); |
| 463 | ?> |
| 464 | <div class="chart-container"> |
| 465 | <div class="chart-placeholder main"></div> |
| 466 | </div> |
| 467 | <script type="text/javascript"> |
| 468 | var main_chart; |
| 469 | |
| 470 | jQuery(function(){ |
| 471 | var order_data = JSON.parse( decodeURIComponent( '<?php echo rawurlencode( $chart_data ); ?>' ) ); |
| 472 | |
| 473 | var drawGraph = function( highlight ) { |
| 474 | var series = [ |
| 475 | { |
| 476 | label: "<?php echo esc_js( __( 'Number of coupons used', 'woocommerce' ) ); ?>", |
| 477 | data: order_data.order_coupon_counts, |
| 478 | color: '<?php echo esc_js( $this->chart_colours['coupon_count'] ); ?>', |
| 479 | bars: { fillColor: '<?php echo esc_js( $this->chart_colours['coupon_count'] ); ?>', fill: true, show: true, lineWidth: 0, barWidth: <?php echo esc_js( $this->barwidth ); ?> * 0.5, align: 'center' }, |
| 480 | shadowSize: 0, |
| 481 | hoverable: false |
| 482 | }, |
| 483 | { |
| 484 | label: "<?php echo esc_js( __( 'Discount amount', 'woocommerce' ) ); ?>", |
| 485 | data: order_data.order_discount_amounts, |
| 486 | yaxis: 2, |
| 487 | color: '<?php echo esc_js( $this->chart_colours['discount_amount'] ); ?>', |
| 488 | points: { show: true, radius: 5, lineWidth: 3, fillColor: '#fff', fill: true }, |
| 489 | lines: { show: true, lineWidth: 4, fill: false }, |
| 490 | shadowSize: 0, |
| 491 | <?php echo $this->get_currency_tooltip(); ?><?php // @codingStandardsIgnoreLine ?> |
| 492 | } |
| 493 | ]; |
| 494 | |
| 495 | if ( highlight !== 'undefined' && series[ highlight ] ) { |
| 496 | highlight_series = series[ highlight ]; |
| 497 | |
| 498 | highlight_series.color = '#9c5d90'; |
| 499 | |
| 500 | if ( highlight_series.bars ) |
| 501 | highlight_series.bars.fillColor = '#9c5d90'; |
| 502 | |
| 503 | if ( highlight_series.lines ) { |
| 504 | highlight_series.lines.lineWidth = 5; |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | main_chart = jQuery.plot( |
| 509 | jQuery('.chart-placeholder.main'), |
| 510 | series, |
| 511 | { |
| 512 | legend: { |
| 513 | show: false |
| 514 | }, |
| 515 | grid: { |
| 516 | color: '#aaa', |
| 517 | borderColor: 'transparent', |
| 518 | borderWidth: 0, |
| 519 | hoverable: true |
| 520 | }, |
| 521 | xaxes: [ { |
| 522 | color: '#aaa', |
| 523 | position: "bottom", |
| 524 | tickColor: 'transparent', |
| 525 | mode: "time", |
| 526 | timeformat: "<?php echo ( 'day' === $this->chart_groupby ) ? '%d %b' : '%b'; ?>", |
| 527 | monthNames: JSON.parse( decodeURIComponent( '<?php echo rawurlencode( wp_json_encode( array_values( $wp_locale->month_abbrev ) ) ); ?>' ) ), |
| 528 | tickLength: 1, |
| 529 | minTickSize: [1, "<?php echo esc_js( $this->chart_groupby ); ?>"], |
| 530 | font: { |
| 531 | color: "#aaa" |
| 532 | } |
| 533 | } ], |
| 534 | yaxes: [ |
| 535 | { |
| 536 | min: 0, |
| 537 | minTickSize: 1, |
| 538 | tickDecimals: 0, |
| 539 | color: '#ecf0f1', |
| 540 | font: { color: "#aaa" } |
| 541 | }, |
| 542 | { |
| 543 | position: "right", |
| 544 | min: 0, |
| 545 | tickDecimals: 2, |
| 546 | alignTicksWithAxis: 1, |
| 547 | color: 'transparent', |
| 548 | font: { color: "#aaa" } |
| 549 | } |
| 550 | ], |
| 551 | } |
| 552 | ); |
| 553 | |
| 554 | jQuery('.chart-placeholder').trigger( 'resize' ); |
| 555 | } |
| 556 | |
| 557 | drawGraph(); |
| 558 | |
| 559 | jQuery('.highlight_series').on( 'mouseenter', |
| 560 | function() { |
| 561 | drawGraph( jQuery(this).data('series') ); |
| 562 | } ).on( 'mouseleave', |
| 563 | function() { |
| 564 | drawGraph(); |
| 565 | } |
| 566 | ); |
| 567 | }); |
| 568 | </script> |
| 569 | <?php |
| 570 | } |
| 571 | } |
| 572 |