Skip to content

Commit

Permalink
Feat: Can poorly update the plot with data
Browse files Browse the repository at this point in the history
  • Loading branch information
Grabt234 committed Nov 25, 2023
1 parent 9bd175f commit 713f997
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 41 deletions.
19 changes: 16 additions & 3 deletions src/lib/SensorGroup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
let ctxTime;
let TimeDomainChart;
let TimeDomainYValues = [0];
export let TimeDomainYValues = [0];
let TimeDomainXValues = [0];
let ctxFreq;
let FreqDomainChart;
let FreqDomainYValues = [0];
let FreqDomainXValues = [0];
// export function InitialiseTimeGraph() {
function initTimeCanvas() {
ctxTime = document.getElementById('TimeDomainChart');
TimeDomainChart = new Chart(ctxTime, {
Expand All @@ -43,6 +41,8 @@
}
}
});
console.log(TimeDomainChart);
}
function initFreqCanvas() {
Expand All @@ -69,9 +69,22 @@
}
onMount(() => {
console.log('00000');
initFreqCanvas();
initTimeCanvas();
});
// Reactive statement to watch 'data' changes and update the plot
function updatePlot() {
// Update chart data efficiently
if (ctxTime) {
console.log(TimeDomainChart);
TimeDomainChart.data.datasets.data = TimeDomainYValues;
TimeDomainChart.data.labels = Array.from({ length: 512 }, (_, index) => index + 1);
TimeDomainChart.update();
}
}
$: updatePlot();
</script>

<div class-="sensorGroup">
Expand Down
68 changes: 30 additions & 38 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -79,54 +79,46 @@
// Check if parsed data exists, otherwise parse it once
console.log('here1');
if (!parsedData) {
const receivedMessage = event.data;
parsedData = JSON.parse(receivedMessage);
// Create datasets array
const colors = ['red', 'green', 'blue', 'yellow', 'orange', 'purple'];
for (
let channelIndex = 0;
channelIndex < parsedData['TimeChunk']['NumChannels'];
channelIndex++
) {
const dataset = {
labels: undefined,
data: [],
borderColor: colors[channelIndex],
fill: false
};
datasets.push(dataset);
}
console.log(parsedData['TimeChunk']['SourceIndentifier']);
}
// if (!parsedData) {
const receivedMessage = event.data;
// // Create datasets array
// const colors = ['red', 'green', 'blue', 'yellow', 'orange', 'purple'];
// for (
// let channelIndex = 0;
// channelIndex < parsedData['TimeChunk']['NumChannels'];
// channelIndex++
// ) {
// const dataset = {
// labels: undefined,
// data: [],
// borderColor: colors[channelIndex],
// fill: false
// };
// datasets.push(dataset);
// }
// console.log(parsedData['TimeChunk']['SourceIndentifier']);
// }
parsedData = JSON.parse(receivedMessage);
console.log('here');
// Lets try get the source identifier key
let sourceIdentifierKey = JSON.parse(event.data)['TimeChunk']['SourceIndentifier'];

Check warning on line 107 in src/routes/+page.svelte

View workflow job for this annotation

GitHub Actions / lint

'sourceIdentifierKey' is assigned a value but never used
// Check if we are tracking it in the mpa already
// And if not then track it
const newData = JSON.parse(event.data)['TimeChunk']['Channels'];
const numChannels = JSON.parse(event.data)['TimeChunk']['NumChannels'];
for (let channelIndex = 0; channelIndex < numChannels; channelIndex++) {
datasets[channelIndex] = newData[channelIndex];
}
updateItemInMap(JSON.parse(event.data)['TimeChunk']['SourceIndentifier'], {
timeSampleRate: JSON.parse(event.data)['TimeChunk']['SampleRate'],
timeChunkSize: JSON.parse(event.data)['TimeChunk']['ChunkSize'],
sourceIdentifier: JSON.parse(event.data)['TimeChunk']['SourceIndentifier']
sourceIdentifier: JSON.parse(event.data)['TimeChunk']['SourceIndentifier'],
TimeDomainYValues: datasets
});
// const numChannels = JSON.parse(event.data)['TimeChunk']['NumChannels'];
// for (let channelIndex = 0; channelIndex < numChannels; channelIndex++) {
// datasets[channelIndex].data = newData[channelIndex];
// }
// // Update chart data efficiently
// TimeDomainChart.data.datasets = datasets;
// TimeDomainChart.data.labels = Array.from({ length: 512 }, (_, index) => index + 1);
// TimeDomainChart.update();
// if (timeSampleRate !== JSON.parse(event.data)['TimeChunk']['SampleRate']) {
// timeSampleRate = JSON.parse(event.data)['TimeChunk']['SampleRate'];
// }
// if (timeChunkSize !== JSON.parse(event.data)['TimeChunk']['ChunkSize']) {
// timeChunkSize = JSON.parse(event.data)['TimeChunk']['ChunkSize'];
// }
});
// const FreqWebSocket = new WebSocket('ws://localhost:10100/DataTypes/FFTMagnitudeChunk');
// let FreqParsedData = null;
Expand Down

0 comments on commit 713f997

Please sign in to comment.