Skip to content

Commit

Permalink
Fix displaying wrong specie label. Raise selected circle
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluesmile82 committed May 4, 2023
1 parent b4fc064 commit e367f75
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/containers/modals/species-analysis-modal/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function SpeciesAnalysisModal({
loading,
cardProps,
speciesData,
setSpecieBySliceNumber,
setSpecieById,
}: SpeciesModalProps) {
const [globalRangeSelected, setGlobalRangeSelected] = useState({
min: 3,
Expand Down Expand Up @@ -112,7 +112,7 @@ function SpeciesAnalysisModal({
globalRangeSelected={globalRangeSelected}
SPSSelected={SPSSelected}
speciesData={speciesData}
setSpecieBySliceNumber={setSpecieBySliceNumber}
setSpecieById={setSpecieById}
/>
</div>
<SpsLegend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ function SpsChart({
SPSSelected,
globalRangeSelected,
speciesData,
setSpecieBySliceNumber,
setSpecieById,
}: SPSChartProps) {
const [tooltipPosition, setTooltipPosition] = useState<
{ top: number; left: number } | undefined
>();
const [tooltipText, setTooltipText] = useState<string | undefined>();
const { id: selectedSpeciesId }: { id: string } = selectedSpecies;
const height: number = useMemo(() => width / 2 + HEIGHT_PADDING, [width]);

if (!data) return null;

useD3Effect({
Expand All @@ -39,7 +38,7 @@ function SpsChart({
data,
setTooltipPosition,
setTooltipText,
setSpecieBySliceNumber,
setSpecieById,
speciesData,
styles,
height,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const useD3Effect = ({
data,
setTooltipPosition,
setTooltipText,
setSpecieBySliceNumber,
setSpecieById,
speciesData,
styles,
}: {
Expand All @@ -92,7 +92,7 @@ export const useD3Effect = ({
data: SPSChartProps['data'];
setTooltipPosition: (tooltipPosition: { top: number; left: number }) => void;
setTooltipText: (tooltipText: string) => void;
setSpecieBySliceNumber: (sliceNumber: number) => void;
setSpecieById: (id: string) => void;
speciesData: SPSChartProps['speciesData'];
styles: {
[className: string]: string;
Expand Down Expand Up @@ -231,7 +231,7 @@ export const useD3Effect = ({
.data(data)
.enter()
.append('g')
.attr('id', (d: SPSData) => `point-${d.SliceNumber}`)
.attr('id', (d: SPSData) => `point-${d.id}`)
.attr('transform', getPointPosition)
.append('circle')
.attr('class', styles.point)
Expand All @@ -257,9 +257,7 @@ export const useD3Effect = ({
)
.on('mouseenter', (d: SPSData) => {
if (speciesData) {
const specie: SpeciesData = speciesData.find(
(s) => s.sliceNumber === d.SliceNumber
);
const specie: SpeciesData = speciesData.find((s) => s.id === d.id);
const PADDING_LEFT = 5;
const TOP_PADDING_CENTER = 25;
setTooltipText(specie.name);
Expand All @@ -275,8 +273,12 @@ export const useD3Effect = ({
setTooltipText(undefined);
})
.on('click', (d: SPSData) => {
setSpecieBySliceNumber(d.SliceNumber);
setSpecieById(d.id);
});

// Raise selected point so we can see it clearly over the rest
const selectedPoint = points.select(`#point-${selectedSpeciesId}`);
selectedPoint.raise();
};

// Recalculate on change
Expand Down Expand Up @@ -313,7 +315,7 @@ export const useD3Effect = ({
data,
setTooltipPosition,
setTooltipText,
setSpecieBySliceNumber,
setSpecieById,
speciesData,
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export type SPSChartProps = {
SPSSelected: Range;
globalRangeSelected: Range;
speciesData: SpeciesData[];
setSpecieBySliceNumber: (sliceNumber: number) => void;
setSpecieById: (id: string) => void;
};
2 changes: 1 addition & 1 deletion src/containers/modals/species-analysis-modal/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ export type SpeciesModalProps = {
selectedSpeciesFilter: { label: string; slug: string };
};
speciesData: SpeciesData[];
setSpecieBySliceNumber: (sliceNumber: number) => void;
setSpecieById: (id: string) => void;
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function Component(props) {
selectedSpeciesFilter,
individualSpeciesData,
handleNextSpeciesSelection,
setSpecieBySliceNumber,
setSpecieById,
handlePreviousSpeciesSelection,
previousImage,
nextImage,
Expand Down Expand Up @@ -314,7 +314,7 @@ function Component(props) {
contextualData={contextualData}
cardProps={props}
speciesData={speciesData && speciesData.species}
setSpecieBySliceNumber={setSpecieBySliceNumber}
setSpecieById={setSpecieById}
selectedSpeciesFilter={selectedSpeciesFilter}
/>
</div>
Expand Down
8 changes: 3 additions & 5 deletions src/containers/sidebars/aoi-sidebar/species-card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,17 +329,15 @@ function SpeciesCardContainer(props) {
}
}, [selectedSpecies, locale, SPSData]);

const setSpecieBySliceNumber = (sliceNumber) => {
setSelectedSpecies(
speciesToDisplay.find((s) => s.sliceNumber === sliceNumber)
);
const setSpecieById = (id) => {
setSelectedSpecies(speciesToDisplay.find((s) => s.id === id));
};
return (
<Component
speciesFilters={speciesFilters}
placeholderText={placeholderText}
individualSpeciesData={individualSpeciesData}
setSpecieBySliceNumber={setSpecieBySliceNumber}
setSpecieById={setSpecieById}
speciesToDisplay={speciesToDisplay}
setSpeciesFilter={setSpeciesFilter}
selectedSpeciesFilter={selectedSpeciesFilter}
Expand Down

0 comments on commit e367f75

Please sign in to comment.