2024-08-01 14:06:16 +01:00
|
|
|
let dataArr = [];
|
|
|
|
const myChart = echarts.init(document.getElementById("chart"));
|
2024-08-14 19:48:58 +01:00
|
|
|
const filename = "final__miner_rewards.json";
|
|
|
|
const periods = [
|
|
|
|
"all time",
|
|
|
|
"last 7 days",
|
|
|
|
"last 28 days",
|
|
|
|
"last 365 days",
|
|
|
|
"last 2 years",
|
|
|
|
];
|
2024-08-01 14:06:16 +01:00
|
|
|
|
2024-08-14 19:48:58 +01:00
|
|
|
async function fetchDataForChart(selectedValue) {
|
2024-08-06 12:03:42 +01:00
|
|
|
try {
|
2024-08-14 17:59:38 +01:00
|
|
|
const apiEndpoint = `${apiURL}/get_json/${filename}?period=${selectedValue}`;
|
2024-08-06 12:03:42 +01:00
|
|
|
const response = await fetch(apiEndpoint);
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
|
}
|
|
|
|
const dataArr = await response.json();
|
|
|
|
initEchart(dataArr);
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Fetching data failed:", error);
|
|
|
|
}
|
|
|
|
}
|
2024-08-01 14:06:16 +01:00
|
|
|
|
2024-08-06 12:03:42 +01:00
|
|
|
function initEchart(dataArr) {
|
2024-08-14 19:48:58 +01:00
|
|
|
console.log(dataArr);
|
2024-08-01 14:06:16 +01:00
|
|
|
const option = {
|
|
|
|
backgroundColor: backgroundColor,
|
2024-08-14 19:48:58 +01:00
|
|
|
tooltip: {
|
|
|
|
...tooltip,
|
|
|
|
formatter: function (params) {
|
|
|
|
let colors = ["#ee6666", "#000000", "#b0da9d", "#8699d5"];
|
|
|
|
let colorSpan = (color) =>
|
|
|
|
'<span style="display:inline-block;margin-right:1px;border-radius:5px;width:9px;height:9px;background-color:' +
|
|
|
|
color +
|
|
|
|
'"></span>';
|
|
|
|
let tooltip = "<p>" + params[0].axisValue + "</p>";
|
|
|
|
params.reverse().forEach((item, index) => {
|
|
|
|
let color = colors[index % colors.length];
|
|
|
|
let labels =
|
|
|
|
"<p>" +
|
|
|
|
colorSpan(color) +
|
|
|
|
" " +
|
|
|
|
item.seriesName +
|
|
|
|
": " +
|
|
|
|
nFormatter(item.data, 3);
|
|
|
|
("</p>");
|
|
|
|
tooltip += labels;
|
|
|
|
});
|
|
|
|
|
|
|
|
return tooltip;
|
|
|
|
},
|
|
|
|
valueFormatter(value, index) {
|
|
|
|
return nFormatter(value, 3);
|
|
|
|
},
|
|
|
|
},
|
2024-08-01 14:06:16 +01:00
|
|
|
toolbox: toolboxParams,
|
|
|
|
xAxis: {
|
|
|
|
data: dataArr.map((row) => row.date),
|
|
|
|
axisTick: axisTick,
|
|
|
|
axisLabel: axisLabel,
|
|
|
|
axisLine: axisLine,
|
|
|
|
},
|
|
|
|
grid: grid,
|
2024-08-14 19:48:58 +01:00
|
|
|
dataZoom: dataZoom(0),
|
2024-08-01 14:06:16 +01:00
|
|
|
yAxis: [
|
|
|
|
{
|
|
|
|
type: "value",
|
2024-08-08 14:28:01 +01:00
|
|
|
name: "Rewards (USD)",
|
2024-08-01 14:06:16 +01:00
|
|
|
nameLocation: "middle",
|
2024-08-14 19:48:58 +01:00
|
|
|
nameGap: 30,
|
2024-08-08 11:53:39 +01:00
|
|
|
nameTextStyle: textStyleMain,
|
2024-08-01 14:06:16 +01:00
|
|
|
position: "left",
|
|
|
|
alignTicks: true,
|
|
|
|
axisTick: axisTick,
|
|
|
|
axisLine: axisLine,
|
|
|
|
splitLine: {
|
|
|
|
show: false,
|
|
|
|
},
|
2024-08-08 11:53:39 +01:00
|
|
|
axisLabel: {
|
|
|
|
...axisLabel,
|
|
|
|
formatter(value, index) {
|
|
|
|
return nFormatter(value, 0);
|
|
|
|
},
|
|
|
|
},
|
2024-08-01 14:06:16 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "value",
|
2024-08-14 19:48:58 +01:00
|
|
|
name: "Subsidy (BTC)",
|
2024-08-01 14:06:16 +01:00
|
|
|
nameLocation: "middle",
|
2024-08-08 14:28:01 +01:00
|
|
|
nameGap: 20,
|
2024-08-08 11:53:39 +01:00
|
|
|
nameTextStyle: {
|
|
|
|
fontSize: 12 * fontScale,
|
|
|
|
color: textColor,
|
|
|
|
},
|
2024-08-01 14:06:16 +01:00
|
|
|
axisTick: axisTick,
|
|
|
|
position: "right",
|
|
|
|
alignTicks: true,
|
|
|
|
axisLine: axisLine,
|
|
|
|
splitLine: {
|
|
|
|
show: false,
|
|
|
|
},
|
|
|
|
axisLabel: {
|
|
|
|
fontSize: 12 * fontScale,
|
2024-08-08 11:53:39 +01:00
|
|
|
color: textColor,
|
2024-08-01 14:06:16 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
series: [
|
|
|
|
{
|
|
|
|
type: "line",
|
2024-08-14 19:48:58 +01:00
|
|
|
name: "Subsidy (USD)",
|
2024-08-01 14:06:16 +01:00
|
|
|
stack: "Total",
|
|
|
|
areaStyle: {},
|
|
|
|
symbol: "none",
|
|
|
|
lineStyle: {
|
|
|
|
width: 0,
|
|
|
|
},
|
|
|
|
data: dataArr.map((row) => row.subsidy_usd),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "line",
|
2024-08-14 19:48:58 +01:00
|
|
|
name: "Fees (USD)",
|
2024-08-01 14:06:16 +01:00
|
|
|
stack: "Total",
|
|
|
|
areaStyle: {},
|
|
|
|
symbol: "none",
|
|
|
|
lineStyle: {
|
|
|
|
width: 0,
|
|
|
|
},
|
|
|
|
data: dataArr.map((row) => row.totalfee_usd),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "line",
|
2024-08-14 19:48:58 +01:00
|
|
|
name: "Total (USD)",
|
2024-08-01 14:06:16 +01:00
|
|
|
symbol: "none",
|
|
|
|
lineStyle: {
|
|
|
|
width: 1,
|
2024-08-08 11:53:39 +01:00
|
|
|
color: textColor,
|
2024-08-01 14:06:16 +01:00
|
|
|
},
|
|
|
|
data: dataArr.map((row) => row.total_reward_usd),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "line",
|
|
|
|
yAxisIndex: 1,
|
|
|
|
name: "Block Subsidy (BTC)",
|
|
|
|
symbol: "none",
|
|
|
|
lineStyle: {
|
|
|
|
width: 3,
|
|
|
|
},
|
|
|
|
data: dataArr.map((row) => row.block_subsidy),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
myChart.setOption(option);
|
|
|
|
}
|
|
|
|
|
2024-08-14 19:48:58 +01:00
|
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
|
|
let periodIndex = 2;
|
|
|
|
periodDropdown(periods, periodIndex);
|
|
|
|
fetchDataForChart(periods[periodIndex]);
|
|
|
|
const selectElement = document.getElementById("select-period-dropdown");
|
|
|
|
|
|
|
|
selectElement.addEventListener("change", function (event) {
|
|
|
|
const selectedValue = event.target.value;
|
|
|
|
fetchDataForChart(selectedValue);
|
|
|
|
});
|
|
|
|
});
|