-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
30 jump to assessment results and filter them if you click on segment…
… in compliance pie chart (#40) * Add onclick event to Chart slices * Add filter feature if status is set in URL * Remove unnecessary getElementById
- Loading branch information
Showing
3 changed files
with
107 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,87 @@ | ||
<script lang="ts"> | ||
import { goto } from '$app/navigation'; | ||
import type { ComplianceStatus } from '$lib/api/evaluation'; | ||
import type { TargetOfEvaluation } from '$lib/api/orchestrator'; | ||
import { Chart, type ChartConfiguration } from 'chart.js/auto'; | ||
import { onMount } from 'svelte'; | ||
let canvas: HTMLCanvasElement; | ||
export let compliance: Map<string, ComplianceStatus>; | ||
export let toe: TargetOfEvaluation; | ||
onMount(() => { | ||
const data = { | ||
labels: ['Non Compliant', 'Compliant', 'Manually set to Compliant', 'Waiting for Data'], | ||
datasets: [ | ||
{ | ||
label: toe.catalogId, | ||
data: [ | ||
Array.from(compliance.values()).filter( | ||
(value) => value == 'EVALUATION_STATUS_NOT_COMPLIANT' | ||
).length, | ||
Array.from(compliance.values()).filter( | ||
(value) => value == 'EVALUATION_STATUS_COMPLIANT' | ||
).length, | ||
Array.from(compliance.values()).filter( | ||
(value) => value == 'EVALUATION_STATUS_COMPLIANT_MANUALLY' | ||
).length, | ||
Array.from(compliance.values()).filter((value) => value == 'EVALUATION_STATUS_PENDING') | ||
.length | ||
], | ||
backgroundColor: ['#991b1b', '#166534', '#007fc3', '#d4d4d4'], | ||
hoverOffset: 4 | ||
} | ||
] | ||
}; | ||
const data = { | ||
labels: ['Non Compliant', 'Compliant', 'Manually set to Compliant', 'Waiting for Data'], | ||
datasets: [ | ||
{ | ||
label: toe.catalogId, | ||
data: [ | ||
Array.from(compliance.values()).filter( | ||
(value) => value == 'EVALUATION_STATUS_NOT_COMPLIANT' | ||
).length, | ||
Array.from(compliance.values()).filter((value) => value == 'EVALUATION_STATUS_COMPLIANT') | ||
.length, | ||
Array.from(compliance.values()).filter( | ||
(value) => value == 'EVALUATION_STATUS_COMPLIANT_MANUALLY' | ||
).length, | ||
Array.from(compliance.values()).filter((value) => value == 'EVALUATION_STATUS_PENDING') | ||
.length | ||
], | ||
backgroundColor: ['#991b1b', '#166534', '#007fc3', '#d4d4d4'], | ||
hoverOffset: 4 | ||
} | ||
] | ||
}; | ||
const config: ChartConfiguration = { | ||
type: 'doughnut', | ||
data: data, | ||
options: { | ||
animation: false, | ||
plugins: { | ||
tooltip: { | ||
titleFont: { | ||
family: 'Inter var' | ||
}, | ||
bodyFont: { | ||
family: 'Inter var' | ||
}, | ||
footerFont: { | ||
family: 'Inter var' | ||
} | ||
const config: ChartConfiguration = { | ||
type: 'doughnut', | ||
data: data, | ||
options: { | ||
animation: false, | ||
plugins: { | ||
tooltip: { | ||
titleFont: { | ||
family: 'Inter var' | ||
}, | ||
bodyFont: { | ||
family: 'Inter var' | ||
}, | ||
legend: { | ||
display: false, | ||
labels: { | ||
font: { | ||
family: 'Inter var' | ||
} | ||
footerFont: { | ||
family: 'Inter var' | ||
} | ||
}, | ||
legend: { | ||
display: false, | ||
labels: { | ||
font: { | ||
family: 'Inter var' | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
}; | ||
new Chart(canvas, config); | ||
}); | ||
onMount(() => { | ||
let chart = new Chart(canvas, config); | ||
export let compliance: Map<string, ComplianceStatus>; | ||
export let toe: TargetOfEvaluation; | ||
canvas.onclick = (evt) => { | ||
const res = chart.getElementsAtEventForMode(evt, 'nearest', { intersect: true }, true); | ||
console.log(res); | ||
if (res.length === 0) { | ||
return; | ||
} else { | ||
goto( | ||
`/cloud/${toe.cloudServiceId}/compliance/${toe.catalogId}/?status=${data.labels[ | ||
res[0].index | ||
].replace(/\s/g, '')}` | ||
); | ||
} | ||
}; | ||
}); | ||
</script> | ||
|
||
<div class="py-3"> | ||
<canvas id="acquisitions" bind:this={canvas} class="h-72 w-72 ml-auto mr-auto" /> | ||
<canvas id="chart" bind:this={canvas} class="h-72 w-72 ml-auto mr-auto" /> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 21 additions & 12 deletions
33
src/routes/(app)/cloud/[id]/compliance/[catalogId]/+page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,35 @@ | ||
import { listEvaluationResults } from "$lib/api/evaluation"; | ||
import { getCatalog, listControls } from "$lib/api/orchestrator"; | ||
import { error } from "@sveltejs/kit"; | ||
import type { PageLoad } from "./$types"; | ||
import { listEvaluationResults } from '$lib/api/evaluation'; | ||
import { getCatalog, listControls } from '$lib/api/orchestrator'; | ||
|
||
export const load = (async ({ fetch, params }) => { | ||
import { error } from '@sveltejs/kit'; | ||
|
||
import type { PageLoad } from './$types'; | ||
|
||
export const load = (async ({ fetch, params, url }) => { | ||
if (params.id == undefined) { | ||
throw error(405, "Required parameter missing") | ||
throw error(405, 'Required parameter missing'); | ||
} | ||
|
||
const catalog = getCatalog(params.catalogId, fetch) | ||
const catalog = getCatalog(params.catalogId, fetch); | ||
|
||
const evaluations = listEvaluationResults( | ||
{ | ||
cloudServiceId: params.id, | ||
catalogId: params.catalogId | ||
}, true, fetch) | ||
}, | ||
true, | ||
fetch | ||
); | ||
|
||
const controls = new Map((await listControls(params.catalogId, undefined, fetch)).map(c => [c.id, c])) | ||
const controls = new Map( | ||
(await listControls(params.catalogId, undefined, fetch)).map((c) => [c.id, c]) | ||
); | ||
const filterStatus = url.searchParams.get('status'); | ||
|
||
return { | ||
evaluations, | ||
catalog, | ||
controls | ||
} | ||
}) satisfies PageLoad | ||
controls, | ||
filterStatus | ||
}; | ||
}) satisfies PageLoad; |