Debian Codegraph @

dojox/color/SimpleColorModel.js

raw symbols SCIP
1 define(["dojo/_base/array", "dojo/_base/declare", "dojox/color"],
2 function(arr, declare, color){
3
4 return declare("dojox.color.SimpleColorModel", null, {
5 // summary:
6 // Base class for color models that return a color from a data value
7 // using an interpolation between two extremum colors.
8
9 _startColor: null,
10 _endColor: null,
11
12 constructor: function(startColor, endColor){
13 // summary:
14 // Construct a color model interpolating between start and end color.
15 // If only start color is provided use it to compute reasonable start and end
16 // colors from it.
17 // startColor: dojo/_base/Color
18 // The start color.
19 // endColor: dojo/_base/Color?
20 // The end color.
21 if(endColor != undefined){
22 this._startColor = startColor;
23 this._endColor = endColor;
24 }else{
25 // When only one color is provided
26 // use only the hue, and compute
27 // the start/end colors by playing
28 // with the luminance...
29 var hsl = startColor.toHsl();
30 hsl.s = 100;
31 hsl.l = 85;
32 this._startColor = color.fromHsl(hsl.h, hsl.s, hsl.l);
33 this._startColor.a = startColor.a;
34 hsl.l = 15;
35 this._endColor = color.fromHsl(hsl.h, hsl.s, hsl.l);
36 this._endColor.a = startColor.a;
37 }
38 },
39
40 _getInterpoledValue: function(from, to, value){
41 return(from + (to - from) * value);
42 },
43
44 getNormalizedValue: function(value){
45 // summary:
46 // Return the normalized (between 0 and 1) value for a given data value.
47 // This function must be implemented by implementations.
48 // value: Number
49 // The data value.
50 },
51
52 getColor: function(value){
53 // summary:
54 // return the color for a given data value.
55 // value: Number
56 // The data value.
57 var completion = this.getNormalizedValue(value);
58 var hslFrom = this._startColor.toHsl();
59 var hslTo = this._endColor.toHsl();
60 var h = this._getInterpoledValue(hslFrom.h, hslTo.h, completion);
61 var s = this._getInterpoledValue(hslFrom.s, hslTo.s, completion);
62 var l = this._getInterpoledValue(hslFrom.l, hslTo.l, completion);
63 var a = this._getInterpoledValue(this._startColor.a, this._endColor.a, completion);
64 var c = color.fromHsl(h, s, l);
65 c.a = a;
66 return c;
67 }
68 });
69 });