Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#106 refactoring front end sliders #139

Merged
merged 10 commits into from
Dec 20, 2022
27 changes: 27 additions & 0 deletions Apps/frontend/src/components/Slider.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<script>
export let onInput = (value) => {
console.error(`Missing implementation of Slider.onInput(${value})!`);
return value;
};

export let value = 1;
export let min = 0;
export let max = 10;
export let step = 0.1;
export let id = undefined;

if (id === undefined) console.error("Missing id for Slider!");
</script>

<div>
<input
{id}
type="range"
class="slider"
on:input={() => onInput(value)}
bind:value
{min}
{max}
{step}
/>
</div>
142 changes: 142 additions & 0 deletions Apps/frontend/src/components/WaveControls.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<script>
import { MAX_AMPLITUDE, MIN_AMPLITUDE, NUM_CHANNELS } from "../const.js";
import StartStopButton from "../views/StartStopButton.svelte";
import OnOffButton from "./OnOffButton.svelte";
import ResetButton from "../views/ResetButton.svelte";
import Slider from "./Slider.svelte";
import { timeSweep } from "../stores.js";
import ThicknessSwitch from "./ThicknessSwitch.svelte";
import TimeSweepSlider from "./TimeSweepSlider.svelte";

export let waveElement;
export let isEnabled;
export let indicatorElement;
let btnOnOff;
</script>

<div class="controls">
<div class="button-wrapper">
<OnOffButton
on:switch-plot-enabled={(e) => {
isEnabled = e.detail.enabled;
}}
bind:this={btnOnOff}
/>
<ResetButton
on:reset={() => {
// if oscilloscope is running, click stop button
if (isEnabled) {
btnOnOff.click();
}
// clear canvas and indicators
indicatorElement.clearCanvas();
waveElement.resetPlot();
}}
/>
</div>
<div class="slider-wrapper">
<div class="sliders">
Start/Stop
<div class="placeholder" />
<br />
<small>Channels</small>
{#each { length: NUM_CHANNELS } as _, index}
<StartStopButton
channel_id={index}
on:startStop={async (event) => {
let hasStarted = event.detail.buttonValue;
waveElement.startStopChannelI(index, hasStarted);
indicatorElement.startStopChannelI(index, hasStarted);
}}
/>
{/each}
</div>
<div class="sliders">
Thickness
<div class="placeholder" />
<br />
<small>Channels</small>
{#each { length: NUM_CHANNELS } as _, index}
<ThicknessSwitch
channel={index}
onClick={(isThick) => {
waveElement.updateChannelThickness(index, !isThick);
}}
/>
{/each}
</div>
<div class="sliders">
Offset
<div class="placeholder" />
<br />
<small>Channels</small>
{#each { length: NUM_CHANNELS } as _, index}
<Slider
id={`offset-slider-${index}`}
onInput={(offsetY) => {
waveElement.updateChannelOffsetY(index, offsetY);
indicatorElement.updateChannelOffsetY(index, offsetY);
}}
value={0}
min={-1.0}
max={1.0}
step={0.01}
/>
{/each}
</div>
<div class="sliders">
Time Sweep
<br />
<small>Common</small>
<TimeSweepSlider channel={NUM_CHANNELS + 1} isCommon={true} />
<small>Channels</small>
{#each { length: NUM_CHANNELS } as _, index}
<Slider
id={`time-sweep-slider-${index}`}
bind:value={$timeSweep[index]}
onInput={() => {}}
/>
{/each}
</div>
<div class="sliders">
Amplitude
<div class="placeholder" />
<br />
<small>Channels</small>
{#each { length: NUM_CHANNELS } as _, index}
<Slider
id={`amplitude-slider-${index}`}
onInput={(value) => {
waveElement.updateChannelScaling(index, value);
indicatorElement.updateChannelScaling(index, value);
}}
max={MAX_AMPLITUDE}
min={MIN_AMPLITUDE}
/>
{/each}
</div>
</div>
</div>

<style>
.controls {
grid-column: 2;
justify-content: center;
}
.slider-wrapper {
display: flex;
}

.sliders {
width: 50%;
}

.button-wrapper {
display: flex;
margin: 1rem;
}

.placeholder {
height: 32.4833px;
}
</style>
124 changes: 2 additions & 122 deletions Apps/frontend/src/views/Oscilloscope.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@
} from "../const";
import CoordinateSystem from "../components/CoordinateSystem.svelte";
import Waves from "../components/Waves.svelte";
import OffsetSlider from "../components/OffsetSlider.svelte";
import StartStopButton from "./StartStopButton.svelte";
import Indicators from "./Indicators.svelte";
import OnOffButton from "../components/OnOffButton.svelte";
import TimeSweepSlider from "../components/TimeSweepSlider.svelte";
import ResetButton from "./ResetButton.svelte";
import AmplitudeSlider from "./AmplitudeSlider.svelte";
import { logSocketCloseCode } from "../helper";
import ThicknessSwitch from "../components/ThicknessSwitch.svelte";
import WaveControls from "../components/WaveControls.svelte";

let waveElement;
let btnOnOff;
let scalesY = Array(NUM_CHANNELS).fill(1); // 1V per horizontal line
let indicatorElement;
let socket;
Expand Down Expand Up @@ -73,98 +66,7 @@
<Waves bind:this={waveElement} {scalesY} />
</div>
</div>
<div class="controls">
<div class="button-wrapper">
<OnOffButton
on:switch-plot-enabled={(e) => {
isEnabled = e.detail.enabled;
}}
bind:this={btnOnOff}
/>
<ResetButton
on:reset={() => {
// if oscilloscope is running, click stop button
if (isEnabled) {
btnOnOff.click();
}
// clear canvas and indicators
indicatorElement.clearCanvas();
waveElement.resetPlot();
}}
/>
</div>
<div class="slider-wrapper">
<div class="sliders">
Start/Stop
<div class="placeholder"></div>
<br>
<small>Channels</small>
{#each { length: NUM_CHANNELS } as _, index}
<StartStopButton
channel_id={index}
on:startStop={async (event) => {
let hasStarted = event.detail.buttonValue;
waveElement.startStopChannelI(index, hasStarted);
indicatorElement.startStopChannelI(index, hasStarted);
}}
/>
{/each}
</div>
<div class="sliders">
Thickness
<div class="placeholder"></div>
<br>
<small>Channels</small>
{#each { length: NUM_CHANNELS } as _, index}
<ThicknessSwitch
channel={index}
onClick={(isThick) => {
waveElement.updateChannelThickness(index, !isThick);
}}
/>
{/each}
</div>
<div class="sliders">
Offset
<div class="placeholder"></div>
<br>
<small>Channels</small>
{#each { length: NUM_CHANNELS } as _, index}
<OffsetSlider
onInput={(offsetY) => {
waveElement.updateChannelOffsetY(index, offsetY);
indicatorElement.updateChannelOffsetY(index, offsetY);
}}
/>
{/each}
</div>
<div class="sliders">
Time Sweep
<br>
<small>Common</small>
<TimeSweepSlider channel={NUM_CHANNELS + 1} isCommon={true} />
<small>Channels</small>
{#each { length: NUM_CHANNELS } as _, index}
<TimeSweepSlider channel={index} />
{/each}
</div>
<div class="sliders">
Amplitude
<div class="placeholder"></div>
<br>
<small>Channels</small>
{#each { length: NUM_CHANNELS } as _, index}
<AmplitudeSlider
channel={index}
onInput={(scaling) => {
waveElement.updateChannelScaling(index, scaling);
indicatorElement.updateChannelScaling(index, scaling);
}}
/>
{/each}
</div>
</div>
</div>
<WaveControls bind:isEnabled bind:waveElement bind:indicatorElement />
</div>
</div>

Expand Down Expand Up @@ -192,26 +94,4 @@
position: absolute;
inset: 0;
}
.controls {
grid-column: 2;
justify-content: center;
}

.slider-wrapper {
display: flex;
}

.button-wrapper {
display: flex;
margin: 1rem;
}

.sliders {
width: 50%;
}

.placeholder {
height: 32.4833px;
}

</style>