function addCommas (nStr) {
nStr += '';
var x = nStr.split('.');
var x1 = x[0];
var x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
Math.cbrt = Math.cbrt || function(x) {
var y = Math.pow(Math.abs(x), 1/3);
return x < 0 ? -y : y;
};
function changeMaterial (childGroup, material) {
for (var w = 0; w < childGroup.length; w++){
if (childGroup[w].material){
childGroup[w].castShadow = true;
//childGroup[w].receiveShadow = true;
childGroup[w].material = material
}
else {
changeMaterial (childGroup[w].children, material)
}
}
}
function makeCorrectSize (object, correctHeight){
var bBox = new THREE.Box3().setFromObject(object);
var currentHeight = bBox.max.y - bBox.min.y
var scale = (1/currentHeight) * correctHeight
object.scale.set(scale, scale, scale);
object.position.x = 0;
object.position.y = 0;
object.position.z = 0;
}
function checkNumeric (value){
if (value === "null"){
return null
}
valueToNum = parseFloat(value)
if (isNaN(valueToNum) === true){
//alert("Some energy values in the dataset are not valid numbers. These will be //replaced with null values")
return null;
}
else if (valueToNum < 0){
//alert("Some energy values in the dataset are negative. These will be replaced //with null values")
return null;
}
else {
return valueToNum
}
}
function massToString (kg) {
var val;
var unit;
if (kg < 1) {
val = kg*1000;
unit = "g"
}
else if (kg < 1000) {
val = kg;
unit = "kg"
}
else {
val = kg/1000;
unit = "t"
}
val = addCommas(parseFloat(val.toPrecision(2)))
return val+" "+unit;
}
function distanceToString (m) {
var val;
var unit;
if (m < 1) {
val = m*100;
unit = "cm"
}
else if (m < 1000) {
val = m;
unit = "m"
}
else {
val = m/1000;
unit = "km"
}
val = addCommas(parseFloat(val.toPrecision(2)))
return val+" "+unit;
}
function volumeToString (m3) {
var val;
var unit;
if (m3 < 0.01) {
val = m3*1000000;
unit = "cm3"
}
else{
val = m3;
unit = "m3"
}
val = addCommas(parseFloat(val.toPrecision(2)))
return val+" "+unit;
}
function numToString (val) {
val = addCommas(parseFloat(val.toPrecision(2)))
return val
}
/*
function createIcon (addevent, src, parent, text, opens, onclick, align, popupTo) {
var popup;
var elem = document.createElement("img")
elem.src = src
elem.title = text
elem.classList.add("icon")
parent.appendChild(elem)
if (opens === true) {
popup = document.createElement("div")
popup.classList.add("popup")
populate (popup)
parent.appendChild(popup)
var eBox = elem.getBoundingClientRect()
var pBox = popup.getBoundingClientRect()
if (align === "top") {
popup.style.top = eBox.y+"px";
}
else if (align === "bottom") {
popup.style.top = eBox.y + eBox.height - pBox.height+"px";
}
else if (align === "left") {
popup.style.left = eBox.x+"px";
}
else {
popup.style.left = eBox.x + eBox.width - pBox.width+"px";
}
if (popupTo === "left") {
popup.style.left = eBox.x - pBox.width-5+"px";
}
else if (popupTo === "right") {
popup.style.left = eBox.x + eBox.width+5+"px";
}
else if (popupTo === "top") {
popup.style.top = eBox.y - pBox.height-5+"px";
}
else {
popup.style.top = eBox.y + eBox.height+5+"px";
}
//console.log(eBox, pBox, popup.style.top, popup.style.left)
if (onClick) {
addevent(elem, "click", function () {
if (!elem.classList.contains("open")) {
var openIcons = document.getElementsByClassName("open")
for (var i = 0; i < openIcons.length; i++){
eventFire(openIcons[i], "click")
}
elem.classList.add("open")
elem.src = "icons/close.svg"
onclick (this, popup, true)
}
else {
elem.classList.remove("open")
elem.src = src;
onclick (this, popup, false)
}
})
}
}
else {
addevent (elem, "click", function () {
onclick ()
})
}
if (popup) {
return popup;
}
}
function showPopup (target, popup, open) {
if (open === true) {
popup.style.display = "block"
}
else {
popup.style.display = "none"
}
}
function eventFire(el, etype){
if (el.fireEvent) {
el.fireEvent('on' + etype);
} else {
var evObj = document.createEvent('Events');
evObj.initEvent(etype, true, false);
el.dispatchEvent(evObj);
}
}
*/