admin-dashboard.js
6 years ago
admin-post.js
6 years ago
admin-quick-edit.js
6 years ago
admin-settings.js
6 years ago
admin-widgets.js
6 years ago
chart.min.js
6 years ago
frontend.js
6 years ago
gutenberg.min.js
6 years ago
admin-dashboard.js
99 lines
| 1 | ( function ( $ ) { |
| 2 | |
| 3 | // set global options |
| 4 | // Chart.defaults.global.tooltips.titleMarginBottom = 0; |
| 5 | // Chart.defaults.global.tooltips.footerMarginTop = 4; |
| 6 | |
| 7 | window.onload = function () { |
| 8 | updateChart( 'this_month' ); |
| 9 | }; |
| 10 | |
| 11 | function updateChart( period ) { |
| 12 | |
| 13 | var container = document.getElementById( 'pvc_dashboard_container' ); |
| 14 | |
| 15 | if ( $( container ).length > 0 ) { |
| 16 | |
| 17 | $( container ).addClass( 'loading' ).append( '<span class="spinner is-active"></span>' ); |
| 18 | |
| 19 | $.ajax( { |
| 20 | url: pvcArgs.ajaxURL, |
| 21 | type: 'POST', |
| 22 | dataType: 'json', |
| 23 | data: ( { |
| 24 | action: 'pvc_dashboard_chart', |
| 25 | nonce: pvcArgs.nonce, |
| 26 | period: period |
| 27 | } ), |
| 28 | success: function ( args ) { |
| 29 | $( container ).removeClass( 'loading' ); |
| 30 | $( container ).find( '.spinner' ).removeClass( 'is-active' ); |
| 31 | |
| 32 | var config = { |
| 33 | type: 'line', |
| 34 | data: args.data, |
| 35 | options: { |
| 36 | responsive: true, |
| 37 | legend: { |
| 38 | display: false, |
| 39 | position: 'bottom', |
| 40 | }, |
| 41 | scales: { |
| 42 | xAxes: [ { |
| 43 | display: true, |
| 44 | scaleLabel: { |
| 45 | display: true, |
| 46 | labelString: args.text.xAxes, |
| 47 | fontSize: 14, |
| 48 | fontFamily: '-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif' |
| 49 | } |
| 50 | } ], |
| 51 | yAxes: [ { |
| 52 | display: true, |
| 53 | scaleLabel: { |
| 54 | display: false, |
| 55 | labelString: args.text.yAxes |
| 56 | } |
| 57 | } ] |
| 58 | }, |
| 59 | hover: { |
| 60 | mode: 'label' |
| 61 | }, |
| 62 | tooltips: { |
| 63 | custom: function ( tooltip ) { |
| 64 | // console.log( tooltip ); |
| 65 | }, |
| 66 | callbacks: { |
| 67 | title: function ( tooltip ) { |
| 68 | return args.data.dates[tooltip[0].index]; |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | $.each( config.data.datasets, function ( i, dataset ) { |
| 76 | dataset.fill = args.design.fill; |
| 77 | dataset.borderColor = args.design.borderColor; |
| 78 | dataset.backgroundColor = args.design.backgroundColor; |
| 79 | dataset.borderWidth = args.design.borderWidth; |
| 80 | dataset.borderDash = args.design.borderDash; |
| 81 | dataset.pointBorderColor = args.design.pointBorderColor; |
| 82 | dataset.pointBackgroundColor = args.design.pointBackgroundColor; |
| 83 | dataset.pointBorderWidth = args.design.pointBorderWidth; |
| 84 | } ); |
| 85 | |
| 86 | window.chartPVC = new Chart( document.getElementById( 'pvc_chart' ).getContext( '2d' ), config ); |
| 87 | } |
| 88 | } ); |
| 89 | |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | function updateLegend() { |
| 94 | $legendContainer = $( '#legendContainer' ); |
| 95 | $legendContainer.empty(); |
| 96 | $legendContainer.append( window.chartPVC.generateLegend() ); |
| 97 | } |
| 98 | |
| 99 | } )( jQuery ); |