@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.
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@decidables/accumulable-elements",
3
+ "version": "0.1.0",
4
+ "description": "accumulable-elements: Web Components for visualizing the Diffusion Decision Model",
5
+ "keywords": [
6
+ "web component",
7
+ "explorable explanation",
8
+ "explorable",
9
+ "decision making",
10
+ "decidables",
11
+ "hyperbolic temporal discounting",
12
+ "temporal discounting",
13
+ "delay discounting",
14
+ "discountable"
15
+ ],
16
+ "type": "module",
17
+ "main": "./lib/accumulableElements.umd.min.js",
18
+ "browser": "./lib/accumulableElements.umd.min.js",
19
+ "module": "./lib/accumulableElements.esm.min.js",
20
+ "exports": {
21
+ "./lib/*.js": "./lib/*.js",
22
+ ".": "./src/index.js",
23
+ "./components": "./src/components/index.js",
24
+ "./equations": "./src/equations/index.js",
25
+ "./examples": "./src/examples/index.js",
26
+ "./*": "./src/*.js"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/decidables/decidables.git",
31
+ "directory": "libraries/accumulable-elements"
32
+ },
33
+ "bugs": "https://github.com/decidables/decidables/issues",
34
+ "homepage": "https://github.com/decidables/decidables/tree/main/libraries/accumulable-elements",
35
+ "author": "Adam Krawitz (https://web.uvic.ca/~akrawitz/)",
36
+ "license": "CC-BY-SA-4.0 AND GPL-3.0-or-later",
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "files": [
41
+ "package.json",
42
+ "*.md",
43
+ "src",
44
+ "lib"
45
+ ],
46
+ "scripts": {
47
+ "lint": "gulp lint",
48
+ "test": "gulp test",
49
+ "build": "gulp build"
50
+ },
51
+ "devDependencies": {
52
+ "gulp": "^5.0.0"
53
+ },
54
+ "dependencies": {
55
+ "@decidables/accumulable-math": "^0.1.0",
56
+ "@decidables/decidables-elements": "^0.4.7",
57
+ "@lit-labs/motion": "^1.0.7",
58
+ "@observablehq/plot": "^0.6.14",
59
+ "bayes.js": "https://github.com/akrawitz/bayes.js.git#commit=c7b091b75f85a86b6a3965a983b31e23d9ef456f",
60
+ "d3": "^7.9.0",
61
+ "lit": "^3.1.3",
62
+ "regenerator-runtime": "^0.14.1"
63
+ },
64
+ "gitHead": "bd8032a47624293a88f7f70e0b331c1cea1ef399"
65
+ }
@@ -0,0 +1,87 @@
1
+
2
+ import {
3
+ css,
4
+ unsafeCSS,
5
+ } from 'lit';
6
+ import * as d3 from 'd3';
7
+
8
+ import {DecidablesElement} from '@decidables/decidables-elements';
9
+
10
+ /*
11
+ AccumulableElement Base Class - Not intended for instantiation!
12
+ */
13
+ export default class AccumulableElement extends DecidablesElement {
14
+ static get properties() {
15
+ return {
16
+ interactive: {
17
+ attribute: 'interactive',
18
+ type: Boolean,
19
+ reflect: true,
20
+ },
21
+ };
22
+ }
23
+
24
+ constructor() {
25
+ super();
26
+ this.interactive = false;
27
+ }
28
+
29
+ static get colors() {
30
+ return {
31
+ a: d3.schemeSet1[0],
32
+ z: d3.schemeSet1[1],
33
+ v: d3.schemeSet1[4],
34
+ t0: d3.schemeSet1[7],
35
+ s: d3.schemeSet1[8],
36
+ left: '#f032e6',
37
+ right: '#10dbc9',
38
+ correct: d3.schemeSet1[2],
39
+ error: d3.schemeSet1[3],
40
+ nr: '#cccccc',
41
+ };
42
+ }
43
+
44
+ static get lights() {
45
+ return Object.keys(AccumulableElement.colors).reduce((acc, cur) => {
46
+ acc[cur] = d3.interpolateRgb(AccumulableElement.colors[cur], '#ffffff')(0.5);
47
+ return acc;
48
+ }, {});
49
+ }
50
+
51
+ static get darks() {
52
+ return Object.keys(AccumulableElement.colors).reduce((acc, cur) => {
53
+ acc[cur] = d3.interpolateRgb(AccumulableElement.colors[cur], '#000000')(0.5);
54
+ return acc;
55
+ }, {});
56
+ }
57
+
58
+ static get styles() {
59
+ return [
60
+ super.styles,
61
+ css`
62
+ :host {
63
+ /* Declare base colors */
64
+ ${
65
+ unsafeCSS(Object.keys(AccumulableElement.colors).map((color) => {
66
+ return `---color-${color}: var(--color-${color}, ${this.colors[color]});`;
67
+ }).join('\n'))
68
+ }
69
+
70
+ /* Declare light colors */
71
+ ${
72
+ unsafeCSS(Object.keys(AccumulableElement.colors).map((color) => {
73
+ return `---color-${color}-light: var(--color-${color}-light, ${this.lights[color]});`;
74
+ }).join('\n'))
75
+ }
76
+
77
+ /* Declare dark colors */
78
+ ${
79
+ unsafeCSS(Object.keys(AccumulableElement.colors).map((color) => {
80
+ return `---color-${color}-dark: var(--color-${color}-dark, ${this.darks[color]});`;
81
+ }).join('\n'))
82
+ }
83
+ }
84
+ `,
85
+ ];
86
+ }
87
+ }
@@ -0,0 +1,249 @@
1
+
2
+ import {html, css} from 'lit';
3
+
4
+ import '@decidables/decidables-elements/button';
5
+ import '@decidables/decidables-elements/slider';
6
+ import '@decidables/decidables-elements/switch';
7
+ import '@decidables/decidables-elements/toggle';
8
+ import '@decidables/decidables-elements/toggle-option';
9
+
10
+ import AccumulableElement from '../accumulable-element';
11
+
12
+ /*
13
+ AccumulableControl element
14
+ <accumulable-control>
15
+
16
+ Attributes:
17
+
18
+ */
19
+ export default class AccumulableControl extends AccumulableElement {
20
+ static get properties() {
21
+ return {
22
+ trials: {
23
+ attribute: 'trials',
24
+ type: Number,
25
+ reflect: true,
26
+ },
27
+ resample: {
28
+ attribute: 'resample',
29
+ type: Boolean,
30
+ reflect: true,
31
+ },
32
+
33
+ duration: {
34
+ attribute: 'duration',
35
+ type: Number,
36
+ reflect: true,
37
+ },
38
+ coherence: {
39
+ attribute: 'coherence',
40
+ type: Number,
41
+ reflect: true,
42
+ },
43
+ color: {
44
+ attribute: 'color',
45
+ type: String,
46
+ reflect: true,
47
+ },
48
+
49
+ run: {
50
+ attribute: 'run',
51
+ type: Boolean,
52
+ reflect: true,
53
+ },
54
+ pause: {
55
+ attribute: 'pause',
56
+ type: Boolean,
57
+ reflect: true,
58
+ },
59
+ reset: {
60
+ attribute: 'reset',
61
+ type: Boolean,
62
+ reflect: true,
63
+ },
64
+
65
+ state: {
66
+ attribute: false,
67
+ type: String,
68
+ reflect: false,
69
+ },
70
+ };
71
+ }
72
+
73
+ constructor() {
74
+ super();
75
+
76
+ // Attributes
77
+ this.trials = undefined;
78
+ this.resample = false;
79
+
80
+ this.duration = undefined;
81
+ this.coherence = undefined;
82
+ this.colors = ['none', 'measure', 'outcome', 'all'];
83
+ this.color = undefined;
84
+
85
+ this.run = false;
86
+ this.pause = false;
87
+ this.reset = false;
88
+
89
+ // Properties
90
+ this.states = ['resetted', 'running', 'paused', 'ended'];
91
+ this.state = 'resetted';
92
+ }
93
+
94
+ setTrials(e) {
95
+ this.trials = e.target.value;
96
+ this.dispatchEvent(new CustomEvent('accumulable-control-trials', {
97
+ detail: {
98
+ trials: this.trials,
99
+ },
100
+ bubbles: true,
101
+ }));
102
+ }
103
+
104
+ doResample() {
105
+ this.dispatchEvent(new CustomEvent('accumulable-control-resample', {
106
+ detail: {},
107
+ bubbles: true,
108
+ }));
109
+ }
110
+
111
+ setDuration(e) {
112
+ this.duration = e.target.value;
113
+ this.dispatchEvent(new CustomEvent('accumulable-control-duration', {
114
+ detail: {
115
+ duration: this.duration,
116
+ },
117
+ bubbles: true,
118
+ }));
119
+ }
120
+
121
+ setCoherence(e) {
122
+ this.coherence = e.target.value;
123
+ this.dispatchEvent(new CustomEvent('accumulable-control-coherence', {
124
+ detail: {
125
+ coherence: this.coherence,
126
+ },
127
+ bubbles: true,
128
+ }));
129
+ }
130
+
131
+ chooseColor(e) {
132
+ this.color = e.target.value;
133
+ this.dispatchEvent(new CustomEvent('accumulable-control-color', {
134
+ detail: {
135
+ color: this.color,
136
+ },
137
+ bubbles: true,
138
+ }));
139
+ }
140
+
141
+ doRun() {
142
+ this.state = 'running';
143
+ this.dispatchEvent(new CustomEvent('accumulable-control-run', {
144
+ detail: {},
145
+ bubbles: true,
146
+ }));
147
+ }
148
+
149
+ doPause() {
150
+ this.state = 'paused';
151
+ this.dispatchEvent(new CustomEvent('accumulable-control-pause', {
152
+ detail: {},
153
+ bubbles: true,
154
+ }));
155
+ }
156
+
157
+ doReset() {
158
+ this.state = 'resetted';
159
+ this.dispatchEvent(new CustomEvent('accumulable-control-reset', {
160
+ detail: {},
161
+ bubbles: true,
162
+ }));
163
+ }
164
+
165
+ complete() {
166
+ this.state = 'ended';
167
+ }
168
+
169
+ static get styles() {
170
+ return [
171
+ super.styles,
172
+ css`
173
+ :host {
174
+ display: inline-block;
175
+ }
176
+
177
+ .holder {
178
+ display: flex;
179
+
180
+ flex-direction: row;
181
+
182
+ align-items: stretch;
183
+ justify-content: center;
184
+ }
185
+
186
+ .buttons {
187
+ display: flex;
188
+
189
+ flex-direction: column;
190
+
191
+ align-items: stretch;
192
+ justify-content: center;
193
+ }
194
+ `,
195
+ ];
196
+ }
197
+
198
+ render() {
199
+ return html`
200
+ <div class="holder">
201
+ ${this.trials
202
+ ? html`<decidables-slider class="trials" min="1" max="100" step="1" .value=${this.trials} @change=${this.setTrials.bind(this)} @input=${this.setTrials.bind(this)}>Trials</decidables-slider>`
203
+ : html``}
204
+ ${this.resample
205
+ ? html`
206
+ <div class="buttons">
207
+ ${this.resample
208
+ ? html`<decidables-button name="resample" @click=${this.doResample.bind(this)}>Resample</decidables-button>`
209
+ : html``}
210
+ </div>
211
+ `
212
+ : html``}
213
+ ${this.duration
214
+ ? html`<decidables-slider class="duration" min="10" max="2000" step="10" .value=${this.duration} @change=${this.setDuration.bind(this)} @input=${this.setDuration.bind(this)}>Duration</decidables-slider>`
215
+ : html``}
216
+ ${this.coherence
217
+ ? html`<decidables-slider class="coherence" min="0" max="1" step=".01" .value=${this.coherence} @change=${this.setCoherence.bind(this)} @input=${this.setCoherence.bind(this)}>Coherence</decidables-slider>`
218
+ : html``}
219
+ ${this.color !== undefined
220
+ ? html`
221
+ <decidables-toggle class="color" @change=${this.chooseColor.bind(this)}>
222
+ <span slot="label">Emphasis</span>
223
+ <decidables-toggle-option name="toggle" value="none" ?checked=${this.color === 'none'}>None</decidables-toggle-option>
224
+ <decidables-toggle-option name="toggle" value="measure" ?checked=${this.color === 'measure'}>Measure</decidables-toggle-option>
225
+ <decidables-toggle-option name="toggle" value="outcome" ?checked=${this.color === 'outcome'}>Outcome</decidables-toggle-option>
226
+ <decidables-toggle-option name="toggle" value="all" ?checked=${this.color === 'all'}>All</decidables-toggle-option>
227
+ </decidables-toggle>
228
+ `
229
+ : html``}
230
+ ${this.run || this.pause || this.reset
231
+ ? html`
232
+ <div class="buttons">
233
+ ${this.run
234
+ ? html`<decidables-button name="run" ?disabled=${this.state === 'running' || this.state === 'ended'} @click=${this.doRun.bind(this)}>Run</decidables-button>`
235
+ : html``}
236
+ ${this.pause
237
+ ? html`<decidables-button name="pause" ?disabled=${this.state !== 'running'} @click=${this.doPause.bind(this)}>Pause</decidables-button>`
238
+ : html``}
239
+ ${this.reset
240
+ ? html`<decidables-button name="reset" ?disabled=${this.state === 'resetted'} @click=${this.doReset.bind(this)}>Reset</decidables-button>`
241
+ : html``}
242
+ </div>
243
+ `
244
+ : html``}
245
+ </div>`;
246
+ }
247
+ }
248
+
249
+ customElements.define('accumulable-control', AccumulableControl);