-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbulletgraph.js
67 lines (56 loc) · 1.58 KB
/
bulletgraph.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function tick( obj, w ) {
var innerDiv = document.createElement('div');
innerDiv.className = 'tick';
innerDiv.style.width = w + "%";
obj.appendChild( innerDiv );
var innerDiv = document.createElement('div');
innerDiv.className = 'tick-label';
innerDiv.style.width = ( w * 2 ) + "%";
innerDiv.innerHTML = w;
obj.appendChild( innerDiv );
}
function ticks( obj, num ) {
var step = 100 / num;
for( var i=0;i<100;i=i+step ) {
tick( obj, Math.round(i) );
}
tick( obj, 100 );
}
function range( obj, list ) {
var index = list.length;
while( index > 0 ) {
var innerDiv = document.createElement('div');
innerDiv.className = 'range range-' + index;
innerDiv.style.width = list[index-1] + "%";
obj.appendChild( innerDiv );
index--;
}
}
function measure( obj, num ) {
var innerDiv = document.createElement('div');
innerDiv.className = 'measure';
innerDiv.style.width = num + "%";
obj.appendChild( innerDiv );
}
function target( obj, num ) {
var innerDiv = document.createElement('div');
innerDiv.className = 'target';
innerDiv.style.width = num + "%";
obj.appendChild( innerDiv );
}
function bullet_graph( id, options ) {
var obj = document.getElementById(id);
obj.className = obj.className + " bulletgraph";
if ( !(options.ticks == undefined) ) {
ticks( obj, options.ticks );
}
if ( !(options.range == undefined) ) {
range( obj, options.range );
}
if ( !(options.measure == undefined) ) {
measure( obj, options.measure );
}
if ( !(options.target == undefined) ) {
target( obj, options.target );
}
}