-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.js
121 lines (107 loc) · 3.5 KB
/
data.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
const CSS_CLASS_POSITIVE_PERCENTAGE = 'perc-pos';
const CSS_CLASS_NEGATIVE_PERCENTAGE = 'perc-neg';
const BITCOIN_ORANGE = "#F7931A";
const BITCOIN_GREY = "#4d4d4e";
const SV_PRICE = 47000;
const CF_PRICE = 40000;
let currentBitcoinPrice;
getBitcoinPrice()
.then(drawMap);
function drawMap() {
new svgMap({
targetElementID: 'svgMap',
colorNoData: BITCOIN_GREY,
colorMin: BITCOIN_ORANGE,
colorMax: BITCOIN_ORANGE,
noDataText: "NGMI",
data: {
data: {
otherLegalTender: {
name: 'Other Legal Tender',
format: '{0}',
},
gdp: {
name: 'GDP',
format: '${0} billion',
thousandSeparator: ',',
thresholdMax: 50000,
thresholdMin: 1000
},
// change: {
// name: 'Change to year before',
// format: '{0} %'
// },
population: {
name: 'Population',
format: '{0}',
thousandSeparator: ',',
},
date: {
name: 'Bitcoin Legal Tender',
format: 'since: {0}',
},
price: {
name: 'Bitcoin price that day',
format: '{0}'
}
},
applyData: 'gdp',
values: {
SV: {
otherLegalTender: "United States Dollar",
gdp: 57.95,
population: 6830000,
date: "Sep 07, 2021",
price: getFormattedPriceInfo(SV_PRICE),
link: "https://www.cbc.ca/news/world/el-salvador-bitcoin-1.6166977",
linkTarget: "_blank"
},
CF: {
otherLegalTender: "Central African CFA Franc",
gdp: 4.262,
population: 4666368,
date: "April 28, 2022",
price: getFormattedPriceInfo(CF_PRICE),
link: "https://news.yahoo.com/central-african-republic-adopts-bitcoin-104407031.html",
linkTarget: "_blank"
},
}
}
});
}
function getBitcoinPrice(){
const options = {
method: 'GET',
};
return fetch('https://blockchain.info/ticker', options)
.then(response => response.json())
.then(response => currentBitcoinPrice = response.USD.last)
.catch(err => console.error(err));
}
function getFormattedPriceInfo(price) {
let percAppendix = "";
if(typeof currentBitcoinPrice == 'number') {
percAppendix = " " + percentageHtmlTag(price, currentBitcoinPrice);
}
return formatPrice(price) + percAppendix;
}
function formatPrice(price) {
priceInK = price / 1000;
return "$" + priceInK + "K";
}
function percentageHtmlTag(base, change) {
return "(<span class='" +
percentageClass(base, change) +
"'>" +
percentageAsString(base, change) +
"</span>)";
}
function percentageClass(base, change) {
return (percentage(base, change) < 0 ? CSS_CLASS_NEGATIVE_PERCENTAGE : CSS_CLASS_POSITIVE_PERCENTAGE);
}
function percentageAsString(base, change) {
return percentage(base, change).toFixed(1) + "%";
}
function percentage(base, change) {
return change / base * 100 - 100;
}