mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-07-22 20:41:40 +02:00
Drop change on zoom for selector with options
- Up to 7 days worth of runtime - No zoomState issue and cached results
This commit is contained in:
@@ -17,6 +17,9 @@
|
||||
Icon,
|
||||
Card,
|
||||
Spinner,
|
||||
Input,
|
||||
InputGroup,
|
||||
InputGroupText
|
||||
} from "@sveltestrap/sveltestrap";
|
||||
import {
|
||||
queryStore,
|
||||
@@ -59,9 +62,11 @@
|
||||
let showFootprint = filterPresets.cluster
|
||||
? !!ccconfig[`plot_list_showFootprint:${filterPresets.cluster}`]
|
||||
: !!ccconfig.plot_list_showFootprint;
|
||||
let numDurationBins;
|
||||
let numMetricBins;
|
||||
|
||||
|
||||
let numDurationBins = "1h";
|
||||
let numMetricBins = 10;
|
||||
let durationBinOptions = ["1m","10m","1h","6h","12h"];
|
||||
let metricBinOptions = [10, 20, 50, 100];
|
||||
|
||||
$: metricsInHistograms = selectedCluster
|
||||
? ccconfig[`user_view_histogramMetrics:${selectedCluster}`] || []
|
||||
@@ -71,7 +76,7 @@
|
||||
$: stats = queryStore({
|
||||
client: client,
|
||||
query: gql`
|
||||
query ($jobFilters: [JobFilter!]!, $metricsInHistograms: [String!], $numDurationBins: Int, $numMetricBins: Int) {
|
||||
query ($jobFilters: [JobFilter!]!, $metricsInHistograms: [String!], $numDurationBins: String, $numMetricBins: Int) {
|
||||
jobsStatistics(filter: $jobFilters, metrics: $metricsInHistograms, numDurationBins: $numDurationBins , numMetricBins: $numMetricBins ) {
|
||||
totalJobs
|
||||
shortJobs
|
||||
@@ -102,38 +107,6 @@
|
||||
variables: { jobFilters, metricsInHistograms, numDurationBins, numMetricBins },
|
||||
});
|
||||
|
||||
let durationZoomState = null;
|
||||
let metricZoomState = null;
|
||||
let pendingDurationBinCount = null;
|
||||
let pendingMetricBinCount = null;
|
||||
let pendingZoomState = null;
|
||||
function handleZoom(detail) {
|
||||
if ( // States have to differ, causes deathloop if just set
|
||||
(pendingZoomState?.x?.min !== detail?.lastZoomState?.x?.min) &&
|
||||
(pendingZoomState?.y?.max !== detail?.lastZoomState?.y?.max)
|
||||
) {
|
||||
pendingZoomState = {...detail.lastZoomState};
|
||||
}
|
||||
|
||||
if (detail?.durationBinCount) { // Triggers GQL
|
||||
pendingDurationBinCount = detail.durationBinCount;
|
||||
}
|
||||
|
||||
if (detail?.metricBinCount) { // Triggers GQL
|
||||
pendingMetricBinCount = detail.metricBinCount;
|
||||
}
|
||||
};
|
||||
|
||||
$: if (pendingDurationBinCount !== numDurationBins) {
|
||||
durationZoomState = {...pendingZoomState};
|
||||
numDurationBins = pendingDurationBinCount;
|
||||
}
|
||||
|
||||
$: if (pendingMetricBinCount !== numMetricBins) {
|
||||
metricZoomState = {...pendingZoomState};
|
||||
numMetricBins = pendingMetricBinCount;
|
||||
}
|
||||
|
||||
onMount(() => filterComponent.updateFilters());
|
||||
</script>
|
||||
|
||||
@@ -153,8 +126,8 @@
|
||||
{/if}
|
||||
|
||||
<!-- ROW2: Tools-->
|
||||
<Row cols={{ xs: 1, md: 2, lg: 4}} class="mb-3">
|
||||
<Col lg="2" class="mb-2 mb-lg-0">
|
||||
<Row cols={{ xs: 1, md: 2, lg: 6}} class="mb-3">
|
||||
<Col class="mb-2 mb-lg-0">
|
||||
<ButtonGroup class="w-100">
|
||||
<Button outline color="primary" on:click={() => (isSortingOpen = true)}>
|
||||
<Icon name="sort-up" /> Sorting
|
||||
@@ -168,7 +141,7 @@
|
||||
</Button>
|
||||
</ButtonGroup>
|
||||
</Col>
|
||||
<Col lg="4" xl="6" class="mb-1 mb-lg-0">
|
||||
<Col lg="4" class="mb-1 mb-lg-0">
|
||||
<Filters
|
||||
{filterPresets}
|
||||
{matchedJobs}
|
||||
@@ -183,12 +156,27 @@
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
<Col lg="3" xl="2" class="mb-2 mb-lg-0">
|
||||
<Col class="mb-2 mb-lg-0">
|
||||
<InputGroup>
|
||||
<InputGroupText>
|
||||
<Icon name="bar-chart-line-fill" />
|
||||
</InputGroupText>
|
||||
<InputGroupText>
|
||||
Duration Bin Size
|
||||
</InputGroupText>
|
||||
<Input type="select" bind:value={numDurationBins} style="max-width: 120px;">
|
||||
{#each durationBinOptions as dbin}
|
||||
<option value={dbin}>{dbin}</option>
|
||||
{/each}
|
||||
</Input>
|
||||
</InputGroup>
|
||||
</Col>
|
||||
<Col class="mb-2 mb-lg-0">
|
||||
<TextFilter
|
||||
on:set-filter={({ detail }) => filterComponent.updateFilters(detail)}
|
||||
/>
|
||||
</Col>
|
||||
<Col lg="3" xl="2" class="mb-1 mb-lg-0">
|
||||
<Col class="mb-1 mb-lg-0">
|
||||
<Refresher on:refresh={() => {
|
||||
jobList.refreshJobs()
|
||||
jobList.refreshAllMetrics()
|
||||
@@ -248,16 +236,13 @@
|
||||
<Col class="px-1">
|
||||
{#key $stats.data.jobsStatistics[0].histDuration}
|
||||
<Histogram
|
||||
on:zoom={({detail}) => { handleZoom(detail) }}
|
||||
data={convert2uplot($stats.data.jobsStatistics[0].histDuration)}
|
||||
title="Duration Distribution"
|
||||
xlabel="Job Runtimes"
|
||||
xunit="Runtime"
|
||||
ylabel="Number of Jobs"
|
||||
yunit="Jobs"
|
||||
lastBinCount={pendingDurationBinCount}
|
||||
{durationZoomState}
|
||||
zoomableHistogram
|
||||
usesBins
|
||||
xtime
|
||||
/>
|
||||
{/key}
|
||||
@@ -278,16 +263,32 @@
|
||||
</Row>
|
||||
|
||||
<!-- ROW4+5: Selectable Histograms -->
|
||||
<Row cols={{ xs: 1, md: 5}}>
|
||||
<Col>
|
||||
<Row>
|
||||
<Col xs="12" md="3" lg="2" class="mb-2 mb-md-0">
|
||||
<Button
|
||||
outline
|
||||
color="secondary"
|
||||
class="w-100"
|
||||
on:click={() => (isHistogramSelectionOpen = true)}
|
||||
>
|
||||
<Icon name="bar-chart-line" /> Select Histograms
|
||||
</Button>
|
||||
</Col>
|
||||
<Col xs="12" md="9" lg="10" class="mb-2 mb-md-0">
|
||||
<InputGroup>
|
||||
<InputGroupText>
|
||||
<Icon name="bar-chart-line-fill" />
|
||||
</InputGroupText>
|
||||
<InputGroupText>
|
||||
Metric Bins
|
||||
</InputGroupText>
|
||||
<Input type="select" bind:value={numMetricBins} style="max-width: 120px;">
|
||||
{#each metricBinOptions as mbin}
|
||||
<option value={mbin}>{mbin}</option>
|
||||
{/each}
|
||||
</Input>
|
||||
</InputGroup>
|
||||
</Col>
|
||||
</Row>
|
||||
{#if metricsInHistograms?.length > 0}
|
||||
{#if $stats.error}
|
||||
@@ -312,17 +313,13 @@
|
||||
itemsPerRow={3}
|
||||
>
|
||||
<Histogram
|
||||
on:zoom={({detail}) => { handleZoom(detail) }}
|
||||
data={convert2uplot(item.data)}
|
||||
usesBins={true}
|
||||
title="Distribution of '{item.metric} ({item.stat})' footprints"
|
||||
xlabel={`${item.metric} bin maximum ${item?.unit ? `[${item.unit}]` : ``}`}
|
||||
xunit={item.unit}
|
||||
ylabel="Number of Jobs"
|
||||
yunit="Jobs"
|
||||
lastBinCount={pendingMetricBinCount}
|
||||
{metricZoomState}
|
||||
zoomableHistogram
|
||||
usesBins
|
||||
/>
|
||||
</PlotGrid>
|
||||
{/key}
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
<script>
|
||||
import uPlot from "uplot";
|
||||
import { getContext, onMount, onDestroy, createEventDispatcher } from "svelte";
|
||||
import { onMount, onDestroy } from "svelte";
|
||||
import { formatNumber } from "../units.js";
|
||||
import { Card } from "@sveltestrap/sveltestrap";
|
||||
|
||||
@@ -29,21 +29,13 @@
|
||||
export let xtime = false;
|
||||
export let ylabel = "";
|
||||
export let yunit = "";
|
||||
export let zoomState = null;
|
||||
export let lastBinCount = null;
|
||||
export let zoomableHistogram = false;
|
||||
|
||||
const { bars } = uPlot.paths;
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
const drawStyles = {
|
||||
bars: 1,
|
||||
points: 2,
|
||||
};
|
||||
|
||||
// TimeBins: Include Hour "24-25"
|
||||
const binCounts = xtime ? [25, 50, 100, 150, 300, 750, 1500] : [10, 20, 50, 100, 200]; // , 500, 1000
|
||||
|
||||
function formatTime(t) {
|
||||
if (t !== null) {
|
||||
if (isNaN(t)) {
|
||||
@@ -52,7 +44,6 @@
|
||||
const tAbs = Math.abs(t);
|
||||
const h = Math.floor(tAbs / 3600);
|
||||
const m = Math.floor((tAbs % 3600) / 60);
|
||||
// Re-Add "negativity" to time ticks only as string, so that if-cases work as intended
|
||||
if (h == 0) return `${m}m`;
|
||||
else if (m == 0) return `${h}h`;
|
||||
else return `${h}:${m}h`;
|
||||
@@ -138,45 +129,6 @@
|
||||
|
||||
function render() {
|
||||
let opts = {
|
||||
hooks: {
|
||||
init: [
|
||||
(u) => {
|
||||
if (zoomableHistogram) {
|
||||
u.over.addEventListener("dblclick", (e) => {
|
||||
console.log('Dispatch Reset')
|
||||
dispatch('zoom', {
|
||||
lastZoomState: {
|
||||
x: { time: false },
|
||||
y: { auto: true }
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
],
|
||||
setScale: [
|
||||
(u, key) => {
|
||||
if (key === 'x') {
|
||||
if (zoomableHistogram) {
|
||||
const numX = (u.series[0].idxs[1] - u.series[0].idxs[0])
|
||||
if (xtime && numX <= 12 && lastBinCount !== 1500) {
|
||||
// console.log("Dispatch for Duration: ", numX, lastBinCount, binCounts[binCounts.indexOf(lastBinCount) + 1])
|
||||
dispatch('zoom', {
|
||||
durationBinCount: binCounts[binCounts.indexOf(lastBinCount) + 1],
|
||||
lastZoomState: u?.scales,
|
||||
});
|
||||
} else if (!xtime && numX <= 6 && lastBinCount !== 200) {
|
||||
// console.log("Dispatch for Metrics: ", numX, lastBinCount, binCounts[binCounts.indexOf(lastBinCount) + 1])
|
||||
dispatch('zoom', {
|
||||
metricBinCount: binCounts[binCounts.indexOf(lastBinCount) + 1],
|
||||
lastZoomState: u?.scales,
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
]
|
||||
},
|
||||
width: width,
|
||||
height: height,
|
||||
title: title,
|
||||
@@ -202,7 +154,7 @@
|
||||
label: xlabel,
|
||||
labelGap: 10,
|
||||
size: 25,
|
||||
incrs: xtime ? [60, 120, 300, 600, 900, 1800, 3600, 7200, 14400, 18000] : [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000],
|
||||
incrs: xtime ? [60, 120, 300, 600, 1800, 3600, 7200, 14400, 18000, 21600, 43200, 86400] : [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000],
|
||||
border: {
|
||||
show: true,
|
||||
stroke: "#000000",
|
||||
@@ -244,7 +196,11 @@
|
||||
{
|
||||
label: xunit !== "" ? xunit : null,
|
||||
value: (u, ts, sidx, didx) => {
|
||||
if (usesBins) {
|
||||
if (usesBins && xtime) {
|
||||
const min = u.data[sidx][didx - 1] ? formatTime(u.data[sidx][didx - 1]) : 0;
|
||||
const max = formatTime(u.data[sidx][didx]);
|
||||
ts = min + " - " + max; // narrow spaces
|
||||
} else if (usesBins) {
|
||||
const min = u.data[sidx][didx - 1] ? u.data[sidx][didx - 1] : 0;
|
||||
const max = u.data[sidx][didx];
|
||||
ts = min + " - " + max; // narrow spaces
|
||||
@@ -273,11 +229,6 @@
|
||||
],
|
||||
};
|
||||
|
||||
if (zoomableHistogram && zoomState) {
|
||||
console.log("Apply ZoomState ...", zoomState)
|
||||
opts.scales = {...zoomState}
|
||||
}
|
||||
|
||||
uplot = new uPlot(opts, data, plotWrapper);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user