This commit is contained in:
Martin Donnelly 2017-01-07 22:33:43 +00:00
parent 7f37f2f19d
commit dd233e830d
6 changed files with 121 additions and 21 deletions

View File

@ -10,6 +10,9 @@
</head>
<body>
<div class="datebox">
<div class="section">local time</div>
<div>
@ -30,6 +33,21 @@
<div class="weatherDescription" id="weatherDescription"></div>
</div>
<div id="graph-p-pane">
<svg id="graph-svg" width="300" height="150" fill="blue">
<line x1="46" y1="12" x2="280" y2="12"
style="stroke:#004c6d;stroke-width:2;"></line>
<text id="graph-txt1" x="36" y="15" text-anchor="end">--</text>
<line x1="46" y1="136" x2="280" y2="136"
style="stroke:#004c6d;stroke-width:2;"></line>
<text id="undefined" x="36" y="139" text-anchor="end">0</text>
<polyline id="graph-line" fill="none" stroke="#2196F3"
text-anchor="end" stroke-width="2"
points=""></polyline>
</svg>
</div>
</div>
<!-- build:vendor -->
<script src="libs/jquery.js"></script>
@ -46,6 +64,7 @@
<script src="js/modules/clock.js"></script>
<script src="js/modules/temp.js"></script>
<script src="js/modules/graph.js"></script>
<script src="js/app.js"></script>
<!-- endbuild -->

View File

@ -10,7 +10,7 @@
*/
(function($) {
/* let TodayDataModel = Backbone.Model.extend({
/* Let TodayDataModel = Backbone.Model.extend({
initialize: function () {
this.set('url', '/today/data');
@ -28,7 +28,11 @@
const tempModel = new TempModel();
let temp = new Temp({model: tempModel});
const graphModel = new GraphModel();
let graph = new Graph({model: graphModel});
webSocketModel.setTemp(tempModel);
webSocketModel.setGraph(graphModel);
})(jQuery);

66
app/js/modules/graph.js Normal file
View File

@ -0,0 +1,66 @@
/**
* Created by martin on 1/7/17.
*/
let GraphModel = Backbone.Model.extend({});
let Graph = Backbone.View.extend({
tagName: 'div',
initialize: function() {
_.bindAll(this, 'update');
this.model.bind('change', this.update);
this.text1ID ='graph-txt1';
this.lineID ='graph-line';
console.log('graph init');
//This.$indoorTemp = $('#indoorTemp');
//this.$fan = $('#fan');
// this.$fan.hide();
},
update: function() {
console.log('Graph:Update');
const data = this.model.get('data');
var _data = data ;
var ceilingLimit;
var ceiling;
ceiling = _data.reduce(function(p, v) {
return (Math.abs(p) > Math.abs(v) ? Math.abs(p) : Math.abs(v));
});
console.dir(ceiling);
var calcArray = [];
ceilingLimit = (Math.ceil((Math.round(ceiling) + 1) / 1.5) * 1.5);
if (ceilingLimit > 1000) {
ceilingLimit = (Math.ceil((Math.round(ceiling) + 1) / 50) * 50);
}
var scale = 124 / ceilingLimit;
// Var xstep = (280 - 46) / 100;
var xstep = 2.34;
var startX = 46 + (100 - _data.length) * xstep;
for (var x = 0;x < _data.length;x++) {
calcArray.push((startX + (x * xstep)).toFixed(2) + ',' + (136 - ((_data[x]) * scale)).toFixed(2));
}
console.log(calcArray);
var elm = document.getElementById(this.lineID);
elm.setAttribute('points',calcArray.join(' '));
elm = document.getElementById(this.text1ID);
elm.textContent = ceilingLimit;
}
});

View File

@ -60,12 +60,20 @@ let SOCKETMANAGER = (function () {
console.log(item);
this.temp.set('data', item.data);
}
if (item.id === 'graph') {
console.log(item);
this.graph.set('data', item.data);
}
}
}
, setTemp: function(obj) {
this.temp = obj;
}, setGraph: function(obj) {
this.graph = obj;
},
getUpdate: function() {
this.webSocket.send('update');

View File

@ -28,7 +28,7 @@ var filePath = {
var fontOptions = { };
gulp.task('appJS', function() {
return gulp.src(['app/js/websocket.js','app/js/tempSocket.js','app/js/modules/clock.js','app/js/modules/temp.js','app/js/app.js'])
return gulp.src(['app/js/websocket.js','app/js/tempSocket.js','app/js/modules/clock.js','app/js/modules/temp.js','app/js/modules/graph.js','app/js/app.js'])
.pipe(stripDebug())
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))

View File

@ -35,7 +35,7 @@ let wemoClient = null;
let wemo = new Wemo();
wemo.discover(function(deviceInfo) {
/*wemo.discover(function(deviceInfo) {
logger.info('Wemo Device Found: %j', deviceInfo);
// Get the client for the found device
@ -48,12 +48,15 @@ wemo.discover(function(deviceInfo) {
// Turn the switch on
wemoClient.setBinaryState(0);
});
});*/
busEmitter.on('changeState', function(mode) {
logger.info('Changing state..');
if (wemoClient !== null) {
wemoClient.setBinaryState(0);
}
});