Skip to content

Commit

Permalink
Fix race condition to initialize symbol size #228
Browse files Browse the repository at this point in the history
  • Loading branch information
cugarteblair committed Jan 13, 2025
1 parent 508c0c1 commit 930ac3d
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 110 deletions.
2 changes: 1 addition & 1 deletion web-client/src/components/SrAnalyzeOptSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { useSrToastStore } from "@/stores/srToastStore";
import SrEditDesc from '@/components/SrEditDesc.vue';
import SrScatterPlotOptions from "@/components/SrScatterPlotOptions.vue";
import { useChartStore } from '@/stores/chartStore';
import { initSymbolSize, updateChartStore } from '@/utils/plotUtils';
import { updateChartStore } from '@/utils/plotUtils';
import SrCustomTooltip from '@/components/SrCustomTooltip.vue';
import Button from 'primevue/button';
import { clicked } from '@/utils/SrMapUtils'
Expand Down
119 changes: 10 additions & 109 deletions web-client/src/components/SrScatterPlot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,9 @@
display="chip"
@update:modelValue="onMainYDataSelectionChange"
/>
<SrSliderStored
v-model="createComputedSymbolSizeFor(computedReqIdStr).value"
@update:modelValue="symbolSizeSelection"
label="symbol size"
inputWidth="2em"
sliderWidth="5rem"
:min="1"
:max="10"
:defaultValue="computedSymbolSize"
:getValue="createGetSymbolSizeFor(computedReqIdStr)"
:setValue="createSetSymbolSizeFor(computedReqIdStr)"
:decimalPlaces=0
tooltipText="Symbol size for Scatter Plot"
<SrSymbolSize
:reqIdStr="computedReqIdStr"
@update:symbolSize="handleSymbolSizeUpdate"
/>
</Fieldset>
</div>
Expand All @@ -82,18 +72,9 @@
display="chip"
@update:modelValue="(newValue) => onOverlayYDataSelectionChange(overlayedReqId, newValue)"
/>
<SrSliderStored
v-model="createComputedSymbolSizeFor(overlayedReqId.toString()).value"
@update:modelValue="symbolSizeSelection"
label="symbol size"
inputWidth="2em"
:min="1"
:max="10"
:defaultValue="computedSymbolSize"
:getValue="createGetSymbolSizeFor(overlayedReqId.toString())"
:setValue="createSetSymbolSizeFor(overlayedReqId.toString())"
:decimalPlaces=0
tooltipText="Symbol size for Scatter Plot"
<SrSymbolSize
:reqIdStr="overlayedReqId.toString()"
@update:symbolSize="handleSymbolSizeUpdate"
/>
</Fieldset>
</div>
Expand Down Expand Up @@ -127,12 +108,12 @@ import { prepareDbForReqId } from '@/utils/SrDuckDbUtils';
import { callPlotUpdateDebounced,getPhotonOverlayRunContext, initSymbolSize } from "@/utils/plotUtils";
import SrRunControl from "./SrRunControl.vue";
import { processRunSlideRuleClicked } from "@/utils/workerDomUtils";
import SrSliderStored from "@/components/SrSliderStored.vue";
import { findReqMenuLabel } from '@/utils/plotUtils';
import { useMapStore } from "@/stores/mapStore";
import Fieldset from "primevue/fieldset";
import { useReqParamsStore } from "@/stores/reqParamsStore";
import SrReqDisplay from '@/components/SrReqDisplay.vue';
import SrSymbolSize from '@/components/SrSymbolSize.vue';
const props = defineProps({
startingReqId: {
Expand All @@ -159,81 +140,11 @@ function getOverlayedReqLegend(overlayedReqId: number): string {
return `${label} - Photon Cloud`;
}
// Create a computed property that updates and retrieves the symbol size
const computedSymbolSize = computed<number>({
get() {
return chartStore.getSymbolSize(computedReqIdStr.value);
},
set(value: number) {
console.log(`computedSymbolSize set value: ${value}`);
chartStore.setSymbolSize(computedReqIdStr.value, value);
}
});
// Function that returns a computed property for a given reqIdStr
function createComputedSymbolSizeFor(reqIdStr: string) {
initSymbolSize(Number(reqIdStr));
return computed<number>({
get() {
return chartStore.getSymbolSize(reqIdStr);
},
set(value: number) {
//console.log(`computedSymbolSize set value: ${value}`);
chartStore.setSymbolSize(reqIdStr, value);
}
});
async function handleSymbolSizeUpdate(newValue: number) {
console.log('Symbol size updated to:', newValue);
await callPlotUpdateDebounced('from handleSymbolSizeUpdate');
}
function createComputedLabelFor(reqId: number) :string {
return `symbol size for ${findReqMenuLabel(reqId)}`;
}
function createGetSymbolSizeFor(reqIdStr: string) {
return () => {
//console.log(`createGetSymbolSizeFor get value: ${chartStore.getSymbolSize(reqIdStr)}`);
return chartStore.getSymbolSize(reqIdStr);
};
}
/**
* Cache all debounced setSymbolSize() functions,
* keyed by reqIdStr.
*/
const debouncedSetSymbolSizeCache = new Map<string, (value: number) => void>();
/**
* Creates OR retrieves a debounced function for setting symbol size.
* - If the function already exists in the cache for a given reqIdStr,
* it returns the **same** function.
* - Otherwise, it creates a new one, stores it, and returns it.
*/
function createSetSymbolSizeFor(reqIdStr: string) {
// Return the existing debounced function if we've created it before
if (debouncedSetSymbolSizeCache.has(reqIdStr)) {
return debouncedSetSymbolSizeCache.get(reqIdStr)!;
}
// The "real" function
function doSetSymbolSize(value: number) {
console.log(`computedSymbolSize set value: ${value}`);
chartStore.setSymbolSize(reqIdStr, value);
setSymbolCounter.value++;
}
// The debounced version
const debounced = debounce(doSetSymbolSize, 300);
// Store in our cache
debouncedSetSymbolSizeCache.set(reqIdStr, debounced);
// Return it so `SrSliderStored` can call it
return debounced;
}
const computedMainOptionLabel = computed(() => {
return `${findReqMenuLabel(atlChartFilterStore.selectedReqIdMenuItem.value)}`;
});
function initializeBindings(reqIds: string[]) {
//console.log('initializeBindings:', reqIds);
reqIds.forEach((reqId) => {
Expand Down Expand Up @@ -283,8 +194,6 @@ onMounted(async () => {
} else if (func.includes('atl08')) {
atl03ColorMapStore.setAtl03ColorKey('atl08_class');
}
computedSymbolSize.value = chartStore.getSymbolSize(computedReqIdStr.value);
console.log('SrScatterPlot onMounted computedSymbolSize:', computedSymbolSize.value);
} else {
console.warn('reqId is undefined');
}
Expand Down Expand Up @@ -313,14 +222,6 @@ watch(() => plotRef.value, async (newPlotRef) => {
}
});
watch(() => setSymbolCounter.value, async (newCounter) => {
console.log('setSymbolCounter changed:', newCounter);
if(newCounter>1){ // ignore first one; it's initializing
//await updateScatterOptionsOnly('from watch setSymbolCounter.value');
await callPlotUpdateDebounced('from watch setSymbolCounter.value');
}
});
const messageClass = computed(() => {
return {
'message': true,
Expand Down
83 changes: 83 additions & 0 deletions web-client/src/components/SrSymbolSize.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<template>
<div class="symbol-size-control">
<label for="symbolSize" class="sr-ss-label">Symbol Size</label>

<div class="sr-ss-number-container">
<InputNumber
v-model="symbolSize"
:min="1"
:max="10"
:step="1"
id="symbolSize"
inputId="symbolSize"
showButtons
class="sr-ss-number"
/>
</div>

</div>
</template>

<script setup lang="ts">
import { computed, defineProps } from 'vue';
import InputNumber from 'primevue/inputnumber';
import { useChartStore } from '@/stores/chartStore';
const props = defineProps<{
/**
* The reqIdStr identifies the portion of state in your chartStore.
*/
reqIdStr: string;
}>();
const emit = defineEmits<{
(event: 'update:symbolSize', value: number): void;
}>();
// Access Pinia store
const chartStore = useChartStore();
/**
* 'symbolSize' is a computed property that:
* - reads symbolSize from the store (get)
* - writes symbolSize to the store (set)
*/
const symbolSize = computed<number>({
get() {
return chartStore.getSymbolSize(props.reqIdStr);
},
set(value) {
chartStore.setSymbolSize(props.reqIdStr, value);
emit('update:symbolSize', value); // Emit the event with the new value
},
});
</script>

<style scoped>
.symbol-size-control {
display: inline-flex; /* Allow the container to shrink-wrap its content */
flex-direction: column;
justify-content: center;
align-items: flex-start; /* Align content to the left */
gap: 0.5rem; /* Add spacing between elements */
width: auto; /* Let the container size itself based on the content */
padding: 0.5rem; /* Optional: Add some padding for spacing */
}
.sr-ss-label {
margin: 0; /* Remove unnecessary margins */
font-size: small; /* Adjust font size if needed */
}
.sr-ss-number-container {
display: inline-flex; /* Allow the input to shrink-wrap */
align-items: center;
}
:deep(.sr-ss-number) {
width: auto; /* Ensure the input adjusts to fit its content */
min-width: 4rem; /* Optional: Set a minimum width for usability */
}
</style>

0 comments on commit 930ac3d

Please sign in to comment.