Permalink
Browse files

Added some colors

  • Loading branch information...
1 parent cbcfc08 commit 09b0598d7ce541c2cfc6f9d284262af12b272fe4 @ryanrolds committed Mar 30, 2012
@@ -6,6 +6,10 @@
}
#list .collector {
+
+}
+
+#list .collector > .name {
height: 20px;
background-color: #EEE;
font-size: 18px;
@@ -18,7 +22,7 @@
}
#list .watchable {
- padding: 5px 0 5px 0px;
+ padding: 5px 0 5px 5px;
}
.clickable {
@@ -16,7 +16,6 @@ Collector.prototype.createUI = function() {
name.appendChild(document.createTextNode(this.id));
$(name).click({'collector': this}, function(e) {
- console.log(e.data);
e.data.collector.toggleWatchables();
});
@@ -66,11 +65,13 @@ Collector.prototype.createWatchable = function(id) {
var watchable = e.data.watchable;
var pos = $.inArray(watchable, collector.active);
if(pos === -1) {
- collector.active.splice(pos, 1);
- e.data.collector.watch(e.data.watchable);
- } else {
collector.active.push(watchable);
- e.data.collector.unwatch(e.data.watchable);
+ collector.watch(e.data.watchable);
+ e.currentTarget.parentNode.style.backgroundColor = collector.parent.getColor();
+ } else {
+ collector.active.splice(pos, 1);
+ collector.unwatch(e.data.watchable);
+ e.currentTarget.parentNode.style.backgroundColor = 'transparent';
}
});
@@ -36,7 +36,6 @@ Monitor.prototype.setupSocketIO = function() {
}
socket.emit('watchables', function(error, response) {
- console.log(error, response);
for(var k in response.collectors) {
that.addCollector(k, response.collectors[k]);
};
@@ -57,13 +56,56 @@ Monitor.prototype.watch = function(id, watchable) {
'hostname': id,
'watchable': watchable
};
- this.socket.emit('watch', data);
+ this.socket.emit('watch', data, function() {
+
+ });
};
Monitor.prototype.unwatch = function(id, watchable) {
var data = {
'hostname': id,
'watchable': watchable
};
- this.socket.emit('unwatch');
+ this.socket.emit('unwatch', data, function() {
+
+ });
};
+
+
+// http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
+Monitor.prototype.getColor = function() {
+ var grc = 0.618033988749895;
+ var h = Math.random();
+ h += 0.618033988749895;
+ h = h % 1;
+ return this.hsvToRGB(h, 0.5, 0.95);
+};
+
+Monitor.prototype.hsvToRGB = function(h, s, v) {
+ var i = Math.floor(h * 6);
+ var f = h * 6 - i;
+ var p = v * (1 - s);
+ var q = v * (1 - f * s);
+ var t = v * (1 - (1 - f) * s);
+
+ var rgb;
+ if(i === 0) {
+ rgb = [v, t, p];
+ } else if(i === 1) {
+ rgb = [q, v, p];
+ } else if(i === 2) {
+ rgb = [p, v, t];
+ } else if(i === 3) {
+ rgb = [p, q, v];
+ } else if(i === 4) {
+ rgb = [t, p, v];
+ } else if(i === 5) {
+ rgb = [v, p, q];
+ }
+
+ rgb[0] = (Math.floor(rgb[0] * 256)).toString(16);
+ rgb[1] = (Math.floor(rgb[1] * 256)).toString(16);
+ rgb[2] = (Math.floor(rgb[2] * 256)).toString(16);
+
+ return '#' + rgb.join('');
+};

0 comments on commit 09b0598

Please sign in to comment.