|
| 1 | +<template> |
| 2 | + <div class="acceptance-plot"> |
| 3 | + <h3 v-if="title">{{ title }}</h3> |
| 4 | + <p v-if="description" class="description">{{ description }}</p> |
| 5 | + |
| 6 | + <div class="plot-controls"> |
| 7 | + <label :for="'energy-select-' + plotId">Energy Mode:</label> |
| 8 | + <select |
| 9 | + :id="'energy-select-' + plotId" |
| 10 | + v-model="localEnergyMode" |
| 11 | + @change="loadImages" |
| 12 | + > |
| 13 | + <option value="">-- Select energy mode --</option> |
| 14 | + <option value="5x41">5×41</option> |
| 15 | + <option value="10x100">10×100</option> |
| 16 | + <option value="10x130">10×130</option> |
| 17 | + <option value="18x75">18×75</option> |
| 18 | + <option value="5x41_vs_10x100">5×41 vs 10×100</option> |
| 19 | + <option value="5x41_vs_18x75">5×41 vs 18×75</option> |
| 20 | + <option value="10x100_vs_10x130">10×100 vs 10×130</option> |
| 21 | + <option value="10x100_vs_18x75">10×100 vs 18×75</option> |
| 22 | + <option value="10x130_vs_18x75">10×130 vs 18×75</option> |
| 23 | + </select> |
| 24 | + </div> |
| 25 | + |
| 26 | + <div v-if="currentImages.length > 0" class="images-container"> |
| 27 | + <div |
| 28 | + v-for="(img, index) in currentImages" |
| 29 | + :key="index" |
| 30 | + class="image-wrapper" |
| 31 | + > |
| 32 | + <h4 v-if="img.label" class="image-label">{{ img.label }}</h4> |
| 33 | + <img |
| 34 | + :src="img.src" |
| 35 | + :alt="img.alt" |
| 36 | + @error="handleImageError" |
| 37 | + class="plot-image" |
| 38 | + /> |
| 39 | + </div> |
| 40 | + </div> |
| 41 | + |
| 42 | + <div v-else-if="localEnergyMode" class="no-data"> |
| 43 | + No plot available for selected energy mode |
| 44 | + </div> |
| 45 | + </div> |
| 46 | +</template> |
| 47 | + |
| 48 | +<script setup lang="ts"> |
| 49 | +import { ref, computed, watch, inject, onMounted } from 'vue' |
| 50 | +import { withBase } from 'vitepress' |
| 51 | +
|
| 52 | +// Props |
| 53 | +const props = defineProps<{ |
| 54 | + plotName: string |
| 55 | + title?: string |
| 56 | + description?: string |
| 57 | +}>() |
| 58 | +
|
| 59 | +// Unique ID for this plot instance |
| 60 | +const plotId = Math.random().toString(36).substr(2, 9) |
| 61 | +
|
| 62 | +// Inject global energy mode |
| 63 | +const globalEnergyMode = inject<any>('globalEnergyMode', ref('')) |
| 64 | +
|
| 65 | +// Local energy mode (can be overridden by user) |
| 66 | +const localEnergyMode = ref('') |
| 67 | +
|
| 68 | +// Current images to display |
| 69 | +interface PlotImage { |
| 70 | + src: string |
| 71 | + alt: string |
| 72 | + label?: string |
| 73 | +} |
| 74 | +
|
| 75 | +const currentImages = ref<PlotImage[]>([]) |
| 76 | +
|
| 77 | +// Watch global mode changes |
| 78 | +watch(globalEnergyMode, (newMode) => { |
| 79 | + if (newMode) { |
| 80 | + localEnergyMode.value = newMode |
| 81 | + loadImages() |
| 82 | + } |
| 83 | +}) |
| 84 | +
|
| 85 | +// Watch local mode changes |
| 86 | +watch(localEnergyMode, () => { |
| 87 | + loadImages() |
| 88 | +}) |
| 89 | +
|
| 90 | +// Load images based on selected mode |
| 91 | +function loadImages() { |
| 92 | + if (!localEnergyMode.value) { |
| 93 | + currentImages.value = [] |
| 94 | + return |
| 95 | + } |
| 96 | +
|
| 97 | + const mode = localEnergyMode.value |
| 98 | + const images: PlotImage[] = [] |
| 99 | +
|
| 100 | + if (mode.includes('_vs_')) { |
| 101 | + // Comparison mode: show two plots |
| 102 | + const [energy1, energy2] = mode.split('_vs_') |
| 103 | +
|
| 104 | + images.push({ |
| 105 | + src: withBase(`/analysis/campaign-2025-08/acceptance/${energy1}/${props.plotName}`), |
| 106 | + alt: `${props.title || props.plotName} - ${energy1}`, |
| 107 | + label: `${energy1.replace('x', '×')} GeV` |
| 108 | + }) |
| 109 | +
|
| 110 | + images.push({ |
| 111 | + src: withBase(`/analysis/campaign-2025-08/acceptance/${energy2}/${props.plotName}`), |
| 112 | + alt: `${props.title || props.plotName} - ${energy2}`, |
| 113 | + label: `${energy2.replace('x', '×')} GeV` |
| 114 | + }) |
| 115 | + } else { |
| 116 | + // Single energy mode |
| 117 | + images.push({ |
| 118 | + src: withBase(`/analysis/campaign-2025-08/acceptance/${mode}/${props.plotName}`), |
| 119 | + alt: `${props.title || props.plotName} - ${mode}`, |
| 120 | + label: undefined |
| 121 | + }) |
| 122 | + } |
| 123 | +
|
| 124 | + currentImages.value = images |
| 125 | +} |
| 126 | +
|
| 127 | +// Handle image loading errors |
| 128 | +function handleImageError(event: Event) { |
| 129 | + const img = event.target as HTMLImageElement |
| 130 | + console.warn(`Failed to load image: ${img.src}`) |
| 131 | +} |
| 132 | +
|
| 133 | +// Initialize on mount |
| 134 | +onMounted(() => { |
| 135 | + if (globalEnergyMode.value) { |
| 136 | + localEnergyMode.value = globalEnergyMode.value |
| 137 | + loadImages() |
| 138 | + } |
| 139 | +}) |
| 140 | +</script> |
| 141 | + |
| 142 | +<style scoped> |
| 143 | +.acceptance-plot { |
| 144 | + margin: 3rem 0; |
| 145 | + padding: 1.5rem; |
| 146 | + background-color: var(--vp-c-bg-soft); |
| 147 | + border-radius: 8px; |
| 148 | + border: 1px solid var(--vp-c-divider); |
| 149 | +} |
| 150 | +
|
| 151 | +.acceptance-plot h3 { |
| 152 | + margin-top: 0; |
| 153 | + margin-bottom: 0.5rem; |
| 154 | + color: var(--vp-c-text-1); |
| 155 | +} |
| 156 | +
|
| 157 | +.description { |
| 158 | + margin-bottom: 1rem; |
| 159 | + color: var(--vp-c-text-2); |
| 160 | + font-size: 14px; |
| 161 | +} |
| 162 | +
|
| 163 | +.plot-controls { |
| 164 | + margin-bottom: 1.5rem; |
| 165 | + padding: 0.75rem; |
| 166 | + background-color: var(--vp-c-bg); |
| 167 | + border-radius: 4px; |
| 168 | + border: 1px solid var(--vp-c-divider); |
| 169 | +} |
| 170 | +
|
| 171 | +.plot-controls label { |
| 172 | + display: block; |
| 173 | + margin-bottom: 0.5rem; |
| 174 | + font-weight: 600; |
| 175 | + color: var(--vp-c-text-1); |
| 176 | + font-size: 14px; |
| 177 | +} |
| 178 | +
|
| 179 | +.plot-controls select { |
| 180 | + width: 100%; |
| 181 | + max-width: 400px; |
| 182 | + padding: 0.5rem; |
| 183 | + border: 1px solid var(--vp-c-divider); |
| 184 | + border-radius: 4px; |
| 185 | + background-color: var(--vp-c-bg); |
| 186 | + color: var(--vp-c-text-1); |
| 187 | + font-size: 14px; |
| 188 | + cursor: pointer; |
| 189 | +} |
| 190 | +
|
| 191 | +.plot-controls select:hover { |
| 192 | + border-color: var(--vp-c-brand); |
| 193 | +} |
| 194 | +
|
| 195 | +.plot-controls select:focus { |
| 196 | + outline: none; |
| 197 | + border-color: var(--vp-c-brand); |
| 198 | + box-shadow: 0 0 0 2px var(--vp-c-brand-soft); |
| 199 | +} |
| 200 | +
|
| 201 | +.images-container { |
| 202 | + display: flex; |
| 203 | + flex-direction: column; |
| 204 | + gap: 2rem; |
| 205 | +} |
| 206 | +
|
| 207 | +.image-wrapper { |
| 208 | + text-align: center; |
| 209 | +} |
| 210 | +
|
| 211 | +.image-label { |
| 212 | + margin-bottom: 0.5rem; |
| 213 | + font-size: 16px; |
| 214 | + font-weight: 600; |
| 215 | + color: var(--vp-c-brand); |
| 216 | +} |
| 217 | +
|
| 218 | +.plot-image { |
| 219 | + width: 100%; |
| 220 | + max-width: 100%; |
| 221 | + height: auto; |
| 222 | + border-radius: 4px; |
| 223 | + border: 1px solid var(--vp-c-divider); |
| 224 | + background-color: var(--vp-c-bg); |
| 225 | +} |
| 226 | +
|
| 227 | +.no-data { |
| 228 | + padding: 2rem; |
| 229 | + text-align: center; |
| 230 | + color: var(--vp-c-text-2); |
| 231 | + font-style: italic; |
| 232 | +} |
| 233 | +
|
| 234 | +/* Dark mode adjustments */ |
| 235 | +.dark .acceptance-plot { |
| 236 | + background-color: var(--vp-c-bg-elv); |
| 237 | +} |
| 238 | +
|
| 239 | +.dark .plot-controls { |
| 240 | + background-color: var(--vp-c-bg-soft); |
| 241 | +} |
| 242 | +
|
| 243 | +.dark .plot-controls select { |
| 244 | + background-color: var(--vp-c-bg-elv); |
| 245 | +} |
| 246 | +
|
| 247 | +/* Responsive design */ |
| 248 | +@media (max-width: 768px) { |
| 249 | + .acceptance-plot { |
| 250 | + padding: 1rem; |
| 251 | + } |
| 252 | +
|
| 253 | + .plot-controls { |
| 254 | + padding: 0.5rem; |
| 255 | + } |
| 256 | +
|
| 257 | + .image-label { |
| 258 | + font-size: 14px; |
| 259 | + } |
| 260 | +} |
| 261 | +
|
| 262 | +/* For comparison view, show images side by side on larger screens */ |
| 263 | +@media (min-width: 1200px) { |
| 264 | + .images-container { |
| 265 | + flex-direction: row; |
| 266 | + flex-wrap: wrap; |
| 267 | + } |
| 268 | +
|
| 269 | + .image-wrapper { |
| 270 | + flex: 1; |
| 271 | + min-width: 45%; |
| 272 | + } |
| 273 | +} |
| 274 | +</style> |
0 commit comments