define(['app/Colour'],
function (Colour) {

    // -----------------------------------------------------------------------------------------------------------------
    // Constructor
    // -----------------------------------------------------------------------------------------------------------------

    /**
     * @constructor
     */
    function ColourMap()
    {
        /** @type {{value:number, colour:Colour}[]} */
        this._colours = [];
        /** @type {!Colour} */
        this._outOfRangeColour = null;
    }

    // -----------------------------------------------------------------------------------------------------------------
    // Private functions
    // -----------------------------------------------------------------------------------------------------------------

    /**
     * @param {{value:number, colour:Colour}[]} colours
     * @param {number} value
     * @returns {number} The index into [this._colours].
     * @private
     */
    function upperBound(colours, value) {
        var i = 0;
        while (i < colours.length && value < colours[i].value) {
            ++i;
        }
        return i;
    }

    // -----------------------------------------------------------------------------------------------------------------
    // Member functions
    // -----------------------------------------------------------------------------------------------------------------

    ColourMap.prototype.clear = function()
    {
        this._colours = [];
    };

    /**
     * @param {number} value
     * @param {Colour} colour
     */
    ColourMap.prototype.addColour = function(value, colour)
    {
        var i = upperBound(this._colours, value);
        this._colours.splice(i, 0, {value:value, colour:colour});
    };

    /**
     * @param {?Colour} colour
     */
    ColourMap.prototype.setOutOfRangeColour = function(colour)
    {
        this._outOfRangeColour = colour;
    };

    /**
     * @param {number} value
     * @returns {Colour}
     */
    ColourMap.prototype.colour = function(value)
    {
        var i = upperBound(this._colours, value);

        if (i == 0) {
            return this._outOfRangeColour || this._colours[0].value;
        }
        else if (i == this._colours.length) {
            return this._outOfRangeColour || this._colours[i-1].colour;
        }

        var low = this._colours[i-1];
        var high = this._colours[i];
        return Colour.interpolate(
            (value - low.value) / (high.value - low.value),
            low.colour,
            high.colour
        );
    };

    return ColourMap;

});

@@ -1003,24 +1003,28 @@
 ours, value)
+%0A   
  %7B%0A        v
@@ -1073,16 +1073,8 @@
 h &&
- value %3C
  col
@@ -1086,16 +1086,24 @@
 i%5D.value
+ %3C value
 ) %7B%0A    
@@ -1635,32 +1635,142 @@
 , colour)%0A    %7B%0A
+        var exists = this._colours.some(function(x) %7B return x.value == value; %7D);%0A        if (!exists) %7B%0A    
         var i = 
@@ -1803,32 +1803,36 @@
 value);%0A        
+ 
+   
 this._colours.sp
@@ -1849,16 +1849,17 @@
  %7Bvalue:
+ 
 value, c
@@ -1864,16 +1864,17 @@
  colour:
+ 
 colour%7D)
@@ -1871,24 +1871,34 @@
 : colour%7D);%0A
+        %7D%0A
     %7D;%0A%0A    

Fix issue in upperBound() and avoid adding duplicates.