Last active
August 29, 2015 14:16
-
-
Save robfallows/9bd0e199fcbcf456d607 to your computer and use it in GitHub Desktop.
Simple tunguska:gauge example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=0, width=device-width"> | |
</head> | |
<body> | |
{{> gauge id="demo" style="basic"}} | |
</body> | |
<template name="gauge"> | |
<div id="demo" style="display:inline-block;width:200px;height:200px;"></div> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GaugeData = new Mongo.Collection('gauge-data'); | |
Template.gauge.rendered = function() { | |
var self = this; | |
self.gauge = new TunguskaGauge({ | |
id: self.data.id, | |
theme: self.data.style | |
}); | |
self.subscribe('current-gauge-data', function() { // Uses new Meteor 1.0.4 Template.subscribe() method | |
self.autorun(function() { | |
self.gauge.set(GaugeData.findOne({_id:'demo'}).value); | |
}); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Meteor.publish('current-gauge-data', function() { | |
var init = false; | |
var self = this; | |
Meteor.setInterval(function() { | |
var ran = Math.floor(Math.random() * 101); | |
if (init) { | |
self.changed('gauge-data', 'test', {value:ran}); | |
} else { | |
self.added('gauge-data', 'test', {value:ran}); | |
} | |
self.ready(); | |
init = true; | |
}, 1000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated client.js for Meteor 1.0.4 Template.subscribe() method
This gist uses a client-only collection (it will not be persisted to a MongoDB collection). A simple pub/sub is set up to send random numbers from the server to the client, where they are rendered by the gauge.
Note that the
client.js
must be in the client folder, or enclosed in aif (Meteor.isClient)
block.Similarly, the
server.js
must be in the server folder, or enclosed in aif (Meteor.isServer)
block.The first gauge in http://tunguska-gauge-demo.meteor.com is generated like this.