UNPKG

psychart

Version:

View air conditions on a psychrometric chart

76 lines (75 loc) 3.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PsyState = void 0; var smath_1 = 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) { var _a, _b, _c; this.db = state.db; switch (state.measurement) { case ('dbrh'): { this.rh = state.other; _a = Psychrolib.CalcPsychrometricsFromRelHum(state.db, state.other, PsyState.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, PsyState.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, PsyState.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; } default: { throw new Error('Invalid measurement type ' + state.measurement + '.'); } } } /** * Compute a first-time initialization of psychrolib. */ PsyState.initialize = function (options) { PsyState.size = options.size; PsyState.padding = options.padding; PsyState.flipXY = options.flipXY; Psychrolib.SetUnitSystem(options.unitSystem === 'IP' ? Psychrolib.IP : Psychrolib.SI); PsyState.atm = Psychrolib.GetStandardAtmPressure(options.altitude); PsyState.dbMin = options.dbMin; PsyState.dbMax = options.dbMax; PsyState.hrMax = Psychrolib.GetHumRatioFromTDewPoint(options.dpMax, PsyState.atm); }; /** * A static helper function to convert a humidity ratio into a dew point. */ PsyState.hr2dp = function (db, hr) { return Psychrolib.GetTDewPointFromHumRatio(db, hr, PsyState.atm); }; /** * Convert this psychrometric state to an X-Y coordinate on a psychrometric chart. */ PsyState.prototype.toXY = function () { if (PsyState.flipXY) { return { x: smath_1.SMath.clamp(smath_1.SMath.translate(this.hr, 0, PsyState.hrMax, PsyState.padding.x, PsyState.size.x - PsyState.padding.x), PsyState.padding.x, PsyState.size.x - PsyState.padding.x), y: smath_1.SMath.clamp(smath_1.SMath.translate(this.db, PsyState.dbMin, PsyState.dbMax, PsyState.size.y - PsyState.padding.y, PsyState.padding.y), PsyState.padding.y, PsyState.size.y - PsyState.padding.y) }; } else { return { x: smath_1.SMath.clamp(smath_1.SMath.translate(this.db, PsyState.dbMin, PsyState.dbMax, PsyState.padding.x, PsyState.size.x - PsyState.padding.x), PsyState.padding.x, PsyState.size.x - PsyState.padding.x), y: smath_1.SMath.clamp(smath_1.SMath.translate(this.hr, 0, PsyState.hrMax, PsyState.size.y - PsyState.padding.y, PsyState.padding.y), PsyState.padding.y, PsyState.size.y - PsyState.padding.y) }; } }; return PsyState; }()); exports.PsyState = PsyState;