Skip to content

Commit

Permalink
Register chartjs-adapter-date-fns-script. Improve support for the cha…
Browse files Browse the repository at this point in the history
…rtjs shortcode for beginYAxisAt0 #15
  • Loading branch information
bobbingwide committed Dec 24, 2021
1 parent 6e14cf8 commit a187ee4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions sb-chart-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ function sb_chart_block_array_get( $array, $index, $default=null ) {
*/
function sb_chart_block_enqueue_scripts() {
wp_enqueue_script( "chartjs-script" );
// @TODO Make optional when using the time scale.
wp_enqueue_script( 'chartjs-adapter-date-fns-script');
}

/**
Expand All @@ -152,8 +154,21 @@ function sb_chart_block_register_scripts() {
}
$file_url = plugin_dir_url( __FILE__ ) . $file;
wp_register_script( "chartjs-script", $file_url, null, $version, true );

if ( defined( 'SCRIPT_DEBUG') && SCRIPT_DEBUG ) {
$file = 'js/chartjs-adapter-date-fns.bundle.min.js';
$version = filemtime( __DIR__ . '/' . $file );
} else {
$file = 'js/chartjs-adapter-date-fns.bundle.min.js';
$version = null;
}
$file_url = plugin_dir_url( __FILE__ ) . $file;
wp_register_script( "chartjs-adapter-date-fns-script", $file_url, null, $version, true );

}



/**
* Enqueues styles - if needed.
*/
Expand All @@ -169,6 +184,7 @@ function sb_chart_enqueue_styles() {
* @return string
*/
function sb_chart_block_shortcode( $atts, $content, $tag ) {
$atts['beginYAxisAt0'] = sb_chart_block_array_get( $atts, 'beginyaxisat0', 'false' );
if ( $content ) {
require_once __DIR__ . '/libs/class-sb-chart-block.php';
$sb_chart_block = new SB_Chart_Block();
Expand Down

0 comments on commit a187ee4

Please sign in to comment.