| 1 |
(function () { |
| 2 |
// Initialize. |
| 3 |
var labels = []; |
| 4 |
var data = []; |
| 5 |
var statify_data_table = jQuery('#statify_chart_data'); |
| 6 |
|
| 7 |
// Abort if no data is present. |
| 8 |
if (!statify_data_table.length) { |
| 9 |
return; |
| 10 |
} |
| 11 |
|
| 12 |
// Collect data from hidden table. |
| 13 |
jQuery('th', statify_data_table).each(function () { |
| 14 |
labels.push(jQuery(this).text()); |
| 15 |
}); |
| 16 |
|
| 17 |
jQuery('td', statify_data_table).each(function () { |
| 18 |
data.push(jQuery(this).text()); |
| 19 |
}); |
| 20 |
|
| 21 |
// Determine maximum value for scaling. |
| 22 |
var maxValue = Math.max.apply(Math, data); |
| 23 |
|
| 24 |
// Draw chart. |
| 25 |
var chart = new Chartist.Line('#statify_chart', { |
| 26 |
labels: labels, |
| 27 |
series: [ |
| 28 |
data |
| 29 |
] |
| 30 |
}, { |
| 31 |
low : 0, |
| 32 |
showArea : true, |
| 33 |
fullWidth: true, |
| 34 |
axisX : { |
| 35 |
showGrid : false, |
| 36 |
showLabel: false, |
| 37 |
offset : 0 |
| 38 |
}, |
| 39 |
axisY : { |
| 40 |
showGrid : false, |
| 41 |
showLabel: true, |
| 42 |
type : Chartist.FixedScaleAxis, |
| 43 |
low : 0, |
| 44 |
high : maxValue + 1, |
| 45 |
ticks : [maxValue], |
| 46 |
offset : 15 |
| 47 |
}, |
| 48 |
plugins : [ |
| 49 |
Chartist.plugins.tooltip({ |
| 50 |
appendToBody: true, |
| 51 |
class : 'statify-chartist-tooltip' |
| 52 |
}) |
| 53 |
] |
| 54 |
}); |
| 55 |
|
| 56 |
var pointRadius = 4; |
| 57 |
if (data.length > 365) pointRadius = 0; |
| 58 |
else if (data.length > 180) pointRadius = 1; |
| 59 |
else if (data.length > 90) pointRadius = 2; |
| 60 |
|
| 61 |
// Replace default points with hollow circles, add "pageview(s) to value and append date (label) as meta data. |
| 62 |
chart.on('draw', function (data) { |
| 63 |
if ('point' === data.type) { |
| 64 |
var circle = new Chartist.Svg('circle', { |
| 65 |
cx: [data.x], |
| 66 |
cy: [data.y], |
| 67 |
r: [pointRadius], |
| 68 |
'ct:value': data.value.y + ' ' + (data.value.y > 1 ? statify_translations.pageviews : statify_translations.pageview), |
| 69 |
'ct:meta': labels[data.index] |
| 70 |
}, 'ct-point'); |
| 71 |
data.element.replace(circle); |
| 72 |
} |
| 73 |
}); |
| 74 |
|
| 75 |
})(); |
| 76 |
|