1

Changing bar graph color based on value

This commit is contained in:
Alex Yatskov 2014-09-25 16:47:56 +09:00
parent 6a8f7bfa6d
commit d10b27b9db
2 changed files with 23 additions and 21 deletions

View File

@ -75,7 +75,7 @@ function Column(canvas, name, params, scale, range, bounds) {
top: this.fillBounds.top,
width: this.fillBounds.width,
height: this.fillBounds.height,
fill: this.fillColor
fill: this.getFillColor()
});
this.updateRect('handleRect', {
@ -83,7 +83,7 @@ function Column(canvas, name, params, scale, range, bounds) {
top: this.handleBounds.top,
width: this.handleBounds.width,
height: this.handleBounds.height,
fill: this.handleColor
fill: this.getHandleColor()
});
if (final && goog.math.Range.containsPoint(this.range, 0.0)) {
@ -133,14 +133,6 @@ function Column(canvas, name, params, scale, range, bounds) {
}
}
this.updateColor = function(color) {
var fillColorRgb = goog.color.hexToRgb(goog.color.parse(color).hex);
var handleColorRgb = goog.color.darken(fillColorRgb, this.handleDarken);
this.fillColor = goog.color.rgbToHex.apply(this, fillColorRgb);
this.handleColor = goog.color.rgbToHex.apply(this, handleColorRgb);
}
this.decimateHints = function(steps, scale) {
var groups = this.groupHints(steps);
@ -245,6 +237,14 @@ function Column(canvas, name, params, scale, range, bounds) {
return handleBounds;
}
this.getFillColor = function() {
return this.value >= 0.0 ? this.fillColorPos : this.fillColorNeg;
}
this.getHandleColor = function() {
return this.value >= 0.0 ? this.handleColorPos : this.handleColorNeg;
}
this.mouseDown = function(position) {
if (this.isGrabbing(position)) {
this.stateTransition(this.State.DRAG, position);
@ -360,6 +360,10 @@ function Column(canvas, name, params, scale, range, bounds) {
this.emptyColor = '#eeeeec';
this.strokeColor = '#d3d7cf';
this.tickColor = '#888a85';
this.fillColorPos = '#3465a4';
this.fillColorNeg = '#cc0000';
this.handleColorPos = '#204a87';
this.handleColorNeg = '#a40000';
this.canvas = canvas;
this.shapes = [];
@ -372,7 +376,6 @@ function Column(canvas, name, params, scale, range, bounds) {
this.bounds = bounds;
this.state = this.State.NORMAL;
this.updateColor(params.color);
this.updateShapes(true);
}

View File

@ -251,7 +251,6 @@ function execQuery(query, callback) {
);
graphColumns[keyword] = {
color: '#607080',
value: query.searchParams[keyword],
hints: searchHints,
steps: query.hintSteps