Skip to content

Commit

Permalink
example: add logarithmic spectrum
Browse files Browse the repository at this point in the history
  • Loading branch information
cdump committed Jun 12, 2021
1 parent 361dc15 commit bffa4b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions radiacode-examples/webserver.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
<div id="app">
<div>
<apexchart type="bar" height="350" :options="spectrumChartOptions" :series="spectrum_series"></apexchart>
<div>
<input type="radio" id="spectrum_linear" v-bind:value="false" v-model="spectrum_logarithmic">
<label for="spectrum_linear">Linear</label>
<input type="radio" id="spectrum_log" v-bind:value="true" v-model="spectrum_logarithmic">
<label for="spectrum_log">Logarithmic</label>
</div>
<button @click="updateSpectrum">Update spectrum</button>
</div>
<div>
Expand All @@ -34,6 +40,8 @@
animations: {enabled: false},
zoom: {autoScaleYaxis: true},
},
tooltip: {intersect: false},
grid: {xaxis: {lines: {show: true}}},
dataLabels: {enabled: false},
};
var app = new Vue({
Expand All @@ -48,6 +56,7 @@
rates_autoupdate: true,
rates_series: [],
spectrum_series: [],
spectrum_logarithmic: true,
ratesChartOptions: {
...common_options,
title: {text: 'CountRate & DoseRate'},
Expand All @@ -64,8 +73,8 @@
return{
...common_options,
title: {text: `Spectrum, ${this.spectrum_duration} seconds`},
xaxis: {type: 'numeric', title: {text: 'keV'}},
// yaxis: {logarithmic: true},
xaxis: {type: 'numeric', title: {text: 'keV'}, tickAmount: 25},
yaxis: {logarithmic: this.spectrum_logarithmic, decimalsInFloat: 0},
};
},
},
Expand Down
3 changes: 2 additions & 1 deletion radiacode-examples/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ async def handle_ws(request):
async def handle_spectrum(request):
spectrum = request.app.rc_conn.spectrum()
spectrum_data = [
(int(spectrum_channel_to_energy(channel, spectrum.a0, spectrum.a1, spectrum.a2)), cnt)
# apexcharts can't handle 0 in logarithmic view
(int(spectrum_channel_to_energy(channel, spectrum.a0, spectrum.a1, spectrum.a2)), cnt if cnt > 0 else 0.5)
for channel, cnt in enumerate(spectrum.counts)
]
print('Spectrum updated')
Expand Down

0 comments on commit bffa4b5

Please sign in to comment.