Permalink
Browse files

Sliding max values.

This had a peripheral changes of only considering active items.  That
was kind of a minor bug fix, but I didn't feel like taking it apart.
  • Loading branch information...
1 parent b04cc79 commit c83db341a061e378b148a4de80d3ac36f817e082 @dustin dustin committed May 25, 2012
Showing with 25 additions and 20 deletions.
  1. +25 −20 static/vbmap.js
View
@@ -885,18 +885,15 @@ function makeVBStatThing(totalWidth, h, container) {
var color = d3.scale.category20();
- var maxvalue = {};
- var prevstat = "";
+ var maxvalues = {};
chart.append("g").attr("class", "rulex");
chart.append("g").attr("class", "ruley");
chart.append("g").attr("class", "plot");
function update(json) {
var stat = $("input[@name=stat]:checked").val();
- if (stat != prevstat) {
- maxvalue[prevstat] = 0;
- }
+ var maxvalue = 0;
update.color = color;
var data = [];
var masters = {};
@@ -907,22 +904,30 @@ function makeVBStatThing(totalWidth, h, container) {
for (var vbid in nstates) {
if (nstates[vbid].state === 'active') {
masters[vbid] = node;
+ var n = parseInt(nstates[vbid][stat]);
+ if (n > update.largeN) {
+ update.largeN = n;
+ update.largeV = vbid;
+ }
+ if (n < update.smallN) {
+ update.smallN = n;
+ update.smallV = vbid;
+ }
+ data[vbid] = n;
+ update.total += n;
+ maxvalue = Math.max(maxvalue, n);
}
- var n = parseInt(nstates[vbid][stat]);
- if (n > update.largeN) {
- update.largeN = n;
- update.largeV = vbid;
- }
- if (n < update.smallN) {
- update.smallN = n;
- update.smallV = vbid;
- }
- data[vbid] = n;
- update.total += n;
- maxvalue[stat] = Math.max(maxvalue[stat] || 0, n);
}
}
+ var mva = maxvalues[stat] || [];
+ mva.push(maxvalue);
+ if (mva.length > 10) {
+ mva.shift();
+ }
+ maxvalues[stat] = mva;
+ maxvalue = d3.max(maxvalues[stat]);
+
function master(n) {
return masters[n];
}
@@ -934,7 +939,7 @@ function makeVBStatThing(totalWidth, h, container) {
.range([0, w]);
y = d3.scale.linear()
- .domain([0, maxvalue[stat]])
+ .domain([0, maxvalue])
.rangeRound([0, h]);
chart.select(".plot").selectAll("rect")
@@ -1003,12 +1008,12 @@ function makeVBStatThing(totalWidth, h, container) {
.attr("dx", -25)
.attr("y", y)
.attr("text-anchor", "middle")
- .text(function(d) { return maxvalue[stat] - d; });
+ .text(function(d) { return maxvalue - d; });
chart.select(".ruley").selectAll(".rule")
.data(y.ticks(10))
.attr("y", y)
- .text(function(d) { return maxvalue[stat] - d; });
+ .text(function(d) { return maxvalue - d; });
chart.select(".ruley").selectAll(".rule")
.data(y.ticks(10))

0 comments on commit c83db34

Please sign in to comment.