From 2f056e72e577e18a51dd5d0486f3ea1e087a01f4 Mon Sep 17 00:00:00 2001 From: Theo Sanderson Date: Tue, 12 Sep 2023 18:55:21 +0100 Subject: [PATCH] kinda there --- taxonium_component/src/Deck.jsx | 27 ++++++++++++ taxonium_component/src/Taxonium.jsx | 7 ++- .../src/components/ColorSettingModal.jsx | 44 +++++++++++++++++++ taxonium_component/src/components/Key.jsx | 18 ++++++-- taxonium_component/src/hooks/useColor.jsx | 2 +- 5 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 taxonium_component/src/components/ColorSettingModal.jsx diff --git a/taxonium_component/src/Deck.jsx b/taxonium_component/src/Deck.jsx index 70528789..10d1ca33 100644 --- a/taxonium_component/src/Deck.jsx +++ b/taxonium_component/src/Deck.jsx @@ -20,6 +20,7 @@ import { TreenomeButtons } from "./components/TreenomeButtons"; import TreenomeModal from "./components/TreenomeModal"; import FirefoxWarning from "./components/FirefoxWarning"; import { JBrowseErrorBoundary } from "./components/JBrowseErrorBoundary"; +import ColorSettingModal from "./components/ColorSettingModal"; import Key from "./components/Key"; const MemoizedKey = React.memo(Key); @@ -42,10 +43,13 @@ function Deck({ isCurrentlyOutsideBounds, deckRef, jbrowseRef, + setAdditionalColorMapping }) { const zoomReset = view.zoomReset; const snapshot = useSnapshot(deckRef); const [deckSettingsOpen, setDeckSettingsOpen] = useState(false); + const [colorSettingOpen, setColorSettingOpen] = useState(false); + const [currentColorSettingKey, setCurrentColorSettingKey] = useState("a"); const [treenomeSettingsOpen, setTreenomeSettingsOpen] = useState(false); //console.log("DATA is ", data); @@ -74,6 +78,8 @@ function Deck({ const mouseDownPos = useRef(); + + const onClickOrMouseMove = useCallback( (event) => { if (event.buttons === 0 && event._reactName === "onPointerMove") { @@ -255,6 +261,24 @@ function Deck({ setDeckSettingsOpen={setDeckSettingsOpen} settings={settings} /> + { + setAdditionalColorMapping(x => { + return {...x, [currentColorSettingKey]: color}; + }); + } + + } + title = {currentColorSettingKey} + /> + + + hoverInfo && hoverInfo.object ? "default" : "pointer"} @@ -338,6 +362,9 @@ function Deck({ colorByGene={colorBy.colorByGene} colorByPosition={colorBy.colorByPosition} config={config} + setCurrentColorSettingKey={setCurrentColorSettingKey} + setColorSettingOpen={setColorSettingOpen} + /> { - return config.colorMapping ? config.colorMapping : {}; - }, [config.colorMapping]); + const initial = config.colorMapping ? config.colorMapping : {}; + return { ...initial, ...additionalColorMapping }; + }, [config.colorMapping, additionalColorMapping]); const colorHook = useColor(colorMapping); //TODO: this is always true for now @@ -193,6 +195,7 @@ function Taxonium({ treenomeState={treenomeState} deckRef={deckRef} jbrowseRef={jbrowseRef} + setAdditionalColorMapping={setAdditionalColorMapping} /> diff --git a/taxonium_component/src/components/ColorSettingModal.jsx b/taxonium_component/src/components/ColorSettingModal.jsx new file mode 100644 index 00000000..638e91ce --- /dev/null +++ b/taxonium_component/src/components/ColorSettingModal.jsx @@ -0,0 +1,44 @@ +import React from "react"; +import Modal from "react-modal"; +import ColorPicker from "./ColorPicker"; + +const modalStyle = { + content: { + top: "50%", + left: "50%", + transform: "translate(-50%, -50%)", + backgroundColor: "#fafafa", + border: '1px solid #e2e8f0', + borderRadius: '8px', + padding: '20px', + maxWidth: '400px', + }, +}; + +const ColorSettingModal = ({ isOpen, setIsOpen, color, setColor, title }) => { + return ( + setIsOpen(false)} + contentLabel={title} + > +

{title}

+ +
+
+ +
+
+ +
+ ); +}; + +export default ColorSettingModal; diff --git a/taxonium_component/src/components/Key.jsx b/taxonium_component/src/components/Key.jsx index 719ea42d..bb236dad 100644 --- a/taxonium_component/src/components/Key.jsx +++ b/taxonium_component/src/components/Key.jsx @@ -7,6 +7,10 @@ const Key = ({ colorByGene, colorByPosition, config, + setCurrentColorSettingKey, + setColorSettingOpen + + }) => { const numLegendEntries = 10; const [collapsed, setCollapsed] = useState(window.innerWidth < 800); @@ -51,19 +55,27 @@ const Key = ({ const rgb = item.color; const color = `rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`; return ( - // small dot with color
+ { + setCurrentColorSettingKey(item.value); + setColorSettingOpen(true); + } + + } + title="Edit color" >
{item.value}
); })} + {isTruncated &&
...
} )} diff --git a/taxonium_component/src/hooks/useColor.jsx b/taxonium_component/src/hooks/useColor.jsx index 2c08a208..b04175b9 100644 --- a/taxonium_component/src/hooks/useColor.jsx +++ b/taxonium_component/src/hooks/useColor.jsx @@ -140,7 +140,7 @@ const useColor = (colorMapping) => { const toRGB = useCallback( (string) => { - if (rgb_cache[string]) { + if (rgb_cache[string]&& !colorMapping[string]) { return rgb_cache[string]; } else { const result = toRGB_uncached(string);