@decidables/accumulable-elements 0.1.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.
@@ -0,0 +1,146 @@
1
+
2
+ import {html} from 'lit';
3
+
4
+ import '@decidables/decidables-elements/spinner';
5
+ import DDMMath from '@decidables/accumulable-math';
6
+
7
+ import DDMEquation from './ddm-equation';
8
+
9
+ /*
10
+ DDMEquationAZV2PC element
11
+ <ddm-equation-azv2pc>
12
+
13
+ Attributes:
14
+ */
15
+ export default class DDMEquationAZV2PC extends DDMEquation {
16
+ static get properties() {
17
+ return {
18
+ a: {
19
+ attribute: 'boundary-separation',
20
+ type: Number,
21
+ reflect: true,
22
+ },
23
+ z: {
24
+ attribute: 'starting-point',
25
+ type: Number,
26
+ reflect: true,
27
+ },
28
+ v: {
29
+ attribute: 'drift-rate',
30
+ type: Number,
31
+ reflect: true,
32
+ },
33
+
34
+ accuracy: {
35
+ attribute: false,
36
+ type: Number,
37
+ reflect: false,
38
+ },
39
+ };
40
+ }
41
+
42
+ constructor() {
43
+ super();
44
+ this.a = 1.5;
45
+ this.z = 0.5;
46
+ this.v = 0.1;
47
+ this.alignState();
48
+ }
49
+
50
+ alignState() {
51
+ this.accuracy = DDMMath.azv2pC(this.a, this.z, this.v);
52
+ }
53
+
54
+ sendEvent() {
55
+ this.dispatchEvent(new CustomEvent('ddm-equation-azv2pc-change', {
56
+ detail: {
57
+ a: this.a,
58
+ z: this.z,
59
+ v: this.v,
60
+ accuracy: this.accuracy,
61
+ },
62
+ bubbles: true,
63
+ }));
64
+ }
65
+
66
+ aInput(event) {
67
+ this.a = parseFloat(event.target.value);
68
+ this.alignState();
69
+ this.sendEvent();
70
+ }
71
+
72
+ zInput(event) {
73
+ this.z = parseFloat(event.target.value);
74
+ this.alignState();
75
+ this.sendEvent();
76
+ }
77
+
78
+ vInput(event) {
79
+ this.v = parseFloat(event.target.value);
80
+ this.alignState();
81
+ this.sendEvent();
82
+ }
83
+
84
+ willUpdate() {
85
+ this.alignState();
86
+ }
87
+
88
+ render() {
89
+ let a;
90
+ let z;
91
+ let v;
92
+ let s;
93
+ let accuracy;
94
+ if (this.numeric) {
95
+ a = html`<decidables-spinner class="a bottom" ?disabled=${!this.interactive} min="0.1" max="2" step="0.01" .value="${this.a}" @input=${this.aInput.bind(this)}>
96
+ <var class="math-var">a</var>
97
+ </decidables-spinner>`;
98
+ z = html`<decidables-spinner class="z bottom" ?disabled=${!this.interactive} min="0.01" max="0.99" step="0.01" .value="${this.z}" @input=${this.zInput.bind(this)}>
99
+ <var class="math-var">z</var>
100
+ </decidables-spinner>`;
101
+ v = html`<decidables-spinner class="v bottom" ?disabled=${!this.interactive} min="0.01" max="5" step="0.01" .value="${this.v}" @input=${this.vInput.bind(this)}>
102
+ <var class="math-var">v</var>
103
+ </decidables-spinner>`;
104
+ s = html`<decidables-spinner class="s bottom" disabled min="0.01" max="1" step="0.01" .value="${DDMMath.s}">
105
+ <var class="math-var">s</var>
106
+ </decidables-spinner>`;
107
+ accuracy = html`<decidables-spinner class="accuracy bottom" disabled min="0" max="1" step="0.01" .value="${+this.accuracy.toFixed(2)}">
108
+ <var>Accuracy</var>
109
+ </decidables-spinner>`;
110
+ } else {
111
+ a = html`<var class="math-var a">a</var>`;
112
+ z = html`<var class="math-var z">z</var>`;
113
+ v = html`<var class="math-var v">v</var>`;
114
+ s = html`<var class="math-var s">s</var>`;
115
+ accuracy = html`<var class="accuracy">Accuracy</var>`;
116
+ }
117
+ const equation = html`
118
+ <tr>
119
+ <td rowspan="2">
120
+ ${accuracy}<span class="equals">=</span>
121
+ </td>
122
+ <td class="underline">
123
+ <var class="math-greek e tight">e</var><sup class="exp"><span class="minus tight">−</span><span class="paren tight">(</span>2${v}${a} / ${s}<sup class="exp">2</sup><span class="paren tight">)</span></sup>
124
+ <span class="minus">−</span>
125
+ <var class="math-greek e tight">e</var><sup class="exp"><span class="minus tight">−</span><span class="paren tight">(</span>2${v}${z} / ${s}<sup class="exp">2</sup><span class="paren tight">)</span></sup>
126
+ </td>
127
+ </tr>
128
+ <tr>
129
+ <td>
130
+ <var class="math-greek e tight">e</var><sup class="exp"><span class="minus tight">−</span><span class="paren tight">(</span>2${v}${a} / ${s}<sup class="exp">2</sup><span class="paren tight">)</span></sup>
131
+ <span class="minus">−</span>
132
+ 1
133
+ </td>
134
+ </tr>`;
135
+ return html`
136
+ <div class="holder">
137
+ <table class="equation">
138
+ <tbody>
139
+ ${equation}
140
+ </tbody>
141
+ </table>
142
+ </div>`;
143
+ }
144
+ }
145
+
146
+ customElements.define('ddm-equation-azv2pc', DDMEquationAZV2PC);
@@ -0,0 +1,182 @@
1
+
2
+ import {html} from 'lit';
3
+
4
+ import '@decidables/decidables-elements/spinner';
5
+ import DDMMath from '@decidables/accumulable-math';
6
+
7
+ import DDMEquation from './ddm-equation';
8
+
9
+ /*
10
+ DDMEquationAZVT02M element
11
+ <ddm-equation-azvt02m>
12
+
13
+ Attributes:
14
+ */
15
+ export default class DDMEquationAZVT02M extends DDMEquation {
16
+ static get properties() {
17
+ return {
18
+ a: {
19
+ attribute: 'boundary-separation',
20
+ type: Number,
21
+ reflect: true,
22
+ },
23
+ z: {
24
+ attribute: 'starting-point',
25
+ type: Number,
26
+ reflect: true,
27
+ },
28
+ v: {
29
+ attribute: 'drift-rate',
30
+ type: Number,
31
+ reflect: true,
32
+ },
33
+ t0: {
34
+ attribute: 'nondecision-time',
35
+ type: Number,
36
+ reflect: true,
37
+ },
38
+
39
+ meanRT: {
40
+ attribute: false,
41
+ type: Number,
42
+ reflect: false,
43
+ },
44
+ };
45
+ }
46
+
47
+ constructor() {
48
+ super();
49
+ this.a = 1.5;
50
+ this.z = 0.5;
51
+ this.v = 0.1;
52
+ this.t0 = 200;
53
+ this.alignState();
54
+ }
55
+
56
+ alignState() {
57
+ this.meanRT = DDMMath.azvt02m(this.a, this.z, this.v, this.t0);
58
+ }
59
+
60
+ sendEvent() {
61
+ this.dispatchEvent(new CustomEvent('ddm-equation-azvt02m-change', {
62
+ detail: {
63
+ a: this.a,
64
+ z: this.z,
65
+ v: this.v,
66
+ t0: this.t0,
67
+ meanRT: this.meanRT,
68
+ },
69
+ bubbles: true,
70
+ }));
71
+ }
72
+
73
+ aInput(event) {
74
+ this.a = parseFloat(event.target.value);
75
+ this.alignState();
76
+ this.sendEvent();
77
+ }
78
+
79
+ zInput(event) {
80
+ this.z = parseFloat(event.target.value);
81
+ this.alignState();
82
+ this.sendEvent();
83
+ }
84
+
85
+ vInput(event) {
86
+ this.v = parseFloat(event.target.value);
87
+ this.alignState();
88
+ this.sendEvent();
89
+ }
90
+
91
+ t0Input(event) {
92
+ this.t0 = parseFloat(event.target.value);
93
+ this.alignState();
94
+ this.sendEvent();
95
+ }
96
+
97
+ willUpdate() {
98
+ this.alignState();
99
+ }
100
+
101
+ render() {
102
+ let a;
103
+ let z;
104
+ let v;
105
+ let t0;
106
+ let s;
107
+ let meanRT;
108
+ if (this.numeric) {
109
+ a = html`<decidables-spinner class="a bottom" ?disabled=${!this.interactive} min="0.1" max="2" step="0.01" .value="${this.a}" @input=${this.aInput.bind(this)}>
110
+ <var class="math-var">a</var>
111
+ </decidables-spinner>`;
112
+ z = html`<decidables-spinner class="z bottom" ?disabled=${!this.interactive} min="0.01" max="0.99" step="0.01" .value="${this.z}" @input=${this.zInput.bind(this)}>
113
+ <var class="math-var">z</var>
114
+ </decidables-spinner>`;
115
+ v = html`<decidables-spinner class="v bottom" ?disabled=${!this.interactive} min="0.01" max="5" step="0.01" .value="${this.v}" @input=${this.vInput.bind(this)}>
116
+ <var class="math-var">v</var>
117
+ </decidables-spinner>`;
118
+ t0 = html`<decidables-spinner class="t0 bottom" ?disabled=${!this.interactive} min="0" max="500" step="1" .value="${this.t0}" @input=${this.t0Input.bind(this)}>
119
+ <var class="math-var">t<sub>0</sub></var>
120
+ </decidables-spinner>`;
121
+ s = html`<decidables-spinner class="s bottom" disabled min="0.01" max="1" step="0.01" .value="${DDMMath.s}">
122
+ <var class="math-var">s</var>
123
+ </decidables-spinner>`;
124
+ meanRT = html`<decidables-spinner class="mean-rt bottom" disabled min="0" max="1" step="0.01" .value="${+this.meanRT.toFixed(0)}">
125
+ <var>Mean RT</var>
126
+ </decidables-spinner>`;
127
+ } else {
128
+ a = html`<var class="math-var a">a</var>`;
129
+ z = html`<var class="math-var z">z</var>`;
130
+ v = html`<var class="math-var v">v</var>`;
131
+ t0 = html`<var class="math-var t0">t<sub>0</sub></var>`;
132
+ s = html`<var class="math-var s">s</var>`;
133
+ meanRT = html`<var class="mean-rt">Mean RT</var>`;
134
+ }
135
+ const equation = html`
136
+ <tr>
137
+ <td rowspan="2">
138
+ ${meanRT}<span class="equals">=</span>
139
+ ${t0}
140
+ <span class="minus">−</span>
141
+ </td>
142
+ <td class="underline">
143
+ ${z}
144
+ </td>
145
+ <td rowspan="2">
146
+ <span class="plus">+</span>
147
+ </td>
148
+ <td class="underline">
149
+ ${a}
150
+ </td>
151
+ <td rowspan="2">&nbsp;</td>
152
+ <td class="underline">
153
+ <var class="math-greek e tight">e</var><sup class="exp"><span class="minus tight">−</span><span class="paren tight">(</span>2${v}${z} / ${s}<sup class="exp">2</sup><span class="paren tight">)</span></sup>
154
+ <span class="minus">−</span>
155
+ 1
156
+ </td>
157
+ </tr>
158
+ <tr>
159
+ <td>
160
+ ${v}
161
+ </td>
162
+ <td>
163
+ ${v}
164
+ </td>
165
+ <td>
166
+ <var class="math-greek e tight">e</var><sup class="exp"><span class="minus tight">−</span><span class="paren tight">(</span>2${v}${a} / ${s}<sup class="exp">2</sup><span class="paren tight">)</span></sup>
167
+ <span class="minus">−</span>
168
+ 1
169
+ </td>
170
+ </tr>`;
171
+ return html`
172
+ <div class="holder">
173
+ <table class="equation">
174
+ <tbody>
175
+ ${equation}
176
+ </tbody>
177
+ </table>
178
+ </div>`;
179
+ }
180
+ }
181
+
182
+ customElements.define('ddm-equation-azvt02m', DDMEquationAZVT02M);
@@ -0,0 +1,193 @@
1
+
2
+ import {css} from 'lit';
3
+
4
+ import AccumulableElement from '../accumulable-element';
5
+
6
+ /*
7
+ DDMEquation Base Class - Not intended for instantiation!
8
+ */
9
+ export default class DDMEquation extends AccumulableElement {
10
+ static get properties() {
11
+ return {
12
+ numeric: {
13
+ attribute: 'numeric',
14
+ type: Boolean,
15
+ reflect: true,
16
+ },
17
+ };
18
+ }
19
+
20
+ constructor() {
21
+ super();
22
+ this.numeric = false;
23
+ }
24
+
25
+ static get styles() {
26
+ return [
27
+ super.styles,
28
+ css`
29
+ :host {
30
+ display: block;
31
+
32
+ margin: 1rem;
33
+ }
34
+
35
+ /* Containing <div> */
36
+ .holder {
37
+ display: flex;
38
+
39
+ flex-direction: row;
40
+
41
+ justify-content: left;
42
+ }
43
+
44
+ /* Overall <table> */
45
+ .equation {
46
+ text-align: center;
47
+ white-space: nowrap;
48
+
49
+ border-collapse: collapse;
50
+
51
+ border: 0;
52
+ }
53
+
54
+ /* Modifies <td> */
55
+ .underline {
56
+ border-bottom: 1px solid var(---color-text);
57
+ }
58
+
59
+ /* Basic <span> and <var> w/modifiers */
60
+ span,
61
+ var {
62
+ padding: 0 0.25rem;
63
+
64
+ font-style: normal;
65
+ }
66
+
67
+ var {
68
+ border-radius: var(---border-radius);
69
+ }
70
+
71
+ .tight {
72
+ padding: 0;
73
+ }
74
+
75
+ .paren {
76
+ font-size: 150%;
77
+ }
78
+
79
+ .bracket {
80
+ font-size: 175%;
81
+ }
82
+
83
+ .brace {
84
+ font-size: 200%;
85
+ }
86
+
87
+ .addend {
88
+ position: relative;
89
+ display: inline-block;
90
+ }
91
+
92
+ .comparison {
93
+ position: relative;
94
+ display: inline-block;
95
+
96
+ font-size: 125%;
97
+ font-weight: 600;
98
+ }
99
+
100
+ .function {
101
+ display: inline-block;
102
+
103
+ border-radius: var(---border-radius);
104
+ }
105
+
106
+ :host([numeric]) .function {
107
+ padding: 0.25rem;
108
+ }
109
+
110
+ .exp {
111
+ display: inline-block;
112
+
113
+ font-size: 0.75rem;
114
+ }
115
+
116
+ .subscript {
117
+ display: inline-block;
118
+
119
+ font-size: 66.667%;
120
+ }
121
+
122
+ .summation {
123
+ display: flex;
124
+
125
+ flex-direction: column;
126
+
127
+ line-height: 0.8;
128
+ }
129
+
130
+ .sigma {
131
+ display: inline-block;
132
+
133
+ font-size: 200%;
134
+ }
135
+
136
+ /* Input wrapping <label> */
137
+ decidables-spinner {
138
+ --decidables-spinner-input-width: 4rem;
139
+
140
+ display: inline-block;
141
+
142
+ padding: 0.125rem 0.375rem 0.375rem;
143
+
144
+ line-height: 1.5;
145
+ vertical-align: middle;
146
+
147
+ border-radius: var(---border-radius);
148
+ }
149
+
150
+ .n {
151
+ --decidables-spinner-input-width: 2rem;
152
+ }
153
+
154
+ .left {
155
+ text-align: left;
156
+ }
157
+
158
+ .right {
159
+ text-align: right;
160
+ }
161
+
162
+ .bottom {
163
+ vertical-align: bottom;
164
+ }
165
+
166
+ .top {
167
+ vertical-align: top;
168
+ }
169
+
170
+ /* Color scheme */
171
+ .a {
172
+ background: var(---color-a-light);
173
+ }
174
+
175
+ .z {
176
+ background: var(---color-z-light);
177
+ }
178
+
179
+ .v {
180
+ background: var(---color-v-light);
181
+ }
182
+
183
+ .t0 {
184
+ background: var(---color-t0-light);
185
+ }
186
+
187
+ .s {
188
+ background: var(---color-s-light);
189
+ }
190
+ `,
191
+ ];
192
+ }
193
+ }
@@ -0,0 +1,3 @@
1
+
2
+ export {default as DDMEquationAZV2PC} from './azv2pc';
3
+ export {default as DDMEquationAZVT02M} from './azvt02m';
@@ -0,0 +1,72 @@
1
+
2
+ import {html, css} from 'lit';
3
+
4
+ import AccumulableElement from '../accumulable-element';
5
+
6
+ /*
7
+ DDMExample Base Class - Not intended for instantiation!
8
+ */
9
+ export default class DDMExample extends AccumulableElement {
10
+ static get styles() {
11
+ return [
12
+ super.styles,
13
+ css`
14
+ :host {
15
+ ---border: var(--border, 1px solid var(---color-border));
16
+ display: inline-block;
17
+
18
+ margin-bottom: 1rem;
19
+ }
20
+
21
+ .holder {
22
+ display: flex;
23
+ }
24
+
25
+ .body {
26
+ display: flex;
27
+
28
+ flex-wrap: wrap;
29
+
30
+ align-items: center;
31
+ justify-content: left;
32
+
33
+ padding: 0.625rem;
34
+
35
+ border: var(---border);
36
+ border-radius: 0.25rem;
37
+ }
38
+
39
+ .body ::slotted(*) {
40
+ margin: 0.625rem;
41
+ }
42
+
43
+ /* HACK: Sibling selectors not working with ::slotted */
44
+ /* .body > rdk-task + sdt-response,
45
+ ::slotted(rdk-task) + ::slotted(sdt-response) { */
46
+ /* .body ::slotted(sdt-response) {
47
+ margin-left: 0;
48
+ } */
49
+
50
+ /* HACK: Sibling selectors not working with ::slotted */
51
+ /* .body > sdt-control + rdk-task,
52
+ ::slotted(sdt-control) + ::slotted(rdk-task) {
53
+ margin-left: 0;
54
+ } */
55
+ /* .body ::slotted(rdk-task) {
56
+ margin-left: 0;
57
+ } */
58
+ `,
59
+ ];
60
+ }
61
+
62
+ render() { /* eslint-disable-line class-methods-use-this */
63
+ return html`
64
+ <div class="holder">
65
+ <div class="body">
66
+ <slot>Empty!</slot>
67
+ </div>
68
+ </div>`;
69
+ }
70
+ }
71
+
72
+ customElements.define('ddm-example', DDMExample);