index.js
function _getGradientTexture() {
        // Only update the texture when the gradient has changed.
        if (this._prevGradientColors === this.props.gradientColors) {
            return this._gradientTexture;
        }
        var canvas = document.createElement('canvas');
        // 512, 10 because these are the same dimensions webgl-heatmap uses for its
        // built in gradient textures.
        var width = 512;
        var height = 10;
        canvas.width = String(width);
        canvas.height = String(height);
        var ctx = canvas.getContext('2d');
        var gradient = ctx.createLinearGradient(0, height / 2, width, height / 2);
        var colors = this.props.gradientColors;
        colors.forEach(function each(color, index) {
            var position = index / (colors.size - 1);
            gradient.addColorStop(position, color);
        });
        ctx.fillStyle = gradient;
        ctx.fillRect(0, 0, width, height);
        var image = new window.Image();
        image.src = canvas.toDataURL('image/png');
        return image;
    }
function _getGradientTexture() {
        // Only update the texture when the gradient has changed.
        if (this._prevGradientColors === this.props.gradientColors) {
            return this._gradientTexture;
        }
        var canvas = document.createElement('canvas');
        // 512, 10 because these are the same dimensions webgl-heatmap uses for its
        // built in gradient textures.
        var width = 512;
        var height = 10;
        canvas.width = String(width);
        canvas.height = String(height);
        var ctx = canvas.getContext('2d');
        var gradient = ctx.createLinearGradient(0, height / 2, width, height / 2);
        var colors = this.props.gradientColors;
        colors.forEach(function each(color, index) {
            var position = index / (colors.size - 1);
            gradient.addColorStop(position, color);
        });
        ctx.fillStyle = gradient;
        ctx.fillRect(0, 0, width, height);
        var image = new window.Image();
        image.src = canvas.toDataURL('image/png');
        return image;
    }
function _getGradientTexture ( ) { // Only update the texture when the gradient has changed. if ( this . _prevGradientColors === this . props . gradientColors ) { return this . _gradientTexture ; } var canvas = document . createElement ( 'canvas' ) ; // 512, 10 because these are the same dimensions webgl-heatmap uses for its // built in gradient textures. var width = 512 ; var height = 10 ; canvas . width = String ( width ) ; canvas . height = String ( height ) ; var ctx = canvas . getContext ( '2d' ) ; var gradient = ctx . createLinearGradient ( 0 , height / 2 , width , height / 2 ) ; var colors = this . props . gradientColors ; colors . forEach ( function each ( color , index ) { var position = index / ( colors . size - 1 ) ; gradient . addColorStop ( position , color ) ; } ) ; ctx . fillStyle = gradient ; ctx . fillRect ( 0 , 0 , width , height ) ; var image = new window . Image ( ) ; image . src = canvas . toDataURL ( 'image/png' ) ; return image ; }
Updates `this._gradientTexture` Image if `props.gradientColors`
has changed.
@returns {Image} `this._gradientTexture`.
Updates this . _gradientTexture Image if props . gradientColors has changed .