-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.js
More file actions
209 lines (169 loc) · 5.29 KB
/
Copy pathcommon.js
File metadata and controls
209 lines (169 loc) · 5.29 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
$(function() {
//SVG Fallback
if(!Modernizr.svg) {
$("img[src*='svg']").attr("src", function() {
return $(this).attr("src").replace(".svg", ".png");
});
};
//E-mail Ajax Send
//Documentation & Example: https://github.com/agragregra/uniMail
$("form").submit(function() { //Change
var th = $(this);
$.ajax({
type: "POST",
url: "mail.php", //Change
data: th.serialize()
}).done(function() {
alert("Thank you!");
setTimeout(function() {
// Done Functions
th.trigger("reset");
}, 1000);
});
return false;
});
var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
// The type of chart we want to create
type: 'line',
// The data for our dataset
data: {
labels : [0],
datasets : [
{
label: "Переходная характеристика",
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#fff",
data : [0]
}
]
},
// Configuration options go here
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
$('img.img-svg').each(function() {
var $img = $(this);
var imgID = $img.attr('id');
var imgClass = $img.attr('class');
var imgURL = $img.attr('src');
$.get(imgURL, function(data) {
// Get the SVG tag, ignore the rest
var $svg = $(data).find('svg');
// Add replaced image's ID to the new SVG
if (typeof imgID !== 'undefined') {
$svg = $svg.attr('id', imgID);
}
// Add replaced image's classes to the new SVG
if (typeof imgClass !== 'undefined') {
$svg = $svg.attr('class', imgClass + ' replaced-svg');
}
// Remove any invalid XML tags as per http://validator.w3.org
$svg = $svg.removeAttr('xmlns:a');
// Check if the viewport is set, if the viewport is not set the SVG wont't scale.
if (!$svg.attr('viewBox') && $svg.attr('height') && $svg.attr('width')) {
$svg.attr('viewBox', '0 0 ' + $svg.attr('height') + ' ' + $svg.attr('width'))
}
// Replace image with new SVG
$img.replaceWith($svg);
}, 'xml');
});
////////////--------------------------------------LAB-work NUMBER 2---------------------------------///////////////////
// get buttons by button`s id
var StartButton = document.getElementById("StartButton");
var StopButton = document.getElementById("StopButton");
var UpButton = document.getElementById("UpButton");
var DownButton = document.getElementById("DownButton");
var ClearButton = document.getElementById("ClearButton");
var NoiseButton = document.getElementById("NoiseButton");
var FastBuild = document.getElementById("FastBuild");
class ElementAP {
constructor(K, T, U, time){
this.K = K;
this.T = T;
this.U = U;
this.timer;
this.time = 10;
this.noise = 0;
}
set setU(U){
this.U = U;
}
get getU(){
return this.U;
}
// `creatingChart` create chart with using library Chart.js, `makechart` launch timer and create chart dynamically depend from real time
creatingChart(){
chart.data.datasets[0].data.push(this.U*this.K*(1 - Math.pow(Math.exp(1), -this.time/this.T)) + this.Noise()); // set new Point at the Y`s axe
var valOfLabel = chart.data.labels[chart.data.labels.length-1] + 1;
chart.data.labels.push(valOfLabel); // set new Point at the X`s axe
chart.update();
this.time = this.time + 100;
}
startTimer(){
if(this.timer == undefined){
this.timer = setInterval(() => {
this.creatingChart();
}, 1000)
}
}
stopTimer(){
if(this.timer != undefined){
clearInterval(this.timer); // if timer exist i stop it
this.timer = undefined;
} else {
console.log("timer is undefined");
}
}
clearChart(){
this.stopTimer();
this.time = 10;
chart.data.datasets[0].data.splice(1, chart.data.datasets[0].data.length);
chart.data.labels.splice(1, chart.data.labels.length);
chart.update();
}
Noise(){
if(NoiseButton.defaultValue == `Noise On`){
return ElementAP.randomNumber(0, 100)/Math.pow(10, 6);
} else {
return 0;
}
}
static randomNumber(min, max){
var rand = min - 0.5 + Math.random() * (max - min + 1)
rand = Math.round(rand);
return rand;
}
fastBuild(){
if(chart.data.labels[chart.data.labels.length-1] == 0){
for(let i = 0; i < 121; i++){
this.creatingChart()
}
}
}
}
// Creating new object with name newTank
var newTank = new ElementAP(9*Math.pow(10, -4), 1087, 1);
// Buttons -----> They start functional of class`s methods
StartButton.onclick = () => { newTank.startTimer(); }
StopButton.onclick = () => { newTank.stopTimer() }
UpButton.onclick = () => { newTank.setU = newTank.getU + 1; }
DownButton.onclick = () => { newTank.setU = newTank.getU - 1; };
ClearButton.onclick = () => { newTank.clearChart(); }
NoiseButton.onclick = () => {
NoiseButton.defaultValue = (NoiseButton.defaultValue == `Noise On`) ? `Noise Off` : `Noise On`;
newTank.Noise();
}
FastBuild.onclick = () => { newTank.fastBuild() }
});