@decidables/accumulable-elements 0.3.4 → 0.3.6

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.4",
3
+ "version": "0.3.6",
4
4
  "description": "accumulable-elements: Web Components for visualizing the Diffusion Decision Model",
5
5
  "keywords": [
6
6
  "web component",
@@ -24,7 +24,8 @@
24
24
  "./components": "./src/components/index.js",
25
25
  "./equations": "./src/equations/index.js",
26
26
  "./examples": "./src/examples/index.js",
27
- "./*": "./src/*.js"
27
+ "./*": "./src/*.js",
28
+ "./colors.yml": "./src/colors.yml"
28
29
  },
29
30
  "repository": {
30
31
  "type": "git",
@@ -53,14 +54,13 @@
53
54
  "gulp": "^5.0.1"
54
55
  },
55
56
  "dependencies": {
56
- "@decidables/accumulable-math": "^0.2.4",
57
- "@decidables/decidables-elements": "^0.5.4",
57
+ "@decidables/accumulable-math": "^0.2.5",
58
+ "@decidables/decidables-elements": "^0.5.5",
58
59
  "@lit-labs/motion": "^1.0.9",
59
60
  "@observablehq/plot": "^0.6.17",
60
61
  "bayes.js": "https://github.com/akrawitz/bayes.js.git#commit=c7b091b75f85a86b6a3965a983b31e23d9ef456f",
61
62
  "d3": "^7.9.0",
62
- "lit": "^3.3.1",
63
- "regenerator-runtime": "^0.14.1"
63
+ "lit": "^3.3.1"
64
64
  },
65
- "gitHead": "40a8d99faef87f4616aa28ae5299893a59873f1d"
65
+ "gitHead": "045955a4696ea4b38440d84d467cad3ddaad812d"
66
66
  }
@@ -546,8 +546,13 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
546
546
  }
547
547
  }
548
548
 
549
- .measure {
550
- stroke-width: 2;
549
+ .measure .line.short {
550
+ stroke-width: 0;
551
+ }
552
+
553
+ .measure .markers {
554
+ fill: none;
555
+ stroke-width: 0;
551
556
  }
552
557
 
553
558
  .measure .label {
@@ -565,12 +570,6 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
565
570
  text-anchor: end;
566
571
  }
567
572
 
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
-
574
573
  .measure.z .line {
575
574
  stroke: var(---color-z);
576
575
  }
@@ -582,12 +581,6 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
582
581
  text-anchor: start;
583
582
  }
584
583
 
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
-
591
584
  .measure.v .line {
592
585
  stroke: var(---color-v);
593
586
  }
@@ -597,12 +590,6 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
597
590
  text-anchor: start;
598
591
  }
599
592
 
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
-
606
593
  .measure.t0 .line {
607
594
  stroke: var(---color-t0);
608
595
  }
@@ -612,6 +599,37 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
612
599
  text-anchor: middle;
613
600
  }
614
601
 
602
+ .measure-arrow {
603
+ fill: context-stroke;
604
+ stroke: context-stroke;
605
+ }
606
+
607
+ .measure-arrow .arrow {
608
+ stroke-width: 1;
609
+ }
610
+
611
+ .measure-arrow.capped .cap {
612
+ stroke-width: 2;
613
+ }
614
+
615
+ /* Hack to avoid lack of context-stroke and context-fill in Safari */
616
+ .measure-arrow.a {
617
+ fill: var(---color-a);
618
+ stroke: var(---color-a);
619
+ }
620
+
621
+ /* Hack to avoid lack of context-stroke and context-fill in Safari */
622
+ .measure-arrow.z {
623
+ fill: var(---color-z);
624
+ stroke: var(---color-z);
625
+ }
626
+
627
+ /* Hack to avoid lack of context-stroke and context-fill in Safari */
628
+ .measure-arrow.v {
629
+ fill: var(---color-v);
630
+ stroke: var(---color-v);
631
+ }
632
+
615
633
  /* Hack to avoid lack of context-stroke and context-fill in Safari */
616
634
  .measure-arrow.t0 {
617
635
  fill: var(---color-t0);
@@ -930,45 +948,41 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
930
948
  .attr('class', `measure-arrow ${parameter}`)
931
949
  .attr('orient', 'auto-start-reverse')
932
950
  .attr('markerUnits', 'userSpaceOnUse')
933
- .attr('viewBox', '-5 -5 10 10')
934
- .attr('refX', '2')
951
+ .attr('viewBox', '-10 -6 12 12')
952
+ .attr('refX', '0')
935
953
  .attr('refY', '0')
936
- .attr('markerWidth', '10')
937
- .attr('markerHeight', '10')
954
+ .attr('markerWidth', '12')
955
+ .attr('markerHeight', '12')
938
956
  .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');
957
+ .attr('class', 'arrow')
958
+ .attr('d', 'M -7 -3 l 6 3 l -6 3 z');
942
959
  };
943
- const measureArrowCap = (parameter) => {
960
+ const measureCappedArrow = (parameter) => {
944
961
  /* Hack to avoid lack of context-stroke and context-fill in Safari */
945
962
  const marker = svgDefs.append('marker')
946
- .attr('id', `measure-arrow-cap-${parameter}`)
947
- .attr('class', `measure-arrow cap ${parameter}`)
963
+ .attr('id', `measure-capped-arrow-${parameter}`)
964
+ .attr('class', `measure-arrow capped ${parameter}`)
948
965
  .attr('orient', 'auto-start-reverse')
949
966
  .attr('markerUnits', 'userSpaceOnUse')
950
- .attr('viewBox', '-5 -5 10 10')
951
- .attr('refX', '2')
967
+ .attr('viewBox', '-10 -6 12 12')
968
+ .attr('refX', '0')
952
969
  .attr('refY', '0')
953
- .attr('markerWidth', '10')
954
- .attr('markerHeight', '10');
970
+ .attr('markerWidth', '12')
971
+ .attr('markerHeight', '12');
955
972
  marker
956
973
  .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');
974
+ .attr('class', 'arrow')
975
+ .attr('d', 'M -7 -3 l 6 3 l -6 3 z');
960
976
  marker
961
977
  .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');
978
+ .attr('class', 'cap')
979
+ .attr('d', 'M 0 -4 l 0 8');
966
980
  };
967
981
  measureArrow('a');
968
982
  measureArrow('z');
969
- measureArrowCap('v');
983
+ measureCappedArrow('v');
970
984
  measureArrow('t0');
971
- measureArrowCap('t0');
985
+ measureCappedArrow('t0');
972
986
  // Flat markers for SDs
973
987
  const sdCap = (outcome) => {
974
988
  /* Hack to avoid lack of context-stroke and context-fill in Safari */
@@ -1922,6 +1936,9 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
1922
1936
  // EXIT
1923
1937
  t0zUpdate.exit().remove();
1924
1938
 
1939
+ // Measures
1940
+ const markerCorrection = 2;
1941
+
1925
1942
  // a Measure
1926
1943
  // DATA-JOIN
1927
1944
  const aUpdate = evidenceOverlayerMerge.selectAll('.measure.a')
@@ -1930,7 +1947,9 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
1930
1947
  const aEnter = aUpdate.enter().append('g')
1931
1948
  .classed('measure a', true);
1932
1949
  aEnter.append('line')
1933
- .classed('line', true)
1950
+ .classed('line', true);
1951
+ aEnter.append('line')
1952
+ .classed('markers', true)
1934
1953
  /* Hack to avoid lack of context-stroke and context-fill in Safari */
1935
1954
  .attr('marker-start', 'url(#measure-arrow-a)')
1936
1955
  .attr('marker-end', 'url(#measure-arrow-a)');
@@ -1945,15 +1964,26 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
1945
1964
  aLabel.append('tspan')
1946
1965
  .classed('value', true);
1947
1966
  // MERGE
1967
+ const aLength = Math.abs(evidenceScale(this.bounds.upper) - evidenceScale(this.bounds.lower));
1968
+ const aShort = aLength <= (markerCorrection * 2);
1948
1969
  const aMerge = aEnter.merge(aUpdate);
1949
1970
  aMerge.select('.line')
1971
+ .classed('short', aShort)
1950
1972
  .transition()
1951
1973
  .duration(this.drag ? 0 : transitionDuration)
1952
1974
  .ease(d3.easeCubicOut)
1953
1975
  .attr('x1', timeScale(this.scale.time.max) - this.rem * 0.75)
1954
- .attr('y1', evidenceScale(this.bounds.upper) + 2)
1976
+ .attr('y1', evidenceScale(this.bounds.upper) + markerCorrection)
1977
+ .attr('x2', timeScale(this.scale.time.max) - this.rem * 0.75)
1978
+ .attr('y2', evidenceScale(this.bounds.lower) - markerCorrection);
1979
+ aMerge.select('.markers')
1980
+ .transition()
1981
+ .duration(this.drag ? 0 : transitionDuration)
1982
+ .ease(d3.easeCubicOut)
1983
+ .attr('x1', timeScale(this.scale.time.max) - this.rem * 0.75)
1984
+ .attr('y1', evidenceScale(this.bounds.upper))
1955
1985
  .attr('x2', timeScale(this.scale.time.max) - this.rem * 0.75)
1956
- .attr('y2', evidenceScale(this.bounds.lower) - 2);
1986
+ .attr('y2', evidenceScale(this.bounds.lower));
1957
1987
  const aLabelMerge = aMerge.select('.label')
1958
1988
  .transition()
1959
1989
  .duration(this.drag ? 0 : transitionDuration)
@@ -1973,7 +2003,9 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
1973
2003
  const zEnter = zUpdate.enter().append('g')
1974
2004
  .classed('measure z', true);
1975
2005
  zEnter.append('line')
1976
- .classed('line', true)
2006
+ .classed('line', true);
2007
+ zEnter.append('line')
2008
+ .classed('markers', true)
1977
2009
  /* Hack to avoid lack of context-stroke and context-fill in Safari */
1978
2010
  .attr('marker-start', 'url(#measure-arrow-z)')
1979
2011
  .attr('marker-end', 'url(#measure-arrow-z)');
@@ -1988,15 +2020,26 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
1988
2020
  zLabel.append('tspan')
1989
2021
  .classed('value', true);
1990
2022
  // MERGE
2023
+ const zLength = Math.abs(evidenceScale(this.startingPoint) - evidenceScale(this.bounds.lower));
2024
+ const zShort = zLength <= (markerCorrection * 2);
1991
2025
  const zMerge = zEnter.merge(zUpdate);
1992
2026
  zMerge.select('.line')
2027
+ .classed('short', zShort)
2028
+ .transition()
2029
+ .duration(this.drag ? 0 : transitionDuration)
2030
+ .ease(d3.easeCubicOut)
2031
+ .attr('x1', timeScale(this.scale.time.min) + this.rem * 0.75)
2032
+ .attr('y1', evidenceScale(this.startingPoint) + markerCorrection)
2033
+ .attr('x2', timeScale(this.scale.time.min) + this.rem * 0.75)
2034
+ .attr('y2', evidenceScale(this.bounds.lower) - markerCorrection);
2035
+ zMerge.select('.markers')
1993
2036
  .transition()
1994
2037
  .duration(this.drag ? 0 : transitionDuration)
1995
2038
  .ease(d3.easeCubicOut)
1996
2039
  .attr('x1', timeScale(this.scale.time.min) + this.rem * 0.75)
1997
- .attr('y1', evidenceScale(this.startingPoint) + 2)
2040
+ .attr('y1', evidenceScale(this.startingPoint))
1998
2041
  .attr('x2', timeScale(this.scale.time.min) + this.rem * 0.75)
1999
- .attr('y2', evidenceScale(this.bounds.lower) - 2);
2042
+ .attr('y2', evidenceScale(this.bounds.lower));
2000
2043
  const zLabelMerge = zMerge.select('.label')
2001
2044
  .transition()
2002
2045
  .duration(this.drag ? 0 : transitionDuration)
@@ -2016,10 +2059,12 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
2016
2059
  const vEnter = vUpdate.enter().append('g')
2017
2060
  .classed('measure v', true);
2018
2061
  vEnter.append('path')
2019
- .classed('line', true)
2062
+ .classed('line', true);
2063
+ vEnter.append('path')
2064
+ .classed('markers', true)
2020
2065
  /* 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)');
2066
+ .attr('marker-start', 'url(#measure-capped-arrow-v)')
2067
+ .attr('marker-end', 'url(#measure-capped-arrow-v)');
2023
2068
  const vLabel = vEnter.append('text')
2024
2069
  .classed('label', true);
2025
2070
  vLabel.append('tspan')
@@ -2031,19 +2076,38 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
2031
2076
  vLabel.append('tspan')
2032
2077
  .classed('value', true);
2033
2078
  // MERGE
2079
+ // Full path
2034
2080
  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;
2081
+ const driftAngle = Math.atan((this.v / 1000) * scaleRatio);
2037
2082
  const driftX = Math.cos(driftAngle) * driftHypotenuse;
2038
2083
  const driftY = Math.sin(driftAngle) * driftHypotenuse;
2084
+ // Corrected path
2085
+ const driftCorrection = markerCorrection / driftHypotenuse;
2086
+ const driftAngleCorrected = Math.atan((this.v / 1000) * scaleRatio) - driftCorrection;
2087
+ const driftStartX = Math.cos(driftCorrection) * driftHypotenuse;
2088
+ const driftStartY = Math.sin(driftCorrection) * driftHypotenuse;
2089
+ const driftEndX = Math.cos(driftAngleCorrected) * driftHypotenuse;
2090
+ const driftEndY = Math.sin(driftAngleCorrected) * driftHypotenuse;
2091
+ // Short path?
2092
+ const vLength = driftAngleCorrected * driftHypotenuse;
2093
+ const vShort = vLength <= (markerCorrection * 2);
2039
2094
  const vMerge = vEnter.merge(vUpdate);
2040
2095
  vMerge.select('.line')
2096
+ .classed('short', vShort)
2097
+ .transition()
2098
+ .duration(this.drag ? 0 : transitionDuration)
2099
+ .ease(d3.easeCubicOut)
2100
+ .attr('d', `
2101
+ M ${timeScale(this.t0) + driftStartX}, ${evidenceScale(this.startingPoint) - driftStartY}
2102
+ A ${timeScale(200) - timeScale(0) + this.rem * 0.75} ${timeScale(200) - timeScale(0) + this.rem * 0.75} 0 0 0 ${timeScale(this.t0) + driftEndX} ${evidenceScale(this.startingPoint) - driftEndY}
2103
+ `);
2104
+ vMerge.select('.markers')
2041
2105
  .transition()
2042
2106
  .duration(this.drag ? 0 : transitionDuration)
2043
2107
  .ease(d3.easeCubicOut)
2044
2108
  .attr('d', `
2045
- M ${timeScale(this.t0 + 200) + this.rem * 0.75}, ${evidenceScale(this.startingPoint) - 2}
2046
- A ${timeScale(200) - timeScale(0)} ${timeScale(200) - timeScale(0)} 0 0 0 ${timeScale(this.t0) + driftX} ${evidenceScale(this.startingPoint) - driftY}
2109
+ M ${timeScale(this.t0 + 200) + this.rem * 0.75}, ${evidenceScale(this.startingPoint)}
2110
+ A ${timeScale(200) - timeScale(0) + this.rem * 0.75} ${timeScale(200) - timeScale(0) + this.rem * 0.75} 0 0 0 ${timeScale(this.t0) + driftX} ${evidenceScale(this.startingPoint) - driftY}
2047
2111
  `);
2048
2112
  const vLabelMerge = vMerge.select('.label')
2049
2113
  .transition()
@@ -2064,10 +2128,12 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
2064
2128
  const t0Enter = t0Update.enter().append('g')
2065
2129
  .classed('measure t0', true);
2066
2130
  t0Enter.append('line')
2067
- .classed('line', true)
2131
+ .classed('line', true);
2132
+ t0Enter.append('line')
2133
+ .classed('markers', true)
2068
2134
  /* Hack to avoid lack of context-stroke and context-fill in Safari */
2069
2135
  .attr('marker-start', 'url(#measure-arrow-t0)')
2070
- .attr('marker-end', 'url(#measure-arrow-cap-t0)');
2136
+ .attr('marker-end', 'url(#measure-capped-arrow-t0)');
2071
2137
  const t0Label = t0Enter.append('text')
2072
2138
  .classed('label', true);
2073
2139
  t0Label.append('tspan')
@@ -2079,14 +2145,25 @@ export default class DDMModel extends DecidablesMixinResizeable(AccumulableEleme
2079
2145
  t0Label.append('tspan')
2080
2146
  .classed('value', true);
2081
2147
  // MERGE
2148
+ const t0Length = Math.abs(timeScale(0) - timeScale(this.t0));
2149
+ const t0Short = t0Length <= (markerCorrection * 2);
2082
2150
  const t0Merge = t0Enter.merge(t0Update);
2083
2151
  t0Merge.select('.line')
2152
+ .classed('short', t0Short)
2084
2153
  .transition()
2085
2154
  .duration(this.drag ? 0 : transitionDuration)
2086
2155
  .ease(d3.easeCubicOut)
2087
- .attr('x1', timeScale(0) + 2)
2156
+ .attr('x1', timeScale(0) + markerCorrection)
2157
+ .attr('y1', evidenceScale(this.startingPoint) - this.rem * 0.75)
2158
+ .attr('x2', timeScale(this.t0) - markerCorrection)
2159
+ .attr('y2', evidenceScale(this.startingPoint) - this.rem * 0.75);
2160
+ t0Merge.select('.markers')
2161
+ .transition()
2162
+ .duration(this.drag ? 0 : transitionDuration)
2163
+ .ease(d3.easeCubicOut)
2164
+ .attr('x1', timeScale(0))
2088
2165
  .attr('y1', evidenceScale(this.startingPoint) - this.rem * 0.75)
2089
- .attr('x2', timeScale(this.t0) - 2)
2166
+ .attr('x2', timeScale(this.t0))
2090
2167
  .attr('y2', evidenceScale(this.startingPoint) - this.rem * 0.75);
2091
2168
  const t0LabelMerge = t0Merge.select('.label')
2092
2169
  .transition()