@decidables/discountable-elements 0.6.0 → 0.6.2
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/CHANGELOG.md +17 -0
- package/lib/discountableElements.esm.js +60 -84
- package/lib/discountableElements.esm.js.map +1 -1
- package/lib/discountableElements.esm.min.js +14 -13
- package/lib/discountableElements.esm.min.js.map +1 -1
- package/lib/discountableElements.umd.js +60 -84
- package/lib/discountableElements.umd.js.map +1 -1
- package/lib/discountableElements.umd.min.js +14 -13
- package/lib/discountableElements.umd.min.js.map +1 -1
- package/package.json +4 -4
- package/src/components/htd-curves.js +74 -98
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decidables/discountable-elements",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "discountable-elements: Web Components for visualizing Hyperbolic Temporal Discounting",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web component",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"gulp": "^5.0.1"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@decidables/decidables-elements": "^0.5.
|
|
56
|
-
"@decidables/discountable-math": "^0.2.
|
|
55
|
+
"@decidables/decidables-elements": "^0.5.4",
|
|
56
|
+
"@decidables/discountable-math": "^0.2.4",
|
|
57
57
|
"@lit-labs/motion": "^1.0.9",
|
|
58
58
|
"@observablehq/plot": "^0.6.17",
|
|
59
59
|
"bayes.js": "https://github.com/akrawitz/bayes.js.git#commit=c7b091b75f85a86b6a3965a983b31e23d9ef456f",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"lit": "^3.3.1",
|
|
62
62
|
"regenerator-runtime": "^0.14.1"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "40a8d99faef87f4616aa28ae5299893a59873f1d"
|
|
65
65
|
}
|
|
@@ -251,25 +251,26 @@ export default class HTDCurves extends DecidablesMixinResizeable(DiscountableEle
|
|
|
251
251
|
|
|
252
252
|
.option .interactive {
|
|
253
253
|
filter: url("#shadow-2");
|
|
254
|
+
outline: none;
|
|
254
255
|
}
|
|
255
256
|
|
|
256
257
|
.option .interactive:hover {
|
|
257
258
|
filter: url("#shadow-4");
|
|
258
259
|
}
|
|
259
260
|
|
|
260
|
-
.option .body.interactive:has(~ .point:hover) {
|
|
261
|
-
filter: url("#shadow-4");
|
|
262
|
-
}
|
|
263
|
-
|
|
264
261
|
.option .interactive:active {
|
|
265
262
|
filter: url("#shadow-8");
|
|
266
263
|
}
|
|
267
264
|
|
|
268
|
-
.option .
|
|
265
|
+
:host(.keyboard) .option .interactive:focus-within {
|
|
269
266
|
filter: url("#shadow-8");
|
|
270
267
|
}
|
|
271
268
|
|
|
272
|
-
|
|
269
|
+
.option .body.interactive:has(~ .point:hover) {
|
|
270
|
+
filter: url("#shadow-4");
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
.option .body.interactive:has(~ .point:active) {
|
|
273
274
|
filter: url("#shadow-8");
|
|
274
275
|
}
|
|
275
276
|
|
|
@@ -721,57 +722,8 @@ export default class HTDCurves extends DecidablesMixinResizeable(DiscountableEle
|
|
|
721
722
|
return (this.interactive && !datum.trial && !d3.select(nodes[index]).select('.body').classed('interactive'));
|
|
722
723
|
})
|
|
723
724
|
.select('.body');
|
|
724
|
-
bodyMergeInteractive.classed('interactive', true)
|
|
725
|
-
// Fill
|
|
726
|
-
bodyMergeInteractive.select('.fill')
|
|
725
|
+
bodyMergeInteractive.classed('interactive', true)
|
|
727
726
|
.attr('tabindex', 0)
|
|
728
|
-
// Drag interaction
|
|
729
|
-
.call(d3.drag()
|
|
730
|
-
.subject((event, datum) => {
|
|
731
|
-
return {
|
|
732
|
-
x: xScale(datum.d),
|
|
733
|
-
y: yScale(datum.a),
|
|
734
|
-
};
|
|
735
|
-
})
|
|
736
|
-
.on('start', (event) => {
|
|
737
|
-
const element = event.currentTarget;
|
|
738
|
-
d3.select(element).classed('dragging', true);
|
|
739
|
-
})
|
|
740
|
-
.on('drag', (event, datum) => {
|
|
741
|
-
this.drag = true;
|
|
742
|
-
const d = xScale.invert(event.x);
|
|
743
|
-
const a = yScale.invert(event.y);
|
|
744
|
-
datum.d = (d < this.scale.time.min)
|
|
745
|
-
? this.scale.time.min
|
|
746
|
-
: (d > this.scale.time.max)
|
|
747
|
-
? this.scale.time.max
|
|
748
|
-
: this.scale.time.round(d);
|
|
749
|
-
datum.a = (a < this.scale.value.min)
|
|
750
|
-
? this.scale.value.min
|
|
751
|
-
: (a > this.scale.value.max)
|
|
752
|
-
? this.scale.value.max
|
|
753
|
-
: this.scale.value.round(a);
|
|
754
|
-
if (datum.name === 'default') {
|
|
755
|
-
this.d = datum.d;
|
|
756
|
-
this.a = datum.a;
|
|
757
|
-
}
|
|
758
|
-
this.alignState();
|
|
759
|
-
this.requestUpdate();
|
|
760
|
-
this.dispatchEvent(new CustomEvent('htd-curves-change', {
|
|
761
|
-
detail: {
|
|
762
|
-
name: datum.name,
|
|
763
|
-
a: datum.a,
|
|
764
|
-
d: datum.d,
|
|
765
|
-
k: this.k,
|
|
766
|
-
label: datum.label,
|
|
767
|
-
},
|
|
768
|
-
bubbles: true,
|
|
769
|
-
}));
|
|
770
|
-
})
|
|
771
|
-
.on('end', (event) => {
|
|
772
|
-
const element = event.currentTarget;
|
|
773
|
-
d3.select(element).classed('dragging', false);
|
|
774
|
-
}))
|
|
775
727
|
// Keyboard interaction
|
|
776
728
|
.on('keydown', (event, datum) => {
|
|
777
729
|
if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(event.key)) {
|
|
@@ -826,8 +778,8 @@ export default class HTDCurves extends DecidablesMixinResizeable(DiscountableEle
|
|
|
826
778
|
event.preventDefault();
|
|
827
779
|
}
|
|
828
780
|
});
|
|
829
|
-
//
|
|
830
|
-
bodyMergeInteractive.select('.
|
|
781
|
+
// Fill
|
|
782
|
+
bodyMergeInteractive.select('.fill')
|
|
831
783
|
// Drag interaction
|
|
832
784
|
.call(d3.drag()
|
|
833
785
|
.subject((event, datum) => {
|
|
@@ -843,13 +795,20 @@ export default class HTDCurves extends DecidablesMixinResizeable(DiscountableEle
|
|
|
843
795
|
.on('drag', (event, datum) => {
|
|
844
796
|
this.drag = true;
|
|
845
797
|
const d = xScale.invert(event.x);
|
|
798
|
+
const a = yScale.invert(event.y);
|
|
846
799
|
datum.d = (d < this.scale.time.min)
|
|
847
800
|
? this.scale.time.min
|
|
848
801
|
: (d > this.scale.time.max)
|
|
849
802
|
? this.scale.time.max
|
|
850
803
|
: this.scale.time.round(d);
|
|
804
|
+
datum.a = (a < this.scale.value.min)
|
|
805
|
+
? this.scale.value.min
|
|
806
|
+
: (a > this.scale.value.max)
|
|
807
|
+
? this.scale.value.max
|
|
808
|
+
: this.scale.value.round(a);
|
|
851
809
|
if (datum.name === 'default') {
|
|
852
810
|
this.d = datum.d;
|
|
811
|
+
this.a = datum.a;
|
|
853
812
|
}
|
|
854
813
|
this.alignState();
|
|
855
814
|
this.requestUpdate();
|
|
@@ -867,47 +826,49 @@ export default class HTDCurves extends DecidablesMixinResizeable(DiscountableEle
|
|
|
867
826
|
.on('end', (event) => {
|
|
868
827
|
const element = event.currentTarget;
|
|
869
828
|
d3.select(element).classed('dragging', false);
|
|
870
|
-
}))
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
829
|
+
}));
|
|
830
|
+
// Bar
|
|
831
|
+
bodyMergeInteractive.select('.bar')
|
|
832
|
+
// Drag interaction
|
|
833
|
+
.call(d3.drag()
|
|
834
|
+
.subject((event, datum) => {
|
|
835
|
+
return {
|
|
836
|
+
x: xScale(datum.d),
|
|
837
|
+
y: yScale(datum.a),
|
|
838
|
+
};
|
|
839
|
+
})
|
|
840
|
+
.on('start', (event) => {
|
|
841
|
+
const element = event.currentTarget;
|
|
842
|
+
d3.select(element).classed('dragging', true);
|
|
843
|
+
})
|
|
844
|
+
.on('drag', (event, datum) => {
|
|
845
|
+
this.drag = true;
|
|
846
|
+
const d = xScale.invert(event.x);
|
|
847
|
+
datum.d = (d < this.scale.time.min)
|
|
886
848
|
? this.scale.time.min
|
|
887
|
-
: (
|
|
849
|
+
: (d > this.scale.time.max)
|
|
888
850
|
? this.scale.time.max
|
|
889
|
-
:
|
|
890
|
-
if (
|
|
891
|
-
|
|
892
|
-
if (datum.name === 'default') {
|
|
893
|
-
this.d = datum.d;
|
|
894
|
-
}
|
|
895
|
-
this.alignState();
|
|
896
|
-
this.requestUpdate();
|
|
897
|
-
this.dispatchEvent(new CustomEvent('htd-curves-change', {
|
|
898
|
-
detail: {
|
|
899
|
-
name: datum.name,
|
|
900
|
-
a: datum.a,
|
|
901
|
-
d: datum.d,
|
|
902
|
-
k: this.k,
|
|
903
|
-
label: datum.label,
|
|
904
|
-
},
|
|
905
|
-
bubbles: true,
|
|
906
|
-
}));
|
|
851
|
+
: this.scale.time.round(d);
|
|
852
|
+
if (datum.name === 'default') {
|
|
853
|
+
this.d = datum.d;
|
|
907
854
|
}
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
855
|
+
this.alignState();
|
|
856
|
+
this.requestUpdate();
|
|
857
|
+
this.dispatchEvent(new CustomEvent('htd-curves-change', {
|
|
858
|
+
detail: {
|
|
859
|
+
name: datum.name,
|
|
860
|
+
a: datum.a,
|
|
861
|
+
d: datum.d,
|
|
862
|
+
k: this.k,
|
|
863
|
+
label: datum.label,
|
|
864
|
+
},
|
|
865
|
+
bubbles: true,
|
|
866
|
+
}));
|
|
867
|
+
})
|
|
868
|
+
.on('end', (event) => {
|
|
869
|
+
const element = event.currentTarget;
|
|
870
|
+
d3.select(element).classed('dragging', false);
|
|
871
|
+
}));
|
|
911
872
|
// Point
|
|
912
873
|
optionMerge
|
|
913
874
|
.filter((datum, index, nodes) => {
|
|
@@ -915,6 +876,7 @@ export default class HTDCurves extends DecidablesMixinResizeable(DiscountableEle
|
|
|
915
876
|
})
|
|
916
877
|
.select('.top-point')
|
|
917
878
|
.classed('interact', true)
|
|
879
|
+
.attr('tabindex', -1)
|
|
918
880
|
// Drag interaction
|
|
919
881
|
.call(d3.drag()
|
|
920
882
|
.subject((event, datum) => {
|
|
@@ -957,8 +919,9 @@ export default class HTDCurves extends DecidablesMixinResizeable(DiscountableEle
|
|
|
957
919
|
}))
|
|
958
920
|
// Keyboard interaction
|
|
959
921
|
.on('keydown', (event, datum) => {
|
|
960
|
-
if (['ArrowUp', 'ArrowDown'].includes(event.key)) {
|
|
922
|
+
if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(event.key)) {
|
|
961
923
|
let keyA = datum.a;
|
|
924
|
+
let keyD = datum.d;
|
|
962
925
|
switch (event.key) {
|
|
963
926
|
case 'ArrowUp':
|
|
964
927
|
keyA += event.shiftKey ? 1 : 5;
|
|
@@ -966,17 +929,30 @@ export default class HTDCurves extends DecidablesMixinResizeable(DiscountableEle
|
|
|
966
929
|
case 'ArrowDown':
|
|
967
930
|
keyA -= event.shiftKey ? 1 : 5;
|
|
968
931
|
break;
|
|
932
|
+
case 'ArrowRight':
|
|
933
|
+
keyD += event.shiftKey ? 1 : 5;
|
|
934
|
+
break;
|
|
935
|
+
case 'ArrowLeft':
|
|
936
|
+
keyD -= event.shiftKey ? 1 : 5;
|
|
937
|
+
break;
|
|
969
938
|
default:
|
|
970
939
|
// no-op
|
|
971
940
|
}
|
|
941
|
+
keyD = (keyD < this.scale.time.min)
|
|
942
|
+
? this.scale.time.min
|
|
943
|
+
: ((keyD > this.scale.time.max)
|
|
944
|
+
? this.scale.time.max
|
|
945
|
+
: keyD);
|
|
972
946
|
keyA = (keyA < this.scale.value.min)
|
|
973
947
|
? this.scale.value.min
|
|
974
948
|
: ((keyA > this.scale.value.max)
|
|
975
949
|
? this.scale.value.max
|
|
976
950
|
: keyA);
|
|
977
|
-
if (keyA !== datum.a) {
|
|
951
|
+
if ((keyD !== datum.d) || (keyA !== datum.a)) {
|
|
952
|
+
datum.d = keyD;
|
|
978
953
|
datum.a = keyA;
|
|
979
954
|
if (datum.name === 'default') {
|
|
955
|
+
this.d = datum.d;
|
|
980
956
|
this.a = datum.a;
|
|
981
957
|
}
|
|
982
958
|
this.alignState();
|