| 1 | import React from "react" |
| 2 | import { MinimapChart } from "semiotic" |
| 3 | |
| 4 | function formatDate(d) { |
| 5 | const date = new Date(d) |
| 6 | const months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"] |
| 7 | return `${months[date.getMonth()]} ${date.getDate()}` |
| 8 | } |
| 9 | |
| 10 | export default function TimeSeriesBrush({ data, width = 700, height = 350 }) { |
| 11 | return ( |
| 12 | <MinimapChart |
| 13 | data={data} |
| 14 | width={width} |
| 15 | height={height} |
| 16 | xAccessor="date" |
| 17 | yAccessor="value" |
| 18 | lineBy="series" |
| 19 | colorBy="series" |
| 20 | colorScheme={["#6366f1", "#22c55e", "#f59e0b"]} |
| 21 | curve="monotoneX" |
| 22 | lineWidth={2} |
| 23 | enableHover={true} |
| 24 | xFormat={formatDate} |
| 25 | margin={{ left: 60, top: 10, bottom: 40, right: 20 }} |
| 26 | minimap={{ |
| 27 | height: 60, |
| 28 | margin: { left: 60, top: 0, bottom: 20, right: 20 }, |
| 29 | }} |
| 30 | tooltip={{ |
| 31 | title: "series", |
| 32 | fields: [ |
| 33 | { field: "date", label: "Date", format: formatDate }, |
| 34 | { field: "value", label: "Value" } |
| 35 | ] |
| 36 | }} |
| 37 | /> |
| 38 | ) |
| 39 | } |
| 40 | |
| 41 | // Usage with flat data: |
| 42 | // const data = [ |
| 43 | // { date: 1704067200000, value: 100, series: "A", color: "#6366f1" }, |
| 44 | // { date: 1704153600000, value: 102, series: "A", color: "#6366f1" }, |
| 45 | // ... |
| 46 | // ] |
| 47 | // <TimeSeriesBrush data={data} width={700} height={350} /> |