2015-07-10 04:32:30 +00:00
|
|
|
jQuery(function( $ ) {
|
2013-06-26 14:11:33 +00:00
|
|
|
|
2015-07-10 04:32:30 +00:00
|
|
|
function showTooltip( x, y, contents ) {
|
|
|
|
$( '<div class="chart-tooltip">' + contents + '</div>' ).css( {
|
|
|
|
top: y - 16,
|
2016-07-19 11:42:19 +00:00
|
|
|
left: x + 20
|
2015-07-10 04:32:30 +00:00
|
|
|
}).appendTo( 'body' ).fadeIn( 200 );
|
2014-08-29 10:29:11 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 04:32:30 +00:00
|
|
|
var prev_data_index = null;
|
|
|
|
var prev_series_index = null;
|
|
|
|
|
|
|
|
$( '.chart-placeholder' ).bind( 'plothover', function ( event, pos, item ) {
|
|
|
|
if ( item ) {
|
|
|
|
if ( prev_data_index !== item.dataIndex || prev_series_index !== item.seriesIndex ) {
|
|
|
|
prev_data_index = item.dataIndex;
|
|
|
|
prev_series_index = item.seriesIndex;
|
|
|
|
|
|
|
|
$( '.chart-tooltip' ).remove();
|
|
|
|
|
|
|
|
if ( item.series.points.show || item.series.enable_tooltip ) {
|
|
|
|
|
|
|
|
var y = item.series.data[item.dataIndex][1],
|
|
|
|
tooltip_content = '';
|
|
|
|
|
|
|
|
if ( item.series.prepend_label ) {
|
|
|
|
tooltip_content = tooltip_content + item.series.label + ': ';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( item.series.prepend_tooltip ) {
|
|
|
|
tooltip_content = tooltip_content + item.series.prepend_tooltip;
|
|
|
|
}
|
|
|
|
|
|
|
|
tooltip_content = tooltip_content + y;
|
|
|
|
|
|
|
|
if ( item.series.append_tooltip ) {
|
|
|
|
tooltip_content = tooltip_content + item.series.append_tooltip;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( item.series.pie.show ) {
|
|
|
|
showTooltip( pos.pageX, pos.pageY, tooltip_content );
|
|
|
|
} else {
|
|
|
|
showTooltip( item.pageX, item.pageY, tooltip_content );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$( '.chart-tooltip' ).remove();
|
|
|
|
prev_data_index = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$( '.wc_sparkline.bars' ).each( function() {
|
|
|
|
var chart_data = $( this ).data( 'sparkline' );
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
grid: {
|
|
|
|
show: false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// main series
|
|
|
|
var series = [{
|
|
|
|
data: chart_data,
|
|
|
|
color: $( this ).data( 'color' ),
|
|
|
|
bars: {
|
|
|
|
fillColor: $( this ).data( 'color' ),
|
|
|
|
fill: true,
|
|
|
|
show: true,
|
|
|
|
lineWidth: 1,
|
|
|
|
barWidth: $( this ).data( 'barwidth' ),
|
|
|
|
align: 'center'
|
|
|
|
},
|
|
|
|
shadowSize: 0
|
|
|
|
}];
|
|
|
|
|
|
|
|
// draw the sparkline
|
|
|
|
$.plot( $( this ), series, options );
|
|
|
|
});
|
|
|
|
|
|
|
|
$( '.wc_sparkline.lines' ).each( function() {
|
|
|
|
var chart_data = $( this ).data( 'sparkline' );
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
grid: {
|
|
|
|
show: false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// main series
|
|
|
|
var series = [{
|
|
|
|
data: chart_data,
|
|
|
|
color: $( this ).data( 'color' ),
|
|
|
|
lines: {
|
|
|
|
fill: false,
|
|
|
|
show: true,
|
|
|
|
lineWidth: 1,
|
|
|
|
align: 'center'
|
|
|
|
},
|
|
|
|
shadowSize: 0
|
|
|
|
}];
|
|
|
|
|
|
|
|
// draw the sparkline
|
|
|
|
$.plot( $( this ), series, options );
|
|
|
|
});
|
|
|
|
|
|
|
|
var dates = $( '.range_datepicker' ).datepicker({
|
|
|
|
changeMonth: true,
|
|
|
|
changeYear: true,
|
|
|
|
defaultDate: '',
|
|
|
|
dateFormat: 'yy-mm-dd',
|
|
|
|
numberOfMonths: 1,
|
2017-04-03 09:46:37 +00:00
|
|
|
minDate: '-20Y',
|
2017-09-26 11:29:22 +00:00
|
|
|
maxDate: '+1D',
|
2015-07-10 04:32:30 +00:00
|
|
|
showButtonPanel: true,
|
|
|
|
showOn: 'focus',
|
|
|
|
buttonImageOnly: true,
|
2017-07-13 11:15:58 +00:00
|
|
|
onSelect: function() {
|
2015-07-10 04:32:30 +00:00
|
|
|
var option = $( this ).is( '.from' ) ? 'minDate' : 'maxDate',
|
2017-07-13 11:15:58 +00:00
|
|
|
date = $( this ).datepicker( 'getDate' );
|
2015-07-10 04:32:30 +00:00
|
|
|
|
|
|
|
dates.not( this ).datepicker( 'option', option, date );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var a = document.createElement( 'a' );
|
|
|
|
|
|
|
|
if ( typeof a.download === 'undefined' ) {
|
|
|
|
$( '.export_csv' ).hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Export
|
|
|
|
$( '.export_csv' ).click( function() {
|
|
|
|
var exclude_series = $( this ).data( 'exclude_series' ) || '';
|
|
|
|
exclude_series = exclude_series.toString();
|
|
|
|
exclude_series = exclude_series.split( ',' );
|
|
|
|
var xaxes_label = $( this ).data( 'xaxes' );
|
|
|
|
var groupby = $( this ) .data( 'groupby' );
|
2017-01-20 14:36:43 +00:00
|
|
|
var index_type = $( this ).data( 'index_type' );
|
2015-07-10 04:32:30 +00:00
|
|
|
var export_format = $( this ).data( 'export' );
|
2017-12-07 15:14:42 +00:00
|
|
|
var csv_data = 'data:text/csv;charset=utf-8,\uFEFF';
|
2015-07-10 05:13:30 +00:00
|
|
|
var s, series_data, d;
|
2015-07-10 04:32:30 +00:00
|
|
|
|
|
|
|
if ( 'table' === export_format ) {
|
|
|
|
|
2016-06-23 16:08:50 +00:00
|
|
|
$( this ).offsetParent().find( 'thead tr,tbody tr' ).each( function() {
|
2015-07-10 04:32:30 +00:00
|
|
|
$( this ).find( 'th, td' ).each( function() {
|
|
|
|
var value = $( this ).text();
|
2016-07-19 11:42:19 +00:00
|
|
|
value = value.replace( '[?]', '' ).replace( '#', '' );
|
2015-07-10 04:32:30 +00:00
|
|
|
csv_data += '"' + value + '"' + ',';
|
|
|
|
});
|
|
|
|
csv_data = csv_data.substring( 0, csv_data.length - 1 );
|
|
|
|
csv_data += '\n';
|
|
|
|
});
|
|
|
|
|
2016-06-23 16:08:50 +00:00
|
|
|
$( this ).offsetParent().find( 'tfoot tr' ).each( function() {
|
2015-07-10 04:32:30 +00:00
|
|
|
$( this ).find( 'th, td' ).each( function() {
|
|
|
|
var value = $( this ).text();
|
2016-07-19 11:42:19 +00:00
|
|
|
value = value.replace( '[?]', '' ).replace( '#', '' );
|
2015-07-10 04:32:30 +00:00
|
|
|
csv_data += '"' + value + '"' + ',';
|
|
|
|
if ( $( this ).attr( 'colspan' ) > 0 ) {
|
|
|
|
for ( i = 1; i < $(this).attr('colspan'); i++ ) {
|
|
|
|
csv_data += '"",';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
csv_data = csv_data.substring( 0, csv_data.length - 1 );
|
|
|
|
csv_data += '\n';
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if ( ! window.main_chart ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var the_series = window.main_chart.getData();
|
|
|
|
var series = [];
|
2016-03-14 12:26:18 +00:00
|
|
|
csv_data += '"' + xaxes_label + '",';
|
2015-07-10 04:32:30 +00:00
|
|
|
|
|
|
|
$.each( the_series, function( index, value ) {
|
|
|
|
if ( ! exclude_series || $.inArray( index.toString(), exclude_series ) === -1 ) {
|
|
|
|
series.push( value );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// CSV Headers
|
2015-07-10 05:13:30 +00:00
|
|
|
for ( s = 0; s < series.length; ++s ) {
|
2016-03-14 12:26:18 +00:00
|
|
|
csv_data += '"' + series[s].label + '",';
|
2015-07-10 04:32:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
csv_data = csv_data.substring( 0, csv_data.length - 1 );
|
|
|
|
csv_data += '\n';
|
|
|
|
|
|
|
|
// Get x axis values
|
|
|
|
var xaxis = {};
|
|
|
|
|
2015-07-10 05:13:30 +00:00
|
|
|
for ( s = 0; s < series.length; ++s ) {
|
|
|
|
series_data = series[s].data;
|
|
|
|
for ( d = 0; d < series_data.length; ++d ) {
|
2015-07-10 04:32:30 +00:00
|
|
|
xaxis[series_data[d][0]] = [];
|
|
|
|
// Zero values to start
|
|
|
|
for ( var i = 0; i < series.length; ++i ) {
|
|
|
|
xaxis[series_data[d][0]].push(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add chart data
|
2015-07-10 05:13:30 +00:00
|
|
|
for ( s = 0; s < series.length; ++s ) {
|
|
|
|
series_data = series[s].data;
|
|
|
|
for ( d = 0; d < series_data.length; ++d ) {
|
2015-07-10 04:32:30 +00:00
|
|
|
xaxis[series_data[d][0]][s] = series_data[d][1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loop data and output to csv string
|
|
|
|
$.each( xaxis, function( index, value ) {
|
|
|
|
var date = new Date( parseInt( index, 10 ) );
|
|
|
|
|
2017-01-20 14:36:43 +00:00
|
|
|
if ( 'none' === index_type ) {
|
|
|
|
csv_data += '"' + index + '",';
|
2015-07-10 04:32:30 +00:00
|
|
|
} else {
|
2017-01-20 14:36:43 +00:00
|
|
|
if ( groupby === 'day' ) {
|
|
|
|
csv_data += '"' + date.getUTCFullYear() + '-' + parseInt( date.getUTCMonth() + 1, 10 ) + '-' + date.getUTCDate() + '",';
|
|
|
|
} else {
|
|
|
|
csv_data += '"' + date.getUTCFullYear() + '-' + parseInt( date.getUTCMonth() + 1, 10 ) + '",';
|
|
|
|
}
|
2015-07-10 04:32:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for ( var d = 0; d < value.length; ++d ) {
|
|
|
|
var val = value[d];
|
|
|
|
|
|
|
|
if ( Math.round( val ) !== val ) {
|
|
|
|
val = parseFloat( val );
|
|
|
|
val = val.toFixed( 2 );
|
|
|
|
}
|
|
|
|
|
2016-03-14 12:26:18 +00:00
|
|
|
csv_data += '"' + val + '",';
|
2015-07-10 04:32:30 +00:00
|
|
|
}
|
|
|
|
csv_data = csv_data.substring( 0, csv_data.length - 1 );
|
|
|
|
csv_data += '\n';
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set data as href and return
|
|
|
|
$( this ).attr( 'href', encodeURI( csv_data ) );
|
|
|
|
return true;
|
|
|
|
});
|
2014-01-31 02:44:17 +00:00
|
|
|
});
|