From 4145f6759326df962982bb710733e107b66513cf Mon Sep 17 00:00:00 2001 From: Daven Quinn Date: Sun, 2 Jun 2024 22:00:02 -0500 Subject: [PATCH] Added settings panel --- src/pages/maps/@id/correlation/+Page.ts | 81 ++++++++++++++++--- .../maps/@id/correlation/main.module.sass | 4 + 2 files changed, 74 insertions(+), 11 deletions(-) diff --git a/src/pages/maps/@id/correlation/+Page.ts b/src/pages/maps/@id/correlation/+Page.ts index e7d734f5..b6f7112f 100644 --- a/src/pages/maps/@id/correlation/+Page.ts +++ b/src/pages/maps/@id/correlation/+Page.ts @@ -3,6 +3,7 @@ import { Spinner, SegmentedControl, FormGroup, + Button, } from "@blueprintjs/core"; import { FullscreenPage } from "~/layouts"; import hyper from "@macrostrat/hyper"; @@ -12,7 +13,7 @@ import { useLegendData, MapInfo } from "../utils"; import { useElementSize, useInDarkMode } from "@macrostrat/ui-components"; import { useMemo, useRef } from "react"; import { Group } from "@visx/group"; -import { scaleBand, scaleLinear } from "@visx/scale"; +import { scaleBand, scaleLinear, scaleLog } from "@visx/scale"; import { AxisLeft } from "@visx/axis"; import { Timescale, TimescaleOrientation } from "@macrostrat/timescale"; import { ForeignObject } from "@macrostrat/column-components"; @@ -35,27 +36,51 @@ export function Page({ map }) { const legendData = useLegendData(map); const [ageMode, setAgeMode] = useState(AgeDisplayMode.MapLegend); + const [ageScale, setAgeScale] = useState("linear"); const correlationChartData = useMemo(() => { return buildCorrelationChartData(legendData, ageMode); }, [legendData, ageMode]); + const [selectedItem, setSelectedLegendID] = + useSelectedLegendID(correlationChartData); + + const settings = h("div.settings", [ + h("h3", "Settings"), + h(AgeScaleSelector, { scale: ageScale, setScale: setAgeScale }), + h(AgeDisplayModeSelector, { + displayMode: ageMode, + setDisplayMode: setAgeMode, + }), + ]); + return h(FullscreenPage, [ h("div.page-inner", [ h("div.flex.row", [ h(PageBreadcrumbs), h("div.spacer"), - h(AgeDisplayModeSelector, { - displayMode: ageMode, - setDisplayMode: setAgeMode, - }), + h( + Popover, + { + content: settings, + usePortal: true, + rootBoundary: ref.current, + onOpening() { + setSelectedLegendID(null); + }, + }, + [h(Button, { icon: "cog", minimal: true })] + ), ]), h("div.vis-container", { ref }, [ h.if(legendData != null)(CorrelationChart, { map, ...size, data: correlationChartData, + selectedItem, + setSelectedLegendID, ageMode, + ageScale, }), ]), ]), @@ -67,24 +92,29 @@ const verticalMargin = 60; export type BarsProps = { width: number; height: number; - events?: boolean; map: MapInfo; data: CorrelationItem[]; ageMode: AgeDisplayMode; + ageScale: AgeScale; + selectedItem: CorrelationItem | null; + setSelectedLegendID: (a: number) => void; }; +type AgeScale = "linear" | "log"; + function CorrelationChart({ width, height, data, ageMode = AgeDisplayMode.MapLegend, + ageScale = "linear", + selectedItem, + setSelectedLegendID, }: BarsProps) { // bounds const xMax = width; const yMax = height - verticalMargin; - const [selectedItem, setSelectedLegendID] = useSelectedLegendID(data); - const domain = useMemo( () => mergeAgeRanges(data.map((d) => getBoundingAgeRange(d, ageMode))), [data, ageMode] @@ -104,12 +134,22 @@ function CorrelationChart({ [xMax, data] ); const yScale = useMemo(() => { + if (ageScale === "log") { + return scaleLog({ + range: [yMax, 0], + round: true, + domain: domain, + nice: true, + base: 10, + }); + } + return scaleLinear({ range: [yMax, 0], round: false, domain, }); - }, [domain, yMax]); + }, [domain, yMax, ageScale]); if (data == null) { return h(Spinner); @@ -357,7 +397,7 @@ function AgeDisplayModeSelector({ displayMode: AgeDisplayMode; setDisplayMode: (a: AgeDisplayMode) => void; }) { - return h(FormGroup, { label: "Age source", inline: true }, [ + return h(FormGroup, { label: "Age source" }, [ h(SegmentedControl, { options: [ { label: "Map legend", value: AgeDisplayMode.MapLegend }, @@ -365,9 +405,28 @@ function AgeDisplayModeSelector({ { label: "Both", value: AgeDisplayMode.Both }, ], small: true, - minimal: true, value: displayMode, onValueChange: setDisplayMode, }), ]); } + +function AgeScaleSelector({ + scale, + setScale, +}: { + scale: AgeScale; + setScale: (a: AgeScale) => void; +}) { + return h(FormGroup, { label: "Age scale" }, [ + h(SegmentedControl, { + options: [ + { label: "Linear", value: "linear" }, + { label: "Log", value: "log" }, + ], + small: true, + value: scale, + onValueChange: setScale, + }), + ]); +} diff --git a/src/pages/maps/@id/correlation/main.module.sass b/src/pages/maps/@id/correlation/main.module.sass index 8c9ea863..1b576064 100644 --- a/src/pages/maps/@id/correlation/main.module.sass +++ b/src/pages/maps/@id/correlation/main.module.sass @@ -72,3 +72,7 @@ div.correlation-chart .unit color: var(--secondary-color) +.settings + padding: 1em + >h3:first-child + margin-top: 0 \ No newline at end of file