audiogram-beta/src/app.js

88 lines
4.6 KiB
JavaScript
Raw Normal View History

2022-12-10 10:27:23 -05:00
import React from "react";
import {html} from "htm";
2022-12-04 16:19:22 -05:00
import * as TW from "./twind.js";
2022-12-03 19:05:26 -05:00
import * as UI from "./ui.js";
2022-12-05 23:22:37 -05:00
import * as Store from "./store.js";
2022-12-03 19:05:26 -05:00
2022-12-10 11:57:45 -05:00
// @ts-ignore:
2022-12-04 16:19:22 -05:00
const ShadowDOM = document.querySelector("#app").attachShadow({mode: "open"});
const ShadowDiv = document.createElement("div");
const ShadowCSS = document.createElement("style");
ShadowDOM.append(ShadowCSS);
ShadowDOM.append(ShadowDiv);
TW.Init(ShadowCSS, ShadowDiv);
2022-12-07 21:58:55 -05:00
const Controls =()=>
{
const [State, Dispatch] = Store.Consumer();
2022-12-06 23:37:39 -05:00
2022-12-07 21:58:55 -05:00
return html`
<div class="flex">
<div>Channel</div>
<div>${State.Chan.Value}</div>
<${UI.Button} light=${State.Chan.Value == 0} inactive=${State.Chan.Value == 0} onClick=${()=>Dispatch({Name:"Chan", Data:-1})}>Left<//>
<${UI.Button} light=${State.Chan.Value == 1} inactive=${State.Chan.Value == 1} onClick=${()=>Dispatch({Name:"Chan", Data:1})}>Right<//>
</div>
<div class="flex">
<div>Frequency</div>
<div>${Store.ColumnMapping[State.Freq.Value][0]}</div>
<${UI.Button} disabled=${State.Freq.Value == State.Freq.Min} onClick=${()=>Dispatch({Name:"Freq", Data:-1})}>-<//>
<${UI.Button} disabled=${State.Freq.Value == State.Freq.Max} onClick=${()=>Dispatch({Name:"Freq", Data:1})}>+<//>
</div>
<div class="flex">
<div>Stimulus</div>
<div>${State.Stim.Value}</div>
<${UI.Button} disabled=${State.Stim.Value == State.Stim.Min} onClick=${()=>Dispatch({Name:"Stim", Data:-1})}>-<//>
<${UI.Button} disabled=${State.Stim.Value == State.Stim.Max} onClick=${()=>Dispatch({Name:"Stim", Data:1})}>+<//>
</div>
<div class="flex">
<div>Mark</div>
<${UI.Button} onClick=${()=>Dispatch({Name:"Mark", Data:true })}>Response<//>
<${UI.Button} onClick=${()=>Dispatch({Name:"Mark", Data:false})}>No Response<//>
<${UI.Button} onClick=${()=>Dispatch({Name:"Mark", Data:null })} disabled=${State.Live.Mark == undefined}>Clear<//>
</div>
`;
};
2022-12-06 23:37:39 -05:00
2022-12-05 23:22:37 -05:00
const Audiogram =()=>
{
2022-12-06 23:37:39 -05:00
const [State] = Store.Consumer();
2022-12-10 13:24:31 -05:00
const testMarksL = State.Draw.TestL.Points.map(p=>html`<${UI.Mark} x=${p.X} y=${p.Y} response=${p.Mark?.Resp} right=${false}/>`);
const userMarksL = State.Draw.UserL.Points.map(p=>html`<${UI.Mark} x=${p.X} y=${p.Y} response=${p.Mark?.Resp} right=${false} classes=${State.Live.Mark == p.Mark ? "stroke-bold":""}/>`);
const testMarksR = State.Draw.TestR.Points.map(p=>html`<${UI.Mark} x=${p.X} y=${p.Y} response=${p.Mark?.Resp} right=${true} />`);
const userMarksR = State.Draw.UserR.Points.map(p=>html`<${UI.Mark} x=${p.X} y=${p.Y} response=${p.Mark?.Resp} right=${true} classes=${State.Live.Mark == p.Mark ? "stroke-bold":""}/>`);
2022-12-05 23:22:37 -05:00
2022-12-10 13:24:31 -05:00
const testLinesL = State.Draw.TestL.Paths.map( p=>html`<line class="opacity-60" x1=${p.Head.X} y1=${p.Head.Y} x2=${p.Tail.X} y2=${p.Tail.Y} />`);
const userLinesL = State.Draw.UserL.Paths.map( p=>html`<line class="opacity-60" x1=${p.Head.X} y1=${p.Head.Y} x2=${p.Tail.X} y2=${p.Tail.Y} />`);
const testLinesR = State.Draw.TestR.Paths.map( p=>html`<line class="opacity-60" x1=${p.Head.X} y1=${p.Head.Y} x2=${p.Tail.X} y2=${p.Tail.Y} />`);
const userLinesR = State.Draw.UserR.Paths.map( p=>html`<line class="opacity-60" x1=${p.Head.X} y1=${p.Head.Y} x2=${p.Tail.X} y2=${p.Tail.Y} />`);
2022-12-05 23:22:37 -05:00
return html`
2022-12-06 23:37:39 -05:00
<svg class="absolute top-0 w-full h-full overflow-visible stroke(blue-700 bold draw) opacity-50">${testMarksL}${testLinesL}</svg>
<svg class="absolute top-0 w-full h-full overflow-visible stroke(red-700 bold draw) opacity-50">${testMarksR}${testLinesR}</svg>
<svg class="absolute top-0 w-full h-full overflow-visible stroke(blue-700 2 draw)">${userMarksL}${userLinesL}</svg>
2022-12-10 00:33:38 -05:00
<svg class="absolute top-0 w-full h-full overflow-visible stroke(red-700 2 draw)">${userMarksR}${userLinesR}</svg>
2022-12-10 13:24:31 -05:00
<svg class="absolute top-0 w-full h-full overflow-visible transition-all duration-500" style=${{top:State.Draw.Cross?.Y, left:State.Draw.Cross?.X}}>
<ellipse cx="0" cy="0" rx="8" ry="30" fill="url(#glow)"></ellipse>
<ellipse cx="0" cy="0" rx="30" ry="8" fill="url(#glow)"></ellipse>
2022-12-10 00:33:38 -05:00
<defs>
<radialGradient id="glow">
2022-12-10 13:24:31 -05:00
<stop stop-color=${State.Chan.Value ? "red" : "blue"} stop-opacity="0.6" offset="0.0"></stop>
<stop stop-color=${State.Chan.Value ? "red" : "blue"} stop-opacity="0.3" offset="0.2"></stop>
<stop stop-color=${State.Chan.Value ? "red" : "blue"} stop-opacity="0.0" offset="1.0"></stop>
2022-12-10 00:33:38 -05:00
</radialGradient>
</defs>
</svg>
`;
2022-12-05 23:22:37 -05:00
};
2022-12-03 19:05:26 -05:00
React.render(html`
2022-12-05 23:22:37 -05:00
<${Store.Provider}>
2022-12-07 21:58:55 -05:00
<${Controls}/>
2022-12-03 19:05:26 -05:00
<${UI.Chart}>
2022-12-05 23:22:37 -05:00
<${Audiogram}/>
2022-12-03 19:05:26 -05:00
<//>
2022-11-27 16:57:06 -05:00
<//>
2022-11-25 15:51:27 -05:00
`, ShadowDiv);