Skip to content

Commit

Permalink
Update map view to work in Storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Bukin committed Sep 28, 2023
1 parent cf33a82 commit 8174d24
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions taxonium_component/src/Deck.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { TreenomeButtons } from "./components/TreenomeButtons";
import TreenomeModal from "./components/TreenomeModal";
import FirefoxWarning from "./components/FirefoxWarning";
import Key from "./components/Key";
import ColorSettingModal from "./components/ColorSettingModal";
import TreenomeBrowser from "./components/TreenomeBrowser";

const MemoizedKey = React.memo(Key);
Expand Down
4 changes: 1 addition & 3 deletions taxonium_component/src/Taxonium.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function Taxonium({

const deckRef = useRef();
const jbrowseRef = useRef();
const [mouseDownIsMinimap, setMouseDownIsMinimap] = useState(false);

const [deckSize, setDeckSize] = useState(null);
const settings = useSettings({ query, updateQuery });
Expand All @@ -74,7 +75,6 @@ function Taxonium({
deckSize,
deckRef,
jbrowseRef,
nodes,
mouseDownIsMinimap,
});

Expand Down Expand Up @@ -125,8 +125,6 @@ function Taxonium({
const { data, boundsForQueries, isCurrentlyOutsideBounds } =
useGetDynamicData(backend, colorBy, view.viewState, config, xType);

useMemo(() => setNodes(data), [data]);

const perNodeFunctions = usePerNodeFunctions(data, config);

useEffect(() => {
Expand Down
14 changes: 9 additions & 5 deletions taxonium_component/src/hooks/useLayers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
GeoJsonLayer,
} from "@deck.gl/layers";

import { useMemo, useCallback } from "react";
import { useMemo, useCallback, useEffect } from "react";
import useTreenomeLayers from "./useTreenomeLayers";
import getSVGfunction from "../utils/deckglToSvg";

Expand Down Expand Up @@ -558,6 +558,7 @@ const useLayers = ({
}

const getColorByCountryCount = (country) => {
console.log("country ", country);
const hookColor = colorHook.toRGB(country);

const GRAY = [169, 169, 169];
Expand All @@ -570,11 +571,11 @@ const useLayers = ({
let lineWidth = 100;
if (viewState["map"]) lineWidth = (1 / viewState["map"].zoom) * 9000;

layers.push(
new GeoJsonLayer({
layers.push({
id: "map",
data: geojson.features,
stroked: true,
layerType: "GeoJsonLayer",
filled: true,
getLineColor: [255, 255, 255],
getLineWidth: lineWidth,
Expand All @@ -585,8 +586,7 @@ const useLayers = ({
getFillColor: data.data.nodes,
},
opacity: 0.8,
})
);
});

const layerFilter = useCallback(
({ layer, viewport, renderPass }) => {
Expand Down Expand Up @@ -615,6 +615,7 @@ const useLayers = ({
return new ScatterplotLayer(layer);
}
if (layer.layerType === "LineLayer") {
console.log('processed ', layer);
return new LineLayer(layer);
}
if (layer.layerType === "PolygonLayer") {
Expand All @@ -626,6 +627,9 @@ const useLayers = ({
if (layer.layerType === "SolidPolygonLayer") {
return new SolidPolygonLayer(layer);
}
if (layer.layerType === "GeoJsonLayer") {
return new GeoJsonLayer(layer);
}
console.log("could not map layer spec for ", layer);
});

Expand Down
12 changes: 7 additions & 5 deletions taxonium_component/src/hooks/useView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ class MyOrthographicController extends OrthographicController {
}
}

const useView = ({ settings, deckSize, deckRef, jbrowseRef, nodes }) => {
const useView = ({
settings,
deckSize,
deckRef,
jbrowseRef,
mouseDownIsMinimap,
}) => {
const [zoomAxis, setZoomAxis] = useState("Y");
const [xzoom, setXzoom] = useState(window.screen.width < 600 ? -1 : 0);
globalSetZoomAxis = setZoomAxis;
Expand Down Expand Up @@ -247,10 +253,6 @@ const useView = ({ settings, deckSize, deckRef, jbrowseRef, nodes }) => {
];
}, [viewState.zoom, xzoom]);

useEffect(() => {
console.log("vs: ", viewState);
}, [viewState]);

const onViewStateChange = useCallback(
({
viewState: newViewState,
Expand Down

0 comments on commit 8174d24

Please sign in to comment.