-
Notifications
You must be signed in to change notification settings - Fork 0
/
treemap-color.js
121 lines (97 loc) · 3.45 KB
/
treemap-color.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
(function(H) {
H.wrap(H.ColorAxis.prototype, 'setLegendColor', function(proceed) {
var grad,
horiz = this.horiz,
options = this.options,
reversed = this.reversed,
one = reversed ? 1 : 0,
zero = reversed ? 0 : 1;
if (this.chart.options.colorAxis.lowerColors &&
this.chart.options.colorAxis.upperColors &&
(this.min !== undefined || this.min !== null)) {
var middlePoint = (this.min + this.max) / 2;
if (this.chart.options.colorAxis.middlePoint !== undefined &&
this.chart.options.colorAxis.middlePoint !== null) {
middlePoint = this.chart.options.colorAxis.middlePoint;
}
var pos = 1 - ((this.max - middlePoint) / ((this.max - this.min) || 1));
var lowerColors = this.chart.options.colorAxis.lowerColors;
var upperColors = this.chart.options.colorAxis.upperColors;
if (reversed) {
lowerColors = {
maxColor: this.chart.options.colorAxis.upperColors.minColor,
minColor: this.chart.options.colorAxis.upperColors.maxColor
}
upperColors = {
maxColor: this.chart.options.colorAxis.lowerColors.minColor,
minColor: this.chart.options.colorAxis.lowerColors.maxColor,
}
}
grad = horiz ? [ one, 0, zero, 0 ] : [ 0, zero, 0, one ]; // #3190
this.legendColor = {
linearGradient: { x1: grad[ 0 ], y1: grad[ 1 ], x2: grad[ 2 ], y2: grad[ 3 ] },
stops: [
[ 0, lowerColors.minColor ], [ pos, upperColors.minColor ], [ 1, upperColors.maxColor ]
]
};
} else {
proceed.apply(this, Array.prototype.slice.call(arguments, 1));
}
});
H.wrap(H.ColorAxis.prototype, 'toColor', function(proceed) {
var pos,
stops = this.stops,
from,
to,
color,
dataClasses = this.dataClasses,
dataClass,
i,
chart = this.chart,
legend = chart.legend,
reversed = this.reversed;
if (this.chart.options.colorAxis.lowerColors &&
this.chart.options.colorAxis.upperColors) {
var value = arguments[ 1 ];
var lowerColors = this.chart.options.colorAxis.lowerColors;
var upperColors = this.chart.options.colorAxis.upperColors;
var middlePoint = (this.min + this.max) / 2;
if (this.chart.options.colorAxis.middlePoint !== undefined &&
this.chart.options.colorAxis.middlePoint !== null) {
middlePoint = this.chart.options.colorAxis.middlePoint;
}
var min = this.min;
var max = this.max;
var colorsToPick = {
minColor: '#ffffff',
maxColor: '#ffffff'
};
if (value >= middlePoint) {
// upper value
min = middlePoint;
colorsToPick = reversed? lowerColors : upperColors;
} else if(value < middlePoint) {
// lower value
max = middlePoint;
colorsToPick = reversed ? upperColors : lowerColors;
}
if (reversed) {
colorsToPick = {
minColor: colorsToPick.maxColor,
maxColor: colorsToPick.minColor
}
}
pos = 1 - ((max - value) / ((max - min) || 1));
color = this.tweenColors(
H.Color(colorsToPick.minColor),
H.Color(colorsToPick.maxColor),
pos
);
this.setLegendColor();
legend.options.enabled ? legend.colorizeItem(this, true) : undefined;
return color;
} else {
return proceed.apply(this, Array.prototype.slice.call(arguments, 1));
}
});
}(Highcharts));