Skip to content

Commit

Permalink
fix: analytics progress radial format value
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Hacene committed Apr 25, 2024
1 parent de25f20 commit 048f004
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
10 changes: 2 additions & 8 deletions frontend/src/lib/components/Forms/Score.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { RangeSlider } from '@skeletonlabs/skeleton';
import * as m from '$paraglide/messages';
import type { AnyZodObject } from 'zod';
import { displayScoreColor } from '$lib/utils/helpers';
import { displayScoreColor, formatScoreValue } from '$lib/utils/helpers';
export let label: string | undefined = undefined;
export let field: string;
Expand All @@ -18,12 +18,6 @@
$: scoringEnabled = $value === null ? false : true;
function formatValue(value: number) {
if (value === null) {
return 0;
}
return (value * 100) / max_score;
}
const status = formFieldProxy(form, 'status')['value'];
$: isApplicable = $status === 'not_applicable' ? false : true;
</script>
Expand Down Expand Up @@ -77,7 +71,7 @@
<ProgressRadial
stroke={100}
meter={displayScoreColor($value, max_score)}
value={formatValue($value)}
value={formatScoreValue($value, max_score)}
font={150}
width={'w-12'}>{$value}</ProgressRadial
>
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/lib/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ export function displayScoreColor(value: number, max_score: number) {
}
return 'stroke-green-500';
}

export function formatScoreValue(value: number, max_score: number) {
if (value === null) {
return 0;
}
return (value * 100) / max_score;
}
7 changes: 5 additions & 2 deletions frontend/src/routes/(app)/analytics/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import { ProgressRadial, Tab, TabGroup, tableSourceMapper } from '@skeletonlabs/skeleton';
import ComposerSelect from './ComposerSelect.svelte';
import CounterCard from './CounterCard.svelte';
import { displayScoreColor } from '$lib/utils/helpers';
import { displayScoreColor, formatScoreValue } from '$lib/utils/helpers';
interface Counters {
domains: number;
Expand Down Expand Up @@ -311,7 +311,10 @@
compliance_assessment.globalScore.score,
compliance_assessment.globalScore.max_score
)}
value={compliance_assessment.globalScore.score}
value={formatScoreValue(
compliance_assessment.globalScore.score,
compliance_assessment.globalScore.max_score
)}
font={150}
width={'w-20'}>{compliance_assessment.globalScore.score}</ProgressRadial
>
Expand Down

0 comments on commit 048f004

Please sign in to comment.