feat: change to resolution increase on zoom

This commit is contained in:
Christoph Kluge 2024-09-02 18:22:34 +02:00
parent 54f3a261c5
commit 7602641909
3 changed files with 90 additions and 41 deletions

View File

@ -32,12 +32,14 @@
? ["core", "accelerator"] ? ["core", "accelerator"]
: ["core"] : ["core"]
: ["node"]; : ["node"];
let selectedResolution = 600;
let zoomStates = {};
const cluster = getContext("clusters").find((c) => c.name == job.cluster); const cluster = getContext("clusters").find((c) => c.name == job.cluster);
const client = getContextClient(); const client = getContextClient();
const query = gql` const query = gql`
query ($id: ID!, $metrics: [String!]!, $scopes: [MetricScope!]!) { query ($id: ID!, $metrics: [String!]!, $scopes: [MetricScope!]!, $selectedResolution: Int) {
jobMetrics(id: $id, metrics: $metrics, scopes: $scopes) { jobMetrics(id: $id, metrics: $metrics, scopes: $scopes, resolution: $selectedResolution) {
name name
scope scope
metric { metric {
@ -66,17 +68,30 @@
} }
`; `;
function handleZoom(detail, metric) {
if (
(zoomStates[metric]?.x?.min !== detail?.lastZoomState?.x?.min) &&
(zoomStates[metric]?.y?.max !== detail?.lastZoomState?.y?.max)
) {
zoomStates[metric] = {...detail.lastZoomState}
}
if (detail?.newRes) { // Triggers GQL
selectedResolution = detail.newRes
}
}
$: metricsQuery = queryStore({ $: metricsQuery = queryStore({
client: client, client: client,
query: query, query: query,
variables: { id, metrics, scopes }, variables: { id, metrics, scopes, selectedResolution },
}); });
function refreshMetrics() { function refreshMetrics() {
metricsQuery = queryStore({ metricsQuery = queryStore({
client: client, client: client,
query: query, query: query,
variables: { id, metrics, scopes }, variables: { id, metrics, scopes, selectedResolution },
// requestPolicy: 'network-only' // use default cache-first for refresh // requestPolicy: 'network-only' // use default cache-first for refresh
}); });
} }
@ -159,10 +174,7 @@
<!-- Subluster Metricconfig remove keyword for jobtables (joblist main, user joblist, project joblist) to be used here as toplevel case--> <!-- Subluster Metricconfig remove keyword for jobtables (joblist main, user joblist, project joblist) to be used here as toplevel case-->
{#if metric.disabled == false && metric.data} {#if metric.disabled == false && metric.data}
<MetricPlot <MetricPlot
on:zoom-in={({ detail }) => { on:zoom={({detail}) => { handleZoom(detail, metric.data.name) }}
// filterComponent.updateFilters(detail)
console.log("Upstream New Res:", detail)
}}
width={plotWidth} width={plotWidth}
height={plotHeight} height={plotHeight}
timestep={metric.data.metric.timestep} timestep={metric.data.metric.timestep}
@ -175,6 +187,7 @@
isShared={job.exclusive != 1} isShared={job.exclusive != 1}
numhwthreads={job.numHWThreads} numhwthreads={job.numHWThreads}
numaccs={job.numAcc} numaccs={job.numAcc}
zoomState={zoomStates[metric.data.name]}
/> />
{:else if metric.disabled == true && metric.data} {:else if metric.disabled == true && metric.data}
<Card body color="info" <Card body color="info"

View File

@ -129,6 +129,9 @@
export let forNode = false; export let forNode = false;
export let numhwthreads = 0; export let numhwthreads = 0;
export let numaccs = 0; export let numaccs = 0;
export let zoomState = null;
// $: console.log('Changed ZoomState for', metric, zoomState)
if (useStatsSeries == null) useStatsSeries = statisticsSeries != null; if (useStatsSeries == null) useStatsSeries = statisticsSeries != null;
@ -393,6 +396,19 @@
bands: plotBands, bands: plotBands,
padding: [5, 10, -20, 0], padding: [5, 10, -20, 0],
hooks: { hooks: {
init: [
(u) => {
u.over.addEventListener("dblclick", (e) => {
console.log('Dispatch Reset')
dispatch('zoom', {
lastZoomState: {
x: { time: false },
y: { auto: true }
}
});
});
}
],
draw: [ draw: [
(u) => { (u) => {
// Draw plot type label: // Draw plot type label:
@ -437,17 +453,26 @@
setScale: [ setScale: [
(u, key) => { (u, key) => {
if (key === 'x') { if (key === 'x') {
// Start const numX = (u.series[0].idxs[1] - u.series[0].idxs[0])
console.log('setScale X', key); if (numX <= 20 && timestep !== 60) { // Zoom IN if not at MAX
console.log('Dispatch Zoom')
// Decide which resolution to request if (timestep == 600) {
dispatch('zoom', {
// Dispatch request newRes: 240,
const res = 1337; lastZoomState: u?.scales
dispatch('zoom-in', {
newres: res,
}); });
} else if (timestep === 240) {
dispatch('zoom', {
newRes: 60,
lastZoomState: u?.scales
});
}
} else {
console.log('Dispatch Update')
dispatch('zoom', {
lastZoomState: u?.scales
});
}
}; };
} }
] ]
@ -481,6 +506,10 @@
if (!uplot) { if (!uplot) {
opts.width = width; opts.width = width;
opts.height = height; opts.height = height;
if (zoomState) {
// console.log('Use last state for uPlot init:', metric, scope, zoomState)
opts.scales = {...zoomState}
}
uplot = new uPlot(opts, plotData, plotWrapper); uplot = new uPlot(opts, plotData, plotWrapper);
} else { } else {
uplot.setSize({ width, height }); uplot.setSize({ width, height });
@ -489,7 +518,6 @@
function onSizeChange() { function onSizeChange() {
if (!uplot) return; if (!uplot) return;
if (timeoutId != null) clearTimeout(timeoutId); if (timeoutId != null) clearTimeout(timeoutId);
timeoutId = setTimeout(() => { timeoutId = setTimeout(() => {

View File

@ -27,7 +27,9 @@
Spinner, Spinner,
Card, Card,
} from "@sveltestrap/sveltestrap"; } from "@sveltestrap/sveltestrap";
import { minScope } from "../generic/utils.js"; import {
minScope,
} from "../generic/utils.js";
import Timeseries from "../generic/plots/MetricPlot.svelte"; import Timeseries from "../generic/plots/MetricPlot.svelte";
export let job; export let job;
@ -39,9 +41,8 @@
export let rawData; export let rawData;
export let isShared = false; export let isShared = false;
let selectedHost = null, let selectedHost = null;
plot, let error = null;
error = null;
let selectedScope = minScope(scopes); let selectedScope = minScope(scopes);
let selectedResolution; let selectedResolution;
let pendingResolution = 600; let pendingResolution = 600;
@ -49,11 +50,12 @@
let patternMatches = false; let patternMatches = false;
let nodeOnly = false; // If, after load-all, still only node scope returned let nodeOnly = false; // If, after load-all, still only node scope returned
let statsSeries = rawData.map((data) => data?.statisticsSeries ? data.statisticsSeries : null); let statsSeries = rawData.map((data) => data?.statisticsSeries ? data.statisticsSeries : null);
let zoomState = null;
let pendingZoomState = null;
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
const statsPattern = /(.*)-stat$/; const statsPattern = /(.*)-stat$/;
const unit = (metricUnit?.prefix ? metricUnit.prefix : "") + (metricUnit?.base ? metricUnit.base : ""); const unit = (metricUnit?.prefix ? metricUnit.prefix : "") + (metricUnit?.base ? metricUnit.base : "");
const resolutions = [600, 240, 60] // DEV: Make configable
const client = getContextClient(); const client = getContextClient();
const subQuery = gql` const subQuery = gql`
query ($dbid: ID!, $selectedMetrics: [String!]!, $selectedScopes: [MetricScope!]!, $selectedResolution: Int) { query ($dbid: ID!, $selectedMetrics: [String!]!, $selectedScopes: [MetricScope!]!, $selectedResolution: Int) {
@ -86,6 +88,19 @@
} }
`; `;
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?.newRes) { // Triggers GQL
pendingResolution = detail.newRes
}
}
let metricData; let metricData;
let selectedScopes = [...scopes] let selectedScopes = [...scopes]
const dbid = job.id; const dbid = job.id;
@ -119,11 +134,15 @@
}); });
if ($metricData && !$metricData.fetching) { if ($metricData && !$metricData.fetching) {
rawData = $metricData.data.singleUpdate.map((x) => x.metric) rawData = $metricData.data.singleUpdate.map((x) => x.metric)
scopes = $metricData.data.singleUpdate.map((x) => x.scope) scopes = $metricData.data.singleUpdate.map((x) => x.scope)
statsSeries = rawData.map((data) => data?.statisticsSeries ? data.statisticsSeries : null) statsSeries = rawData.map((data) => data?.statisticsSeries ? data.statisticsSeries : null)
// Keep Zoomlevel if ResChange By Zoom
if (pendingZoomState) {
zoomState = {...pendingZoomState}
}
// Set selected scope to min of returned scopes // Set selected scope to min of returned scopes
if (selectedScope == "load-all") { if (selectedScope == "load-all") {
selectedScope = minScope(scopes) selectedScope = minScope(scopes)
@ -176,11 +195,6 @@
{/each} {/each}
</select> </select>
{/if} {/if}
<select class="form-select" bind:value={pendingResolution}>
{#each resolutions as res}
<option value={res}>Timestep: {res}</option>
{/each}
</select>
</InputGroup> </InputGroup>
{#key series} {#key series}
{#if $metricData?.fetching == true} {#if $metricData?.fetching == true}
@ -189,11 +203,7 @@
<Card body color="danger">{error.message}</Card> <Card body color="danger">{error.message}</Card>
{:else if series != null && !patternMatches} {:else if series != null && !patternMatches}
<Timeseries <Timeseries
bind:this={plot} on:zoom={({detail}) => { handleZoom(detail) }}
on:zoom-in={({ detail }) => {
// filterComponent.updateFilters(detail)
console.log("Upstream New Res:", detail)
}}
{width} {width}
height={300} height={300}
cluster={job.cluster} cluster={job.cluster}
@ -203,14 +213,11 @@
metric={metricName} metric={metricName}
{series} {series}
{isShared} {isShared}
{zoomState}
/> />
{:else if statsSeries[selectedScopeIndex] != null && patternMatches} {:else if statsSeries[selectedScopeIndex] != null && patternMatches}
<Timeseries <Timeseries
bind:this={plot} on:zoom={({detail}) => { handleZoom(detail) }}
on:zoom-in={({ detail }) => {
// filterComponent.updateFilters(detail)
console.log("Upstream New Res:", detail)
}}
{width} {width}
height={300} height={300}
cluster={job.cluster} cluster={job.cluster}
@ -220,6 +227,7 @@
metric={metricName} metric={metricName}
{series} {series}
{isShared} {isShared}
{zoomState}
statisticsSeries={statsSeries[selectedScopeIndex]} statisticsSeries={statsSeries[selectedScopeIndex]}
useStatsSeries={!!statsSeries[selectedScopeIndex]} useStatsSeries={!!statsSeries[selectedScopeIndex]}
/> />