-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheatmap.rb
89 lines (83 loc) · 1.81 KB
/
heatmap.rb
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
require 'json'
def make_chart(
title: "Chart", subtitle: nil,
xtitle: nil, ytitle: nil,
placeholder: 'PLACEHOLDER', height: 400)
tooltip_formatter = "function() { return '' + this.point.count + ' occurrences / ' + this.point.total + ' total words' }"
xlabels, ylabels, data = [], [], []
for x in 1..300
for y in 1..300
xlabels << x
ylabels << y
data << [x-1, y-1, x*y]
end
end
{
chart: {
renderTo: "|div|",
height: height,
type: 'heatmap'
},
title: {
text: title,
x: -20
},
subtitle: {
text: subtitle,
x: -20
},
xAxis: {
# categories: xlabels,
title: { text: xtitle }
},
yAxis: {
min: 0,
# categories: ylabels,
title: { text: ytitle }
},
colorAxis: {
# min: 0,
# minColor: '#FFFFFF',
# maxColor: "|Highcharts.getOptions().colors[0]|"
stops: [
[0, '#3060cf'],
[0.5, '#fffbbc'],
[0.9, '#c4463a'],
[1, '#c4463a']
],
startOnTick: false,
endOnTick: false,
labels: {
format: 'Score: {value}'
}
},
tooltip: {
formatter: "|#{tooltip_formatter}|"
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: [{
data: data,
dataLabels: {
enabled: true,
color: '#000000'
}
}]
}
end
def script_chart(**args)
"<script>\n" +
"var div = document.createElement('div'), " +
"script = document.scripts[document.scripts.length - 1]; " +
"script.parentElement.insertBefore(div, script); " +
"new Highcharts.Chart(" +
make_chart(**args).to_json.gsub(/"\|(.+?)\|"/, '\\1') +
");\n</script>"
end
puts script_chart(
title: "Heatmap"
)