Skip to content

Commit

Permalink
Fist commit of (mostly) fixed code
Browse files Browse the repository at this point in the history
  • Loading branch information
sulkaharo committed Aug 4, 2019
1 parent 6985a91 commit 8c74b24
Show file tree
Hide file tree
Showing 25 changed files with 8,562 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
"plugins": [ ],
"extends": [
"eslint:recommended"
],
"parser": "babel-eslint",
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true,
"jquery": true
}
};
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

node_modules/*
16 changes: 16 additions & 0 deletions .jsbeautifyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"indent_size": 2
, "indent_char": " "
, "comma_first": true
, "keep-array-indentation": true
, "space_after_named_function": true
, "space_after_anon_function": true
, "end_with_newline": true
, "brace_style": "collapse,preserve-inline"
, "space_in_brace": true
, "space-in-paren": false
, "break-chained-methods": false
, "max-preserve-newlines": 2
, "space-after-anon-function": false
, "indent-empty-lines": false
}
3 changes: 3 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"esversion": 6
}
122 changes: 122 additions & 0 deletions app/graph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { me as device } from "device";

// Screen dimension fallback for older firmware
if (!device.screen) device.screen = {
width: 348,
height: 250
};

export default class Graph {

constructor(id) {

this._id = id;
this._xscale = 0;
this._yscale = 0;
this._xmin = 0;
this._xmax = 0;
this._ymin = 0;
this._ymax = 0;
this._pointsize = 2;

this._bg = this._id.getElementById("bg");

this._vals = this._id.getElementsByClassName("gval");

this._tHigh = 162;
this._tLow = 72;

this._tHighLine = this._id.getElementById("tHigh");
this._tLowLine = this._id.getElementById("tLow");

this._defaultYmin = 40;
this._defaultYmax = 400;

}

setPosition(x, y) {
this._id.x = x;
this._id.y = y;
}

setSize(w, h) {
this._width = w;
this._height = h;
}

setXRange(xmin, xmax) {
this._xmin = xmin;
this._xmax = xmax;
this._xscale = (xmax - xmin) / this._width;
//console.log("XSCALE: " + this._xscale);
}

setYRange(ymin, ymax) {

this._ymin = ymin;
this._ymax = ymax;
this._yscale = (ymax - ymin) / this._id.height;
//console.log("YSCALE: " + this._yscale);
}

getYmin() {
return this._ymin;
}

getYmax() {
return this._ymax;
}

setBGColor(c) {
this._bgcolor = c;
this._bg.style.fill = c;
}

update(v, highThreshold, lowThreshold) {

console.log("Updating Graph...");

//this._bg.style.fill = this._bgcolor;

this._tHighLine.y1 = this._id.height - ((this._tHigh - this._ymin) / this._yscale);
this._tHighLine.y2 = this._id.height - ((this._tHigh - this._ymin) / this._yscale);
this._tLowLine.y1 = this._id.height - ((this._tLow - this._ymin) / this._yscale);
this._tLowLine.y2 = this._id.height - ((this._tLow - this._ymin) / this._yscale);

// 24 points total
// 120 minutes

for (var index = 0; index < this._vals.length; index++) {

//console.log(`V${index}: ${v[index].sgv}`);
//console.log(this._vals[index]);

//console.log("SGV" + index + ": " + v[index].sgv + " TIME: " + v[index].date);
//this._vals[index].cx = this._width - ((v[index].date-this._xmin) / this._xscale);

if (!v[index]) continue;

let graphEntry = this._vals[index];

let sgv = v[index];

let timeDeltaMinutes = sgv.timedelta / (5 * 60 * 1000);

graphEntry.cy = this._id.height - ((sgv.sgv - this._ymin) / this._yscale);
// console.log('sgv.timedelta: ' + sgv.timedelta + 'sgv is ' + sgv.sgv);
// console.log('cx is: ' + graphEntry.cx + ' and setting it to '+ (this._id.width / 24) * timeDeltaMinutes);
const padding = this._id.width / 48;

graphEntry.cx = this._id.width - ((this._id.width / 24) * timeDeltaMinutes) - padding;

graphEntry.style.fill = 'green';
if (sgv.sgv >= highThreshold || sgv.sgv <= lowThreshold) {
graphEntry.style.fill = 'red';
}

//this._vals[index].cy = this._height - 20;
//this._vals[index].r = this._pointsize;

}
}
};
Loading

0 comments on commit 8c74b24

Please sign in to comment.