hayun-vite 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.html CHANGED
@@ -21,36 +21,51 @@
21
21
  import speechUI from "/src/Speech/SpeechUI.js"
22
22
  import formsUI from "/src/Forms/FormsUI.js"
23
23
  import reflexUI from "/src/Reflex/ReflexUI.js"
24
+ import tympanogramUI from "/src/Tympanogram/TympanogramUI"
25
+ import audiogramUI from "/src/Audiogram/AudiogramUI"
26
+
24
27
 
25
28
  const { appSettingData, officeData, patientData } = currentData
26
- let data = patientData.sessions[0].speech
27
- speechUI.draw({ containerId: '#app' })
28
- speechUI.update({ data })
29
29
 
30
- // فراخوانی متد آپدیت بدون پارامتر مقادیر وارد شده کاربر را به دیتاآبجکت جاری میفرستد
30
+ let data
31
+ data = patientData.sessions[0].audiogram
32
+ audiogramUI.draw({ containerId: '#app' })
33
+ audiogramUI.update({ data })
34
+
35
+
36
+ // data = patientData.sessions[0].speech
37
+ // speechUI.draw({ containerId: '#app' })
38
+ // speechUI.update({ data })
39
+ // // فراخوانی متد آپدیت بدون پارامتر مقادیر وارد شده کاربر را به دیتاآبجکت جاری میفرستد
31
40
  // setInterval(() => { speechUI.update() }, 3000);
32
41
 
33
- // Accoustic Reflexes Section
34
- data = patientData.sessions[0].reflex
35
- reflexUI.draw({ containerId: '#app' })
36
- reflexUI.update({ data })
42
+ // data = patientData.sessions[0].tympanogram
43
+ // tympanogramUI.draw({ containerId: '#app' })
44
+ // tympanogramUI.update({ data })
45
+ // setInterval(() => { tympanogramUI.update() }, 2000);
37
46
 
38
- // formsUI Section
39
- // data = patientData.sessions[0]
40
- // formsUI.draw({ containerId: '#app' })
41
- // formsUI.update({ patientData, sessionIndex: 0 })
42
47
 
43
- // setInterval(() => {
44
- // formsUI.update({ patientData, sessionIndex: 0 })
45
- // console.log('forms update!');
46
48
 
47
- // }, 2000)
48
49
 
49
50
 
50
- // document.querySelector('#log').addEventListener('click', () => {
51
- // console.log(data.R, data.L);
52
51
 
53
- // })
52
+ // Accoustic Reflexes Section
53
+ // data = patientData.sessions[0].reflex
54
+ // reflexUI.draw({ containerId: '#app' })
55
+ // reflexUI.update({ data })
56
+ // setInterval(() => { reflexUI.update() }, 3000);
57
+
58
+
59
+
60
+ // formsUI Section
61
+ data = patientData.sessions[0]
62
+ formsUI.draw({ containerId: '#app' })
63
+ formsUI.update({ patientData, sessionIndex: 0 })
64
+
65
+ setInterval(() => {
66
+ formsUI.update({ patientData, sessionIndex: 0 })
67
+ console.log('forms update!');
68
+ }, 2000)
54
69
 
55
70
 
56
71
  </script>
package/index.js CHANGED
@@ -20,6 +20,9 @@ import logo2 from './assets/logos/logo-2.png'
20
20
  import Speech from './src/Speech/Speech'
21
21
  // import { ReflexUI } from './src/components'
22
22
  import speechUI from './src/Speech/SpeechUI'
23
+ import reflexUI from './src/Reflex/ReflexUI'
24
+ import tympanogramUI from './src/Tympanogram/TympanogramUI'
25
+ import audiogramUI from './src/Audiogram/AudiogramUI'
23
26
 
24
27
  const logos = [logo0, logo1, logo2]
25
28
 
@@ -28,6 +31,6 @@ const logos = [logo0, logo1, logo2]
28
31
 
29
32
  export {
30
33
  Audiogram, Forms, dims, currentData, combo_template,
31
- logos, Speech, speechUI, formsUI
34
+ logos, Speech, speechUI, reflexUI, tympanogramUI, formsUI, audiogramUI
32
35
 
33
36
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hayun-vite",
3
3
  "private": false,
4
- "version": "1.2.0",
4
+ "version": "1.4.0",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -444,7 +444,7 @@ export default class Audiogram {
444
444
  // پاک کردن نودهای سمبل دیتای قبلی در صورت وجود از نود مربوطه
445
445
  this.svg.querySelectorAll('[data-name=symbol]').forEach(symbol => symbol.remove())
446
446
  // پاک کردن خطوط اتصال دیتای قبلی در صورت وجود از نود مربوطه
447
- this.svg.querySelectorAll('[data-name=junction]').forEach(symbol => symbol.remove())
447
+ this.svg.querySelectorAll('[data-name=junction]').forEach(line => line.remove())
448
448
 
449
449
  const junctions = { AC: {}, BC: {}, side };
450
450
  this.junctions = junctions;
@@ -0,0 +1,66 @@
1
+ import Audiogram from "./Audiogram";
2
+
3
+ class AudiogramUI {
4
+ constructor() {
5
+ this.data = { R: '', L: '' }
6
+ }
7
+
8
+ draw({ containerId = '#app' } = {}) {
9
+
10
+ document.querySelector(containerId).insertAdjacentHTML('beforeend', `
11
+ <div class="center border">
12
+ <section id="r-audiogram"></section>
13
+ <section id="l-audiogram"></section>
14
+ </div>
15
+ `);
16
+
17
+
18
+ const dims = {
19
+ "blank": false,
20
+ "name": "RAudiogram",
21
+ "w": 100,
22
+ "h": 90,
23
+ "margin": {
24
+ "left": 1,
25
+ "top": 1,
26
+ "right": 1,
27
+ "bottom": 1
28
+ },
29
+ "display": "inline",
30
+ "borderBox": "display",
31
+ "width": 600,
32
+ "height": 600
33
+ }
34
+ this.rcontainer = document.getElementById('r-audiogram')
35
+ this.rchart = new Audiogram({ container: this.rcontainer, side: 'R', dims })
36
+
37
+
38
+ this.lcontainer = document.getElementById('l-audiogram')
39
+ this.lchart = new Audiogram({ container: this.lcontainer, side: 'L', dims })
40
+
41
+ }
42
+
43
+ update({ data } = {}) {
44
+
45
+ this.rchart.update({ data: data.R, side: 'R' })
46
+ this.lchart.update({ data: data.L, side: 'L' })
47
+ // if (data) {
48
+ // this.rchart.update(data.R, this.rcontainer)
49
+ // this.lchart.update(data.L, this.lcontainer)
50
+ // this.data = { R: data.R, L: data.L }
51
+ // } else
52
+ // // اگر این تابع بدون پارامتر فراخوانی شود مقادیر اینپوت کاربر گرفته و دیتاآبجکت را آپدیت کند
53
+ // {
54
+ // console.log('without param');
55
+
56
+ // this.rchart.fetchInputUserData()
57
+ // this.lchart.fetchInputUserData()
58
+ // this.data.R = this.rchart.data
59
+ // this.data.L = this.lchart.data
60
+ // }
61
+
62
+ }
63
+ }
64
+
65
+ export default new AudiogramUI()
66
+
@@ -116,10 +116,20 @@ export default class Reflex {
116
116
  }
117
117
 
118
118
  // جایگذاری داده های رفلکس
119
- update(data) {
119
+ update(data, container) {
120
+
121
+ this.data = data
122
+
123
+ // انتخاب اینکه اینپوت های کاربر را آپدیت کنه یا اس وی جی تکست ها رو
124
+ // بر حسب اینکه پارامتر کانتینر باشه یا نباشه
125
+ const prop = container ? 'value' : 'textContent'
126
+ const elem = container ? 'input' : 'text';
127
+ !container && (container = this.chart);
128
+
120
129
  for (const key in data) {
121
130
  for (const freq in data[key]) {
122
- this.chart.querySelector(`text[name=${key}-${freq}]`).innerHTML = data?.[key]?.[freq] || "";
131
+ container.querySelector(`${elem}[name=${key}-${freq}]`)[prop] = data?.[key]?.[freq] || "";
132
+ // container.querySelector(`${elem}[name=${label}]`)[prop] = data?.[label] || "";
123
133
  }
124
134
  }
125
135
  }
@@ -169,4 +179,21 @@ export default class Reflex {
169
179
  })
170
180
  // firstInput.focus()
171
181
  }
182
+
183
+ // دریافت دیتای کاربر از اینپوت ها و جایگزین کردن در دیتای آبجکت کلاس
184
+ // تغییر این دیتا باعث تغییر دیتای جاری می‌شود. چون آبجکت ها اشاره گر هستن
185
+ fetchInputUserData() {
186
+ [500, 1000, 2000, 4000].
187
+ forEach(freq => {
188
+ const value = this.container.querySelector(`input[name=ipsi-${freq}]`).value
189
+ this.data.ipsi[freq] = value // جایگزین کردن پراپرتی آبجکت دیتای جاری و اینجا
190
+ });
191
+
192
+ [500, 1000, 2000, 4000].
193
+ forEach(freq => {
194
+ const value = this.container.querySelector(`input[name=contra-${freq}]`).value
195
+ this.data.contra[freq] = value // جایگزین کردن پراپرتی آبجکت دیتای جاری و اینجا
196
+ });
197
+
198
+ }
172
199
  }
@@ -41,11 +41,11 @@ class ReflexUI {
41
41
  this.rchart = new Reflex({ container: this.rcontainer, dims, side: 'R' })
42
42
 
43
43
  // فراخوانی متد ایجاد اینپوت روی چارت اسپیچ
44
- // this.rchart.createUserInput({ container: this.rcontainer })
44
+ this.rchart.createUserInput({ container: this.rcontainer })
45
45
 
46
46
  this.lcontainer = document.getElementById('l-reflex')
47
47
  this.lchart = new Reflex({ container: this.lcontainer, dims, side: 'L' })
48
- // this.lchart.createUserInput({ container: this.lcontainer })
48
+ this.lchart.createUserInput({ container: this.lcontainer })
49
49
 
50
50
  }
51
51
 
@@ -57,12 +57,13 @@ class ReflexUI {
57
57
  } else
58
58
  // اگر این تابع بدون پارامتر فراخوانی شود مقادیر اینپوت کاربر گرفته و دیتاآبجکت را آپدیت کند
59
59
  {
60
- console.log('without param');
61
60
 
62
- // this.rchart.fetchInputUserData()
63
- // this.lchart.fetchInputUserData()
64
- // this.data.R = this.rchart.data
65
- // this.data.L = this.lchart.data
61
+ this.rchart.fetchInputUserData()
62
+ this.lchart.fetchInputUserData()
63
+ this.data.R = this.rchart.data
64
+ this.data.L = this.lchart.data
65
+ console.log('without param', this.data.R);
66
+
66
67
  }
67
68
 
68
69
  }
@@ -169,9 +169,6 @@ export default class Speech {
169
169
  font-family: Vazirmatn;
170
170
  `
171
171
  const color = (this.side === 'R') ? 'crimson' : 'blue';
172
- // ایجاد یک المنت اینپوت
173
- // let input
174
- // آماده سازی اولین نود اینپوت از داکیومنت و سپس ساختن بقیه نودها از روی آن
175
172
  // const firstInput = input // نگهداری اولین اینپوت برای برگشت و فوکوس کردن بهش
176
173
  let inputDims = this.inputDims
177
174
 
@@ -161,12 +161,13 @@ export default class Tympanogram {
161
161
  { name: 'MEP', x: getX(-300), y: getY(compliance.min), dy: 10, dx: 11 },
162
162
  { name: 'SC', x: getX(0), y: getY(compliance.min), dy: 10, dx: 8 },
163
163
  { name: 'G', x: getX(300), y: getY(compliance.min), dy: 10, dx: 4 },
164
- { name: 'type', x: getX(-500), y: getY(2.5), dx: 9, dy: 0 },
164
+ { name: 'type', x: getX(-490), y: getY(2.5), dx: 9, dy: 0 },
165
165
  ]
166
166
  .forEach(input => {
167
167
  const { name, x, y, dx, dy } = input
168
168
  putText({ container: svg, value, style, name, x, y, dx, dy })
169
- this.inputDims.push({ name, x: (x + dx + padding.left) * kx, y: (y + dy + padding.top) * ky })
169
+ // نگهداری مختصات اینپوت ها برای استفاده بعدی
170
+ this.inputDims.push({ name, x: (x + dx + padding.left + 4) * kx, y: (y + dy + padding.top) * ky })
170
171
  // putPoint({ container: svg, x, y, dx, dy, r: 0.8, fill: 'brown' })
171
172
  });
172
173
 
@@ -232,8 +233,16 @@ export default class Tympanogram {
232
233
  }
233
234
  }
234
235
 
235
- update(data) {
236
+ update(data, container) {
236
237
  this.data = data
238
+ // انتخاب اینکه اینپوت های کاربر را آپدیت کنه یا اس وی جی تکست ها رو
239
+ // بر حسب اینکه پارامتر کانتینر باشه یا نباشه
240
+ const prop = container ? 'value' : 'textContent'
241
+ const elem = container ? 'input' : 'text';
242
+ !container && (container = this.chart);
243
+
244
+ // container.querySelector(`${elem}[name=${label}]`)[prop] = data?.[label] || "";
245
+
237
246
 
238
247
  let { ECV, SC, MEP, G } = data
239
248
 
@@ -243,21 +252,22 @@ export default class Tympanogram {
243
252
  G && (G = (+G).toFixed(2));
244
253
 
245
254
  // جایگذاری مقادیر تمپانومتری در تکست‌باکس ها
246
- this.chart.querySelector(`text[name="type"]`).innerHTML = data?.type || "-";
247
- this.chart.querySelector(`text[name="ECV"]`).innerHTML = ECV || "-";
248
- this.chart.querySelector(`text[name="MEP"]`).innerHTML = data?.MEP || "-";
249
- this.chart.querySelector(`text[name="SC"]`).innerHTML = SC || "-";
250
- this.chart.querySelector(`text[name="G"]`).innerHTML = G || "-";
251
- // پاک کردن منحنی قبلی از کانتینر جاری
252
- // console.log(this.chart.querySelector(`path[name="curve"]`));
255
+ container.querySelector(`${elem}[name="type"]`)[prop] = data?.type || "-";
256
+ container.querySelector(`${elem}[name="ECV"]`)[prop] = ECV || "";
257
+ container.querySelector(`${elem}[name="MEP"]`)[prop] = data?.MEP || "";
258
+ container.querySelector(`${elem}[name="SC"]`)[prop] = SC || "";
259
+ container.querySelector(`${elem}[name="G"]`)[prop] = G || "";
253
260
 
254
- this.chart.querySelector(`path[name="curve"]`)?.remove();
255
261
  // رسم منحنی
256
262
  this.drawCurve(data);
257
263
  }
258
264
 
259
265
  // توابع داخلی
260
266
  drawCurve(data) {
267
+
268
+ // پاک کردن منحنی قبلی از کانتینر جاری
269
+ this.chart.querySelector(`path[name="curve"]`)?.remove();
270
+
261
271
  let { type, ECV, SC, MEP, G, expanded, cp, cpp } = data
262
272
 
263
273
  // Ensure to Convert to Numbers //
@@ -377,45 +387,68 @@ export default class Tympanogram {
377
387
  }
378
388
  }
379
389
 
380
- // ایجاد اینپوت‌های کاربر در کانتینر چارت
381
390
  createUserInput({ container }) {
382
391
  // استایل دهی نسبی به کانتینر
383
392
  container.style.position = 'relative'
384
- // ایجاد یک المنت اینپوت
385
- let input = document.createElement('input')
386
- input.name = 'SAT'
387
- input.type = 'text'
388
- input.maxLength = 4
389
- input.autocomplete = 'off'
390
- input.placeholder = '---'
391
- const width = 70 // به دست آوردن پهنای اینپوت برای محاسبه مختصات نقطه مرکزش
392
- const height = 25 // به دست آوردن پهنای اینپوت برای محاسبه مختصات نقطه مرکزش
393
+ const width = 60 // به دست آوردن پهنای اینپوت برای محاسبه مختصات نقطه مرکزش
394
+ const height = 30 // به دست آوردن پهنای اینپوت برای محاسبه مختصات نقطه مرکزش
395
+
393
396
  let style = `
394
- margin: 0;
395
- padding: 0;
396
- text-align: center;
397
- font-size: 24px;
398
- font-weight: bold;
399
- color: crimson;
400
- position: absolute;
397
+ all: revert;
401
398
  width: ${width}px;
402
399
  height: ${height}px;
400
+ box-sizing: border-box;
403
401
  border: none;
402
+ /* Ensures padding doesn't increase height */
403
+ position: absolute;
404
+ padding-top: 4px;
405
+ text-align: center;
406
+ font-size: 24px;
407
+ font-weight: bold;
408
+ font-family: Vazirmatn;
404
409
  `
405
- input.style = style
406
- // آماده سازی اولین نود اینپوت از داکیومنت و سپس ساختن بقیه نودها از روی آن
407
- const firstInput = input // نگهداری اولین اینپوت برای برگشت و فوکوس کردن بهش
410
+ const color = (this.side === 'R') ? 'crimson' : 'blue';
411
+ // const firstInput = input // نگهداری اولین اینپوت برای برگشت و فوکوس کردن بهش
408
412
  let inputDims = this.inputDims
409
- input.style.color = (this.side === 'R') ? 'crimson' : 'blue';
410
413
 
411
414
  inputDims.forEach(dims => {
415
+ const input = document.createElement('input')
416
+ // input.className = 'user-input'
417
+ input.name = dims.name
418
+ input.type = 'text'
419
+ input.maxLength = 4
420
+ input.autocomplete = 'off'
421
+ input.placeholder = '---'
422
+ input.style = style
423
+ input.style.color = color
412
424
  input.style.left = dims.x - width / 2 + 'px'
413
425
  input.style.top = dims.y - height / 2 + 'px'
414
- input.setAttribute('name', dims.name)
415
426
  container.appendChild(input)
416
- input = input.cloneNode() // در آخر یک المنت اضافه ایجاد شده است - باگ بی آزار
427
+ // input = input.cloneNode() // در آخر یک المنت اضافه ایجاد شده است - باگ بی آزار
417
428
  })
418
429
 
419
- firstInput.focus()
430
+ //افزودن رویداد به اینپوت ها
431
+ this.createUserInputEvent()
432
+ // firstInput.focus()
433
+ }
434
+
435
+ // دریافت دیتای کاربر از اینپوت ها و جایگزین کردن در دیتای آبجکت کلاس
436
+ // تغییر این دیتا باعث تغییر دیتای جاری می‌شود. چون آبجکت ها اشاره گر هستن
437
+ fetchInputUserData() {
438
+ ['type', 'ECV', 'MEP', 'SC', 'G'].forEach(name => {
439
+ const value = this.container.querySelector(`input[name= ${name}]`).value
440
+ this.data[name] = value // جایگزین کردن پراپرتی آبجکت دیتای جاری و اینجا
441
+ })
442
+ }
443
+
444
+ createUserInputEvent() {
445
+ ['type', 'ECV', 'MEP', 'SC', 'G'].forEach(name => {
446
+ this.container.querySelector(`input[name= ${name}]`).
447
+ addEventListener('change', (e) => {
448
+ console.log(e.target.value)
449
+ this.fetchInputUserData() // همه مقادیر اینپوت ها میگیره و دیتای کلاس رو به روز میکنه
450
+ this.drawCurve(this.data) // رسم مجدد منحنی با دیتای جدید
451
+ })
452
+ })
420
453
  }
421
454
  }
@@ -1,166 +1,188 @@
1
- import { BaseComponent } from "../core/BaseComponent.js";
2
- import Tympanogram from "../Tympanogram/Tympanogram";
3
-
4
-
5
- export class TympanogramUI extends BaseComponent {
6
- constructor(selector, props = {}) {
7
- super(selector, props);
8
- }
9
-
10
- render() {
11
- this.element.innerHTML = `
12
- <h1 class="center">Tympanograms</h1>
13
- <div class="center">
14
- <div>
15
- <h2 class="center red">Right</h2>
16
- <section id="r-tympanogram" style="position: relative;">
17
- <input type="text" name="type" maxlength="4" placeholder="---" autocomplete="off" />
18
- </section>
19
- <section name="r-tympanogram">
20
- <p>Curve settings:</p>
21
- <input type="range" id="cp" name="cp" min="10" max="150" value="70" step="5" />
22
- <label for="cp">cp</label>
23
- <input type="range" id="cpp" name="cpp" min="1" max="10" value="5" step="1" />
24
- <label for="cpp">cpp</label>
25
- <div>
26
- <input type="checkbox" name="extra-sc" id="r-extra-sc">
27
- <label for="r-extra-sc">Extra SC</label>
28
- </div>
29
- <div>
30
- <input type="checkbox" name="compensated" id="r-compensated">
31
- <label for="r-compensated">Compensated</label>
32
- </div>
33
- </section>
34
- </div>
35
-
36
- <div>
37
- <h2 class="center blue">Left</h2>
38
- <section id="l-tympanogram" style="position: relative;">
39
- <input type="text" name="type" maxlength="4" placeholder="---" autocomplete="off" />
40
- </section>
41
- <section name="l-tympanogram">
42
- <p>Curve settings:</p>
43
- <input type="range" id="cp" name="cp" min="10" max="150" value="70" step="5" />
44
- <label for="cp">cp</label>
45
- <input type="range" id="cpp" name="cpp" min="1" max="10" value="5" step="1" />
46
- <label for="cpp">cpp</label>
47
- <div>
48
- <input type="checkbox" name="extra-sc" id="l-extra-sc">
49
- <label for="l-extra-sc">Extra SC</label>
50
- </div>
51
- <div>
52
- <input type="checkbox" name="compensated" id="l-compensated">
53
- <label for="l-compensated">Compensated</label>
54
- </section>
55
- </div>
56
- </div>
57
- `;
58
- let dims = {
59
- "name": "RTympanogram",
60
- "w": 100,
61
- "h": 60,
62
- "margin": {
63
- "left": 2,
64
- "top": 0,
65
- "right": 2,
66
- "bottom": 0
67
- },
68
- "display": "inline",
69
- "width": 100 * 6,
70
- "height": 60 * 6,
71
- }
72
-
73
- let data = {
74
- type: "An",
75
- ECV: '1.30',
76
- SC: '0.80',
77
- MEP: '-130',
78
- G: 0.2,
79
- expanded: false, // by default is false for expand pressure from -600 to +400
80
-
81
- }
82
-
83
- let cp = 70, cpp = 5, extraCompliance, compensated
84
-
85
- const width = 50 // به دست آوردن پهنای اینپوت برای محاسبه مختصات نقطه مرکزش
86
- const height = 25 // به دست آوردن پهنای اینپوت برای محاسبه مختصات نقطه مرکزش
87
-
88
- let style = `
89
- margin: 0;
90
- padding: 0;
91
- text-align: center;
92
- font-size: 22px;
93
- font-weight: bold;
94
- color: crimson;
95
- position: absolute;
96
- width: ${width}px;
97
- height: ${height}px;
98
- border: none;
99
- `
100
- insertInputs({ containerID: 'r-tympanogram', side: 'R', dims, style }).focus()
101
-
102
- insertInputs({ containerID: 'l-tympanogram', side: 'L', dims, style })
103
-
104
-
105
- function insertInputs({ containerID, side, dims, style }) {
106
- let container = document.getElementById(containerID)
107
- const tympanogram = new Tympanogram({ container, dims, side })
108
- tympanogram.update(data)
109
-
110
- let input = container.querySelector('[name=type]')
111
- const firstInput = input // اولین اینپوت
112
-
113
- let inputDims = tympanogram.inputDims
114
- input.style = style
115
- input.style.color = (side === 'R') ? 'crimson' : 'blue';
116
- input.style.left = inputDims[0].x - width / 2 + 'px'
117
- input.style.top = inputDims[0].y - height / 2 + 'px'
118
- inputDims.shift() // حذف اولین عنصر آرایه بخاط اینکه استفاده شد در نود بالایی
119
-
120
- inputDims.forEach(dims => {
121
- input = input.cloneNode()
122
- input.style.left = dims.x - width / 2 + 'px'
123
- input.style.top = dims.y - height / 2 + 'px'
124
- input.setAttribute('name', dims.name)
125
- container.appendChild(input)
126
- })
127
-
128
- container = document.querySelector(`[name=${containerID}]`)
129
- container.querySelector("[name=compensated]").addEventListener("input", e => {
130
- compensated = e.target.checked
131
- console.log(e.target.checked);
132
- dims = { ...dims, compensated }
133
- tympanogram.draw({ dims })
134
- })
135
-
136
- container.querySelector("[name=extra-sc]").addEventListener("input", e => {
137
- extraCompliance = e.target.checked
138
- console.log(e.target.checked);
139
- dims = { ...dims, extraCompliance }
140
- tympanogram.draw({ dims })
141
- })
142
-
143
- container.querySelector("#cp").addEventListener("input", e => {
144
- cp = e.target.value
145
- console.log(cp);
146
- data = { ...data, cp }
147
- tympanogram.update(data)
148
- })
149
-
150
- container.querySelector("#cpp").addEventListener("input", e => {
151
- cpp = e.target.value
152
- console.log(cpp);
153
- data = { ...data, cpp }
154
- tympanogram.update(data)
155
- })
156
-
157
- return firstInput
158
- }
159
-
160
-
161
- }
162
-
163
- bindEvents() {
164
-
165
- }
1
+ import Tympanogram from "./Tympanogram";
2
+
3
+ class TympanogramUI {
4
+ constructor() {
5
+ this.data = { R: '', L: '' }
6
+ }
7
+
8
+ draw({ containerId = '#app' } = {}) {
9
+
10
+ document.querySelector(containerId).insertAdjacentHTML('beforeend', `
11
+ <div name="tympanograms">
12
+ <h1 class="center title">Tympanograms</h1>
13
+ <div class="center">
14
+ <div>
15
+ <h2 class="center side red">Right</h2>
16
+ <section id="r-tympanogram"></section>
17
+ <section name="r-tympanogram">
18
+ <p>Curve settings:</p>
19
+ <input type="range" id="cp" name="cp" min="10" max="150" value="70" step="5" />
20
+ <label for="cp">cp</label>
21
+ <input type="range" id="cpp" name="cpp" min="1" max="10" value="5" step="1" />
22
+ <label for="cpp">cpp</label>
23
+ <div>
24
+ <input type="checkbox" name="extra-sc" id="r-extra-sc">
25
+ <label for="r-extra-sc">Extra SC</label>
26
+ </div>
27
+ <div>
28
+ <input type="checkbox" name="compensated" id="r-compensated">
29
+ <label for="r-compensated">Compensated</label>
30
+ </div>
31
+ </section>
32
+ </div>
33
+
34
+ <div>
35
+ <h2 class="center side blue">Left</h2>
36
+ <section id="l-tympanogram"></section>
37
+ <section name="l-tympanogram">
38
+ <p>Curve settings:</p>
39
+ <input type="range" id="cp" name="cp" min="10" max="150" value="70" step="5" />
40
+ <label for="cp">cp</label>
41
+ <input type="range" id="cpp" name="cpp" min="1" max="10" value="5" step="1" />
42
+ <label for="cpp">cpp</label>
43
+ <div>
44
+ <input type="checkbox" name="extra-sc" id="l-extra-sc">
45
+ <label for="l-extra-sc">Extra SC</label>
46
+ </div>
47
+ <div>
48
+ <input type="checkbox" name="compensated" id="l-compensated">
49
+ <label for="l-compensated">Compensated</label>
50
+ </section>
51
+ </div>
52
+ </div>
53
+ </div>
54
+ `);
55
+
56
+ this.dims = {
57
+ "name": "RTympanogram",
58
+ "w": 100,
59
+ "h": 60,
60
+ "margin": {
61
+ "left": 2,
62
+ "top": 0,
63
+ "right": 2,
64
+ "bottom": 0
65
+ },
66
+ "display": "inline",
67
+ "width": 100 * 6,
68
+ "height": 60 * 6,
69
+ }
70
+
71
+ // let data = {
72
+ // type: "An",
73
+ // ECV: '1.30',
74
+ // SC: '0.80',
75
+ // MEP: '-130',
76
+ // G: 0.2,
77
+ // expanded: false, // by default is false for expand pressure from -600 to +400
78
+
79
+ // }
80
+ const dims = this.dims
81
+
82
+
83
+ const width = 50 // به دست آوردن پهنای اینپوت برای محاسبه مختصات نقطه مرکزش
84
+ const height = 25 // به دست آوردن پهنای اینپوت برای محاسبه مختصات نقطه مرکزش
85
+
86
+ let style = `
87
+ margin: 0;
88
+ padding: 0;
89
+ text-align: center;
90
+ font-size: 22px;
91
+ font-weight: bold;
92
+ color: crimson;
93
+ position: absolute;
94
+ width: ${width}px;
95
+ height: ${height}px;
96
+ border: none;
97
+ `
98
+ this.rcontainer = document.getElementById('r-tympanogram')
99
+ this.rchart = new Tympanogram({ container: this.rcontainer, dims, side: 'R' })
100
+ // فراخوانی متد ایجاد اینپوت روی چارت اسپیچ
101
+ this.rchart.createUserInput({ container: this.rcontainer })
102
+
103
+
104
+ this.lcontainer = document.getElementById('l-tympanogram')
105
+ this.lchart = new Tympanogram({ container: this.lcontainer, dims, side: 'L' })
106
+ // فراخوانی متد ایجاد اینپوت روی چارت اسپیچ
107
+ this.lchart.createUserInput({ container: this.lcontainer })
108
+
109
+ // cereateEvents(this.lcontainer, this.lchart, 'l-tympanogram')
110
+
111
+
112
+
113
+
114
+ }
115
+
116
+ update({ data } = {}) {
117
+ if (data) {
118
+ this.rchart.update(data.R, this.rcontainer)
119
+ this.lchart.update(data.L, this.lcontainer)
120
+ this.data = { R: data.R, L: data.L }
121
+ // در اولین دیتادهی رویدادها ایجاد شود
122
+ this.cereateEvents(this.rcontainer, this.rchart, 'r-tympanogram', data.R)
123
+ this.cereateEvents(this.lcontainer, this.lchart, 'l-tympanogram', data.L)
124
+
125
+ } else
126
+ // اگر این تابع بدون پارامتر فراخوانی شود مقادیر اینپوت کاربر گرفته و دیتاآبجکت را آپدیت کند
127
+ {
128
+ console.log('without param');
129
+
130
+ this.rchart.fetchInputUserData()
131
+ this.lchart.fetchInputUserData()
132
+ this.data.R = this.rchart.data
133
+ this.data.L = this.lchart.data
134
+ console.log(this.data.L);
135
+
136
+ }
137
+ }
138
+
139
+ cereateEvents(container, tympanogram, containerId, data) {
140
+ // کنترلرهای منحنی
141
+ let cp = 70, cpp = 5, extraCompliance, compensated, dims
142
+
143
+ container = document.querySelector(`[name=${containerId}]`)
144
+ container.querySelector("[name=compensated]").addEventListener("input", e => {
145
+ compensated = e.target.checked
146
+ console.log(e.target.checked);
147
+ dims = { ...this.dims, compensated }
148
+ tympanogram.draw({ dims })
149
+ })
150
+
151
+ container.querySelector("[name=extra-sc]").addEventListener("input", e => {
152
+ extraCompliance = e.target.checked
153
+ console.log(e.target.checked);
154
+ dims = { ...this.dims, extraCompliance }
155
+ tympanogram.draw({ dims })
156
+ })
157
+
158
+ container.querySelector("#cp").addEventListener("input", e => {
159
+ cp = e.target.value
160
+ console.log(cp);
161
+ data = { ...data, cp }
162
+ tympanogram.update(data)
163
+ })
164
+
165
+ container.querySelector("#cpp").addEventListener("input", e => {
166
+ cpp = e.target.value
167
+ console.log(cpp);
168
+ data = { ...data, cpp }
169
+ tympanogram.update(data)
170
+ })
171
+ }
172
+
166
173
  }
174
+
175
+ export default new TympanogramUI()
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
@@ -0,0 +1,5 @@
1
+ import speechUI from "/src/Speech/SpeechUI.js"
2
+ import formsUI from "/src/Forms/FormsUI.js"
3
+ import reflexUI from "/src/Reflex/ReflexUI.js"
4
+ import tympanogramUI from "/src/Tympanogram/TympanogramUI"
5
+ import audiogramUI from "/src/Audiogram/AudiogramUI"
@@ -1,165 +0,0 @@
1
- import Tympanogram from "./Tympanogram";
2
-
3
- document.querySelector('#app').insertAdjacentHTML('beforeend', `
4
- <div name="tympanograms">
5
- <h1 class="center">Tympanograms</h1>
6
- <div class="center">
7
- <div>
8
- <h2 class="center red">Right</h2>
9
- <section id="r-tympanogram" style="position: relative;">
10
- <input type="text" name="type" maxlength="4" placeholder="---" autocomplete="off" />
11
- </section>
12
- <section name="r-tympanogram">
13
- <p>Curve settings:</p>
14
- <input type="range" id="cp" name="cp" min="10" max="150" value="70" step="5" />
15
- <label for="cp">cp</label>
16
- <input type="range" id="cpp" name="cpp" min="1" max="10" value="5" step="1" />
17
- <label for="cpp">cpp</label>
18
- <div>
19
- <input type="checkbox" name="extra-sc" id="r-extra-sc">
20
- <label for="r-extra-sc">Extra SC</label>
21
- </div>
22
- <div>
23
- <input type="checkbox" name="compensated" id="r-compensated">
24
- <label for="r-compensated">Compensated</label>
25
- </div>
26
- </section>
27
- </div>
28
-
29
- <div>
30
- <h2 class="center blue">Left</h2>
31
- <section id="l-tympanogram" style="position: relative;">
32
- <input type="text" name="type" maxlength="4" placeholder="---" autocomplete="off" />
33
- </section>
34
- <section name="l-tympanogram">
35
- <p>Curve settings:</p>
36
- <input type="range" id="cp" name="cp" min="10" max="150" value="70" step="5" />
37
- <label for="cp">cp</label>
38
- <input type="range" id="cpp" name="cpp" min="1" max="10" value="5" step="1" />
39
- <label for="cpp">cpp</label>
40
- <div>
41
- <input type="checkbox" name="extra-sc" id="l-extra-sc">
42
- <label for="l-extra-sc">Extra SC</label>
43
- </div>
44
- <div>
45
- <input type="checkbox" name="compensated" id="l-compensated">
46
- <label for="l-compensated">Compensated</label>
47
- </section>
48
- </div>
49
- </div>
50
- </div>
51
- `);
52
-
53
- let dims = {
54
- "name": "RTympanogram",
55
- "w": 100,
56
- "h": 60,
57
- "margin": {
58
- "left": 2,
59
- "top": 0,
60
- "right": 2,
61
- "bottom": 0
62
- },
63
- "display": "inline",
64
- "width": 100 * 6,
65
- "height": 60 * 6,
66
- }
67
-
68
- let data = {
69
- type: "An",
70
- ECV: '1.30',
71
- SC: '0.80',
72
- MEP: '-130',
73
- G: 0.2,
74
- expanded: false, // by default is false for expand pressure from -600 to +400
75
-
76
- }
77
-
78
- let cp = 70, cpp = 5, extraCompliance, compensated
79
-
80
- const width = 50 // به دست آوردن پهنای اینپوت برای محاسبه مختصات نقطه مرکزش
81
- const height = 25 // به دست آوردن پهنای اینپوت برای محاسبه مختصات نقطه مرکزش
82
-
83
- let style = `
84
- margin: 0;
85
- padding: 0;
86
- text-align: center;
87
- font-size: 22px;
88
- font-weight: bold;
89
- color: crimson;
90
- position: absolute;
91
- width: ${width}px;
92
- height: ${height}px;
93
- border: none;
94
- `
95
- insertInputs({ containerID: 'r-tympanogram', side: 'R', dims, style }).focus()
96
-
97
- insertInputs({ containerID: 'l-tympanogram', side: 'L', dims, style })
98
-
99
-
100
- function insertInputs({ containerID, side, dims, style }) {
101
- let container = document.getElementById(containerID)
102
- const tympanogram = new Tympanogram({ container, dims, side })
103
- tympanogram.update(data)
104
-
105
- let input = container.querySelector('[name=type]')
106
- const firstInput = input // اولین اینپوت
107
-
108
- let inputDims = tympanogram.inputDims
109
- input.style = style
110
- input.style.color = (side === 'R') ? 'crimson' : 'blue';
111
- input.style.left = inputDims[0].x - width / 2 + 'px'
112
- input.style.top = inputDims[0].y - height / 2 + 'px'
113
- inputDims.shift() // حذف اولین عنصر آرایه بخاط اینکه استفاده شد در نود بالایی
114
-
115
- inputDims.forEach(dims => {
116
- input = input.cloneNode()
117
- input.style.left = dims.x - width / 2 + 'px'
118
- input.style.top = dims.y - height / 2 + 'px'
119
- input.setAttribute('name', dims.name)
120
- container.appendChild(input)
121
- })
122
-
123
- container = document.querySelector(`[name=${containerID}]`)
124
- console.log(container);
125
-
126
- container.querySelector("[name=compensated]").addEventListener("input", e => {
127
- compensated = e.target.checked
128
- console.log(e.target.checked);
129
- dims = { ...dims, compensated }
130
- tympanogram.draw({ dims })
131
- })
132
-
133
- container.querySelector("[name=extra-sc]").addEventListener("input", e => {
134
- extraCompliance = e.target.checked
135
- console.log(e.target.checked);
136
- dims = { ...dims, extraCompliance }
137
- tympanogram.draw({ dims })
138
- })
139
-
140
- container.querySelector("#cp").addEventListener("input", e => {
141
- cp = e.target.value
142
- console.log(cp);
143
- data = { ...data, cp }
144
- tympanogram.update(data)
145
- })
146
-
147
- container.querySelector("#cpp").addEventListener("input", e => {
148
- cpp = e.target.value
149
- console.log(cpp);
150
- data = { ...data, cpp }
151
- tympanogram.update(data)
152
- })
153
-
154
- return firstInput
155
- }
156
-
157
-
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
-