-
Notifications
You must be signed in to change notification settings - Fork 7
/
D3LiquidFillGauge.js
104 lines (86 loc) · 3.59 KB
/
D3LiquidFillGauge.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
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
/*globals define, console*/
define(["jquery", "./liquidfillgauge-properties", "./source-d3liquidfillgauge", "./d3"], function($, properties) {'use strict';
return {
type : "D3 Liquid Fill Gauge",
//Refer to the properties file
definition : properties,
initialProperties : {
version: 1.0,
qHyperCubeDef : {
qDimensions : [],
qMeasures : [],
qInitialDataFetch : [{
qWidth : 2,
qHeight : 50
}]
},
fontSize : {
min : 8,
max : 24
}
},
snapshot : {
canTakeSnapshot : true
},
paint : function($element, layout) {
var self = this;
var w = $element.width(), h = $element.height();
var i;
//check that we have data to render
if(layout.qHyperCube.qDataPages[0].qMatrix.length) {
$.each(layout.qHyperCube.qDataPages[0].qMatrix, function(key, row) {
var measure = row[0];
var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
svg.id = "fillgauge" + Math.floor(Math.random() * (10000000 - 1)) + 1;
svg.setAttribute('width', '85%');
svg.setAttribute('height', '85%');
svg.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xlink", "http://www.w3.org/1999/xlink");
$element.html(svg);
var gaugeConfig = liquidFillGaugeDefaultSettings();
gaugeConfig.minValue = layout.minValue,
gaugeConfig.maxValue = layout.maxValue,
gaugeConfig.circleFillGap = layout.circleFillGap,
gaugeConfig.waveHeight = layout.waveHeight,
gaugeConfig.waveCount = layout.waveCount,
gaugeConfig.waveRiseTime = layout.waveRiseTime,
gaugeConfig.waveAnimateTime = layout.waveAnimateTime,
gaugeConfig.waveHeightScaling = layout.waveHeightScaling,
gaugeConfig.textVertPosition = layout.textVertPosition,
gaugeConfig.textSize = layout.textSize,
gaugeConfig.circleColor = getColorHex(layout.circleColor);
gaugeConfig.textColor = getColorHex(layout.textColor);
gaugeConfig.waveTextColor = getColorHex(layout.waveTextColor);
gaugeConfig.waveColor = getColorHex(layout.waveColor);
gaugeConfig.circleThickness = layout.circleThickness;
gaugeConfig.waveRise = layout.waveRise;
gaugeConfig.waveAnimate = layout.waveAnimate;
gaugeConfig.valueCountUp = layout.valueCountUp;
gaugeConfig.displayPercent = layout.displayPercent;
var currentcolor;
if(layout.props.colorsSwitch)
{
if(measure.qNum <= layout.props.inferiorLimit1)
{
currentcolor = layout.props.Color1;
}
else if(measure.qNum > layout.props.inferiorLimit2)
{
currentcolor = layout.props.Color3;
}
else
{
currentcolor = layout.props.Color2;
}
gaugeConfig.circleColor = getColorHex(currentcolor);
gaugeConfig.textColor = getColorHex(currentcolor);
}
loadLiquidFillGauge(svg.id, measure.qNum, gaugeConfig);
});
}
},
clearSelectedValues : function($element) {
//jQuery can not change class of SVG element, need d3 for that
d3.select($element[0]).selectAll(".selected").classed("selected", false);
}
};
});