psychart
Version:
View air conditions on a psychrometric chart
70 lines (69 loc) • 3.75 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PsyState = void 0;
var SMath = require("smath");
var Psychrolib = require("psychrolib");
/**
* Represents a single air condition using several states.
*/
var PsyState = /** @class */ (function () {
/**
* Initialize a new psychrometric state.
*/
function PsyState(state, options) {
var _a, _b, _c, _d;
this.state = state;
this.options = options;
Psychrolib.SetUnitSystem(options.unitSystem === 'IP' ? Psychrolib.IP : Psychrolib.SI);
this.atm = Psychrolib.GetStandardAtmPressure(options.altitude);
this.hrMax = Psychrolib.GetHumRatioFromTDewPoint(options.dpMax, this.atm);
this.db = state.db;
switch (state.measurement) {
case ('dbrh'): {
this.rh = state.other;
_a = Psychrolib.CalcPsychrometricsFromRelHum(state.db, state.other, this.atm), this.hr = _a[0], this.wb = _a[1], this.dp = _a[2], this.vp = _a[3], this.h = _a[4], this.v = _a[5], this.s = _a[6];
break;
}
case ('dbwb'): {
this.wb = state.other;
_b = Psychrolib.CalcPsychrometricsFromTWetBulb(state.db, state.other, this.atm), this.hr = _b[0], this.dp = _b[1], this.rh = _b[2], this.vp = _b[3], this.h = _b[4], this.v = _b[5], this.s = _b[6];
break;
}
case ('dbdp'): {
this.dp = state.other;
_c = Psychrolib.CalcPsychrometricsFromTDewPoint(state.db, state.other, this.atm), this.hr = _c[0], this.wb = _c[1], this.rh = _c[2], this.vp = _c[3], this.h = _c[4], this.v = _c[5], this.s = _c[6];
break;
}
case ('dbhr'): {
this.dp = Psychrolib.GetTDewPointFromHumRatio(state.db, state.other, this.atm);
_d = Psychrolib.CalcPsychrometricsFromTDewPoint(state.db, this.dp, this.atm), this.hr = _d[0], this.wb = _d[1], this.rh = _d[2], this.vp = _d[3], this.h = _d[4], this.v = _d[5], this.s = _d[6];
if (!SMath.approx(this.hr, state.other) && SMath.error(this.hr, state.other) > 0.01) {
throw new Error('Error in psychrolib computation. Expected: ' + state.other + ', Found: ' + this.hr);
}
break;
}
default: {
throw new Error('Invalid measurement type ' + state.measurement + '.');
}
}
}
/**
* Convert this psychrometric state to an X-Y coordinate on a psychrometric chart.
*/
PsyState.prototype.toXY = function () {
if (this.options.flipXY) {
return {
x: SMath.clamp(SMath.translate(this.hr, 0, this.hrMax, this.options.padding.x, this.options.size.x - this.options.padding.x), this.options.padding.x, this.options.size.x - this.options.padding.x),
y: SMath.clamp(SMath.translate(this.db, this.options.dbMin, this.options.dbMax, this.options.size.y - this.options.padding.y, this.options.padding.y), this.options.padding.y, this.options.size.y - this.options.padding.y)
};
}
else {
return {
x: SMath.clamp(SMath.translate(this.db, this.options.dbMin, this.options.dbMax, this.options.padding.x, this.options.size.x - this.options.padding.x), this.options.padding.x, this.options.size.x - this.options.padding.x),
y: SMath.clamp(SMath.translate(this.hr, 0, this.hrMax, this.options.size.y - this.options.padding.y, this.options.padding.y), this.options.padding.y, this.options.size.y - this.options.padding.y)
};
}
};
return PsyState;
}());
exports.PsyState = PsyState;