Merge branch 'module/poll' into dev
This commit is contained in:
28
frontend/src/Components/Histogram.svelte
Normal file
28
frontend/src/Components/Histogram.svelte
Normal file
@@ -0,0 +1,28 @@
|
||||
<script>
|
||||
import { t } from '../translations.svelte';
|
||||
let { data = {} } = $props();
|
||||
|
||||
let max = $derived(Math.max(...Object.values(data)));
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.histo {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.bar {
|
||||
display: flex; /* flexbox for text alignment */
|
||||
align-items: flex-end; /* text sticks to bottom of bar */
|
||||
height: 100%; /* full height of flex item */
|
||||
padding: 0 2px; /* space for text */
|
||||
box-sizing: border-box; /* include padding in height */
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="histo">
|
||||
{#each Object.entries(data).sort((a,b) => a[0] - b[0]) as [weight,count]}
|
||||
<div class="bar" style="height: {100*count/max}%" title={t('voted {count} times',{count})}>{weight}</div>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -1,4 +1,5 @@
|
||||
<script>
|
||||
import Histogram from '../../Components/Histogram.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import { api, get } from '../../urls.svelte';
|
||||
import { error, yikes } from '../../warn.svelte';
|
||||
@@ -62,25 +63,22 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each Object.entries(poll.evaluation) as [option_id,hist]}
|
||||
{#each Object.entries(poll.evaluation).sort((a,b) => b[0] - a[0]) as [avg,optionset]}
|
||||
{#each Object.entries(optionset) as [option_id,histo]}
|
||||
<tr>
|
||||
<td>
|
||||
{poll.options[option_id].name}
|
||||
</td>
|
||||
<td>
|
||||
{average(hist)}
|
||||
{(+avg).toFixed(3)}
|
||||
</td>
|
||||
<td class="histogram">
|
||||
{#each Object.entries(hist).sort((a,b) => a[0] - b[0]) as [weight,count]}
|
||||
<span style="height: {100*count/max_val(hist)}%" title={t('voted {count} times',{count:count})}>
|
||||
<span>{weight}</span>
|
||||
</span>
|
||||
{/each}
|
||||
<td>
|
||||
<Histogram data={histo} />
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
{/if}
|
||||
<span class="warn">TODO: sort by average</span>
|
||||
Reference in New Issue
Block a user