Migrate plotgrid, adapt parent components with new snippets

This commit is contained in:
Christoph Kluge 2025-06-25 18:19:24 +02:00
parent 79a6c9e90d
commit db5f6c7540
7 changed files with 96 additions and 92 deletions

View File

@ -562,8 +562,19 @@
</Row> </Row>
<Row> <Row>
<Col> <Col>
{#snippet histoGridContent(item)}
<Histogram
data={convert2uplot(item.bins)}
usesBins={true}
title="Average Distribution of '{item.metric}'"
xlabel={`${item.metric} bin maximum [${metricUnits[item.metric]}]`}
xunit={`${metricUnits[item.metric]}`}
ylabel="Normalized Hours"
yunit="Hours"
/>
{/snippet}
<PlotGrid <PlotGrid
let:item
items={metricsInHistograms.map((metric) => ({ items={metricsInHistograms.map((metric) => ({
metric, metric,
...binsFromFootprint( ...binsFromFootprint(
@ -576,17 +587,8 @@
), ),
}))} }))}
itemsPerRow={ccconfig.plot_view_plotsPerRow} itemsPerRow={ccconfig.plot_view_plotsPerRow}
> gridContent={histoGridContent}
<Histogram
data={convert2uplot(item.bins)}
usesBins={true}
title="Average Distribution of '{item.metric}'"
xlabel={`${item.metric} bin maximum [${metricUnits[item.metric]}]`}
xunit={`${metricUnits[item.metric]}`}
ylabel="Normalized Hours"
yunit="Hours"
/> />
</PlotGrid>
</Col> </Col>
</Row> </Row>
<br /> <br />
@ -604,9 +606,19 @@
</Row> </Row>
<Row> <Row>
<Col> <Col>
{#snippet metricsGridContent(item)}
<ScatterPlot
height={250}
color={"rgba(0, 102, 204, 0.33)"}
xLabel={`${item.m1} [${metricUnits[item.m1]}]`}
yLabel={`${item.m2} [${metricUnits[item.m2]}]`}
X={item.f1}
Y={item.f2}
S={$footprintsQuery.data.footprints.timeWeights.nodeHours}
/>
{/snippet}
<PlotGrid <PlotGrid
let:item
let:width
items={metricsInScatterplots.map(([m1, m2]) => ({ items={metricsInScatterplots.map(([m1, m2]) => ({
m1, m1,
f1: $footprintsQuery.data.footprints.metrics.find( f1: $footprintsQuery.data.footprints.metrics.find(
@ -618,18 +630,8 @@
).data, ).data,
}))} }))}
itemsPerRow={ccconfig.plot_view_plotsPerRow} itemsPerRow={ccconfig.plot_view_plotsPerRow}
> gridContent={metricsGridContent}
<ScatterPlot
{width}
height={250}
color={"rgba(0, 102, 204, 0.33)"}
xLabel={`${item.m1} [${metricUnits[item.m1]}]`}
yLabel={`${item.m2} [${metricUnits[item.m2]}]`}
X={item.f1}
Y={item.f2}
S={$footprintsQuery.data.footprints.timeWeights.nodeHours}
/> />
</PlotGrid>
</Col> </Col>
</Row> </Row>
{/if} {/if}

View File

@ -334,14 +334,8 @@
</Col> </Col>
</Row> </Row>
{:else if $initq?.data && $jobMetrics?.data?.jobMetrics} {:else if $initq?.data && $jobMetrics?.data?.jobMetrics}
<PlotGrid <!-- Note: Ignore 'Expected If ...' Error in IDE -->
let:item {#snippet gridContent(item)}
items={orderAndMap(
groupByScope($jobMetrics.data.jobMetrics),
selectedMetrics,
)}
itemsPerRow={ccconfig.plot_view_plotsPerRow}
>
{#if item.data} {#if item.data}
<Metric <Metric
bind:this={plots[item.metric]} bind:this={plots[item.metric]}
@ -373,7 +367,16 @@
</CardBody> </CardBody>
</Card> </Card>
{/if} {/if}
</PlotGrid> {/snippet}
<PlotGrid
items={orderAndMap(
groupByScope($jobMetrics.data.jobMetrics),
selectedMetrics,
)}
itemsPerRow={ccconfig.plot_view_plotsPerRow}
{gridContent}
/>
{/if} {/if}
</CardBody> </CardBody>
</Card> </Card>

View File

@ -204,20 +204,7 @@
{:else if $nodeMetricsData.fetching || $initq.fetching} {:else if $nodeMetricsData.fetching || $initq.fetching}
<Spinner /> <Spinner />
{:else} {:else}
<PlotGrid {#snippet gridContent(item)}
let:item
itemsPerRow={ccconfig.plot_view_plotsPerRow}
items={$nodeMetricsData.data.nodeMetrics[0].metrics
.map((m) => ({
...m,
disabled: checkMetricDisabled(
m.name,
cluster,
$nodeMetricsData.data.nodeMetrics[0].subCluster,
),
}))
.sort((a, b) => a.name.localeCompare(b.name))}
>
<h4 style="text-align: center; padding-top:15px;"> <h4 style="text-align: center; padding-top:15px;">
{item.name} {item.name}
{systemUnits[item.name] ? "(" + systemUnits[item.name] + ")" : ""} {systemUnits[item.name] ? "(" + systemUnits[item.name] + ")" : ""}
@ -246,7 +233,22 @@
>No dataset returned for <code>{item.name}</code></Card >No dataset returned for <code>{item.name}</code></Card
> >
{/if} {/if}
</PlotGrid> {/snippet}
<PlotGrid
items={$nodeMetricsData.data.nodeMetrics[0].metrics
.map((m) => ({
...m,
disabled: checkMetricDisabled(
m.name,
cluster,
$nodeMetricsData.data.nodeMetrics[0].subCluster,
),
}))
.sort((a, b) => a.name.localeCompare(b.name))}
itemsPerRow={ccconfig.plot_view_plotsPerRow}
{gridContent}
/>
{/if} {/if}
</Col> </Col>
</Row> </Row>

View File

@ -676,12 +676,7 @@
<!-- Selectable Stats as Histograms : Average Values of Running Jobs --> <!-- Selectable Stats as Histograms : Average Values of Running Jobs -->
{#if selectedHistograms} {#if selectedHistograms}
{#key $mainQuery.data.stats[0].histMetrics} {#snippet gridContent(item)}
<PlotGrid
let:item
items={$mainQuery.data.stats[0].histMetrics}
itemsPerRow={2}
>
<Histogram <Histogram
data={convert2uplot(item.data)} data={convert2uplot(item.data)}
usesBins={true} usesBins={true}
@ -691,7 +686,14 @@
ylabel="Number of Jobs" ylabel="Number of Jobs"
yunit="Jobs" yunit="Jobs"
/> />
</PlotGrid> {/snippet}
{#key $mainQuery.data.stats[0].histMetrics}
<PlotGrid
items={$mainQuery.data.stats[0].histMetrics}
itemsPerRow={2}
{gridContent}
/>
{/key} {/key}
{/if} {/if}
{/if} {/if}

View File

@ -335,12 +335,7 @@
</Row> </Row>
{:else} {:else}
<hr class="my-2"/> <hr class="my-2"/>
{#key $stats.data.jobsStatistics[0].histMetrics} {#snippet gridContent(item)}
<PlotGrid
let:item
items={$stats.data.jobsStatistics[0].histMetrics}
itemsPerRow={3}
>
<Histogram <Histogram
data={convert2uplot(item.data)} data={convert2uplot(item.data)}
title="Distribution of '{item.metric} ({item.stat})' footprints" title="Distribution of '{item.metric} ({item.stat})' footprints"
@ -350,7 +345,14 @@
yunit="Jobs" yunit="Jobs"
usesBins usesBins
/> />
</PlotGrid> {/snippet}
{#key $stats.data.jobsStatistics[0].histMetrics}
<PlotGrid
items={$stats.data.jobsStatistics[0].histMetrics}
itemsPerRow={3}
{gridContent}
/>
{/key} {/key}
{/if} {/if}
{:else} {:else}

View File

@ -12,26 +12,19 @@
Col, Col,
} from "@sveltestrap/sveltestrap"; } from "@sveltestrap/sveltestrap";
export let itemsPerRow /* Svelte 5 Props */
export let items let {
items,
/* Migtation Notes itemsPerRow,
* Requirements gridContent
* - Parent Components must be already Migrated } = $props();
* - TODO: Job.root.svelte, Node.root.svelte
* - DONE: Analysis, Status, User
*
* How-To
* - Define "Plot-Slotcode" as SV5 Snippet with argument "item" in parent (!)
* - Pass new snippet as argument/prop to here
* - @render snippet in items-loop with argument == item
*/
</script> </script>
<Row cols={{ xs: 1, sm: 2, md: 3, lg: itemsPerRow}}> <Row cols={{ xs: 1, sm: 2, md: 3, lg: itemsPerRow}}>
{#each items as item} {#each items as item}
<Col class="px-1"> <Col class="px-1">
<slot {item}/> <!-- Note: Ignore '@' Error in IDE -->
{@render gridContent(item)}
</Col> </Col>
{/each} {/each}
</Row> </Row>

View File

@ -182,6 +182,6 @@
</script> </script>
<div class="cc-plot"> <div class="cc-plot" bind:clientWidth={width}>
<canvas bind:this={canvasElement} width="{width}" height="{height}"></canvas> <canvas bind:this={canvasElement} {width} {height}></canvas>
</div> </div>