gazeplotter
Version:
Gazeplotter is a Svelte application for visualizing eye-tracking data.
28 lines (27 loc) • 910 B
JavaScript
import { writable } from 'svelte/store';
import { getParticipantsGroups, data } from './dataStore.ts';
/**
* Store for participants groups data in working memory of modal
*/
export const participantsGroupsStore = writable(getParticipantsGroups());
export const addGroup = (groups) => {
const id = (groups.map(d => d.id).sort((a, b) => b - a)[0] ?? 0) + 1;
const name = `Group ${id}`;
const group = {
id,
name,
participantsIds: [],
};
participantsGroupsStore.update(groups => [...groups, group]);
};
export const removeGroup = (id) => {
participantsGroupsStore.update(groups => groups.filter(d => d.id !== id));
};
/**
* It must refresh the store when the data is changed.
* Otherwise, it could happen that after uploading new data,
* the old groups would be displayed.
*/
data.subscribe(d => {
participantsGroupsStore.set(getParticipantsGroups());
});