-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04-chart.js
More file actions
130 lines (123 loc) · 4.17 KB
/
04-chart.js
File metadata and controls
130 lines (123 loc) · 4.17 KB
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
122
123
124
125
126
127
128
129
// ---- Chart -----------------------------------------------
function buildChartData() {
const tokens = getCurrentTokens();
const historical = HISTORICAL_DATA.map((d) => ({ x: d.date, y: d.tokensT }));
// 60-month projection with 50 % annual growth in token-production rate,
// producing the hockey-stick acceleration observed historically.
const projection = generateProjectionData(tokens, TOKENS_PER_SECOND, 60, undefined, 0.5).map((d) => ({
x: d.date,
y: +d.tokensT.toFixed(2),
}));
return { historical, projection };
}
function chartColors() {
const dark = currentTheme === 'dark';
return {
histLine: dark ? '#ff3333' : '#cc0000',
projLine: dark ? '#ff8800' : '#cc6600',
gridColor: dark ? 'rgba(255,255,255,0.07)' : 'rgba(0,0,0,0.08)',
tickColor: dark ? '#888' : '#555',
bg: dark ? '#161616' : '#ffffff',
};
}
function initChart() {
const canvas = document.getElementById('tokenChart');
if (!canvas || typeof Chart === 'undefined') return;
const { historical, projection } = buildChartData();
const colors = chartColors();
// Milestone annotations as horizontal lines
const annotations = {};
MILESTONES.forEach((m, i) => {
annotations['milestone_' + i] = {
type: 'line',
yMin: m.tokens / 1e12,
yMax: m.tokens / 1e12,
borderColor: 'rgba(0,204,119,0.4)',
borderWidth: 1,
borderDash: [4, 4],
label: {
content: m.icon + ' ' + m.shortDesc,
display: false,
},
};
});
chartInstance = new Chart(canvas, {
type: 'line',
data: {
datasets: [
{
label: 'Historical (estimated)',
data: historical,
borderColor: colors.histLine,
backgroundColor: 'transparent',
borderWidth: 2,
pointRadius: 3,
pointHoverRadius: 5,
tension: 0.35,
fill: false,
},
{
label: 'Projected',
data: projection,
borderColor: colors.projLine,
backgroundColor: 'transparent',
borderWidth: 2,
borderDash: [6, 4],
pointRadius: 0,
tension: 0.35,
fill: false,
},
],
},
options: {
responsive: true,
maintainAspectRatio: false,
interaction: { mode: 'index', intersect: false },
scales: {
x: {
type: 'time',
time: { tooltipFormat: 'MMM yyyy', displayFormats: { month: 'MMM yy', year: 'yyyy', quarter: 'MMM yy' } },
grid: { color: colors.gridColor },
ticks: { color: colors.tickColor, maxRotation: 45 },
},
y: {
type: 'logarithmic',
title: {
display: true,
text: 'Cumulative Tokens (Trillions, log scale)',
color: colors.tickColor,
font: { size: 11 },
},
grid: { color: colors.gridColor },
ticks: {
color: colors.tickColor,
callback: (v) => formatTokenCountShort(v * 1e12),
},
},
},
plugins: {
legend: {
labels: { color: colors.tickColor, boxWidth: 20, padding: 16, font: { size: 12 } },
},
tooltip: {
callbacks: {
label: (ctx) => ' ' + formatTokenCount(ctx.parsed.y * 1e12) + ' tokens',
},
},
},
},
});
}
function updateChartColors() {
if (!chartInstance) return;
const colors = chartColors();
chartInstance.data.datasets[0].borderColor = colors.histLine;
chartInstance.data.datasets[1].borderColor = colors.projLine;
chartInstance.options.scales.x.grid.color = colors.gridColor;
chartInstance.options.scales.y.grid.color = colors.gridColor;
chartInstance.options.scales.x.ticks.color = colors.tickColor;
chartInstance.options.scales.y.ticks.color = colors.tickColor;
chartInstance.options.scales.y.title.color = colors.tickColor;
chartInstance.options.plugins.legend.labels.color = colors.tickColor;
chartInstance.update('none');
}