Skip to content

Commit

Permalink
Merge pull request #453 from VEuPathDB/handle-date-bubbles
Browse files Browse the repository at this point in the history
Interim non-handling of date variables for bubble markers (but allows EdaDataService#309 to be merged)
  • Loading branch information
bobular authored Oct 19, 2023
2 parents 339b0d1 + 42eb71e commit 193d026
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
8 changes: 4 additions & 4 deletions packages/libs/eda/src/lib/core/api/DataClient/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ export const BubbleOverlayConfig = type({
denominatorValues: array(string),
}),
type({
overlayType: literal('continuous'),
overlayType: literal('continuous'), // TO DO for dates: probably redefine as 'number' | 'date'
aggregator: keyof({ mean: null, median: null }),
}),
]),
Expand Down Expand Up @@ -889,7 +889,7 @@ export const StandaloneMapBubblesResponse = type({
intersection([
MapElement,
type({
overlayValue: number,
overlayValue: string,
}),
])
),
Expand All @@ -914,8 +914,8 @@ export type StandaloneMapBubblesLegendResponse = TypeOf<
typeof StandaloneMapBubblesLegendResponse
>;
export const StandaloneMapBubblesLegendResponse = type({
minColorValue: number,
maxColorValue: number,
minColorValue: string,
maxColorValue: string,
minSizeValue: number,
maxSizeValue: number,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
aggregationHelp,
AggregationInputs,
} from '../../../core/components/visualizations/implementations/LineplotVisualization';
import { DataElementConstraint } from '../../../core/types/visualization';
import { DataElementConstraint } from '../../../core/types/visualization'; // TO DO for dates: remove

type AggregatorOption = typeof aggregatorOptions[number];
const aggregatorOptions = ['mean', 'median'] as const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@ interface MapMarkers {
// vocabulary: string[] | undefined;
/** data for creating a legend */
legendItems: LegendItemsProps[];
bubbleLegendData?: StandaloneMapBubblesLegendResponse;
bubbleLegendData?: // TO DO for dates: use StandaloneMapBubblesLegendResponse instead;
{
minColorValue: number;
maxColorValue: number;
minSizeValue: number;
maxSizeValue: number;
};
bubbleValueToDiameterMapper?: (value: number) => number;
bubbleValueToColorMapper?: (value: number) => string;
/** is the request pending? */
Expand Down Expand Up @@ -200,12 +206,7 @@ export function useStandaloneMapMarkers(
| StandaloneMapMarkersResponse
| StandaloneMapBubblesResponse;
vocabulary: string[] | undefined;
bubbleLegendData?: {
minColorValue: number;
maxColorValue: number;
minSizeValue: number;
maxSizeValue: number;
};
bubbleLegendData?: StandaloneMapBubblesLegendResponse;
}
| undefined
>(
Expand Down Expand Up @@ -414,7 +415,18 @@ export function useStandaloneMapMarkers(
) as NumberRange;

const vocabulary = rawPromise.value?.vocabulary;
const bubbleLegendData = rawPromise.value?.bubbleLegendData;

// temporarily convert potentially date-strings to numbers
// but don't worry - we are also temporarily disabling date variables from bubble mode
const temp = rawPromise.value?.bubbleLegendData;
const bubbleLegendData = temp
? {
minColorValue: Number(temp.minColorValue),
maxColorValue: Number(temp.maxColorValue),
minSizeValue: temp.minSizeValue,
maxSizeValue: temp.maxSizeValue,
}
: undefined;

const adjustedSizeData = useMemo(
() =>
Expand Down Expand Up @@ -727,13 +739,13 @@ const processRawBubblesData = (
const bubbleData = {
value: entityCount,
diameter: bubbleValueToDiameterMapper?.(entityCount) ?? 0,
colorValue: overlayValue,
colorValue: Number(overlayValue), // TO DO for dates: handle dates!
colorLabel: aggregationConfig
? aggregationConfig.overlayType === 'continuous'
? _.capitalize(aggregationConfig.aggregator)
: 'Proportion'
: undefined,
color: bubbleValueToColorMapper?.(overlayValue),
color: bubbleValueToColorMapper?.(Number(overlayValue)),
};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
OverlayConfig,
StudyEntity,
Variable,
VariableType,
} from '../../../core';
import { DataClient, SubsettingClient } from '../../../core/api';
import { BinningMethod, MarkerConfiguration } from '../appState';
Expand Down Expand Up @@ -92,7 +93,7 @@ export async function getDefaultOverlayConfig(
return {
overlayVariable: overlayVariableDescriptor,
aggregationConfig: {
overlayType: 'continuous',
overlayType: 'continuous', // TO DO for dates: might do `overlayVariable.type === 'date' ? 'date' : 'number'`
aggregator,
},
};
Expand Down

0 comments on commit 193d026

Please sign in to comment.