/
Utils.js
77 lines (71 loc) · 2.24 KB
/
Utils.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
var lz = require('lz-string');
module.exports = {
// SVG helper to generate icon code
// usage: <span dangerouslySetInnerHTML={{__html: Utils.svgHelper('#settings-icon')}}></span>
svgHelper: function (id) {
return "<svg class='u-svgIcon' xmlns='http://www.w3.org/2000/svg' ><use xlink:href='" + id + "'></use></svg>";
},
// Chart colors for datasets
colorschemes: [
{
fillColor: "rgba(87,198,185,0.1)",
strokeColor: "rgba(87,198,185,1)",
pointColor: "rgba(87,198,185,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(122,178,234,1)",
},
{
fillColor: "rgba(163,142,243,0.1)",
strokeColor: "rgba(163,142,243,1)",
pointColor: "rgba(163,142,243,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(163,142,243,1)",
},
{
fillColor: "rgba(233,102,132,0.1)",
strokeColor: "rgba(233,102,132,1)",
pointColor: "rgba(233,102,132,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(122,178,234,1)",
},
{
fillColor: "rgba(122,178,234,0.1)",
strokeColor: "rgba(122,178,234,1)",
pointColor: "rgba(122,178,234,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(122,178,234,1)",
},
{
fillColor: "rgba(230,187,114,0.1)",
strokeColor: "rgba(230,187,114,1)",
pointColor: "rgba(230,187,114,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(230,187,114,1)",
}
],
// assign colorschemes to datasets
assignColors: function (input, colors) {
var output = _.cloneDeep(input);
for (var i=0; i < output.datasets.length; i++) {
for (var prop in colors[i]) {
output.datasets[i][prop] = colors[i][prop];
}
}
return output;
},
// set url from encoded data
setUrl: function (data) {
if (!data) {
return window.history.replaceState({}, 'clear', '/');
}
var compressed = lz.compressToEncodedURIComponent(JSON.stringify(data));
var url = '#/share/' + compressed;
window.history.replaceState({}, 'share', url);
return url;
}
};