Skip to content

Commit

Permalink
feat: add message for empty charts
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriesauer committed Dec 18, 2024
1 parent 2d19ebe commit 2ea9ec9
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions packages/lib/src/components/results/ChartComponent.wc.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
/**
* initialize the chart
*/
let noDataAvailable: boolean = false;
let canvas!: HTMLCanvasElement;
let chart: Chart;
Expand Down Expand Up @@ -391,15 +394,23 @@
* @param responseStore - the response store
*/
const setChartData = (responseStore: ResponseStore): void => {
if (responseStore.size === 0) return;
if (responseStore.size === 0) {
noDataAvailable = true;
return;
}
let isDataAvailable: boolean = false;
responseStore.forEach((value) => {
if (value.data !== null) isDataAvailable = true;
});
if (!isDataAvailable) return;
if (!isDataAvailable) {
noDataAvailable = true;
return;
}
noDataAvailable = false;
let chartLabels: string[] = [];
Expand Down Expand Up @@ -589,6 +600,11 @@
{#if options.hintText}
<InfoButtonComponent message={options.hintText} />
{/if}

{#if noDataAvailable}
<p>No Data Available</p>
{/if}

<canvas
part="chart-canvas"
bind:this={canvas}
Expand All @@ -597,3 +613,12 @@
/>
<slot />
</div>

<style>
p {
position: absolute;
top: 45%;
font-weight: bold;
left: 30%;
}
</style>

0 comments on commit 2ea9ec9

Please sign in to comment.