forked from aterrien/jQuery-Knob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
163 lines (139 loc) · 5.88 KB
/
test.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jQuery Knob demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<!--[if IE]><script type="text/javascript" src="excanvas.js"></script><![endif]-->
<script src="js/testJquery.knob.js"></script>
<script>
$(function($) {
$(".knob").knob({
// change : function (value) {
// console.log("change : " + value);
// },
// release : function (value) {
//// console.log(this.$.attr('value'));
// console.log("release : " + value);
// },
// cancel : function () {
// console.log("cancel : ", this);
// },
// format : function (value) {
// return value + '%';
// },x
draw : function () {
// "tron" case
if(this.$.data('skin') == 'tron') {
this.o.min = 5.0;
this.o.max = 35.0;
this.o.step = 0.5;
this.cursorExt = 0.3;
var a = this.arc(this.cv) // Arc
, pa // Previous arc
, r = 1;
this.g.lineWidth = this.lineWidth;
if(this.v != null && this.v != ""){
this.v = 15;
}
var k2 = window.devicePixelRatio
//current temp / the value in center
var mtv = (this.v).toFixed(1);
this.g.font = 60*k2+"px bold Arial";
this.g.fillStyle = '#005c99';
this.g.textAlign = 'center';
this.g.textBaseline = 'middle';
this.g.moveTo(this.xy,this.xy);
this.g.fillText(mtv, this.xy,this.xy);
//draw tag ℃
this.g.font = 20*k2+"px Arial";
this.g.fillStyle = '#005c99';
this.g.textAlign = 'center';
this.g.textBaseline = 'middle';
this.g.moveTo(this.xy+this.radius*(2/3),this.xy);
this.g.fillText("℃", this.xy+this.radius*(2/3),this.xy);
var ast = (5/3) * Math.PI*((this.v-this.o.min)/(this.o.max-this.o.min))+(2/3) * Math.PI;
var fxxs = this.radius*Math.cos(ast)+this.xy;
var fxys = this.radius*Math.sin(ast)+this.xy;
var fxxe = this.radius*Math.cos(a.e)+this.xy;
var fxye = this.radius*Math.sin(a.e)+this.xy;
if(this.cv > this.v){
var grd=this.g.createLinearGradient(fxxs,fxys,fxxe,fxye);
grd.addColorStop(0,"#ffeb00");
grd.addColorStop(1,"#ff0505");
this.g.beginPath();
this.g.strokeStyle = grd;
this.g.arc(this.xy, this.xy, this.radius + this.lineWidth*(1/2), ast,a.e, a.d);
this.g.stroke();
}else{
var grd=this.g.createLinearGradient(fxxe,fxye,fxxs,fxys);
grd.addColorStop(0,"#0000FF");
grd.addColorStop(1,"#11f3b4");
this.g.beginPath();
this.g.strokeStyle = grd;
this.g.arc(this.xy, this.xy, this.radius + this.lineWidth*(1/2), ast,a.e,true);
this.g.stroke();
}
this.g.lineWidth = 2;
this.g.beginPath();
this.g.strokeStyle = "#005c99";
this.g.arc( this.xy, this.xy, this.radius, (2/3) * Math.PI, (7/3) * Math.PI);
this.g.stroke();
var k1 = 1.3
var ty= this.radius*Math.cos((1/3)*Math.PI/2);
var fx = this.xy;
var fy = this.xy+ty;
//drow small circle
this.g.beginPath();
this.g.moveTo(fxxe,fxye);
this.g.strokeStyle = "#ddd";
this.g.arc(fxxe, fxye, this.lineWidth*(7/6), 0, Math.PI*2);
this.g.fill();
//the value in small circle
this.g.font = 10*k2+"px Arial";
this.g.fillStyle = '#fff';
this.g.textAlign = 'center';
this.g.textBaseline = 'middle';
this.g.moveTo(fxxe,fxye);
this.g.fillText((this.cv).toFixed(1), fxxe,fxye);
var fontSize= (this.radius-parseInt(ty))*1.5*k1;
//tag
this.g.font = "bold "+fontSize+ "px Arial";
this.g.fillStyle = '#005c99';
this.g.textAlign = 'center';
this.g.textBaseline = 'middle';
this.g.moveTo(fx,fy);
this.g.fillText("BFR", fx, fy);
return false;
}
}
});
});
</script>
<style>
body{
padding: 0;
margin: 0px 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 300;
text-rendering: optimizelegibility;
}
p{font-size: 30px; line-height: 30px}
div.demo{text-align: center; width: 280px;}
div.demo > p{font-size: 20px}
</style>
</head>
<body>
<div style="width:100%;font-size:40px;letter-spacing:-8px;line-height:40px;">
<h1>jQuery Knob</h1>
</div>
<div style="height: 340px;">
<div class="demo" style="margin: 10px auto;">
<input class="knob" data-width="300" data-height="300" data-angleOffset="-150" data-angleArc="300" data-displayInput="false" data-fgColor="#333" data-skin="tron" data-thickness=".1" value="22.0">
</div>
</div>
<div style="margin-top:30px;text-align:center">
<p style="font-size:20px;">jQuery Knob is © 2012 Anthony Terrien - MIT License</p>
</div>
</body>
</html>