-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCircularKPI.js
More file actions
181 lines (162 loc) · 6.32 KB
/
CircularKPI.js
File metadata and controls
181 lines (162 loc) · 6.32 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*globals define*/
define(["jquery", "text!./scripts/style.css", "./scripts/themes", "./scripts/d3.min", "./scripts/radialProgress"], function($, cssContent, chart_theme) {
'use strict';
$("<style>").html(cssContent).appendTo("head");
return {
initialProperties: {
qHyperCubeDef: {
qDimensions: [],
qMeasures: [],
qInitialDataFetch: [{
qWidth: 3,
qHeight: 200
}]
}
},
definition: {
type: "items",
component: "accordion",
items: {
dimensions: {
uses: "dimensions",
min: 0,
max: 2
},
measures: {
uses: "measures",
min: 1,
max: 1
},
sorting: {
uses: "sorting"
},
settings: {
uses: "settings",
items: {
ThemeDropDown: {
type: "string",
component: "dropdown",
label: "Theme",
ref: "theme",
options: chart_theme,
defaultValue: ["#64b5f6", "#1976d2", "#ef6c00", "#ffd54f", "#455a64", "#96a6a6", "#dd2c00", "#00838f", "#00bfa5", "#ffa000"]
},
extras: {
type: "items",
label: "Extra Settings",
items: {
scrollaftermax: {
type: "integer",
label: "Animation time (ms)",
ref: "animationtime",
defaultValue: 1000
},
singlekpilabel: {
type: "string",
label: "Single KPI Label",
ref: "singlekpilabel",
defaultValue: ""
},
showdecimals: {
type: "boolean",
label: "Show decimal values",
ref: "showdecimals",
defaultValue: false
},
showpercentage: {
type: "boolean",
label: "Show percent (%) symbol",
ref: "showpercentage",
defaultValue: true
}
}
}
}
}
}
},
snapshot: {
canTakeSnapshot: true
},
paint: function($element, layout) {
$element.empty();
var id = "container_" + layout.qInfo.qId;
var width = $element.width();
var height = $element.height();
if(document.getElementById(id)) {
$("#" + id).empty();
}
else {
$element.append($('<div />').attr("id", id).attr("class", "viz").width(width).height(height));
}
var IS_SPARK_LAYOUT = this.options.layoutMode === 1;
var HAS_DIMENSION = layout.qHyperCube.qDimensionInfo.length > 0;
var HAS_TWO_DIMENSION = layout.qHyperCube.qDimensionInfo.length > 1;
var data = layout.qHyperCube.qDataPages[0].qMatrix;
var label = layout.qHyperCube.qMeasureInfo[0].qFallbackTitle;
var colors = [layout.theme[0], layout.theme[1], layout.theme[2]];
var animationTime = layout.animationtime;
var showdecimals = layout.showdecimals;
var showpercentage = layout.showpercentage;
var rows, columns;
if (height > width) {
columns = Math.ceil(Math.sqrt(data.length));
rows = Math.ceil(data.length / columns);
} else {
columns = Math.ceil(Math.sqrt(1.5 * data.length) / 1.5);
rows = Math.ceil(data.length / columns);
};
var area = d3.select($("#" + id).get(0))
.selectAll('.area')
.data(data)
.enter()
.append('div')
.attr('class', 'circular-kpi-tile')
.attr('id', function(d, i) {
return id + '_circular-kpi-tile-' + i;
})
.attr('selected', 'no')
.style('width', Math.ceil(width / columns, 10) - 5 + 'px')
.style('height', Math.ceil(height / rows, 10) - 5 + 'px');
data.forEach(function(d, i) {
if(HAS_TWO_DIMENSION) {
var value = d[2].qNum;
//For a multidim chart - calculate the color to use so we loop over the # of colors in the theme.
var colorIter = Math.round(d[1].qElemNumber/(layout.theme.length-2) % 1 * (layout.theme.length-2));
colors = [layout.theme[colorIter], layout.theme[colorIter+1], layout.theme[colorIter+2]];
}
else {
var value = HAS_DIMENSION ? d[1].qNum : d[0].qNum;
}
if(layout.singlekpilabel.length>0) {var label = HAS_DIMENSION ? d[0].qText : layout.singlekpilabel};
if(layout.singlekpilabel.length==0) {var label = HAS_DIMENSION ? d[0].qText : label};
var extraLabel = HAS_TWO_DIMENSION ? d[1].qText : "";
var element = document.getElementById(id + '_circular-kpi-tile-' + i);
var width = element.offsetWidth - 5, height = element.offsetHeight - 5;
var select = function() {
$('#' + id + '_circular-kpi-tile-' + i).attr('selected', '1');
toggleOpacity();
return HAS_DIMENSION ? this.selectValues(0, [d[0].qElemNumber], true) : false;
}.bind(this);
if (width < height) {
height = width;
} else {
width = height;
};
radialProgress(element, width, height, colors, animationTime, showdecimals, showpercentage)
.diameter(width)
.label(label)
.extraLabel(extraLabel)
.onClick(select)
.value(value * 100)
.render();
}.bind(this));
function toggleOpacity() {
$("#" +id).find("[selected=no]")
.css({ opacity: 0.5 });
$("#" +id).find("[selected=selected]")
.css({ opacity: 1 });
};
}
};
});