2011-08-19 14:48:41 +00:00
|
|
|
jQuery(function(){
|
|
|
|
|
|
|
|
function weekendAreas(axes) {
|
|
|
|
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);
|
|
|
|
|
|
|
|
return markings;
|
|
|
|
}
|
|
|
|
|
|
|
|
var order_data = jQuery.parseJSON( params.order_data.replace(/"/g, '"') );
|
|
|
|
|
|
|
|
var d = order_data.order_counts;
|
|
|
|
var d2 = order_data.order_amounts;
|
|
|
|
|
|
|
|
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;
|
2011-09-16 08:51:19 +00:00
|
|
|
|
|
|
|
var placeholder = jQuery("#placeholder");
|
|
|
|
|
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
|
|
|
|
},
|
|
|
|
xaxis: {
|
|
|
|
mode: "time",
|
|
|
|
timeformat: "%d %b",
|
2012-06-11 09:08:53 +00:00
|
|
|
monthNames: params.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
|
|
|
});
|
2011-09-16 08:51:19 +00:00
|
|
|
|
|
|
|
placeholder.resize();
|
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,
|
2011-09-16 12:45:46 +00:00
|
|
|
padding: '5px 10px',
|
|
|
|
border: '3px solid #3da5d5',
|
|
|
|
background: '#288ab7'
|
2011-08-19 14:48:41 +00:00
|
|
|
}).appendTo("body").fadeIn(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
var previousPoint = null;
|
|
|
|
jQuery("#placeholder").bind("plothover", function (event, pos, item) {
|
|
|
|
if (item) {
|
|
|
|
if (previousPoint != item.dataIndex) {
|
|
|
|
previousPoint = item.dataIndex;
|
|
|
|
|
|
|
|
jQuery("#tooltip").remove();
|
|
|
|
|
2012-03-15 14:02:38 +00:00
|
|
|
if (item.series.label==params.number_of_sales) {
|
2011-08-19 14:48:41 +00:00
|
|
|
|
|
|
|
var y = item.datapoint[1];
|
2012-10-12 08:39:31 +00:00
|
|
|
showTooltip(item.pageX, item.pageY, params.sold + ": " + y);
|
2011-08-19 14:48:41 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
var y = item.datapoint[1].toFixed(2);
|
2012-10-12 08:39:31 +00:00
|
|
|
showTooltip(item.pageX, item.pageY, params.earned + ": " + params.currency_symbol + y);
|
2011-08-19 14:48:41 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
jQuery("#tooltip").remove();
|
|
|
|
previousPoint = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|