-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchartist-plugin-barhighlight.js
More file actions
35 lines (30 loc) · 988 Bytes
/
chartist-plugin-barhighlight.js
File metadata and controls
35 lines (30 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* Chartist.js plugin to highlight some bars in a bar chart based on value limit.
*
*/
/* global Chartist */
(function(window, document, Chartist) {
'use strict';
var defaultOptions = {
limit: null,
highlightBarClass: 'ct-bar-highlight'
};
Chartist.plugins = Chartist.plugins || {};
Chartist.plugins.ctBarHighlight = function(options) {
options = Chartist.extend({}, defaultOptions, options);
return function ctBarHighlight(chart) {
if(chart instanceof Chartist.Bar) {
chart.on('draw', function(data) {
if(data.type === 'bar') {
// Add highlight class if the value is equal or over the limit
if (options.limit !== null && data.value >= options.limit)
{
var element = data.element._node;
element.setAttribute('class', element.getAttribute('class') + ' ' + options.highlightBarClass);
}
}
});
}
};
};
}(window, document, Chartist));