Skip to content

Instantly share code, notes, and snippets.

@dreadedhamish
Last active January 16, 2022 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dreadedhamish/8edae494983ff2eaea5bbbb77752b2c2 to your computer and use it in GitHub Desktop.
Save dreadedhamish/8edae494983ff2eaea5bbbb77752b2c2 to your computer and use it in GitHub Desktop.
Quickchart-ICY-reflections.js
import fetch from 'node-fetch';
const chartStr = `{
type: 'bar',
data: {
labels: __labelsPlaceholder__,
datasets: [{
data: __valuesPlaceholder__,
backgroundColor: 'rgba(75, 192, 192, 0.4)',
borderColor: 'rgb(75, 192, 192)',
borderWidth: 1
}]
},
options: {
title: {
},
plugins: {
roundedBars: {
cornerRadius: 3
},
backgroundImageUrl: 'https://drive.google.com/uc?id=1nYjRNjZ7Ugx1sLIvlUbUtk_0nTkXeD7P',
},
scales: {
xAxes: [
{
ticks: {
// beginAtZero: true,
fontFamily: 'Noto Sans',
fontSize: 8,
fontColor: '#FFFFFF',
},
},
],
yAxes: [
{
ticks: {
beginAtZero: true,
fontFamily: 'Noto Sans',
//fontSize: 8,
fontColor: '#FFFFFF',
},
scaleLabel: {
display: true,
labelString: '$ETH',
fontColor: '#FFFFFF',
fontStyle: 'bold',
},
},
],
},
legend: {
display: false,
},
layout: {
padding: {
left: 10,
right: 20,
top: 80,
bottom: 20
}
}
},
}`;
var covalent_URL = "https://api.covalenthq.com/v1/43114/events/topics/0x000000000000000000000000344b2732a76af5bf0cf9e5ec6f0891065d4f9156/?starting-block=8599500&ending-block=latest&secondary-topics=0x000000000000000000000000fe15c2695f1f920da45c30aae47d11de51007af9&page-size=400&group={%20%22_id%22:%20{%20%22year%22:%20{%20%22$year%22:%20%22block_signed_at%22%20},%20%22month%22:%20{%20%22$month%22:%20%22block_signed_at%22%20},%20%22day%22:%20{%20%22$dayOfMonth%22:%20%22block_signed_at%22%20}%20},%20%22reflections_ETH%22:%20{%20%22$sum%22:%20%22decoded.params.2.value%22%20}%20}&sort={%20%22block_signed_at%22:%20-1%20}&key=ckey_15512f3e6ceb4f0eb275cda7c9e"
async function getTheAPI(){
var obj;
fetch(covalent_URL, {
method: 'GET', // *GET, POST, PUT, DELETE, etc.
// mode: 'no-cors', // no-cors, *cors, same-origin
// cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
// credentials: 'same-origin', // include, *same-origin, omit
// headers: {
// 'Content-Type': 'application/json'
// // 'Content-Type': 'application/x-www-form-urlencoded',
// },
// redirect: 'follow', // manual, *follow, error
// referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
//body: JSON.stringify(data) // body data type must match "Content-Type" header
})
.then(response => {
console.log(response);
return response.json();
})
.then(data => {
obj = data;
console.log(data);
restructure(data);
})
.catch(error => console.log('Error resulting from json(): ' + error))
}
function restructure(obj){
var covalent_trimmed = obj.data.items
var value = []
var label = []
for(var i = 1; i < 8; i++) {
label[i] = covalent_trimmed[i].id.day.toString() + "/" + covalent_trimmed[i].id.month.toString()
value[i] = covalent_trimmed[i].reflections_ETH * Math.pow(10, -18);
}
console.log("label")
console.log(label);
console.log(JSON.stringify(label))
console.log("value")
console.log(value);
var mapObj = {
//__labelsPlaceholder__: '["Jan", "Feb", "Mar", "Apr", "May"]',
__labelsPlaceholder__: JSON.stringify(label.reverse()),
//__valuesPlaceholder__: '[ 50, 60, 70, 180, 190 ]'
__valuesPlaceholder__: JSON.stringify(value.reverse())
};
const chartStr2 = chartStr.replace(/__labelsPlaceholder__|__valuesPlaceholder__/gi, function(matched){
return mapObj[matched];
});
console.log(chartStr2);
console.log(encodeURIComponent(chartStr2));
}
getTheAPI()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment