Skip to content

Commit b69313a

Browse files
committed
feat(periodic_table): add temperature slider
1 parent 97cafc8 commit b69313a

File tree

3 files changed

+67
-32
lines changed

3 files changed

+67
-32
lines changed

src/modules/types/science/chemistry/periodic_table/controller.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ define(['modules/default/defaultcontroller'], function (Default) {
4747
};
4848
};
4949

50-
Controller.prototype.configAliases = {};
50+
Controller.prototype.configAliases = {
51+
};
5152

5253
return Controller;
5354

src/modules/types/science/chemistry/periodic_table/style.css

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -248,22 +248,9 @@ td.solid, td.liquid, td.gas, td.unknown {
248248
display: none;
249249
}
250250

251-
252-
253-
254-
255-
256-
257-
258-
259-
260-
261-
262-
263-
264-
265-
266-
251+
#periodicTemperatureSlider {
252+
width: 200px;
253+
}
267254

268255

269256
/*grey : #5A5A5A*/

src/modules/types/science/chemistry/periodic_table/view.js

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
define(['modules/default/defaultview', 'lib/twigjs/twig', 'src/util/debug'], function (Default, Twig, Debug) {
44

5+
const MIN_TEMPERATURE = 0;
6+
const MAX_TEMPERATURE = 6000;
7+
const INITIAL_TEMPERATURE = 293;
8+
const STEP_TEMPERATURE = 1;
9+
510
function View() {
6-
}
11+
};
712

813
$.extend(true, View.prototype, Default, {
914
init: function () {
@@ -22,6 +27,9 @@ define(['modules/default/defaultview', 'lib/twigjs/twig', 'src/util/debug'], fun
2227
data: ''
2328
});
2429
this.dom.html('');
30+
},
31+
value: function () {
32+
this.dom.html('');
2533
}
2634
},
2735
inDom: function () {
@@ -53,6 +61,7 @@ define(['modules/default/defaultview', 'lib/twigjs/twig', 'src/util/debug'], fun
5361
}
5462
}
5563
},
64+
5665
render: function () {
5766
var that = this;
5867
this.dom.html('');
@@ -72,11 +81,11 @@ define(['modules/default/defaultview', 'lib/twigjs/twig', 'src/util/debug'], fun
7281
var $element = $('<div>' + this.template.render({element: this.elements[i]}) + '</div>').data('idx', i);
7382

7483
$element.addClass('element' +
75-
' e' + this.elements[i].Z +
76-
' period' + this.elements[i].period +
77-
' group' + this.elements[i].group +
78-
' block-' + this.elements[i].block +
79-
' ' + this.elements[i].serie);
84+
' e' + this.elements[i].Z +
85+
' period' + this.elements[i].period +
86+
' group' + this.elements[i].group +
87+
' block-' + this.elements[i].block +
88+
' ' + this.elements[i].serie);
8089

8190
this.dom.append($element);
8291
}
@@ -102,18 +111,25 @@ define(['modules/default/defaultview', 'lib/twigjs/twig', 'src/util/debug'], fun
102111
'<li class="nonmetal">Nonmetals</li>' +
103112
'<li class="halogen">Halogens</li>' +
104113
'<li class="noble">Noble gases</li>' +
105-
'</ul>');
106-
innerLegend.append('<div class="stateOfMatter"><table><tbody>' +
107-
'<tr><td class="solid">S</td><td>Solid</td></tr>' +
108-
'<tr><td class="liquid">L</td><td>Liquid</td></tr>' +
109-
'<tr><td class="gas"">G</td><td>Gas</td></tr>' +
110-
'<tr><td class="unknown">U</td><td>Unknown</td></tr>' +
111-
'</tbody></table>' +
112-
'<dl><dt>Temperature</dt><dd>293.5 K</dd>' +
113-
'<dt>Pressure</dt><dd>101.325 kPa</dd></dl></div>');
114+
'</ul>');
115+
innerLegend.append(`<div class="stateOfMatter"><table><tbody>
116+
<tr><td class="solid">S</td><td>Solid</td></tr>
117+
<tr><td class="liquid">L</td><td>Liquid</td></tr>
118+
<tr><td class="gas"">G</td><td>Gas</td></tr>
119+
<tr><td class="unknown">U</td><td>Unknown</td></tr>
120+
</tbody></table>
121+
<dl><dt>Temperature</dt><dd id="periodicTemperature">${INITIAL_TEMPERATURE} K</dd>
122+
<dt>Pressure</dt><dd>101.325 kPa</dd></dl></div>
123+
<input id="periodicTemperatureSlider" type="range" min="${MIN_TEMPERATURE}" max="${MAX_TEMPERATURE}" step="${STEP_TEMPERATURE}" value="${INITIAL_TEMPERATURE}"/>`);
114124

115125
var isFixed = false;
116126

127+
innerLegend.on('input', '#periodicTemperatureSlider', event => {
128+
console.log(event.target.value);
129+
innerLegend.find('#periodicTemperature').html('' + event.target.value + ' K');
130+
this.updateElementPhase();
131+
});
132+
117133
$('.element').mouseenter(function () {
118134
if (isFixed) return;
119135
renderElement($(this));
@@ -159,6 +175,37 @@ define(['modules/default/defaultview', 'lib/twigjs/twig', 'src/util/debug'], fun
159175
var lanthanid = ('<div class="indic-f period6"><p>57-71</p></div>');
160176
$('div.e56').after(lanthanid);
161177
$('div.e88').after(actinid);
178+
},
179+
180+
updateElementPhase: function () {
181+
var $elements = this.dom.find('.element');
182+
var temperature = this.getTemperature();
183+
for (let i = 0; i < $elements.length; i++) {
184+
let $el = $($elements[i]);
185+
var idx = $el.data('idx');
186+
if (idx !== undefined) {
187+
let el = this.elements[idx];
188+
let boiling = +el.boiling;
189+
let melting = +el.melting;
190+
if (isNaN(boiling) && isNaN(melting)) {
191+
$el.removeClass('solid liquid gas');
192+
$el.addClass('unknown');
193+
} else if (temperature < melting) {
194+
$el.removeClass('liquid gas unknown');
195+
$el.addClass('solid');
196+
} else if(temperature < boiling) {
197+
$el.removeClass('solid gas unknown');
198+
$el.addClass('liquid');
199+
} else {
200+
$el.removeClass('liquid solid unknown');
201+
$el.addClass('gas');
202+
}
203+
}
204+
}
205+
},
206+
207+
getTemperature() {
208+
return this.dom.find('#periodicTemperatureSlider')[0].value;
162209
}
163210

164211

0 commit comments

Comments
 (0)