Newer
Older
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
130
131
132
133
import classNames from "classnames";
import React, { useState, useRef } from "react";
import ReactECharts from "echarts-for-react";
import { useCryptoTimeSeriesRangeData } from "../../queries";
import moment from "moment";
const unixNow = () => {
return moment().unix();
};
const unixSubtractId = (id) => {
return moment().subtract(id[0], id.substring(1)).unix();
};
function CompareChart() {
const [timerange, setTimerange] = useState("6month");
const chartRef = useRef(null);
const cryptoQuery = useCryptoTimeSeriesRangeData(
"solana",
unixSubtractId(timerange),
unixNow()
);
const cryptoQuery2 = useCryptoTimeSeriesRangeData(
"avalanche-2",
unixSubtractId(timerange),
unixNow()
);
const option = {
tooltip: {
trigger: "axis",
axisPointer: {
type: "shadow",
},
},
grid: {
bottom: 30,
right: 10,
top: 10,
left: 50,
},
dataZoom: [
{
type: "inside",
},
],
xAxis: {
type: "time",
silent: false,
splitLine: {
show: false,
},
splitArea: {
show: false,
},
},
yAxis: {
type: "value",
splitArea: {
show: false,
},
splitLine: {
show: false,
},
},
series: [
{
type: "line",
data: cryptoQuery.data?.prices,
name: "Solana",
smooth: true,
symbol: "none",
},
{
type: "line",
data: cryptoQuery2.data?.prices,
name: "Avalanche",
smooth: true,
symbol: "none",
},
],
};
return (
<div className="dark:bg-dark-600 p-8 rounded-3xl">
<div className="flex flex-row space-x-3">
<ToggleButton id="1hour" active={timerange} setActive={setTimerange}>
1H
</ToggleButton>
<ToggleButton id="1day" active={timerange} setActive={setTimerange}>
1D
</ToggleButton>
<ToggleButton id="1week" active={timerange} setActive={setTimerange}>
1W
</ToggleButton>
<ToggleButton id="1month" active={timerange} setActive={setTimerange}>
1M
</ToggleButton>
<ToggleButton id="6month" active={timerange} setActive={setTimerange}>
6M
</ToggleButton>
<ToggleButton id="1year" active={timerange} setActive={setTimerange}>
1Y
</ToggleButton>
</div>
<div className="h-[600px] mt-10">
<ReactECharts
ref={chartRef}
option={option}
style={{
height: "100%",
}}
/>
</div>
</div>
);
}
function ToggleButton({ children, setActive, active, id }) {
return (
<button
className={classNames(" px-3 py-2 rounded-md font-light", {
"dark:bg-white dark:text-gray-800": active === id,
"dark:bg-black dark:text-gray-400": active !== id,
})}
onClick={() => setActive(id)}
>
{children}
</button>
);
}
export default CompareChart;