Skip to content

Commit e1cc003

Browse files
authored
Merge pull request hshoff#2 from hshoff/vs02
[eth] add volume bars
2 parents f5267b1 + 4f0c6a5 commit e1cc003

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

components/ethereum/banner/Banner.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ export default function Banner({
6161
<Logo />
6262
</div>
6363
<div className="controls">
64-
<button onClick={decreaseNumItems}>-</button>
64+
<button onClick={increaseNumItems}>+</button>
6565
<span className="numitems">
6666
{numItems}
6767
</span>
68-
<button onClick={increaseNumItems}>+</button>
68+
<button onClick={decreaseNumItems}>-</button>
6969
</div>
7070
<style jsx>{`
7171
.banner {

components/ethereum/chart/Chart.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import { AxisLeft, AxisBottom } from '@vx/axis';
77
import { Bar } from '@vx/shape';
88
import { format } from 'd3-format';
99
import { timeFormat } from 'd3-time-format';
10+
import Volume from './Volume';
1011

1112
const formatPrice = format('$,.2f');
1213
const formatTime = timeFormat('%I:%M%p');
1314

1415
class Chart extends React.Component {
1516
render() {
1617
const { parentWidth, parentHeight, data } = this.props;
17-
const { buckets, start, end, maxHighPrice, minLowPrice } = data;
18+
const { buckets, start, end, maxHighPrice, minLowPrice, maxVolume } = data;
1819

1920
const margin = {
2021
top: 0,
@@ -40,6 +41,12 @@ class Chart extends React.Component {
4041
domain: [minLowPrice - 3, maxHighPrice]
4142
});
4243

44+
const volumeHeight = (height - margin.bottom) * 0.25;
45+
const yVolumeScale = scaleLinear({
46+
range: [volumeHeight, 0],
47+
domain: [0, maxVolume]
48+
});
49+
4350
return (
4451
<svg width={width} height={height}>
4552
<Group top={margin.top} left={margin.left}>
@@ -96,6 +103,13 @@ class Chart extends React.Component {
96103
x={xScale(b.closeTime)}
97104
y={b.hollow ? yScale(b.closePrice) : yScale(b.openPrice)}
98105
/>
106+
<Volume
107+
top={height - margin.bottom - volumeHeight}
108+
height={volumeHeight}
109+
scale={yVolumeScale}
110+
xScale={xScale}
111+
data={b}
112+
/>
99113
</g>
100114
);
101115
})}

components/ethereum/chart/Volume.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Group } from '@vx/group';
2+
import { AxisRight } from '@vx/axis';
3+
import { Bar } from '@vx/shape';
4+
5+
export default function Volume({ top, scale, xScale, height, data }) {
6+
return (
7+
<Group top={top}>
8+
<AxisRight
9+
scale={scale}
10+
hideZero
11+
hideTicks
12+
hideAxisLine
13+
tickLength={0}
14+
tickValues={scale.ticks(5)}
15+
tickLabelComponent={<text dx="0.33em" fill="white" fontSize={8} />}
16+
/>
17+
<Bar
18+
data={data}
19+
width={xScale.bandwidth()}
20+
height={height - scale(data.volume)}
21+
x={xScale(data.closeTime)}
22+
y={scale(data.volume)}
23+
fill="white"
24+
fillOpacity={0.3}
25+
/>
26+
</Group>
27+
);
28+
}

pages/ethereum.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class Ethereum extends React.Component {
6565
const minLowPrice = Math.min(
6666
...buckets.map(b => Math.min(...[b.lowPrice, b.openPrice, b.closePrice]))
6767
);
68+
const maxVolume = Math.max(...buckets.map(b => b.volume));
6869

6970
const start = sortedBuckets[0].closeTime;
7071
const end = sortedBuckets[sortedBuckets.length - 1].closeTime;
@@ -79,7 +80,8 @@ class Ethereum extends React.Component {
7980
start,
8081
end,
8182
maxHighPrice,
82-
minLowPrice
83+
minLowPrice,
84+
maxVolume
8385
}}
8486
/>
8587
</div>

0 commit comments

Comments
 (0)