2011-08-19 14:48:41 +00:00
|
|
|
jQuery(function(){
|
2013-05-28 14:27:26 +00:00
|
|
|
|
|
|
|
function weekendAreas(axes) {
|
2011-08-19 14:48:41 +00:00
|
|
|
var markings = [];
|
|
|
|
var d = new Date(axes.xaxis.min);
|
|
|
|
// go to the first Saturday
|
|
|
|
d.setUTCDate(d.getUTCDate() - ((d.getUTCDay() + 1) % 7))
|
|
|
|
d.setUTCSeconds(0);
|
|
|
|
d.setUTCMinutes(0);
|
|
|
|
d.setUTCHours(0);
|
|
|
|
var i = d.getTime();
|
|
|
|
do {
|
|
|
|
// when we don't set yaxis, the rectangle automatically
|
|
|
|
// extends to infinity upwards and downwards
|
|
|
|
markings.push({ xaxis: { from: i, to: i + 2 * 24 * 60 * 60 * 1000 } });
|
|
|
|
i += 7 * 24 * 60 * 60 * 1000;
|
|
|
|
} while (i < axes.xaxis.max);
|
2013-05-28 14:27:26 +00:00
|
|
|
|
2011-08-19 14:48:41 +00:00
|
|
|
return markings;
|
|
|
|
}
|
2013-05-28 14:27:26 +00:00
|
|
|
|
2011-08-19 14:48:41 +00:00
|
|
|
var order_data = jQuery.parseJSON( params.order_data.replace(/"/g, '"') );
|
2013-05-28 14:27:26 +00:00
|
|
|
|
2011-08-19 14:48:41 +00:00
|
|
|
var d = order_data.order_counts;
|
|
|
|
var d2 = order_data.order_amounts;
|
2013-05-28 14:27:26 +00:00
|
|
|
|
2011-08-19 14:48:41 +00:00
|
|
|
for (var i = 0; i < d.length; ++i) d[i][0] += 60 * 60 * 1000;
|
|
|
|
for (var i = 0; i < d2.length; ++i) d2[i][0] += 60 * 60 * 1000;
|
2013-05-28 14:27:26 +00:00
|
|
|
|
2011-09-16 08:51:19 +00:00
|
|
|
var placeholder = jQuery("#placeholder");
|
2013-05-28 14:27:26 +00:00
|
|
|
|
2012-03-15 14:02:38 +00:00
|
|
|
var plot = jQuery.plot(placeholder, [ { label: params.number_of_sales, data: d }, { label: params.sales_amount, data: d2, yaxis: 2 } ], {
|
2011-08-19 14:48:41 +00:00
|
|
|
series: {
|
2012-08-31 13:11:30 +00:00
|
|
|
lines: { show: true, fill: true },
|
2011-08-19 14:48:41 +00:00
|
|
|
points: { show: true }
|
|
|
|
},
|
|
|
|
grid: {
|
|
|
|
show: true,
|
|
|
|
aboveData: false,
|
|
|
|
color: '#ccc',
|
|
|
|
backgroundColor: '#fff',
|
|
|
|
borderWidth: 2,
|
|
|
|
borderColor: '#ccc',
|
|
|
|
clickable: false,
|
|
|
|
hoverable: true,
|
|
|
|
markings: weekendAreas
|
|
|
|
},
|
2013-05-28 14:27:26 +00:00
|
|
|
xaxis: {
|
2011-08-19 14:48:41 +00:00
|
|
|
mode: "time",
|
2013-05-28 14:27:26 +00:00
|
|
|
timeformat: "%d %b",
|
|
|
|
monthNames: params.i18n_month_names,
|
2011-08-19 14:48:41 +00:00
|
|
|
tickLength: 1,
|
|
|
|
minTickSize: [1, "day"]
|
|
|
|
},
|
2012-01-18 16:54:05 +00:00
|
|
|
yaxes: [ { min: 0, tickSize: 10, tickDecimals: 0 }, { position: "right", min: 0, tickDecimals: 2 } ],
|
2012-10-12 08:45:37 +00:00
|
|
|
colors: ["#8a4b75", "#47a03e"],
|
|
|
|
legend: {
|
|
|
|
show: true,
|
|
|
|
position: "nw"
|
|
|
|
}
|
2011-08-19 14:48:41 +00:00
|
|
|
});
|
2013-05-28 14:27:26 +00:00
|
|
|
|
2011-09-16 08:51:19 +00:00
|
|
|
placeholder.resize();
|
2013-05-28 14:27:26 +00:00
|
|
|
|
2011-08-19 14:48:41 +00:00
|
|
|
function showTooltip(x, y, contents) {
|
|
|
|
jQuery('<div id="tooltip">' + contents + '</div>').css( {
|
|
|
|
position: 'absolute',
|
|
|
|
display: 'none',
|
|
|
|
top: y + 5,
|
|
|
|
left: x + 5,
|
2013-05-28 14:27:26 +00:00
|
|
|
padding: '5px 10px',
|
|
|
|
border: '3px solid #3da5d5',
|
2011-09-16 12:45:46 +00:00
|
|
|
background: '#288ab7'
|
2011-08-19 14:48:41 +00:00
|
|
|
}).appendTo("body").fadeIn(200);
|
|
|
|
}
|
2013-05-28 14:27:26 +00:00
|
|
|
|
2011-08-19 14:48:41 +00:00
|
|
|
var previousPoint = null;
|
|
|
|
jQuery("#placeholder").bind("plothover", function (event, pos, item) {
|
|
|
|
if (item) {
|
|
|
|
if (previousPoint != item.dataIndex) {
|
|
|
|
previousPoint = item.dataIndex;
|
2013-05-28 14:27:26 +00:00
|
|
|
|
2011-08-19 14:48:41 +00:00
|
|
|
jQuery("#tooltip").remove();
|
2013-05-28 14:27:26 +00:00
|
|
|
|
2012-03-15 14:02:38 +00:00
|
|
|
if (item.series.label==params.number_of_sales) {
|
2013-05-28 14:27:26 +00:00
|
|
|
|
2011-08-19 14:48:41 +00:00
|
|
|
var y = item.datapoint[1];
|
2013-05-28 14:27:26 +00:00
|
|
|
showTooltip(item.pageX, item.pageY, params.i18n_sold + ": " + y);
|
|
|
|
|
2011-08-19 14:48:41 +00:00
|
|
|
} else {
|
2013-05-28 14:27:26 +00:00
|
|
|
|
2011-08-19 14:48:41 +00:00
|
|
|
var y = item.datapoint[1].toFixed(2);
|
2013-05-28 14:27:26 +00:00
|
|
|
|
|
|
|
var formatted_total = accounting.formatMoney( y, {
|
|
|
|
symbol : params.currency_format_symbol,
|
|
|
|
decimal : params.currency_format_decimal_sep,
|
|
|
|
thousand : params.currency_format_thousand_sep,
|
|
|
|
precision : params.currency_format_num_decimals,
|
|
|
|
format : params.currency_format
|
|
|
|
} );
|
|
|
|
|
|
|
|
showTooltip( item.pageX, item.pageY, params.i18n_earned + ": " + formatted_total );
|
2011-08-19 14:48:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
jQuery("#tooltip").remove();
|
2013-05-28 14:27:26 +00:00
|
|
|
previousPoint = null;
|
2011-08-19 14:48:41 +00:00
|
|
|
}
|
|
|
|
});
|
2013-05-28 14:27:26 +00:00
|
|
|
|
2011-08-19 14:48:41 +00:00
|
|
|
});
|