-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
150 lines (148 loc) · 5.23 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>Circle Calculations</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<link rel="stylesheet" href="jquery.circliful.css">
<link rel="stylesheet" href="custom.css">
</head>
<body class="bg-light">
<div class="container">
<div class="row">
<div class="col-lg-12 mt-5">
<h1>Sketch calculator</h1>
</div>
<div class="col-6 mt-5">
<div class="form-group">
<label for="pixelWidth" class="mb-0">Pixel Width</label>
<div class="d-block">
<small class="form-text text-danger" id="inputWarning">Please enter a value</small>
</div>
<input type="text" class="form-control" name="pixelWidth" id="pixelWidth" value="0">
</div>
<div class="form-group">
<label for="formControlRange" class="mb-0">Percentage of circle</label>
<div class="d-block">
<small class="form-text text-danger mb-5" id="sliderWarning">Please set a value</small>
</div>
<input type="range" class="form-control-range mt-3" id="percentage" min="0" max="100" value="0" step="1">
<output for="percentage" class="input-value"></output>
</div>
<div class="row mb-5">
<div class="col-6">
<label for="dashValue"><strong>Dash Value</strong></label>
<p id="dashValue"></p>
</div>
<div class="col-6">
<label for="gapValue"><strong>Gap Value</strong></label>
<p id="gapValue"></p>
</div>
<div class="col-12 mt-5">
<button class="btn btn-primary float-right" id="calc">Calculate</button>
</div>
</div>
</div>
<div class="col-6">
<div id="renderTarget"></div>
</div>
</div>
<footer>
<div class="row">
<div class="col-lg-12">
<a href="https://github.com/Fisher26/circle_calc/archive/master.zip"><button class="btn btn-warning float-right text-light">Downlaod repo from git</button></a>
</div>
</div>
</footer>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
<script src="jquery.circliful.min.js"></script>
<script type="text/javascript">
$( document ).ready(function(){
var initial;
function calculate(){
let percentage = $('#percentage').val()
pw = $('#pixelWidth').val();
circumference = 2 * 3.14 * (pw/2)
dV = circumference * (percentage/100)
gV = circumference - (dV/2);
if(pw > 0 && percentage > 0){
initial = 'complete';
$('.text-danger').hide();
$('#dashValue').html(dV.toFixed(3));
$('#gapValue').html(gV.toFixed(3));
$('#renderTarget').html(' ');
$('#renderTarget').circliful({
backgroundColor: 'none',
foregroundBorderWidth: 5,
fontColor: '#0069d9',
foregroundColor: '#0069d9',
percent: percentage
});
}
else if(pw == 0){
$('#inputWarning').show();
}
else if(percentage == 0){
$('#sliderWarning').show();
}
else if(pw == 0 && percentage ==0){
$('.text-danger').show();
}
}
$('#percentage').on('input', function(){
let el = $(this)
width = el.width()
newPoint = (el.val() - el.attr("min")) / (el.attr('max') - el.attr('min'));
offset = -2.5;
if (newPoint < 0) { newPlace = 0; }
else if (newPoint > 1) { newPlace = width; }
else { newPlace = width * newPoint + offset; offset -= newPoint; }
el.next('.input-value').css({
left: newPlace,
marginLeft: offset + "%"}).text(el.val());
}).trigger('change');
$('#percentage').on('input', function(){
let val = $('#percentage').val()
newVal = 360 * val / 100
change = val - newVal;
$('.circle').attr('stroke-dasharray', newVal + ', 20000');
$('.number').html(val);
let pw = $('#pixelWidth').val();
circumference = 2 * 3.14 * (pw/2)
dV = circumference * (val/100)
gV = circumference - (dV/2);
if(initial == 'complete'){
$('.text-danger').hide();
$('#dashValue').html(dV.toFixed(3));
$('#gapValue').html(gV.toFixed(3));
};
});
$('#calc').on('click', function(){
if(initial != 'complete'){
calculate();
}
});
$('#pixelWidth').on('input', function(){
if(initial == 'complete'){
let val = $('#percentage').val()
newVal = 360 * val / 100
change = val - newVal;
$('.circle').attr('stroke-dasharray', newVal + ', 20000');
$('.number').html(val);
let pw = $('#pixelWidth').val();
circumference = 2 * 3.14 * (pw/2)
dV = circumference * (val/100)
gV = circumference - (dV/2);
if(initial == 'complete'){
$('.text-danger').hide();
$('#dashValue').html(dV.toFixed(3));
$('#gapValue').html(gV.toFixed(3));
};
}
})
});
</script>
</body>
</html>