|
| 1 | +// deck.gl-community |
| 2 | +// SPDX-License-Identifier: MIT |
| 3 | +// Copyright (c) vis.gl contributors |
| 4 | + |
| 5 | +import React from 'react'; |
| 6 | +import DeckGL from '@deck.gl/react'; |
| 7 | +import {OrthographicView} from '@deck.gl/core'; |
| 8 | +import {HorizonGraphLayer} from '@deck.gl-community/layers'; |
| 9 | + |
| 10 | +const INITIAL_VIEW_STATE = { |
| 11 | + target: [0, 0, 0], |
| 12 | + zoom: 1 |
| 13 | +}; |
| 14 | + |
| 15 | +export default function App(): React.ReactElement { |
| 16 | + const [bands, setBands] = React.useState(4); |
| 17 | + |
| 18 | + // Generate sample time-series data |
| 19 | + const sampleData = React.useMemo(() => { |
| 20 | + const data = []; |
| 21 | + const seriesCount = 3; |
| 22 | + const pointsPerSeries = 100; |
| 23 | + |
| 24 | + for (let series = 0; series < seriesCount; series++) { |
| 25 | + for (let i = 0; i < pointsPerSeries; i++) { |
| 26 | + const x = i; |
| 27 | + const y = Math.sin(i * 0.1 + series) * 50 + Math.random() * 20 - 10; |
| 28 | + data.push({ |
| 29 | + x, |
| 30 | + y, |
| 31 | + series |
| 32 | + }); |
| 33 | + } |
| 34 | + } |
| 35 | + return data; |
| 36 | + }, []); |
| 37 | + |
| 38 | + const layers = [ |
| 39 | + new HorizonGraphLayer({ |
| 40 | + id: 'horizon-graph-layer', |
| 41 | + data: sampleData, |
| 42 | + getX: (d: any) => d.x, |
| 43 | + getY: (d: any) => d.y, |
| 44 | + getSeries: (d: any) => d.series, |
| 45 | + bands, |
| 46 | + height: 300, |
| 47 | + width: 800, |
| 48 | + positiveColor: [0, 123, 255], |
| 49 | + negativeColor: [220, 53, 69], |
| 50 | + dividerColor: [0, 0, 0] |
| 51 | + }) |
| 52 | + ]; |
| 53 | + |
| 54 | + return ( |
| 55 | + <div style={{ position: 'relative', width: '100vw', height: '100vh' }}> |
| 56 | + <div style={{ |
| 57 | + position: 'absolute', |
| 58 | + top: 10, |
| 59 | + left: 10, |
| 60 | + zIndex: 1000, |
| 61 | + background: 'rgba(255, 255, 255, 0.9)', |
| 62 | + padding: '10px', |
| 63 | + borderRadius: '4px', |
| 64 | + fontFamily: 'Arial, sans-serif' |
| 65 | + }}> |
| 66 | + <label> |
| 67 | + Bands: |
| 68 | + <select |
| 69 | + value={bands} |
| 70 | + onChange={(e) => setBands(Number(e.target.value))} |
| 71 | + style={{ marginLeft: '10px' }} |
| 72 | + > |
| 73 | + <option value={1}>1 (Regular Area Chart)</option> |
| 74 | + <option value={2}>2</option> |
| 75 | + <option value={3}>3</option> |
| 76 | + <option value={4}>4</option> |
| 77 | + <option value={5}>5</option> |
| 78 | + <option value={6}>6</option> |
| 79 | + </select> |
| 80 | + </label> |
| 81 | + </div> |
| 82 | + <DeckGL |
| 83 | + views={new OrthographicView()} |
| 84 | + initialViewState={INITIAL_VIEW_STATE} |
| 85 | + controller={true} |
| 86 | + layers={layers} |
| 87 | + /> |
| 88 | + </div> |
| 89 | + ); |
| 90 | +} |
0 commit comments