You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import { load } from '@loaders.gl/core';
import { CSVLoader } from '@loaders.gl/csv';
import { useQuery } from '@tanstack/react-query';
import { Select, Slider, Space, Spin } from 'antd';
import { scaleLinear } from 'd3-scale';
import { interpolateViridis } from 'd3-scale-chromatic';
import { DeckGL, GridCellLayer, ScatterplotLayer } from 'deck.gl';
import 'maplibre-gl/dist/maplibre-gl.css';
import { useState } from 'react';
import Map from 'react-map-gl/maplibre';
const colorScale = scaleLinear<string, string>().domain([0, 10000]).range([interpolateViridis(0), interpolateViridis(1)]);
const radiusScale = scaleLinear().domain([0, 12000]).range([50, 250]);
function App() {
const [value, setValue] = useState(0);
const [attr, setAttr] = useState("00:00:00");
const [day, setDay] = useState("2023-12-01")
const { isPending, error, data } = useQuery({
queryKey: [day],
queryFn: () => load(`./${day}.csv`, CSVLoader, { csv: {} }),
})
if (error) {
console.log(error)
}
const layers = isPending ? [] : [
new GridCellLayer({
id: 'deckgl-grid',
//@ts-ignore
data: data.data,
getPosition: d => [d.x, d.y],
//@ts-ignore
getFillColor: d => colorScale(d[attr]).slice(4, -1).split(", ").map(Number),
cellSize: 505,
extruded: false,
updateTriggers: {
getFillColor: [attr],
}
}),
new ScatterplotLayer({
id: 'deckgl-circle2',
//@ts-ignore
// data: isPending ? [] : data.data,
getPosition: d => [d.x, d.y],
//@ts-ignore
getFillColor: d => colorScale(d[attr]).slice(4, -1).split(", ").map(Number),
getRadius: d => radiusScale(d[attr]),
updateTriggers: {
getFillColor: [attr],
getRadius: [attr]
}
}),
];
return (
<>
<DeckGL
initialViewState={{
longitude: 37.028,
latitude: 55.778,
zoom: 7
}}
controller
layers={layers}
>
<Map mapStyle="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json" hash={true} />
</DeckGL>
<Space style={{ position: "absolute", zIndex: 1, justifyContent: "center", padding: 30 }} direction='vertical'>
<Spin spinning={isPending} />
<Select
onChange={setDay}
options={[{ value: "2023-12-01" }, { value: "2023-12-02" }]}
value={day}
/>
<Slider
value={value}
min={0}
max={47}
onChange={e => setValue(e)}
onChangeComplete={hour => {
const hours = Math.floor(hour / 2).toString().padStart(2, "0");
const minutes = ((hour % 2) * 30).toString().padStart(2, "0");
const field = hours + ":" + minutes + ":00";
setAttr(field);
}}
/>
<p id="time">{attr}</p>
<button onClick={() => {
setValue((value + 1))
//@ts-ignore
const hour = parseInt(value);
const hours = Math.floor(hour / 2).toString().padStart(2, "0");
const minutes = ((hour % 2) * 30).toString().padStart(2, "0");
const field = hours + ":" + minutes + ":00";
setAttr(field);
}}>Плюс</button>
</Space>
</>
);
}
export default App