diff --git a/src/actions/index.js b/src/actions/index.js index b0c7722..9730c21 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -121,6 +121,7 @@ export function fetchDomain() { } dispatch(toggleFetchingDomain()); dispatch(setInitialCategories(result.associations)); + dispatch(setInitialShapes(result.shapes)); return result; }) .catch((err) => { @@ -245,6 +246,14 @@ export function setInitialCategories(values) { }; } +export const SET_INITIAL_SHAPES = "SET_INITIAL_SHAPES"; +export function setInitialShapes(values) { + return { + type: SET_INITIAL_SHAPES, + values, + }; +} + export const UPDATE_TIMERANGE = "UPDATE_TIMERANGE"; export function updateTimeRange(timerange) { return { diff --git a/src/common/utilities.js b/src/common/utilities.js index 5afe61c..6aefd98 100644 --- a/src/common/utilities.js +++ b/src/common/utilities.js @@ -513,10 +513,10 @@ export function setD3Locale(d3) { export function mapStyleByShape(shapes, activeShapes) { const styledShapes = shapes.map((s) => { - const { colour, shape, title } = s; + const { colour, shape, id } = s; const style = { checkboxStyles: { - background: activeShapes.includes(title) ? colour : "black", + background: activeShapes.includes(id) ? colour : "black", border: "none", clipPath: POLYGON_CLIP_PATH[shape], }, diff --git a/src/components/controls/CategoriesListPanel.js b/src/components/controls/CategoriesListPanel.js index 43d1535..47c85b7 100644 --- a/src/components/controls/CategoriesListPanel.js +++ b/src/components/controls/CategoriesListPanel.js @@ -1,6 +1,7 @@ import React from "react"; import marked from "marked"; import PanelTree from "./atoms/PanelTree"; +import { ASSOCIATION_MODES } from "../../common/constants"; const CategoriesListPanel = ({ categories, @@ -22,6 +23,7 @@ const CategoriesListPanel = ({ data={categories} activeValues={activeCategories} onSelect={onCategoryFilter} + type={ASSOCIATION_MODES.CATEGORY} /> ); diff --git a/src/components/controls/ShapesListPanel.js b/src/components/controls/ShapesListPanel.js index 04cf2e2..f72669c 100644 --- a/src/components/controls/ShapesListPanel.js +++ b/src/components/controls/ShapesListPanel.js @@ -2,6 +2,7 @@ import React from "react"; import marked from "marked"; import PanelTree from "./atoms/PanelTree"; import { mapStyleByShape } from "../../common/utilities"; +import { SHAPE } from "../../common/constants"; const ShapesListPanel = ({ shapes, @@ -24,6 +25,7 @@ const ShapesListPanel = ({ data={styledShapes} activeValues={activeShapes} onSelect={onShapeFilter} + type={SHAPE} /> ); diff --git a/src/components/controls/atoms/PanelTree.js b/src/components/controls/atoms/PanelTree.js index 47796ae..6da7098 100644 --- a/src/components/controls/atoms/PanelTree.js +++ b/src/components/controls/atoms/PanelTree.js @@ -1,11 +1,13 @@ import React from "react"; import Checkbox from "../../atoms/Checkbox"; +import { ASSOCIATION_MODES } from "../../../common/constants"; -const PanelTree = ({ data, activeValues, onSelect }) => { +const PanelTree = ({ data, activeValues, onSelect, type }) => { + // If the parent panel is of type 'CATEGORY': filter on title. If panel is 'SHAPE': filter on id + const onSelectionType = type === ASSOCIATION_MODES.CATEGORY ? "title" : "id"; return (