@decidables/accumulable-elements 0.3.2 → 0.3.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decidables/accumulable-elements",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "accumulable-elements: Web Components for visualizing the Diffusion Decision Model",
5
5
  "keywords": [
6
6
  "web component",
@@ -53,8 +53,8 @@
53
53
  "gulp": "^5.0.1"
54
54
  },
55
55
  "dependencies": {
56
- "@decidables/accumulable-math": "^0.2.2",
57
- "@decidables/decidables-elements": "^0.5.2",
56
+ "@decidables/accumulable-math": "^0.2.4",
57
+ "@decidables/decidables-elements": "^0.5.4",
58
58
  "@lit-labs/motion": "^1.0.9",
59
59
  "@observablehq/plot": "^0.6.17",
60
60
  "bayes.js": "https://github.com/akrawitz/bayes.js.git#commit=c7b091b75f85a86b6a3965a983b31e23d9ef456f",
@@ -62,5 +62,5 @@
62
62
  "lit": "^3.3.1",
63
63
  "regenerator-runtime": "^0.14.1"
64
64
  },
65
- "gitHead": "481166fb550a7c616e2e7ebc8658073467081636"
65
+ "gitHead": "40a8d99faef87f4616aa28ae5299893a59873f1d"
66
66
  }
@@ -565,15 +565,29 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
565
565
  text-anchor: end;
566
566
  }
567
567
 
568
+ /* Hack to avoid lack of context-stroke and context-fill in Safari */
569
+ .measure-arrow.a {
570
+ fill: var(---color-a);
571
+ stroke: var(---color-a);
572
+ }
573
+
568
574
  .measure.z .line {
569
575
  stroke: var(---color-z);
570
576
  }
571
577
 
572
- .measure.z .label {
578
+ .measure.z .label,
579
+ /* Hack to avoid Safari weirdness */
580
+ .measure.z .label tspan {
573
581
  dominant-baseline: hanging;
574
582
  text-anchor: start;
575
583
  }
576
584
 
585
+ /* Hack to avoid lack of context-stroke and context-fill in Safari */
586
+ .measure-arrow.z {
587
+ fill: var(---color-z);
588
+ stroke: var(---color-z);
589
+ }
590
+
577
591
  .measure.v .line {
578
592
  stroke: var(---color-v);
579
593
  }
@@ -583,6 +597,12 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
583
597
  text-anchor: start;
584
598
  }
585
599
 
600
+ /* Hack to avoid lack of context-stroke and context-fill in Safari */
601
+ .measure-arrow.v {
602
+ fill: var(---color-v);
603
+ stroke: var(---color-v);
604
+ }
605
+
586
606
  .measure.t0 .line {
587
607
  stroke: var(---color-t0);
588
608
  }
@@ -592,6 +612,12 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
592
612
  text-anchor: middle;
593
613
  }
594
614
 
615
+ /* Hack to avoid lack of context-stroke and context-fill in Safari */
616
+ .measure-arrow.t0 {
617
+ fill: var(---color-t0);
618
+ stroke: var(---color-t0);
619
+ }
620
+
595
621
  .sd .indicator,
596
622
  .mean .indicator {
597
623
  stroke-width: 2;
@@ -617,6 +643,20 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
617
643
  stroke: var(---color-error-dark);
618
644
  }
619
645
 
646
+ /* Hack to avoid lack of context-stroke and context-fill in Safari */
647
+ .cap.correct {
648
+ fill: var(---color-correct-dark);
649
+ stroke: var(---color-correct-dark);
650
+ stroke-dasharray: 100%;
651
+ }
652
+
653
+ /* Hack to avoid lack of context-stroke and context-fill in Safari */
654
+ .cap.error {
655
+ fill: var(---color-error-dark);
656
+ stroke: var(---color-error-dark);
657
+ stroke-dasharray: 100%;
658
+ }
659
+
620
660
  .rt-label rect {
621
661
  filter: url("#shadow-2");
622
662
 
@@ -883,48 +923,88 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
883
923
  .html(AccumulableElement.svgDefs);
884
924
  const svgDefs = svgEnter.append('defs');
885
925
  // Arrowhead marker for measures
886
- svgDefs.append('marker')
887
- .attr('id', 'measure-arrow')
888
- .attr('orient', 'auto-start-reverse')
889
- .attr('markerUnits', 'userSpaceOnUse')
890
- .attr('viewBox', '-5 -5 10 10')
891
- .attr('refX', '2')
892
- .attr('refY', '0')
893
- .attr('markerWidth', '10')
894
- .attr('markerHeight', '10')
895
- .append('path')
896
- .attr('stroke', 'context-stroke')
897
- .attr('fill', 'context-stroke')
898
- .attr('d', 'M -3 -3 l 6 3 l -6 3 z');
926
+ const measureArrow = (parameter) => {
927
+ /* Hack to avoid lack of context-stroke and context-fill in Safari */
928
+ svgDefs.append('marker')
929
+ .attr('id', `measure-arrow-${parameter}`)
930
+ .attr('class', `measure-arrow ${parameter}`)
931
+ .attr('orient', 'auto-start-reverse')
932
+ .attr('markerUnits', 'userSpaceOnUse')
933
+ .attr('viewBox', '-5 -5 10 10')
934
+ .attr('refX', '2')
935
+ .attr('refY', '0')
936
+ .attr('markerWidth', '10')
937
+ .attr('markerHeight', '10')
938
+ .append('path')
939
+ .attr('stroke', 'context-stroke')
940
+ .attr('fill', 'context-stroke')
941
+ .attr('d', 'M -3 -3 l 6 3 l -6 3 z');
942
+ };
943
+ const measureArrowCap = (parameter) => {
944
+ /* Hack to avoid lack of context-stroke and context-fill in Safari */
945
+ const marker = svgDefs.append('marker')
946
+ .attr('id', `measure-arrow-cap-${parameter}`)
947
+ .attr('class', `measure-arrow cap ${parameter}`)
948
+ .attr('orient', 'auto-start-reverse')
949
+ .attr('markerUnits', 'userSpaceOnUse')
950
+ .attr('viewBox', '-5 -5 10 10')
951
+ .attr('refX', '2')
952
+ .attr('refY', '0')
953
+ .attr('markerWidth', '10')
954
+ .attr('markerHeight', '10');
955
+ marker
956
+ .append('path')
957
+ .attr('stroke', 'context-stroke')
958
+ .attr('fill', 'context-stroke')
959
+ .attr('d', 'M -3 -3 l 6 3 l -6 3 z');
960
+ marker
961
+ .append('path')
962
+ .attr('stroke', 'context-stroke')
963
+ .attr('fill', 'context-stroke')
964
+ .attr('stroke-width', '2')
965
+ .attr('d', 'M 4 -4 l 0 8');
966
+ };
967
+ measureArrow('a');
968
+ measureArrow('z');
969
+ measureArrowCap('v');
970
+ measureArrow('t0');
971
+ measureArrowCap('t0');
899
972
  // Flat markers for SDs
900
- svgDefs.append('marker')
901
- .attr('id', 'model-sd-cap')
902
- .attr('orient', 'auto-start-reverse')
903
- .attr('markerUnits', 'userSpaceOnUse')
904
- .attr('viewBox', '-5 -5 10 10')
905
- .attr('refX', '0')
906
- .attr('refY', '0')
907
- .attr('markerWidth', '10')
908
- .attr('markerHeight', '10')
909
- .append('path')
910
- .attr('stroke', 'context-stroke')
911
- .attr('fill', 'context-stroke')
912
- .attr('stroke-width', '2')
913
- .attr('d', 'M 0 -4 l 0 8');
914
- svgDefs.append('marker')
915
- .attr('id', 'data-sd-cap')
916
- .attr('orient', 'auto-start-reverse')
917
- .attr('markerUnits', 'userSpaceOnUse')
918
- .attr('viewBox', '-5 -5 10 10')
919
- .attr('refX', '0')
920
- .attr('refY', '0')
921
- .attr('markerWidth', '10')
922
- .attr('markerHeight', '10')
923
- .append('path')
924
- .attr('stroke', 'context-stroke')
925
- .attr('fill', 'context-stroke')
926
- .attr('stroke-width', '2')
927
- .attr('d', 'M 0 -3 l 0 6');
973
+ const sdCap = (outcome) => {
974
+ /* Hack to avoid lack of context-stroke and context-fill in Safari */
975
+ svgDefs.append('marker')
976
+ .attr('id', `model-sd-cap-${outcome}`)
977
+ .attr('class', `model-sd cap ${outcome}`)
978
+ .attr('orient', 'auto-start-reverse')
979
+ .attr('markerUnits', 'userSpaceOnUse')
980
+ .attr('viewBox', '-5 -5 10 10')
981
+ .attr('refX', '0')
982
+ .attr('refY', '0')
983
+ .attr('markerWidth', '10')
984
+ .attr('markerHeight', '10')
985
+ .append('path')
986
+ .attr('stroke', 'context-stroke')
987
+ .attr('fill', 'context-stroke')
988
+ .attr('stroke-width', '2')
989
+ .attr('d', 'M 0 -4 l 0 8');
990
+ svgDefs.append('marker')
991
+ .attr('id', `data-sd-cap-${outcome}`)
992
+ .attr('class', `data-sd cap ${outcome}`)
993
+ .attr('orient', 'auto-start-reverse')
994
+ .attr('markerUnits', 'userSpaceOnUse')
995
+ .attr('viewBox', '-5 -5 10 10')
996
+ .attr('refX', '0')
997
+ .attr('refY', '0')
998
+ .attr('markerWidth', '10')
999
+ .attr('markerHeight', '10')
1000
+ .append('path')
1001
+ .attr('stroke', 'context-stroke')
1002
+ .attr('fill', 'context-stroke')
1003
+ .attr('stroke-width', '2')
1004
+ .attr('d', 'M 0 -3 l 0 6');
1005
+ };
1006
+ sdCap('error');
1007
+ sdCap('correct');
928
1008
  const gradient = svgDefs.append('linearGradient')
929
1009
  .attr('id', 'path-animate')
930
1010
  .attr('gradientUnits', 'userSpaceOnUse')
@@ -1851,8 +1931,9 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
1851
1931
  .classed('measure a', true);
1852
1932
  aEnter.append('line')
1853
1933
  .classed('line', true)
1854
- .attr('marker-start', 'url(#measure-arrow)')
1855
- .attr('marker-end', 'url(#measure-arrow)');
1934
+ /* Hack to avoid lack of context-stroke and context-fill in Safari */
1935
+ .attr('marker-start', 'url(#measure-arrow-a)')
1936
+ .attr('marker-end', 'url(#measure-arrow-a)');
1856
1937
  const aLabel = aEnter.append('text')
1857
1938
  .classed('label', true);
1858
1939
  aLabel.append('tspan')
@@ -1893,8 +1974,9 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
1893
1974
  .classed('measure z', true);
1894
1975
  zEnter.append('line')
1895
1976
  .classed('line', true)
1896
- .attr('marker-start', 'url(#measure-arrow)')
1897
- .attr('marker-end', 'url(#measure-arrow)');
1977
+ /* Hack to avoid lack of context-stroke and context-fill in Safari */
1978
+ .attr('marker-start', 'url(#measure-arrow-z)')
1979
+ .attr('marker-end', 'url(#measure-arrow-z)');
1898
1980
  const zLabel = zEnter.append('text')
1899
1981
  .classed('label', true);
1900
1982
  zLabel.append('tspan')
@@ -1935,8 +2017,9 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
1935
2017
  .classed('measure v', true);
1936
2018
  vEnter.append('path')
1937
2019
  .classed('line', true)
1938
- .attr('marker-start', 'url(#measure-arrow)')
1939
- .attr('marker-end', 'url(#measure-arrow)');
2020
+ /* Hack to avoid lack of context-stroke and context-fill in Safari */
2021
+ .attr('marker-start', 'url(#measure-arrow-cap-v)')
2022
+ .attr('marker-end', 'url(#measure-arrow-cap-v)');
1940
2023
  const vLabel = vEnter.append('text')
1941
2024
  .classed('label', true);
1942
2025
  vLabel.append('tspan')
@@ -1948,8 +2031,9 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
1948
2031
  vLabel.append('tspan')
1949
2032
  .classed('value', true);
1950
2033
  // MERGE
1951
- const driftAngle = Math.atan((this.v / 1000) * scaleRatio);
1952
2034
  const driftHypotenuse = timeScale(200) - timeScale(0) + this.rem * 0.75;
2035
+ const driftCorrection = 2 / driftHypotenuse;
2036
+ const driftAngle = Math.atan((this.v / 1000) * scaleRatio) - driftCorrection;
1953
2037
  const driftX = Math.cos(driftAngle) * driftHypotenuse;
1954
2038
  const driftY = Math.sin(driftAngle) * driftHypotenuse;
1955
2039
  const vMerge = vEnter.merge(vUpdate);
@@ -1958,7 +2042,7 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
1958
2042
  .duration(this.drag ? 0 : transitionDuration)
1959
2043
  .ease(d3.easeCubicOut)
1960
2044
  .attr('d', `
1961
- M ${timeScale(this.t0 + 200) + this.rem * 0.75}, ${evidenceScale(this.startingPoint)}
2045
+ M ${timeScale(this.t0 + 200) + this.rem * 0.75}, ${evidenceScale(this.startingPoint) - 2}
1962
2046
  A ${timeScale(200) - timeScale(0)} ${timeScale(200) - timeScale(0)} 0 0 0 ${timeScale(this.t0) + driftX} ${evidenceScale(this.startingPoint) - driftY}
1963
2047
  `);
1964
2048
  const vLabelMerge = vMerge.select('.label')
@@ -1981,8 +2065,9 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
1981
2065
  .classed('measure t0', true);
1982
2066
  t0Enter.append('line')
1983
2067
  .classed('line', true)
1984
- .attr('marker-start', 'url(#measure-arrow)')
1985
- .attr('marker-end', 'url(#measure-arrow)');
2068
+ /* Hack to avoid lack of context-stroke and context-fill in Safari */
2069
+ .attr('marker-start', 'url(#measure-arrow-t0)')
2070
+ .attr('marker-end', 'url(#measure-arrow-cap-t0)');
1986
2071
  const t0Label = t0Enter.append('text')
1987
2072
  .classed('label', true);
1988
2073
  t0Label.append('tspan')
@@ -2091,8 +2176,9 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
2091
2176
  .attr('class', (datum) => { return `model sd ${datum.outcome}`; });
2092
2177
  sdEnter.append('line')
2093
2178
  .classed('indicator', true)
2094
- .attr('marker-start', 'url(#model-sd-cap)')
2095
- .attr('marker-end', 'url(#model-sd-cap)');
2179
+ /* Hack to avoid lack of context-stroke and context-fill in Safari */
2180
+ .attr('marker-start', (datum) => { return `url(#model-sd-cap-${datum.outcome})`; })
2181
+ .attr('marker-end', (datum) => { return `url(#model-sd-cap-${datum.outcome})`; });
2096
2182
  // MERGE
2097
2183
  const sdMerge = sdEnter.merge(sdUpdate);
2098
2184
  sdMerge.select('.indicator')
@@ -2119,8 +2205,9 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
2119
2205
  .attr('class', (datum) => { return `data sd ${datum.outcome}`; });
2120
2206
  dataSDEnter.append('line')
2121
2207
  .classed('indicator', true)
2122
- .attr('marker-start', 'url(#data-sd-cap)')
2123
- .attr('marker-end', 'url(#data-sd-cap)')
2208
+ /* Hack to avoid lack of context-stroke and context-fill in Safari */
2209
+ .attr('marker-start', (datum) => { return `url(#data-sd-cap-${datum.outcome})`; })
2210
+ .attr('marker-end', (datum) => { return `url(#data-sd-cap-${datum.outcome})`; })
2124
2211
  .attr('y1', (datum) => {
2125
2212
  return datum.densityScale(0) + ((datum.outcome === 'correct') ? 0.375 : -0.375) * this.rem;
2126
2213
  })