hayun-vite 0.13.0 → 0.14.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/src/Form/Form.js CHANGED
@@ -9,18 +9,19 @@ import MultiText from "../MultiText/MultiText.js";
9
9
  const svgNS = "http://www.w3.org/2000/svg";
10
10
 
11
11
  export default class Form {
12
- constructor({ container, template } = {}) {
12
+ constructor({ container, template, mode = "production" } = {}) {
13
13
  this.template = template;
14
14
  this.container = container;
15
+ this.mode = mode;
15
16
  this.data = {};
16
17
  let { width, height, margin, paper } = template;
17
- this.page = this.create({ paper, margin });
18
- this.page.style.display = 'none';
18
+ this.svg = this.create({ paper, margin }); // اس‌وی‌جی مادر فرم را صفحه نامگذاری میکنیم بذاریم همون اس‌وی‌جی؟
19
+ this.svg.style.display = 'none';
19
20
  let dims;
20
21
  // رسم مارجین های فرم
21
- this.drawMarginLines({ container: this.page, width, height });
22
+ this.drawMarginLines({ container: this.svg, width, height });
22
23
 
23
- const sections = new Sections({ container: this.page, dims: template });
24
+ const sections = new Sections({ container: this.svg, dims: template });
24
25
  this.sections = sections;
25
26
 
26
27
  if (sections.header) {
@@ -57,51 +58,53 @@ export default class Form {
57
58
  })
58
59
  }
59
60
  if (sections['Speech Titles']) {
60
- dims= template['Speech Titles'];
61
+ dims = template['Speech Titles'];
61
62
  const titles = new MultiText({ container: sections['Speech Titles'], dims });
62
63
  }
63
64
  if (sections['RSpeech']) {
64
- dims= template.RSpeech
65
- this.RSpeech = new Speech({ container: sections.RSpeech, side: 'R', dims})
65
+ dims = template.RSpeech
66
+ this.RSpeech = new Speech({ container: sections.RSpeech, side: 'R', dims })
66
67
  }
67
68
  if (sections.LSpeech) {
68
- dims= template.LSpeech
69
+ dims = template.LSpeech
69
70
  this.LSpeech = new Speech({ container: sections.LSpeech, side: 'L', dims })
70
71
  }
71
72
  if (sections['Tympanogram Titles']) {
72
- dims= template['Tympanogram Titles'];
73
+ dims = template['Tympanogram Titles'];
73
74
  new MultiText({ container: sections['Tympanogram Titles'], dims });
74
75
  }
75
76
  if (sections.RTympanogram) {
76
- dims= template.RTympanogram
77
+ dims = template.RTympanogram
77
78
  this.RTympanogram = new Tympanogram({ container: sections.RTympanogram, side: 'R', dims })
78
79
  }
79
80
  if (sections.LTympanogram) {
80
- dims= template.LTympanogram
81
+ dims = template.LTympanogram
81
82
  this.LTympanogram = new Tympanogram({ container: sections.LTympanogram, side: 'L', dims })
82
83
  }
83
84
  if (sections['Reflex Titles']) {
84
- dims= template['Reflex Titles'];
85
+ dims = template['Reflex Titles'];
85
86
  const titles = new MultiText({ container: sections['Reflex Titles'], dims });
86
87
  }
87
88
  if (sections.RReflex) {
88
- dims= template.RReflex
89
+ dims = template.RReflex
89
90
  this.RReflex = new Reflex({ container: sections.RReflex, side: 'R', dims })
90
91
  }
91
92
  if (sections.LReflex) {
92
- dims= template.LReflex
93
+ dims = template.LReflex
93
94
  this.LReflex = new Reflex({ container: sections.LReflex, side: 'L', dims })
94
95
  }
95
96
  if (sections.report) {
96
- dims= template.report;
97
+ dims = template.report;
97
98
  this.report = new MultiText({ container: sections.report, dims })
98
99
  }
99
100
  if (sections.footer) {
100
- dims= template.footer;
101
- this.footer = new MultiText({ container: sections.footer, dims})
101
+ dims = template.footer;
102
+ this.footer = new MultiText({ container: sections.footer, dims })
102
103
  }
103
104
 
104
- this.container.appendChild(this.page);
105
+ this.container.appendChild(this.svg);
106
+
107
+ this.addEvent()
105
108
  }
106
109
 
107
110
 
@@ -130,43 +133,35 @@ export default class Form {
130
133
  return svg
131
134
  }
132
135
 
133
- update({ data, officeData, patientData, sessionIndex = 0 }) {
136
+ update({ officeData, patientData, sessionIndex = 0 }) {
134
137
 
135
138
  const session = patientData.sessions[sessionIndex]
136
- // Prevent undefined error
137
- if (!data) {
138
- data = {
139
- common: {
140
- audiometer: "",
141
- tympanometers: "",
142
- },
143
- header: {
144
- officeName: officeData.name,
145
- officeLogo: officeData.logo,
146
- createDate: patientData.sessions[sessionIndex]?.createDate,
147
- },
148
- patient: {
149
- name: patientData.name,
150
- lastName: patientData.lastName,
151
- gender: patientData?.gender,
152
- // خط زیر محاسبه درست سن هست. موقتا کامنت می‌شود تا در اپ اصلی فیلد سن رو در سشن ها قرار دهیم
153
- // age: patientData.sessions[sessionIndex]?.age,
154
- age: patientData?.age,
155
- referrer: patientData.sessions[sessionIndex]?.referrer,
156
- date: new Date().toLocaleDateString('fa-IR'),
157
-
158
- },
159
- footer: {
160
- address: officeData.addresses[0],
161
- tel: officeData.tels[0],
162
- },
163
- id: +sessionIndex + 1,
164
- };
165
- // data = { audiogram: {}, common: {}, footer: {}, header: {}, patient: {}, reflex: {}, report: {}, speech: {}, tympanometry: {} }
166
- }
167
- // find which data reach and then call corresponding update function
168
- // get array of keys (audiogram, header, footer, ...)
169
- let keys = Object.keys(data)
139
+
140
+ let data = {
141
+
142
+ header: {
143
+ officeName: officeData.name,
144
+ officeLogo: officeData.logos[officeData.selectedLogoIndex],
145
+ createDate: patientData.sessions[sessionIndex]?.createDate,
146
+ },
147
+ patient: {
148
+ name: patientData.name,
149
+ lastName: patientData.lastName,
150
+ gender: patientData?.gender,
151
+ // خط زیر محاسبه درست سن هست. موقتا کامنت می‌شود تا در اپ اصلی فیلد سن رو در سشن ها قرار دهیم
152
+ // age: patientData.sessions[sessionIndex]?.age,
153
+ age: patientData?.age,
154
+ referrer: patientData.sessions[sessionIndex]?.referrer,
155
+ date: new Date().toLocaleDateString('fa-IR'),
156
+ },
157
+ footer: {
158
+ address: officeData.addresses[0],
159
+ tel: officeData.tels[0],
160
+ },
161
+ id: +sessionIndex + 1,
162
+ };
163
+
164
+ // let keys = Object.keys(data)
170
165
  // if (keys.includes("header")) {
171
166
 
172
167
  this.header?.update(data.header)
@@ -175,7 +170,6 @@ export default class Form {
175
170
  this.patient?.update(data.patient)
176
171
  // }
177
172
  // if (keys.includes("history")) {
178
-
179
173
  this.history?.update(session?.history)
180
174
  this.data.history = session.history;
181
175
  // }
@@ -204,11 +198,8 @@ export default class Form {
204
198
  this.data.report = session.report;
205
199
  // }
206
200
  // if (keys.includes("footer")) {
207
- // console.log("footer Data:", data?.footer);
208
-
209
201
  this.footer?.update(data?.footer)
210
202
  this.data.footer = data.footer;
211
- // }
212
203
  }
213
204
 
214
205
  // خطوط نقطه چین مارجین فرم
@@ -224,4 +215,12 @@ export default class Form {
224
215
  `;
225
216
  putRect({ container, x: 0, y: 0, width, height, style, className: 'no-print' })
226
217
  }
218
+
219
+ // افزودن رویداد کلیک روی فرم
220
+ addEvent({ } = {}) {
221
+ this.svg.addEventListener("click", e => {
222
+ console.log(e.target.dataset['name']);
223
+
224
+ })
225
+ }
227
226
  }
@@ -1,32 +1,28 @@
1
1
  // import '../styles.css' // برای تست منتقل شد به فایل ایندکس اصلی اچ‌تی‌ام‌ال و برای توسعه منتقل شده به ایندکس جی اس
2
- import putLine from "../common/putLine.js";
3
- import printForm from "./printForm.js";
4
- import Form from "../Form/Form.js";
2
+ import printForm from "./printForm.js"
3
+ import Form from "../Form/Form.js"
4
+ import putGrid from "../common/putGrid.js"
5
5
 
6
- const svgNS = "http://www.w3.org/2000/svg";
6
+ const svgNS = "http://www.w3.org/2000/svg"
7
7
 
8
- // import combo from "./templates/combo.js"; // این در حقیقیت یک تمپلت هست
9
- // import rasaAud from "./templates/rasa_audiometry.js";
10
- // import rasaTymp from './templates/rasa_tymp_reflex.js'
11
-
12
- // خط کد زیر لازم هست
13
- // import '/fonts/webfonts/Vazirmatn-Regular.woff2'
8
+ import templCombo from "../../assets/templates/templCombo.js" // این در حقیقیت یک تمپلت هست
9
+ import templAudiometry from "../../assets/templates/templAudiometry.js"
14
10
 
15
11
  // کلاس جدید که فرم‌های مختلف را نمایش میدهد
16
12
  export default class Forms {
17
13
  constructor({ assets, container, templates, defaultTemplateIndex = 0, mode = 'production' } = {}) {
18
14
  this.container = container
19
15
  this.mode = mode;
20
- // this.addForms({ templates: [rasaAud, rasaTymp, combo], defaultTemplateIndex })
21
- this.addForms({ templates, defaultTemplateIndex })
16
+ this.forms = [] // آرایه آبجکت های فرم های مختلف
17
+ this.addForms({ templates: [templCombo, templAudiometry], defaultTemplateIndex })
22
18
  }
23
19
 
24
20
  // افزودن فرم
25
21
  addForms({ templates, defaultTemplateIndex }) {
22
+ const forms = this.forms;
26
23
  const container = this.container
27
24
  // ایجاد یک دیو برای قرار دادن دکمه ها و لینک های فرم
28
25
  const div = document.createElement('div');
29
-
30
26
  div.style = 'border: 1px solid brown; margin: 0; padding: 0;'
31
27
  container.appendChild(div);
32
28
 
@@ -34,101 +30,88 @@ export default class Forms {
34
30
  let className = 'button-form persian';
35
31
  const btns = [];
36
32
 
37
- const forms = []; // آرایه آبجکت های فرم های مختلف
38
- this.forms = forms;
39
-
40
33
  templates.
41
34
  forEach((template, index) => {
35
+
42
36
  this.mode == 'develop' &&
43
- (btns[index] = this.putButton({ container: div, text: template.label, className }));
44
- this.forms.push(new Form({ container, template }));
45
- });
37
+ (btns[index] = this.putButton({ container: div, text: template.label, className }))
38
+ this.forms.push(new Form({ container, template, mode: this.mode }))
39
+ })
40
+
46
41
 
47
42
  // انتخاب فرم پیش‌فرض
48
- let selectedIndex = defaultTemplateIndex;
49
- forms[selectedIndex].page.style.display = 'block';
50
- this.selectedForm = this.forms[selectedIndex];
51
- (this.mode == 'develop') && (btns[selectedIndex].style.backgroundColor = ' #1c15e1');
43
+ let selectedIndex = defaultTemplateIndex
44
+ this.selectedIndex = selectedIndex // برای استفاده در متد آپدیت
52
45
 
53
- if (this.mode == 'develop') {
46
+ forms[selectedIndex].svg.style.display = 'block'
47
+ // this.selectedForm = this.forms[selectedIndex] // سمی‌کالن واجب
54
48
 
55
- const printBtn = this.putButton({ container: div, text: 'چاپ', className });
56
- // تعریف رویداد دکمه چاپ فرم نمایشی
57
- printBtn.addEventListener('click', () => { printForm({ container: this.selectedForm.page }) });
49
+ this.mode == 'develop' &&
50
+ (btns[selectedIndex].style.backgroundColor = ' #1c15e1') // اگر عبارت اول توی پرانتز باشه سمی‌کالن واجب
58
51
 
52
+ // به ازای هر فرم یک دکمه هم به دیو بالای فرم اضافه میکند در حالت دولوپ
53
+ // افزودن دکمه مربوطه به فرمها به دام
54
+ this.mode == 'develop' &&
59
55
  btns.forEach((btn, index) => {
60
56
  btn.addEventListener('click', () => {
61
57
  // Hide All forms
62
58
  forms.forEach((form, i) => {
63
- form.page.style.display = 'none'
59
+ form.svg.style.display = 'none'
64
60
  btns[i].style.backgroundColor = ' #7472e2'
61
+ })
65
62
 
66
- });
67
-
68
- forms[index].page.style.display = 'block';
63
+ forms[index].svg.style.display = 'block'
69
64
  btns[index].style.backgroundColor = ' #1c15e1'
70
65
 
71
- this.selectedForm = forms[index];
66
+ // this.selectedForm = forms[index]
72
67
  selectedIndex = index
73
- this.update(this.allData);
68
+ this.selectedIndex = selectedIndex
69
+ this.update(this.dataParams)
74
70
  })
75
- })
71
+ }) // سمی‌کالن واجب
76
72
 
77
- // دکمه نمایش و پنهان خطوط سکشن
78
- this.putButton({ container: div, text: 'Show/Hide Section Borders', className })
79
- .addEventListener('click', () => {
80
- this.toggleDisplay({ container: forms[selectedIndex].page, borderName: 'section-border' })
81
- });
82
-
83
- // دکمه نمایش و پنهان خطوط بوردر
84
- this.putButton({ container: div, text: 'Show/Hide Box Borders', className })
85
- .addEventListener('click', () => {
86
- this.toggleDisplay({ container: forms[selectedIndex].page, borderName: 'box-border' })
87
- });
88
-
89
- // دکمه نمایش و پنهان شطرنجی
90
- this.putButton({ container: div, text: 'Show/Hide Grid', className })
91
- .addEventListener('mouseenter', () => {
92
- this.grid({ container: forms[selectedIndex].page })
93
- });
94
- // فراخوانی تابع شطرنجی در اولین اجرا
95
- this.grid({ container: forms[selectedIndex].page })
96
- }
73
+ // افزودن چهار دکمه چاپ صفحه فرم انتخاب شده و تاگل پنهان یا نمایش
74
+ this.mode == 'develop' &&
75
+ this.addButtons({ container: div, className, svg: forms[selectedIndex].svg })
97
76
  }
98
77
 
99
- grid({ container }) {
100
- console.log(container);
101
- const cord = { xStart: -5, yStart: -5, xEnd: 210 - 5, yEnd: 297 - 5, xStep: 1, yStep: 1 }
102
- let { xStart, yStart, xEnd, yEnd, xStep, yStep } = cord
78
+ // افزودن چهار دکمه چاپ صفحه فرم انتخاب شده و تاگل پنهان یا نمایش
79
+ addButtons({ container, className, svg }) {
103
80
 
104
- // رسم خطوط افقی
105
- let style = 'stroke: blue; stroke-width: 0.05 ; stroke-opacity: 0.8; stroke-dasharray: 0.2;'
106
- let x1 = xStart
107
- let y1
108
-
109
- let x2 = xEnd
110
- let y2
81
+ // تعریف دکمه و رویداد دکمه چاپ صفحه فرم نمایشی
82
+ this.putButton({ container, text: 'چاپ', className })
83
+ .addEventListener('click', () => {
84
+ printForm({ container: this.forms[this.selectedIndex].svg })
85
+ });
111
86
 
112
- for (let y1 = yStart; y1 <= yEnd; y1 += yStep) {
113
- y2 = y1
114
- putLine({ container, x1, y1, x2, y2, style, name: 'grid' })
115
- }
87
+ // دکمه و رویداد نمایش و پنهان خطوط سکشن
88
+ this.putButton({ container, text: 'Show/Hide Section Borders', className })
89
+ .addEventListener('click', () => {
90
+ this.toggleDisplay({ container: svg, borderName: 'section-border' })
91
+ });
116
92
 
117
- // رسم خطوط عمودی
118
- y1 = yStart
119
- for (x1 = xStart; x1 <= xEnd; x1 += xStep) {
120
- const x2 = x1
121
- putLine({ container, x1, y1, x2, y2, style, name: 'grid' })
122
- }
93
+ // دکمه و رویداد نمایش و پنهان خطوط بوردر
94
+ this.putButton({ container, text: 'Show/Hide Box Borders', className })
95
+ .addEventListener('click', () => {
96
+ this.toggleDisplay({ container: svg, borderName: 'box-border' })
97
+ });
123
98
 
99
+ // دکمه نمایش و پنهان شطرنجی
100
+ this.putButton({ container, text: 'Show/Hide Grid', className })
101
+ .addEventListener('mouseenter', () => {
102
+ putGrid({ container: svg })
103
+ });
104
+ // فراخوانی تابع شطرنجی در اولین اجرا
105
+ // putGrid({ container: forms[selectedIndex].svg })
124
106
 
125
107
  }
126
108
 
127
109
  // این تابع یک بار از بیرون کلاس فراخوانی میشه و یک بار وقتی از داخل تمپلت فرم را عوض میکنیم
128
- update({ data, officeData, patientData, sessionIndex = 0 }) {
110
+ update({ officeData, patientData, sessionIndex = 0 }) {
129
111
  // ذخیره کل دیتا برای استفاده داخلی آپدیت فرم انتخاب شده
130
- this.allData = { data, officeData, patientData, sessionIndex }
131
- this.selectedForm.update({ data, officeData, patientData, sessionIndex })
112
+ this.dataParams = { officeData, patientData, sessionIndex }
113
+ // this.selectedForm.update({ officeData, patientData, sessionIndex })
114
+ this.forms[this.selectedIndex].update(this.dataParams)
132
115
  }
133
116
 
134
117
  // توابع داخلی ایجاد دکمه و لینک های بالای فرم
@@ -0,0 +1,18 @@
1
+ import { officeData, patientData } from "../../assets/data/sampleData";
2
+ import templAudiometry from "../../assets/templates/templAudiometry";
3
+ import templCombo from "../../assets/templates/templCombo";
4
+ import Forms from "./Forms";
5
+
6
+ document.querySelector('#app').innerHTML = `
7
+ <div id="test"></div>
8
+ `;
9
+
10
+ const container = document.getElementById('test')
11
+
12
+ const forms = new Forms({ container, templates: [templCombo, templAudiometry], mode: 'develop' });
13
+
14
+ forms.update({ officeData, patientData, sessionIndex: 0 })
15
+
16
+ // خط برای کپی پیست نقشی در کد ندارد
17
+
18
+
@@ -18,11 +18,11 @@ export default class Header {
18
18
  let x = dims.margin.left;
19
19
  let y = dims.margin.top;
20
20
 
21
- const svg = putSVG({ x, y, width, height, style: 'direction: rtl !important; user-select: none;' })
21
+ const svg = putSVG({ x, y, width, height, style: 'font-family: Vazir; direction: rtl !important; user-select: none;' })
22
22
 
23
23
  // Logo
24
24
  let image = document.createElementNS(svgNS, "image");
25
- image.setAttribute("data-name", "officeLogo")
25
+ image.setAttribute("data-name", "officeLogo") // برای تابع آپدیت استفاده می‌شود
26
26
  image.setAttribute("width", "17");
27
27
  image.setAttribute("height", height - 1);
28
28
  image.setAttribute("x", width - 16);
@@ -30,14 +30,10 @@ export default class Header {
30
30
  svg.appendChild(image);
31
31
 
32
32
  let style = `
33
- user-select: none;
34
- direction: rtl;
35
- /* text-align: center; */
36
- font-family: Vazir;
37
33
  font-size: 0.8mm;
38
34
  font-weight: bolder;
39
- text-anchor: start; /*تراز افقی*/
40
- dominant-baseline: auto; /* تراز عمودی*/
35
+ text-anchor: start;
36
+ dominant-baseline: auto;
41
37
  `;
42
38
 
43
39
  // اگر مقدار استروک درست بود لیبل ها را چاپ کن
@@ -87,16 +87,18 @@ export default class MultiText {
87
87
  const textInput = this.container.querySelector(`text[data-name=${input.name}]`)
88
88
 
89
89
  // پیدا کردن کاراکترهای رفتن به سرخط در متن
90
- const textLines = value.toString().split(/\n|\r|\r\n/);
91
- const x = textInput.getAttribute('x')
92
- // اگر متن چند خطی بود
93
- if (textLines.length >= 2) {
94
- let y = 5;
95
- textLines.forEach(value => {
96
- putTspan({ container: textInput, value, x, y });
97
- y += 6;
98
- })
99
- } else textInput.innerHTML = value || "";
90
+ if (value) {
91
+ const textLines = value.toString().split(/\n|\r|\r\n/);
92
+ const x = textInput.getAttribute('x')
93
+ // اگر متن چند خطی بود
94
+ if (textLines.length >= 2) {
95
+ let y = 5;
96
+ textLines.forEach(value => {
97
+ putTspan({ container: textInput, value, x, y });
98
+ y += 6;
99
+ })
100
+ } else textInput.innerHTML = value || "";
101
+ }
100
102
  });
101
103
  }
102
104
  }
@@ -12,25 +12,31 @@ export default class Tympanogram {
12
12
  this.draw({ dims })
13
13
  }
14
14
 
15
- draw({ dims, extraCompliance = false }) {
16
- let width = dims.width;
17
- let height = dims.height;
15
+ draw({ dims }) {
16
+ // پاک کردن چارت قبلی اگر وجود دارد
17
+ this.chart && this.chart.remove()
18
+
19
+ // داده‌های یونتیت خوانده میشود و بعد داده‌های دیمز به آن اضافه می‌‌شودکه می‌تواند جایگزین داده‌های قبلی یونیتز شود
20
+ dims = { ...units, ...dims }
21
+
22
+ let { width, height } = dims
18
23
  let x = dims.margin.left;
19
24
  let y = dims.margin.top;
20
- let style;
25
+ const { extraCompliance, compensated } = dims
21
26
 
22
27
  const { pressure, padding, styles } = units
23
28
 
24
29
  const compliance = extraCompliance ? units.compliance.extra : units.compliance.normal
25
30
 
26
-
27
31
  let { vbWidth, vbHeight } = units;
28
32
 
29
33
  // کل چارت
34
+ let style
30
35
  style = styles.svg
31
36
  vbHeight = (vbWidth * height) / width // متناسب سازی ارتفاع ویباکس با پهنا و ارتفاع ورودی
32
37
  const viewBox = [-padding.left, -padding.top, vbWidth, vbHeight].join(' ')
33
38
  const svg = putSVG({ x, y, width, height, viewBox, style })
39
+ this.chart = svg;
34
40
  // این خط شد دو خط کد طلایی که مشکل سایز فونت در دیسپلی و کاغذ رو حل کرد
35
41
  width = vbWidth; // ثابت می‌ماند همیشه
36
42
  height = vbHeight // با نسبت پهنا و ارتفاع ورودی تغییر میکند
@@ -45,7 +51,10 @@ export default class Tympanogram {
45
51
  mm: height - (padding.top + padding.bottom)
46
52
  }
47
53
 
48
- this.chartInfo = { pressure, compliance, padding, pressureAxiosLength, complianceAxiosLength }
54
+ this.chartInfo = {
55
+ pressure, compliance, padding,
56
+ pressureAxiosLength, complianceAxiosLength, compensated,
57
+ }
49
58
 
50
59
  // point({ container: svg, x: getX(pressure.min), y: getY(compliance.max), color: 'red' })
51
60
  // point({ container: svg, x: getX(pressure.max), y: getY(compliance.min), color: 'green' })
@@ -175,7 +184,7 @@ export default class Tympanogram {
175
184
  putText({
176
185
  container: svg, value: c.toFixed(1),
177
186
  x, y: getY(c), dx: -1,
178
- style: style,
187
+ style,
179
188
  });
180
189
  }
181
190
 
@@ -193,8 +202,9 @@ export default class Tympanogram {
193
202
  style = 'fill: transparent; stroke: green; stroke-width: 0.5;';
194
203
  // یک بوردر راهنمای توسعه برای اس‌ وی جی به تمام پهنا و ارتفاع رسم می‌کنیم
195
204
  putRect({ container: svg, x: -padding.left, y: -padding.top, width, height, name: dims.name, style })
196
- this.chart = svg;
197
205
  this.container.appendChild(svg);
206
+ // اگر آبجکت از قبل دیتایی دارد اون رو آپدیت کن
207
+ this.data && this.update(this.data)
198
208
 
199
209
  // بلاک توابع داخلی مورد نیاز تابع اصلی
200
210
  // توابع تبدیل فشار و کامپلیانس به مختصات میلیمتر
@@ -229,14 +239,9 @@ export default class Tympanogram {
229
239
  }
230
240
 
231
241
  update(data) {
232
- let { ECV, SC, MEP, G, extraCompliance } = data
242
+ this.data = data
243
+ let { ECV, SC, MEP, G } = data
233
244
 
234
- // اگر اکسترا کامپلیانس بود چارت دوباره باید رسم شود و چارت قبلی پاک شود
235
- if (extraCompliance) {
236
- this.chart.remove()
237
- this.draw({ dims: this.dims, extraCompliance })
238
- }
239
-
240
245
  // تبدبل اعداد رشته ای به عدد با دو رقم اعشاری
241
246
  ECV && (ECV = (+ECV).toFixed(2));
242
247
  SC && (SC = (+SC).toFixed(2));
@@ -256,33 +261,38 @@ export default class Tympanogram {
256
261
 
257
262
  // توابع داخلی
258
263
  drawCurve(data) {
259
- let { Type, ECV, SC, MEP, G, expanded } = data
260
-
264
+ let { Type, ECV, SC, MEP, G, expanded, cp, cpp } = data
261
265
 
262
266
  // Ensure to Convert to Numbers //
263
- SC = +SC;
264
- ECV = +ECV;
265
- MEP = +MEP;
266
- G = +G;
267
+ SC = +SC
268
+ ECV = +ECV
269
+ MEP = +MEP
270
+ G = +G
271
+ cp = +cp
272
+ cpp = +cpp
267
273
 
268
274
  // اگر این مقادیر وجود نداشته باشه مقدار صفر میدیم بهشون که خطا در رسم منحنی نخوریم
269
275
  SC || (SC = 0)
270
276
  MEP || (MEP = 0)
271
277
 
272
-
273
278
  const container = this.chart
274
- const { pressure, compliance, pressureAxiosLength, complianceAxiosLength } = this.chartInfo;
279
+ const { pressure, compliance, pressureAxiosLength, complianceAxiosLength, compensated } = this.chartInfo;
280
+
281
+ let cmp = 0 // for non-compensated
282
+ compensated && (cmp = ECV)
275
283
 
276
284
  // مقداردهی دستی برای تست شکل منحنی
277
285
  // data.SC = 0.5;
278
286
  // data.MEP = -75;
279
287
  // با توجه به اندازه اس ‌سی میشه برای مقادیر زیر یک سری رل گذاشت با منحنی قشنگ تر باشد
280
- let cp = 70 // جابجایی نقطه کنترل منحنی های راست و چپ روی محور افقی
288
+ // let cp = 70 // جابجایی نقطه کنترل منحنی های راست و چپ روی محور افقی
289
+ !cp && (cp = 70)
281
290
  // let k = 0.5; // width and height change [0, 1]
282
- let cpp = 5 //جابجایی نقطه کنترل قله ها روی محور افقی
291
+ !cpp && (cpp = 5) //جابجایی نقطه کنترل قله ها روی محور افقی
283
292
  // رل‌هایی برای تغییر مقادیر بالا برای زیبایی بیشتر منحنی در نقطه قله
284
293
  // (data.SC <= 0.30)? k=0
285
- let k = (SC > 0.30) ? 0.5 : 0.1 // width and height change [0, 1]
294
+ let k
295
+ k = (SC > 0.30) ? 0.5 : 0.1 // width and height change [0, 1]
286
296
  k = (SC > 1.0) ? 0.2 : k
287
297
  // k = (data.SC < 1.0) ? 0 : k;
288
298
 
@@ -299,24 +309,24 @@ export default class Tympanogram {
299
309
 
300
310
  const curve = {
301
311
  R: {
302
- P1: { p: RV.max, c: 0 },
303
- P2: { p: MEP + pw, c: SC - ph },
304
- C: { p: MEP + cp, c: 0 }
312
+ P1: { p: RV.max, c: cmp },
313
+ P2: { p: MEP + pw, c: cmp + SC - ph },
314
+ C: { p: MEP + cp, c: cmp }
305
315
  },
306
316
  RM: {
307
317
  P1: {}, // Define later
308
- P2: { p: MEP, c: SC },
309
- C: { p: MEP + cpp, c: SC }
318
+ P2: { p: MEP, c: cmp + SC },
319
+ C: { p: MEP + cpp, c: cmp + SC }
310
320
  },
311
321
  LM: {
312
322
  P1: {}, // Define later
313
- P2: { p: MEP - pw, c: SC - ph },
314
- C: { p: MEP - cpp, c: SC }
323
+ P2: { p: MEP - pw, c: cmp + SC - ph },
324
+ C: { p: MEP - cpp, c: cmp + SC }
315
325
  },
316
326
  L: {
317
327
  P1: {}, // Define later
318
- P2: { p: RV.min, c: 0 },
319
- C: { p: MEP - cp, c: 0 }
328
+ P2: { p: RV.min, c: cmp },
329
+ C: { p: MEP - cp, c: cmp }
320
330
  }
321
331
  }
322
332