Skip to content

Instantly share code, notes, and snippets.

@robfallows
Last active August 29, 2015 14:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robfallows/9bd0e199fcbcf456d607 to your computer and use it in GitHub Desktop.
Save robfallows/9bd0e199fcbcf456d607 to your computer and use it in GitHub Desktop.
Simple tunguska:gauge example
<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>
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);
});
});
}
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);
});
@robfallows
Copy link
Author

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 a if (Meteor.isClient) block.

Similarly, the server.js must be in the server folder, or enclosed in a if (Meteor.isServer) block.

The first gauge in http://tunguska-gauge-demo.meteor.com is generated like this.

@ionescu77
Copy link

Wow, this looks amazing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment