-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interactive chart with symbol dropdown
- Loading branch information
1 parent
c0bd32d
commit f2c4d12
Showing
9 changed files
with
655 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { useRecords } from "beneath-react"; | ||
import { FC } from "react"; | ||
import { | ||
Line, | ||
LineChart, | ||
ResponsiveContainer, | ||
Tooltip, | ||
XAxis, | ||
YAxis, | ||
} from "recharts"; | ||
|
||
interface Props { | ||
filter: string; | ||
} | ||
|
||
const StockLineChart: FC<Props> = ({ filter }) => { | ||
const { records, loading, error } = useRecords({ | ||
table: "examples/wallstreetbets-analytics/stock-mentions-rollup-daily", | ||
query: { type: "index", filter }, | ||
subscribe: false, | ||
pageSize: 30, | ||
}); | ||
|
||
// Q: This gets hit 3 times. Are the records getting fetched three times? | ||
console.log(records); | ||
|
||
return ( | ||
<ResponsiveContainer width={"100%"} height={400}> | ||
<LineChart width={500} height={300} data={records}> | ||
<XAxis | ||
dataKey="day" | ||
tickFormatter={(tickItem) => { | ||
const d = new Date(tickItem); | ||
return d.toLocaleDateString("en-US"); | ||
}} | ||
/> | ||
<YAxis | ||
yAxisId="left" | ||
dataKey="num_mentions" | ||
label={{ value: "Mentions", angle: -90, position: "insideLeft" }} | ||
/> | ||
<Line | ||
type="monotone" | ||
dataKey="num_mentions" | ||
stroke="#8884d8" | ||
yAxisId="left" | ||
isAnimationActive={false} | ||
/> | ||
<Line | ||
type="monotone" | ||
dataKey="num_positive" | ||
stroke="#82ca9d" | ||
yAxisId="left" | ||
isAnimationActive={false} | ||
/> | ||
<Tooltip /> | ||
</LineChart> | ||
</ResponsiveContainer> | ||
); | ||
}; | ||
|
||
export default StockLineChart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { TextField } from "@material-ui/core"; | ||
import { Autocomplete } from "@material-ui/lab"; | ||
import React, { FC } from "react"; | ||
import { SYMBOLS } from "../lib/symbols"; | ||
|
||
interface Props { | ||
symbol: string; | ||
setSymbol: (symbol: string) => void; | ||
} | ||
|
||
const SymbolDropdown: FC<Props> = ({ symbol, setSymbol }) => { | ||
return ( | ||
<> | ||
<Autocomplete | ||
id="combo-box-demo" | ||
options={SYMBOLS} | ||
style={{ width: 200 }} | ||
value={symbol} | ||
onChange={(event, newValue) => { | ||
setSymbol(newValue); | ||
}} | ||
renderInput={(params) => ( | ||
<TextField {...params} label="Combo box" variant="outlined" /> | ||
)} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default SymbolDropdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// TODO: add the full list | ||
export const SYMBOLS = ["AAPL", "TSLA", "BABA"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/types/global" /> | ||
/// <reference types="next/image-types/global" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Container } from "@material-ui/core"; | ||
import { useState } from "react"; | ||
import StockLineChart from "../components/StockLineChart"; | ||
import SymbolDropdown from "../components/SymbolDropdown"; | ||
|
||
const TIME_WINDOW = 30; // days | ||
|
||
const makeFilter = (symbol: string) => { | ||
var d = new Date(); | ||
d.setDate(d.getDate() - TIME_WINDOW); | ||
return `{ "symbol": "${symbol}", "day":{"_gt":"${d.toISOString()}"}}`; | ||
}; | ||
|
||
export default function Home() { | ||
const [symbol, setSymbol] = useState("AAPL"); | ||
const filter = makeFilter(symbol); | ||
|
||
return ( | ||
<Container> | ||
<h1>Stock mentions on r/wallstreetbets</h1> | ||
<SymbolDropdown | ||
symbol={symbol} | ||
setSymbol={(symbol) => setSymbol(symbol)} | ||
/> | ||
<h2>{symbol}</h2> | ||
<StockLineChart filter={filter} /> | ||
</Container> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"lib": [ | ||
"dom", | ||
"dom.iterable", | ||
"esnext" | ||
], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": false, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve" | ||
}, | ||
"include": [ | ||
"next-env.d.ts", | ||
"**/*.ts", | ||
"**/*.tsx" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
Oops, something went wrong.