Skip to content

Commit

Permalink
WIP Improve the legend integration with multiple series #202
Browse files Browse the repository at this point in the history
  • Loading branch information
cugarteblair committed Jan 14, 2025
1 parent 15664bc commit 9a71670
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 159 deletions.
2 changes: 1 addition & 1 deletion web-client/src/components/SrAppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const mobileMenu = ref<InstanceType<typeof Menu> | null>(null);
const mobileMenuItems = [
{
label: 'Map',
label: 'Request',
icon: 'pi pi-sliders-h',
command: handleRequestButtonClick
},
Expand Down
167 changes: 108 additions & 59 deletions web-client/src/components/SrAtl03ColorLegend.vue
Original file line number Diff line number Diff line change
@@ -1,65 +1,114 @@
<template>
<div class="legend">
<div
v-for="option in atl03CnfOptions"
:key="option.value"
class="legend-item"
>
<div
class="color-box"
:style="{ backgroundColor: getColorForAtl03CnfValue(option.value) }"
></div>
<div class="label">
{{ formatLabel(option.label) }} ({{ option.value }})
<div class="legend">
<!-- Existing ATL03 CNF color items -->
<Fieldset
class="sr-legend-box"
legend="ATL03 Colors"
:toggleable="false"
:collapsed="false"
>
<div v-for="option in atl03CnfOptions" :key="option.value" class="legend-item">
<div class="color-box" :style="{ backgroundColor: getColorForAtl03CnfValue(option.value) }"></div>
<div class="label">{{ formatLabel(option.label) }} ({{ option.value }})</div>
</div>
</Fieldset>
<!-- New Manage Colors button -->
<div class="sr-restore-defaults">
<Button label="Manage Atl03 Colors" @click="showDialog = true" size="small" />
</div>

<!-- Dialog that contains SrAtl03CnfColors when visible -->
<Dialog
v-model:visible="showDialog"
:modal="true"
:draggable="false"
:resizable="false"
header="Manage ATL03 Colors"
@hide="onDialogHide"
>
<SrAtl03CnfColors
@selectionChanged="atl03CnfColorChanged"
@defaultsChanged="atl03CnfColorChanged"
/>
</Dialog>
</div>
</div>
</template>

<script setup lang="ts">
import { onMounted, computed } from 'vue';
import { useAtl03ColorMapStore } from '@/stores/atl03ColorMapStore';
const store = useAtl03ColorMapStore();
</template>

<script setup lang="ts">
import { ref, onMounted, computed } from 'vue';
import Button from 'primevue/button';
import Dialog from 'primevue/dialog';
import SrAtl03CnfColors from './SrAtl03CnfColors.vue';
import { useAtl03ColorMapStore } from '@/stores/atl03ColorMapStore';
import Fieldset from 'primevue/fieldset';
onMounted(async () => {
if (!store.isInitialized) {
await store.initializeAtl03ColorMapStore();
const emit = defineEmits(['restore-defaults-click', 'atl03CnfColorChanged']);
const atl03ColorMapStore = useAtl03ColorMapStore();
// Dialog visibility state
const showDialog = ref(false);
onMounted(async () => {
if (!atl03ColorMapStore.isInitialized) {
await atl03ColorMapStore.initializeAtl03ColorMapStore();
}
});
const atl03CnfOptions = computed(() => atl03ColorMapStore.atl03CnfOptions);
const getColorForAtl03CnfValue = (value: number): string => {
return atl03ColorMapStore.getColorForAtl03CnfValue(value);
};
const formatLabel = (label: string): string => {
return label.replace(/^atl03_/, '').replace(/_/g, ' ');
};
// Emitted when a color changes
const atl03CnfColorChanged = (event: { label: string; color: string }) => {
emit('atl03CnfColorChanged', event);
};
function onDialogHide() {
// If you need to do something on close of the popup, do it here.
// e.g., reload color map, etc.
}
</script>

<style scoped>
.legend {
display: flex;
flex-direction: column;
gap: 8px;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
}
.color-box {
width: 20px;
height: 20px;
border: 1px solid #000;
}
.label {
font-size: 14px;
}
.sr-restore-defaults {
margin-top: 1rem;
}
});
const atl03CnfOptions = computed(() => store.atl03CnfOptions);
const getColorForAtl03CnfValue = (value: number): string => {
return store.getColorForAtl03CnfValue(value);
};
// Function to format the label
const formatLabel = (label: string): string => {
return label.replace(/^atl03_/, '').replace(/_/g, ' ');
};
</script>

<style scoped>
.legend {
display: flex;
flex-direction: column;
gap: 8px;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
}
.color-box {
width: 20px;
height: 20px;
border: 1px solid #000;
}
.label {
font-size: 14px;
}
</style>
.sr-legend-box {
padding: 0.3125rem;
border-radius: var(--p-border-radius);
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
</style>

56 changes: 9 additions & 47 deletions web-client/src/components/SrColorPalette.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="sr-color-palette">
<Fieldset legend="Color Palette" class="sr-color-palette-content" :toggleable="true" :collapsed="false">
<h2>Select Your Color Palette</h2>
<PickList v-model="colors" dataKey="label">
<PickList v-model="srColorTable" dataKey="label">
<!-- Custom source header with different background color -->
<template #sourceheader>
<div class="source-header">Available Colors</div>
Expand Down Expand Up @@ -37,7 +37,7 @@
<SrMenu
label="YAPC Color Map"
v-model="atl03ColorMapStore.selectedAtl03YapcColorMapName"
:menuOptions="colorMapNames"
:menuOptions="srColorMapNames"
:getSelectedMenuItem="atl03ColorMapStore.getSelectedAtl03YapcColorMapName"
:setSelectedMenuItem="atl03ColorMapStore.setSelectedAtl03YapcColorMapName"
tooltipText="YAPC Color Map for atl03 scatter plot"
Expand All @@ -47,71 +47,33 @@
</template>

<script setup lang="ts">
import { onMounted, ref, computed } from 'vue';
import { onMounted } from 'vue';
import PickList from 'primevue/picklist';
import Button from 'primevue/button';
import { useAtl03ColorMapStore } from '@/stores/atl03ColorMapStore';
import Fieldset from 'primevue/fieldset';
import SrAtl03CnfColors from './SrAtl03CnfColors.vue';
import SrAtl08ClassColors from './SrAtl08ClassColors.vue';
import SrMenu from './SrMenu.vue';
import { colorMapNames } from '@/utils/colorUtils';
import { srColorMapNames,srColorTable } from '@/utils/colorUtils';
const atl03ColorMapStore = useAtl03ColorMapStore();
// Predefined list of CSS color names
const cssColorNames = [
"AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige", "Bisque", "Black",
"BlanchedAlmond", "Blue", "BlueViolet", "Brown", "BurlyWood", "CadetBlue", "Chartreuse",
"Chocolate", "Coral", "CornflowerBlue", "Cornsilk", "Crimson", "Cyan", "DarkBlue",
"DarkCyan", "DarkGoldenRod", "DarkGray", "DarkGreen", "DarkKhaki", "DarkMagenta",
"DarkOliveGreen", "DarkOrange", "DarkOrchid", "DarkRed", "DarkSalmon", "DarkSeaGreen",
"DarkSlateBlue", "DarkSlateGray", "DarkTurquoise", "DarkViolet", "DeepPink", "DeepSkyBlue",
"DimGray", "DodgerBlue", "FireBrick", "FloralWhite", "ForestGreen", "Fuchsia", "Gainsboro",
"GhostWhite", "Gold", "GoldenRod", "Gray", "Green", "GreenYellow", "HoneyDew", "HotPink",
"IndianRed", "Indigo", "Ivory", "Khaki", "Lavender", "LavenderBlush", "LawnGreen",
"LemonChiffon", "LightBlue", "LightCoral", "LightCyan", "LightGoldenRodYellow", "LightGray",
"LightGreen", "LightPink", "LightSalmon", "LightSeaGreen", "LightSkyBlue", "LightSlateGray",
"LightSteelBlue", "LightYellow", "Lime", "LimeGreen", "Linen", "Magenta", "Maroon", "MediumAquaMarine",
"MediumBlue", "MediumOrchid", "MediumPurple", "MediumSeaGreen", "MediumSlateBlue",
"MediumSpringGreen", "MediumTurquoise", "MediumVioletRed", "MidnightBlue", "MintCream",
"MistyRose", "Moccasin", "NavajoWhite", "Navy", "OldLace", "Olive", "OliveDrab", "Orange",
"OrangeRed", "Orchid", "PaleGoldenRod", "PaleGreen", "PaleTurquoise", "PaleVioletRed",
"PapayaWhip", "PeachPuff", "Peru", "Pink", "Plum", "PowderBlue", "Purple", "RebeccaPurple",
"Red", "RosyBrown", "RoyalBlue", "SaddleBrown", "Salmon", "SandyBrown", "SeaGreen", "SeaShell",
"Sienna", "Silver", "SkyBlue", "SlateBlue", "SlateGray", "Snow", "SpringGreen", "SteelBlue",
"Tan", "Teal", "Thistle", "Tomato", "Turquoise", "Violet", "Wheat", "White", "WhiteSmoke",
"Yellow", "YellowGreen"
];
interface AtColorChangeEvent {
label: string;
color?: string; // color can be undefined
}
const selectedColors = computed({
get: () => atl03ColorMapStore.getNamedColorPalette(),
set: (value) => atl03ColorMapStore.setNamedColorPalette(value)
});
// Initialize the source and target lists for the PickList
const colors = ref([
cssColorNames.map(color => ({ label: color, value: color })),
selectedColors.value.map(color => ({ label: color, value: color }))
]);
onMounted(() => {
atl03ColorMapStore.initializeAtl03ColorMapStore();
colors.value[1] = atl03ColorMapStore.getNamedColorPalette().map(color => ({ label: color, value: color }));
console.log('Mounted SrColorPalette colors:', colors.value);
srColorTable.value[1] = atl03ColorMapStore.getNamedColorPalette().map(color => ({ label: color, value: color }));
console.log('Mounted SrColorPalette colors:', srColorTable.value);
});
const restoreDefaultColors = async () => {
await atl03ColorMapStore.restoreDefaultColors();
colors.value[1] = atl03ColorMapStore.getNamedColorPalette().map(color => ({ label: color, value: color }));
console.log('SrColorPalette colors:', atl03ColorMapStore.getNamedColorPalette());
};
await restoreDefaultColors();
console.log('SrColorPalette colors:', srColorTable.value);
};
const atl03CnfColorChanged = async (colorKey:string): Promise<void> =>{
console.log(`atl03CnfColorChanged:`,colorKey);
Expand Down
Loading

0 comments on commit 9a71670

Please sign in to comment.