@veritone-ce/design-system 2.9.0-next.2 → 2.9.0-next.3

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.
Files changed (629) hide show
  1. package/dist/cjs/bundled_modules/d3-array/src/ascending.js +9 -0
  2. package/dist/cjs/bundled_modules/d3-array/src/bisect.js +16 -0
  3. package/dist/cjs/bundled_modules/d3-array/src/bisector.js +62 -0
  4. package/dist/cjs/bundled_modules/d3-array/src/descending.js +13 -0
  5. package/dist/cjs/bundled_modules/d3-array/src/deviation.js +12 -0
  6. package/dist/cjs/bundled_modules/d3-array/src/fsum.js +45 -0
  7. package/dist/cjs/bundled_modules/d3-array/src/intersection.js +25 -0
  8. package/dist/cjs/bundled_modules/d3-array/src/max.js +26 -0
  9. package/dist/cjs/bundled_modules/d3-array/src/mean.js +25 -0
  10. package/dist/cjs/bundled_modules/d3-array/src/median.js +11 -0
  11. package/dist/cjs/bundled_modules/d3-array/src/merge.js +15 -0
  12. package/dist/cjs/bundled_modules/d3-array/src/min.js +26 -0
  13. package/dist/cjs/bundled_modules/d3-array/src/number.js +27 -0
  14. package/dist/cjs/bundled_modules/d3-array/src/permute.js +9 -0
  15. package/dist/cjs/bundled_modules/d3-array/src/quantile.js +36 -0
  16. package/dist/cjs/bundled_modules/d3-array/src/quickselect.js +59 -0
  17. package/dist/cjs/bundled_modules/d3-array/src/range.js +19 -0
  18. package/dist/cjs/bundled_modules/d3-array/src/sort.js +20 -0
  19. package/dist/cjs/bundled_modules/d3-array/src/sum.js +17 -0
  20. package/dist/cjs/bundled_modules/d3-array/src/ticks.js +63 -0
  21. package/dist/cjs/bundled_modules/d3-array/src/union.js +17 -0
  22. package/dist/cjs/bundled_modules/d3-array/src/variance.js +31 -0
  23. package/dist/cjs/bundled_modules/d3-color/src/color.js +410 -0
  24. package/dist/cjs/bundled_modules/d3-color/src/cubehelix.js +68 -0
  25. package/dist/cjs/bundled_modules/d3-color/src/define.js +17 -0
  26. package/dist/cjs/bundled_modules/d3-color/src/lab.js +124 -0
  27. package/dist/cjs/bundled_modules/d3-color/src/math.js +7 -0
  28. package/dist/cjs/bundled_modules/d3-delaunay/src/delaunay.js +254 -0
  29. package/dist/cjs/bundled_modules/d3-delaunay/src/path.js +43 -0
  30. package/dist/cjs/bundled_modules/d3-delaunay/src/polygon.js +23 -0
  31. package/dist/cjs/bundled_modules/d3-delaunay/src/voronoi.js +338 -0
  32. package/dist/cjs/bundled_modules/d3-dispatch/src/dispatch.js +88 -0
  33. package/dist/cjs/bundled_modules/d3-dsv/src/dsv.js +170 -0
  34. package/dist/cjs/bundled_modules/d3-force/src/center.js +46 -0
  35. package/dist/cjs/bundled_modules/d3-force/src/collide.js +106 -0
  36. package/dist/cjs/bundled_modules/d3-force/src/constant.js +11 -0
  37. package/dist/cjs/bundled_modules/d3-force/src/jiggle.js +9 -0
  38. package/dist/cjs/bundled_modules/d3-force/src/lcg.js +15 -0
  39. package/dist/cjs/bundled_modules/d3-force/src/link.js +123 -0
  40. package/dist/cjs/bundled_modules/d3-force/src/manyBody.js +122 -0
  41. package/dist/cjs/bundled_modules/d3-force/src/simulation.js +164 -0
  42. package/dist/cjs/bundled_modules/d3-force/src/x.js +47 -0
  43. package/dist/cjs/bundled_modules/d3-force/src/y.js +47 -0
  44. package/dist/cjs/bundled_modules/d3-format/src/defaultLocale.js +24 -0
  45. package/dist/cjs/bundled_modules/d3-format/src/exponent.js +11 -0
  46. package/dist/cjs/bundled_modules/d3-format/src/formatDecimal.js +27 -0
  47. package/dist/cjs/bundled_modules/d3-format/src/formatGroup.js +24 -0
  48. package/dist/cjs/bundled_modules/d3-format/src/formatNumerals.js +13 -0
  49. package/dist/cjs/bundled_modules/d3-format/src/formatPrefixAuto.js +22 -0
  50. package/dist/cjs/bundled_modules/d3-format/src/formatRounded.js +17 -0
  51. package/dist/cjs/bundled_modules/d3-format/src/formatSpecifier.js +54 -0
  52. package/dist/cjs/bundled_modules/d3-format/src/formatTrim.js +17 -0
  53. package/dist/cjs/bundled_modules/d3-format/src/formatTypes.js +25 -0
  54. package/dist/cjs/bundled_modules/d3-format/src/identity.js +9 -0
  55. package/dist/cjs/bundled_modules/d3-format/src/locale.js +154 -0
  56. package/dist/cjs/bundled_modules/d3-format/src/precisionFixed.js +11 -0
  57. package/dist/cjs/bundled_modules/d3-format/src/precisionPrefix.js +11 -0
  58. package/dist/cjs/bundled_modules/d3-format/src/precisionRound.js +12 -0
  59. package/dist/cjs/bundled_modules/d3-geo/src/area.js +83 -0
  60. package/dist/cjs/bundled_modules/d3-geo/src/bounds.js +185 -0
  61. package/dist/cjs/bundled_modules/d3-geo/src/cartesian.js +43 -0
  62. package/dist/cjs/bundled_modules/d3-geo/src/centroid.js +149 -0
  63. package/dist/cjs/bundled_modules/d3-geo/src/circle.js +35 -0
  64. package/dist/cjs/bundled_modules/d3-geo/src/clip/antimeridian.js +98 -0
  65. package/dist/cjs/bundled_modules/d3-geo/src/clip/buffer.js +30 -0
  66. package/dist/cjs/bundled_modules/d3-geo/src/clip/circle.js +183 -0
  67. package/dist/cjs/bundled_modules/d3-geo/src/clip/index.js +137 -0
  68. package/dist/cjs/bundled_modules/d3-geo/src/clip/line.js +65 -0
  69. package/dist/cjs/bundled_modules/d3-geo/src/clip/rectangle.js +174 -0
  70. package/dist/cjs/bundled_modules/d3-geo/src/clip/rejoin.js +109 -0
  71. package/dist/cjs/bundled_modules/d3-geo/src/compose.js +18 -0
  72. package/dist/cjs/bundled_modules/d3-geo/src/graticule.js +107 -0
  73. package/dist/cjs/bundled_modules/d3-geo/src/identity.js +7 -0
  74. package/dist/cjs/bundled_modules/d3-geo/src/math.js +57 -0
  75. package/dist/cjs/bundled_modules/d3-geo/src/noop.js +7 -0
  76. package/dist/cjs/bundled_modules/d3-geo/src/path/area.js +54 -0
  77. package/dist/cjs/bundled_modules/d3-geo/src/path/bounds.js +32 -0
  78. package/dist/cjs/bundled_modules/d3-geo/src/path/centroid.js +104 -0
  79. package/dist/cjs/bundled_modules/d3-geo/src/path/context.js +51 -0
  80. package/dist/cjs/bundled_modules/d3-geo/src/path/index.js +82 -0
  81. package/dist/cjs/bundled_modules/d3-geo/src/path/measure.js +49 -0
  82. package/dist/cjs/bundled_modules/d3-geo/src/path/string.js +92 -0
  83. package/dist/cjs/bundled_modules/d3-geo/src/pointEqual.js +11 -0
  84. package/dist/cjs/bundled_modules/d3-geo/src/polygonContains.js +80 -0
  85. package/dist/cjs/bundled_modules/d3-geo/src/projection/albers.js +16 -0
  86. package/dist/cjs/bundled_modules/d3-geo/src/projection/albersUsa.js +117 -0
  87. package/dist/cjs/bundled_modules/d3-geo/src/projection/azimuthal.js +32 -0
  88. package/dist/cjs/bundled_modules/d3-geo/src/projection/azimuthalEqualArea.js +24 -0
  89. package/dist/cjs/bundled_modules/d3-geo/src/projection/azimuthalEquidistant.js +24 -0
  90. package/dist/cjs/bundled_modules/d3-geo/src/projection/conic.js +19 -0
  91. package/dist/cjs/bundled_modules/d3-geo/src/projection/conicConformal.js +45 -0
  92. package/dist/cjs/bundled_modules/d3-geo/src/projection/conicEqualArea.js +40 -0
  93. package/dist/cjs/bundled_modules/d3-geo/src/projection/conicEquidistant.js +39 -0
  94. package/dist/cjs/bundled_modules/d3-geo/src/projection/cylindricalEqualArea.js +19 -0
  95. package/dist/cjs/bundled_modules/d3-geo/src/projection/equalEarth.js +43 -0
  96. package/dist/cjs/bundled_modules/d3-geo/src/projection/equirectangular.js +19 -0
  97. package/dist/cjs/bundled_modules/d3-geo/src/projection/fit.js +54 -0
  98. package/dist/cjs/bundled_modules/d3-geo/src/projection/gnomonic.js +23 -0
  99. package/dist/cjs/bundled_modules/d3-geo/src/projection/identity.js +91 -0
  100. package/dist/cjs/bundled_modules/d3-geo/src/projection/index.js +184 -0
  101. package/dist/cjs/bundled_modules/d3-geo/src/projection/mercator.js +60 -0
  102. package/dist/cjs/bundled_modules/d3-geo/src/projection/naturalEarth1.js +35 -0
  103. package/dist/cjs/bundled_modules/d3-geo/src/projection/orthographic.js +22 -0
  104. package/dist/cjs/bundled_modules/d3-geo/src/projection/resample.js +108 -0
  105. package/dist/cjs/bundled_modules/d3-geo/src/projection/stereographic.js +25 -0
  106. package/dist/cjs/bundled_modules/d3-geo/src/projection/transverseMercator.js +34 -0
  107. package/dist/cjs/bundled_modules/d3-geo/src/rotation.js +86 -0
  108. package/dist/cjs/bundled_modules/d3-geo/src/stream.js +75 -0
  109. package/dist/cjs/bundled_modules/d3-geo/src/transform.js +24 -0
  110. package/dist/cjs/bundled_modules/d3-geo-projection/src/math.js +28 -0
  111. package/dist/cjs/bundled_modules/d3-geo-projection/src/mollweide.js +38 -0
  112. package/dist/cjs/bundled_modules/d3-hierarchy/src/accessors.js +13 -0
  113. package/dist/cjs/bundled_modules/d3-hierarchy/src/array.js +27 -0
  114. package/dist/cjs/bundled_modules/d3-hierarchy/src/cluster.js +90 -0
  115. package/dist/cjs/bundled_modules/d3-hierarchy/src/constant.js +16 -0
  116. package/dist/cjs/bundled_modules/d3-hierarchy/src/hierarchy/ancestors.js +13 -0
  117. package/dist/cjs/bundled_modules/d3-hierarchy/src/hierarchy/count.js +18 -0
  118. package/dist/cjs/bundled_modules/d3-hierarchy/src/hierarchy/descendants.js +9 -0
  119. package/dist/cjs/bundled_modules/d3-hierarchy/src/hierarchy/each.js +13 -0
  120. package/dist/cjs/bundled_modules/d3-hierarchy/src/hierarchy/eachAfter.js +21 -0
  121. package/dist/cjs/bundled_modules/d3-hierarchy/src/hierarchy/eachBefore.js +18 -0
  122. package/dist/cjs/bundled_modules/d3-hierarchy/src/hierarchy/find.js +14 -0
  123. package/dist/cjs/bundled_modules/d3-hierarchy/src/hierarchy/index.js +99 -0
  124. package/dist/cjs/bundled_modules/d3-hierarchy/src/hierarchy/iterator.js +20 -0
  125. package/dist/cjs/bundled_modules/d3-hierarchy/src/hierarchy/leaves.js +15 -0
  126. package/dist/cjs/bundled_modules/d3-hierarchy/src/hierarchy/links.js +15 -0
  127. package/dist/cjs/bundled_modules/d3-hierarchy/src/hierarchy/path.js +36 -0
  128. package/dist/cjs/bundled_modules/d3-hierarchy/src/hierarchy/sort.js +13 -0
  129. package/dist/cjs/bundled_modules/d3-hierarchy/src/hierarchy/sum.js +15 -0
  130. package/dist/cjs/bundled_modules/d3-hierarchy/src/lcg.js +15 -0
  131. package/dist/cjs/bundled_modules/d3-hierarchy/src/pack/enclose.js +122 -0
  132. package/dist/cjs/bundled_modules/d3-hierarchy/src/pack/index.js +87 -0
  133. package/dist/cjs/bundled_modules/d3-hierarchy/src/pack/siblings.js +118 -0
  134. package/dist/cjs/bundled_modules/d3-hierarchy/src/partition.js +58 -0
  135. package/dist/cjs/bundled_modules/d3-hierarchy/src/stratify.js +151 -0
  136. package/dist/cjs/bundled_modules/d3-hierarchy/src/tree.js +243 -0
  137. package/dist/cjs/bundled_modules/d3-hierarchy/src/treemap/binary.js +52 -0
  138. package/dist/cjs/bundled_modules/d3-hierarchy/src/treemap/dice.js +18 -0
  139. package/dist/cjs/bundled_modules/d3-hierarchy/src/treemap/index.js +100 -0
  140. package/dist/cjs/bundled_modules/d3-hierarchy/src/treemap/resquarify.js +42 -0
  141. package/dist/cjs/bundled_modules/d3-hierarchy/src/treemap/round.js +12 -0
  142. package/dist/cjs/bundled_modules/d3-hierarchy/src/treemap/slice.js +18 -0
  143. package/dist/cjs/bundled_modules/d3-hierarchy/src/treemap/sliceDice.js +12 -0
  144. package/dist/cjs/bundled_modules/d3-hierarchy/src/treemap/squarify.js +74 -0
  145. package/dist/cjs/bundled_modules/d3-interpolate/src/array.js +29 -0
  146. package/dist/cjs/bundled_modules/d3-interpolate/src/basis.js +26 -0
  147. package/dist/cjs/bundled_modules/d3-interpolate/src/basisClosed.js +19 -0
  148. package/dist/cjs/bundled_modules/d3-interpolate/src/color.js +37 -0
  149. package/dist/cjs/bundled_modules/d3-interpolate/src/constant.js +7 -0
  150. package/dist/cjs/bundled_modules/d3-interpolate/src/cubehelix.js +36 -0
  151. package/dist/cjs/bundled_modules/d3-interpolate/src/date.js +12 -0
  152. package/dist/cjs/bundled_modules/d3-interpolate/src/discrete.js +12 -0
  153. package/dist/cjs/bundled_modules/d3-interpolate/src/hcl.js +28 -0
  154. package/dist/cjs/bundled_modules/d3-interpolate/src/hsl.js +28 -0
  155. package/dist/cjs/bundled_modules/d3-interpolate/src/hue.js +15 -0
  156. package/dist/cjs/bundled_modules/d3-interpolate/src/index.js +53 -0
  157. package/dist/cjs/bundled_modules/d3-interpolate/src/lab.js +22 -0
  158. package/dist/cjs/bundled_modules/d3-interpolate/src/number.js +11 -0
  159. package/dist/cjs/bundled_modules/d3-interpolate/src/numberArray.js +21 -0
  160. package/dist/cjs/bundled_modules/d3-interpolate/src/object.js +29 -0
  161. package/dist/cjs/bundled_modules/d3-interpolate/src/piecewise.js +17 -0
  162. package/dist/cjs/bundled_modules/d3-interpolate/src/quantize.js +11 -0
  163. package/dist/cjs/bundled_modules/d3-interpolate/src/rgb.js +63 -0
  164. package/dist/cjs/bundled_modules/d3-interpolate/src/round.js +11 -0
  165. package/dist/cjs/bundled_modules/d3-interpolate/src/string.js +70 -0
  166. package/dist/cjs/bundled_modules/d3-interpolate/src/transform/decompose.js +33 -0
  167. package/dist/cjs/bundled_modules/d3-interpolate/src/transform/index.js +68 -0
  168. package/dist/cjs/bundled_modules/d3-interpolate/src/transform/parse.js +23 -0
  169. package/dist/cjs/bundled_modules/d3-interpolate/src/value.js +28 -0
  170. package/dist/cjs/bundled_modules/d3-interpolate/src/zoom.js +77 -0
  171. package/dist/cjs/bundled_modules/d3-path/src/path.js +157 -0
  172. package/dist/cjs/bundled_modules/d3-quadtree/src/add.js +91 -0
  173. package/dist/cjs/bundled_modules/d3-quadtree/src/cover.js +49 -0
  174. package/dist/cjs/bundled_modules/d3-quadtree/src/data.js +13 -0
  175. package/dist/cjs/bundled_modules/d3-quadtree/src/extent.js +11 -0
  176. package/dist/cjs/bundled_modules/d3-quadtree/src/find.js +76 -0
  177. package/dist/cjs/bundled_modules/d3-quadtree/src/quad.js +13 -0
  178. package/dist/cjs/bundled_modules/d3-quadtree/src/quadtree.js +79 -0
  179. package/dist/cjs/bundled_modules/d3-quadtree/src/remove.js +69 -0
  180. package/dist/cjs/bundled_modules/d3-quadtree/src/root.js +9 -0
  181. package/dist/cjs/bundled_modules/d3-quadtree/src/size.js +13 -0
  182. package/dist/cjs/bundled_modules/d3-quadtree/src/visit.js +22 -0
  183. package/dist/cjs/bundled_modules/d3-quadtree/src/visitAfter.js +27 -0
  184. package/dist/cjs/bundled_modules/d3-quadtree/src/x.js +14 -0
  185. package/dist/cjs/bundled_modules/d3-quadtree/src/y.js +14 -0
  186. package/dist/cjs/bundled_modules/d3-scale/src/constant.js +11 -0
  187. package/dist/cjs/bundled_modules/d3-scale/src/continuous.js +136 -0
  188. package/dist/cjs/bundled_modules/d3-scale/src/diverging.js +116 -0
  189. package/dist/cjs/bundled_modules/d3-scale/src/identity.js +34 -0
  190. package/dist/cjs/bundled_modules/d3-scale/src/init.js +31 -0
  191. package/dist/cjs/bundled_modules/d3-scale/src/linear.js +77 -0
  192. package/dist/cjs/bundled_modules/d3-scale/src/log.js +148 -0
  193. package/dist/cjs/bundled_modules/d3-scale/src/nice.js +24 -0
  194. package/dist/cjs/bundled_modules/d3-scale/src/number.js +9 -0
  195. package/dist/cjs/bundled_modules/d3-scale/src/ordinal.js +53 -0
  196. package/dist/cjs/bundled_modules/d3-scale/src/pow.js +58 -0
  197. package/dist/cjs/bundled_modules/d3-scale/src/quantile.js +65 -0
  198. package/dist/cjs/bundled_modules/d3-scale/src/quantize.js +62 -0
  199. package/dist/cjs/bundled_modules/d3-scale/src/sequential.js +119 -0
  200. package/dist/cjs/bundled_modules/d3-scale/src/symlog.js +42 -0
  201. package/dist/cjs/bundled_modules/d3-scale/src/threshold.js +45 -0
  202. package/dist/cjs/bundled_modules/d3-scale/src/tickFormat.js +39 -0
  203. package/dist/cjs/bundled_modules/d3-scale/src/time.js +85 -0
  204. package/dist/cjs/bundled_modules/d3-scale/src/utcTime.js +21 -0
  205. package/dist/cjs/bundled_modules/d3-scale-chromatic/src/categorical/Accent.js +9 -0
  206. package/dist/cjs/bundled_modules/d3-scale-chromatic/src/categorical/Dark2.js +9 -0
  207. package/dist/cjs/bundled_modules/d3-scale-chromatic/src/categorical/Paired.js +9 -0
  208. package/dist/cjs/bundled_modules/d3-scale-chromatic/src/categorical/Pastel1.js +9 -0
  209. package/dist/cjs/bundled_modules/d3-scale-chromatic/src/categorical/Pastel2.js +9 -0
  210. package/dist/cjs/bundled_modules/d3-scale-chromatic/src/categorical/Set1.js +9 -0
  211. package/dist/cjs/bundled_modules/d3-scale-chromatic/src/categorical/Set2.js +9 -0
  212. package/dist/cjs/bundled_modules/d3-scale-chromatic/src/categorical/Set3.js +9 -0
  213. package/dist/cjs/bundled_modules/d3-scale-chromatic/src/categorical/category10.js +9 -0
  214. package/dist/cjs/bundled_modules/d3-scale-chromatic/src/categorical/observable10.js +9 -0
  215. package/dist/cjs/bundled_modules/d3-scale-chromatic/src/colors.js +11 -0
  216. package/dist/cjs/bundled_modules/d3-shape/src/arc.js +274 -0
  217. package/dist/cjs/bundled_modules/d3-shape/src/area.js +118 -0
  218. package/dist/cjs/bundled_modules/d3-shape/src/array.js +11 -0
  219. package/dist/cjs/bundled_modules/d3-shape/src/constant.js +11 -0
  220. package/dist/cjs/bundled_modules/d3-shape/src/curve/basis.js +59 -0
  221. package/dist/cjs/bundled_modules/d3-shape/src/curve/basisClosed.js +58 -0
  222. package/dist/cjs/bundled_modules/d3-shape/src/curve/basisOpen.js +45 -0
  223. package/dist/cjs/bundled_modules/d3-shape/src/curve/bundle.js +62 -0
  224. package/dist/cjs/bundled_modules/d3-shape/src/curve/cardinal.js +69 -0
  225. package/dist/cjs/bundled_modules/d3-shape/src/curve/cardinalClosed.js +68 -0
  226. package/dist/cjs/bundled_modules/d3-shape/src/curve/cardinalOpen.js +56 -0
  227. package/dist/cjs/bundled_modules/d3-shape/src/curve/catmullRom.js +95 -0
  228. package/dist/cjs/bundled_modules/d3-shape/src/curve/catmullRomClosed.js +80 -0
  229. package/dist/cjs/bundled_modules/d3-shape/src/curve/catmullRomOpen.js +68 -0
  230. package/dist/cjs/bundled_modules/d3-shape/src/curve/linear.js +37 -0
  231. package/dist/cjs/bundled_modules/d3-shape/src/curve/linearClosed.js +31 -0
  232. package/dist/cjs/bundled_modules/d3-shape/src/curve/monotone.js +109 -0
  233. package/dist/cjs/bundled_modules/d3-shape/src/curve/natural.js +71 -0
  234. package/dist/cjs/bundled_modules/d3-shape/src/curve/step.js +61 -0
  235. package/dist/cjs/bundled_modules/d3-shape/src/line.js +64 -0
  236. package/dist/cjs/bundled_modules/d3-shape/src/math.js +36 -0
  237. package/dist/cjs/bundled_modules/d3-shape/src/noop.js +7 -0
  238. package/dist/cjs/bundled_modules/d3-shape/src/path.js +23 -0
  239. package/dist/cjs/bundled_modules/d3-shape/src/point.js +12 -0
  240. package/dist/cjs/bundled_modules/d3-shape/src/symbol/circle.js +15 -0
  241. package/dist/cjs/bundled_modules/d3-shape/src/symbol.js +38 -0
  242. package/dist/cjs/bundled_modules/d3-time/src/day.js +41 -0
  243. package/dist/cjs/bundled_modules/d3-time/src/duration.js +17 -0
  244. package/dist/cjs/bundled_modules/d3-time/src/hour.js +31 -0
  245. package/dist/cjs/bundled_modules/d3-time/src/interval.js +73 -0
  246. package/dist/cjs/bundled_modules/d3-time/src/millisecond.js +29 -0
  247. package/dist/cjs/bundled_modules/d3-time/src/minute.js +31 -0
  248. package/dist/cjs/bundled_modules/d3-time/src/month.js +32 -0
  249. package/dist/cjs/bundled_modules/d3-time/src/second.js +18 -0
  250. package/dist/cjs/bundled_modules/d3-time/src/ticks.js +64 -0
  251. package/dist/cjs/bundled_modules/d3-time/src/week.js +73 -0
  252. package/dist/cjs/bundled_modules/d3-time/src/year.js +54 -0
  253. package/dist/cjs/bundled_modules/d3-time-format/src/defaultLocale.js +33 -0
  254. package/dist/cjs/bundled_modules/d3-time-format/src/locale.js +694 -0
  255. package/dist/cjs/bundled_modules/d3-timer/src/interval.js +23 -0
  256. package/dist/cjs/bundled_modules/d3-timer/src/timer.js +117 -0
  257. package/dist/cjs/bundled_modules/delaunator/index.js +485 -0
  258. package/dist/cjs/bundled_modules/internmap/src/index.js +66 -0
  259. package/dist/cjs/bundled_modules/json-stringify-pretty-compact/index.js +104 -0
  260. package/dist/cjs/bundled_modules/robust-predicates/esm/orient2d.js +184 -0
  261. package/dist/cjs/bundled_modules/robust-predicates/esm/util.js +95 -0
  262. package/dist/cjs/bundled_modules/topojson-client/src/feature.js +77 -0
  263. package/dist/cjs/bundled_modules/topojson-client/src/identity.js +9 -0
  264. package/dist/cjs/bundled_modules/topojson-client/src/mesh.js +60 -0
  265. package/dist/cjs/bundled_modules/topojson-client/src/reverse.js +10 -0
  266. package/dist/cjs/bundled_modules/topojson-client/src/stitch.js +79 -0
  267. package/dist/cjs/bundled_modules/topojson-client/src/transform.js +25 -0
  268. package/dist/cjs/bundled_modules/vega/build/vega.module.js +272 -0
  269. package/dist/cjs/bundled_modules/vega-canvas/build/vega-canvas.browser.js +18 -0
  270. package/dist/cjs/bundled_modules/vega-crossfilter/build/vega-crossfilter.js +676 -0
  271. package/dist/cjs/bundled_modules/vega-dataflow/build/vega-dataflow.js +2102 -0
  272. package/dist/cjs/bundled_modules/vega-embed/build/embed.js +2939 -0
  273. package/dist/cjs/bundled_modules/vega-encode/build/vega-encode.js +962 -0
  274. package/dist/cjs/bundled_modules/vega-event-selector/build/vega-event-selector.js +192 -0
  275. package/dist/cjs/bundled_modules/vega-expression/build/vega-expression.js +1615 -0
  276. package/dist/cjs/bundled_modules/vega-force/build/vega-force.js +295 -0
  277. package/dist/cjs/bundled_modules/vega-format/build/vega-format.js +201 -0
  278. package/dist/cjs/bundled_modules/vega-functions/build/vega-functions.js +842 -0
  279. package/dist/cjs/bundled_modules/vega-geo/build/vega-geo.js +1333 -0
  280. package/dist/cjs/bundled_modules/vega-hierarchy/build/vega-hierarchy.js +580 -0
  281. package/dist/cjs/bundled_modules/vega-interpreter/build/vega-interpreter.js +310 -0
  282. package/dist/cjs/bundled_modules/vega-label/build/vega-label.js +876 -0
  283. package/dist/cjs/bundled_modules/vega-lite/build/index.js +20157 -0
  284. package/dist/cjs/bundled_modules/vega-loader/build/vega-loader.browser.js +337 -0
  285. package/dist/cjs/bundled_modules/vega-parser/build/vega-parser.js +3805 -0
  286. package/dist/cjs/bundled_modules/vega-projection/build/vega-projection.js +90 -0
  287. package/dist/cjs/bundled_modules/vega-regression/build/vega-regression.js +236 -0
  288. package/dist/cjs/bundled_modules/vega-runtime/build/vega-runtime.js +588 -0
  289. package/dist/cjs/bundled_modules/vega-scale/build/vega-scale.js +846 -0
  290. package/dist/cjs/bundled_modules/vega-scenegraph/build/vega-scenegraph.js +5040 -0
  291. package/dist/cjs/bundled_modules/vega-schema-url-parser/dist/parser.modern.js +7 -0
  292. package/dist/cjs/bundled_modules/vega-selections/build/vega-selection.js +342 -0
  293. package/dist/cjs/bundled_modules/vega-statistics/build/vega-statistics.js +1193 -0
  294. package/dist/cjs/bundled_modules/vega-themes/build/index.js +853 -0
  295. package/dist/cjs/bundled_modules/vega-time/build/vega-time.js +342 -0
  296. package/dist/cjs/bundled_modules/vega-tooltip/build/index.js +353 -0
  297. package/dist/cjs/bundled_modules/vega-transforms/build/vega-transforms.js +3781 -0
  298. package/dist/cjs/bundled_modules/vega-util/build/vega-util.js +824 -0
  299. package/dist/cjs/bundled_modules/vega-view/build/vega-view.js +1306 -0
  300. package/dist/cjs/bundled_modules/vega-view-transforms/build/vega-view-transforms.js +1313 -0
  301. package/dist/cjs/bundled_modules/vega-voronoi/build/vega-voronoi.js +80 -0
  302. package/dist/cjs/bundled_modules/vega-wordcloud/build/vega-wordcloud.js +540 -0
  303. package/dist/cjs/unstable/extras/chart/BarChart.js +42 -0
  304. package/dist/cjs/unstable/extras/chart/Chart.js +100 -0
  305. package/dist/cjs/unstable/extras/chart/DistributionChart.js +84 -0
  306. package/dist/cjs/unstable/extras/chart/DonutChart.js +43 -0
  307. package/dist/cjs/unstable/extras/chart/LineChart.js +45 -0
  308. package/dist/cjs/unstable/extras/chart/PieChart.js +39 -0
  309. package/dist/cjs/unstable/extras/chart/TimelineChart.js +48 -0
  310. package/dist/cjs/unstable/extras/chart/index.js +23 -0
  311. package/dist/esm/bundled_modules/d3-array/src/ascending.js +5 -0
  312. package/dist/esm/bundled_modules/d3-array/src/bisect.js +10 -0
  313. package/dist/esm/bundled_modules/d3-array/src/bisector.js +58 -0
  314. package/dist/esm/bundled_modules/d3-array/src/descending.js +9 -0
  315. package/dist/esm/bundled_modules/d3-array/src/deviation.js +8 -0
  316. package/dist/esm/bundled_modules/d3-array/src/fsum.js +43 -0
  317. package/dist/esm/bundled_modules/d3-array/src/intersection.js +21 -0
  318. package/dist/esm/bundled_modules/d3-array/src/max.js +22 -0
  319. package/dist/esm/bundled_modules/d3-array/src/mean.js +21 -0
  320. package/dist/esm/bundled_modules/d3-array/src/median.js +7 -0
  321. package/dist/esm/bundled_modules/d3-array/src/merge.js +11 -0
  322. package/dist/esm/bundled_modules/d3-array/src/min.js +22 -0
  323. package/dist/esm/bundled_modules/d3-array/src/number.js +22 -0
  324. package/dist/esm/bundled_modules/d3-array/src/permute.js +5 -0
  325. package/dist/esm/bundled_modules/d3-array/src/quantile.js +31 -0
  326. package/dist/esm/bundled_modules/d3-array/src/quickselect.js +55 -0
  327. package/dist/esm/bundled_modules/d3-array/src/range.js +15 -0
  328. package/dist/esm/bundled_modules/d3-array/src/sort.js +17 -0
  329. package/dist/esm/bundled_modules/d3-array/src/sum.js +13 -0
  330. package/dist/esm/bundled_modules/d3-array/src/ticks.js +57 -0
  331. package/dist/esm/bundled_modules/d3-array/src/union.js +13 -0
  332. package/dist/esm/bundled_modules/d3-array/src/variance.js +27 -0
  333. package/dist/esm/bundled_modules/d3-color/src/color.js +398 -0
  334. package/dist/esm/bundled_modules/d3-color/src/cubehelix.js +63 -0
  335. package/dist/esm/bundled_modules/d3-color/src/define.js +12 -0
  336. package/dist/esm/bundled_modules/d3-color/src/lab.js +117 -0
  337. package/dist/esm/bundled_modules/d3-color/src/math.js +4 -0
  338. package/dist/esm/bundled_modules/d3-delaunay/src/delaunay.js +250 -0
  339. package/dist/esm/bundled_modules/d3-delaunay/src/path.js +39 -0
  340. package/dist/esm/bundled_modules/d3-delaunay/src/polygon.js +19 -0
  341. package/dist/esm/bundled_modules/d3-delaunay/src/voronoi.js +334 -0
  342. package/dist/esm/bundled_modules/d3-dispatch/src/dispatch.js +84 -0
  343. package/dist/esm/bundled_modules/d3-dsv/src/dsv.js +166 -0
  344. package/dist/esm/bundled_modules/d3-force/src/center.js +42 -0
  345. package/dist/esm/bundled_modules/d3-force/src/collide.js +102 -0
  346. package/dist/esm/bundled_modules/d3-force/src/constant.js +7 -0
  347. package/dist/esm/bundled_modules/d3-force/src/jiggle.js +5 -0
  348. package/dist/esm/bundled_modules/d3-force/src/lcg.js +11 -0
  349. package/dist/esm/bundled_modules/d3-force/src/link.js +119 -0
  350. package/dist/esm/bundled_modules/d3-force/src/manyBody.js +118 -0
  351. package/dist/esm/bundled_modules/d3-force/src/simulation.js +158 -0
  352. package/dist/esm/bundled_modules/d3-force/src/x.js +43 -0
  353. package/dist/esm/bundled_modules/d3-force/src/y.js +43 -0
  354. package/dist/esm/bundled_modules/d3-format/src/defaultLocale.js +20 -0
  355. package/dist/esm/bundled_modules/d3-format/src/exponent.js +7 -0
  356. package/dist/esm/bundled_modules/d3-format/src/formatDecimal.js +22 -0
  357. package/dist/esm/bundled_modules/d3-format/src/formatGroup.js +20 -0
  358. package/dist/esm/bundled_modules/d3-format/src/formatNumerals.js +9 -0
  359. package/dist/esm/bundled_modules/d3-format/src/formatPrefixAuto.js +18 -0
  360. package/dist/esm/bundled_modules/d3-format/src/formatRounded.js +13 -0
  361. package/dist/esm/bundled_modules/d3-format/src/formatSpecifier.js +49 -0
  362. package/dist/esm/bundled_modules/d3-format/src/formatTrim.js +13 -0
  363. package/dist/esm/bundled_modules/d3-format/src/formatTypes.js +21 -0
  364. package/dist/esm/bundled_modules/d3-format/src/identity.js +5 -0
  365. package/dist/esm/bundled_modules/d3-format/src/locale.js +150 -0
  366. package/dist/esm/bundled_modules/d3-format/src/precisionFixed.js +7 -0
  367. package/dist/esm/bundled_modules/d3-format/src/precisionPrefix.js +7 -0
  368. package/dist/esm/bundled_modules/d3-format/src/precisionRound.js +8 -0
  369. package/dist/esm/bundled_modules/d3-geo/src/area.js +78 -0
  370. package/dist/esm/bundled_modules/d3-geo/src/bounds.js +181 -0
  371. package/dist/esm/bundled_modules/d3-geo/src/cartesian.js +35 -0
  372. package/dist/esm/bundled_modules/d3-geo/src/centroid.js +145 -0
  373. package/dist/esm/bundled_modules/d3-geo/src/circle.js +33 -0
  374. package/dist/esm/bundled_modules/d3-geo/src/clip/antimeridian.js +94 -0
  375. package/dist/esm/bundled_modules/d3-geo/src/clip/buffer.js +26 -0
  376. package/dist/esm/bundled_modules/d3-geo/src/clip/circle.js +179 -0
  377. package/dist/esm/bundled_modules/d3-geo/src/clip/index.js +133 -0
  378. package/dist/esm/bundled_modules/d3-geo/src/clip/line.js +61 -0
  379. package/dist/esm/bundled_modules/d3-geo/src/clip/rectangle.js +170 -0
  380. package/dist/esm/bundled_modules/d3-geo/src/clip/rejoin.js +105 -0
  381. package/dist/esm/bundled_modules/d3-geo/src/compose.js +14 -0
  382. package/dist/esm/bundled_modules/d3-geo/src/graticule.js +103 -0
  383. package/dist/esm/bundled_modules/d3-geo/src/identity.js +3 -0
  384. package/dist/esm/bundled_modules/d3-geo/src/math.js +33 -0
  385. package/dist/esm/bundled_modules/d3-geo/src/noop.js +3 -0
  386. package/dist/esm/bundled_modules/d3-geo/src/path/area.js +50 -0
  387. package/dist/esm/bundled_modules/d3-geo/src/path/bounds.js +28 -0
  388. package/dist/esm/bundled_modules/d3-geo/src/path/centroid.js +100 -0
  389. package/dist/esm/bundled_modules/d3-geo/src/path/context.js +47 -0
  390. package/dist/esm/bundled_modules/d3-geo/src/path/index.js +78 -0
  391. package/dist/esm/bundled_modules/d3-geo/src/path/measure.js +45 -0
  392. package/dist/esm/bundled_modules/d3-geo/src/path/string.js +88 -0
  393. package/dist/esm/bundled_modules/d3-geo/src/pointEqual.js +7 -0
  394. package/dist/esm/bundled_modules/d3-geo/src/polygonContains.js +76 -0
  395. package/dist/esm/bundled_modules/d3-geo/src/projection/albers.js +12 -0
  396. package/dist/esm/bundled_modules/d3-geo/src/projection/albersUsa.js +113 -0
  397. package/dist/esm/bundled_modules/d3-geo/src/projection/azimuthal.js +29 -0
  398. package/dist/esm/bundled_modules/d3-geo/src/projection/azimuthalEqualArea.js +19 -0
  399. package/dist/esm/bundled_modules/d3-geo/src/projection/azimuthalEquidistant.js +19 -0
  400. package/dist/esm/bundled_modules/d3-geo/src/projection/conic.js +17 -0
  401. package/dist/esm/bundled_modules/d3-geo/src/projection/conicConformal.js +40 -0
  402. package/dist/esm/bundled_modules/d3-geo/src/projection/conicEqualArea.js +35 -0
  403. package/dist/esm/bundled_modules/d3-geo/src/projection/conicEquidistant.js +34 -0
  404. package/dist/esm/bundled_modules/d3-geo/src/projection/cylindricalEqualArea.js +17 -0
  405. package/dist/esm/bundled_modules/d3-geo/src/projection/equalEarth.js +38 -0
  406. package/dist/esm/bundled_modules/d3-geo/src/projection/equirectangular.js +14 -0
  407. package/dist/esm/bundled_modules/d3-geo/src/projection/fit.js +49 -0
  408. package/dist/esm/bundled_modules/d3-geo/src/projection/gnomonic.js +18 -0
  409. package/dist/esm/bundled_modules/d3-geo/src/projection/identity.js +87 -0
  410. package/dist/esm/bundled_modules/d3-geo/src/projection/index.js +179 -0
  411. package/dist/esm/bundled_modules/d3-geo/src/projection/mercator.js +54 -0
  412. package/dist/esm/bundled_modules/d3-geo/src/projection/naturalEarth1.js +30 -0
  413. package/dist/esm/bundled_modules/d3-geo/src/projection/orthographic.js +17 -0
  414. package/dist/esm/bundled_modules/d3-geo/src/projection/resample.js +104 -0
  415. package/dist/esm/bundled_modules/d3-geo/src/projection/stereographic.js +20 -0
  416. package/dist/esm/bundled_modules/d3-geo/src/projection/transverseMercator.js +29 -0
  417. package/dist/esm/bundled_modules/d3-geo/src/rotation.js +81 -0
  418. package/dist/esm/bundled_modules/d3-geo/src/stream.js +71 -0
  419. package/dist/esm/bundled_modules/d3-geo/src/transform.js +22 -0
  420. package/dist/esm/bundled_modules/d3-geo-projection/src/math.js +18 -0
  421. package/dist/esm/bundled_modules/d3-geo-projection/src/mollweide.js +31 -0
  422. package/dist/esm/bundled_modules/d3-hierarchy/src/accessors.js +10 -0
  423. package/dist/esm/bundled_modules/d3-hierarchy/src/array.js +22 -0
  424. package/dist/esm/bundled_modules/d3-hierarchy/src/cluster.js +86 -0
  425. package/dist/esm/bundled_modules/d3-hierarchy/src/constant.js +11 -0
  426. package/dist/esm/bundled_modules/d3-hierarchy/src/hierarchy/ancestors.js +9 -0
  427. package/dist/esm/bundled_modules/d3-hierarchy/src/hierarchy/count.js +14 -0
  428. package/dist/esm/bundled_modules/d3-hierarchy/src/hierarchy/descendants.js +5 -0
  429. package/dist/esm/bundled_modules/d3-hierarchy/src/hierarchy/each.js +9 -0
  430. package/dist/esm/bundled_modules/d3-hierarchy/src/hierarchy/eachAfter.js +17 -0
  431. package/dist/esm/bundled_modules/d3-hierarchy/src/hierarchy/eachBefore.js +14 -0
  432. package/dist/esm/bundled_modules/d3-hierarchy/src/hierarchy/find.js +10 -0
  433. package/dist/esm/bundled_modules/d3-hierarchy/src/hierarchy/index.js +93 -0
  434. package/dist/esm/bundled_modules/d3-hierarchy/src/hierarchy/iterator.js +16 -0
  435. package/dist/esm/bundled_modules/d3-hierarchy/src/hierarchy/leaves.js +11 -0
  436. package/dist/esm/bundled_modules/d3-hierarchy/src/hierarchy/links.js +11 -0
  437. package/dist/esm/bundled_modules/d3-hierarchy/src/hierarchy/path.js +32 -0
  438. package/dist/esm/bundled_modules/d3-hierarchy/src/hierarchy/sort.js +9 -0
  439. package/dist/esm/bundled_modules/d3-hierarchy/src/hierarchy/sum.js +11 -0
  440. package/dist/esm/bundled_modules/d3-hierarchy/src/lcg.js +11 -0
  441. package/dist/esm/bundled_modules/d3-hierarchy/src/pack/enclose.js +120 -0
  442. package/dist/esm/bundled_modules/d3-hierarchy/src/pack/index.js +83 -0
  443. package/dist/esm/bundled_modules/d3-hierarchy/src/pack/siblings.js +116 -0
  444. package/dist/esm/bundled_modules/d3-hierarchy/src/partition.js +54 -0
  445. package/dist/esm/bundled_modules/d3-hierarchy/src/stratify.js +147 -0
  446. package/dist/esm/bundled_modules/d3-hierarchy/src/tree.js +239 -0
  447. package/dist/esm/bundled_modules/d3-hierarchy/src/treemap/binary.js +48 -0
  448. package/dist/esm/bundled_modules/d3-hierarchy/src/treemap/dice.js +14 -0
  449. package/dist/esm/bundled_modules/d3-hierarchy/src/treemap/index.js +96 -0
  450. package/dist/esm/bundled_modules/d3-hierarchy/src/treemap/resquarify.js +38 -0
  451. package/dist/esm/bundled_modules/d3-hierarchy/src/treemap/round.js +8 -0
  452. package/dist/esm/bundled_modules/d3-hierarchy/src/treemap/slice.js +14 -0
  453. package/dist/esm/bundled_modules/d3-hierarchy/src/treemap/sliceDice.js +8 -0
  454. package/dist/esm/bundled_modules/d3-hierarchy/src/treemap/squarify.js +68 -0
  455. package/dist/esm/bundled_modules/d3-interpolate/src/array.js +24 -0
  456. package/dist/esm/bundled_modules/d3-interpolate/src/basis.js +21 -0
  457. package/dist/esm/bundled_modules/d3-interpolate/src/basisClosed.js +15 -0
  458. package/dist/esm/bundled_modules/d3-interpolate/src/color.js +31 -0
  459. package/dist/esm/bundled_modules/d3-interpolate/src/constant.js +3 -0
  460. package/dist/esm/bundled_modules/d3-interpolate/src/cubehelix.js +31 -0
  461. package/dist/esm/bundled_modules/d3-interpolate/src/date.js +8 -0
  462. package/dist/esm/bundled_modules/d3-interpolate/src/discrete.js +8 -0
  463. package/dist/esm/bundled_modules/d3-interpolate/src/hcl.js +23 -0
  464. package/dist/esm/bundled_modules/d3-interpolate/src/hsl.js +23 -0
  465. package/dist/esm/bundled_modules/d3-interpolate/src/hue.js +11 -0
  466. package/dist/esm/bundled_modules/d3-interpolate/src/index.js +21 -0
  467. package/dist/esm/bundled_modules/d3-interpolate/src/lab.js +18 -0
  468. package/dist/esm/bundled_modules/d3-interpolate/src/number.js +7 -0
  469. package/dist/esm/bundled_modules/d3-interpolate/src/numberArray.js +16 -0
  470. package/dist/esm/bundled_modules/d3-interpolate/src/object.js +25 -0
  471. package/dist/esm/bundled_modules/d3-interpolate/src/piecewise.js +13 -0
  472. package/dist/esm/bundled_modules/d3-interpolate/src/quantize.js +7 -0
  473. package/dist/esm/bundled_modules/d3-interpolate/src/rgb.js +57 -0
  474. package/dist/esm/bundled_modules/d3-interpolate/src/round.js +7 -0
  475. package/dist/esm/bundled_modules/d3-interpolate/src/string.js +66 -0
  476. package/dist/esm/bundled_modules/d3-interpolate/src/transform/decompose.js +28 -0
  477. package/dist/esm/bundled_modules/d3-interpolate/src/transform/index.js +65 -0
  478. package/dist/esm/bundled_modules/d3-interpolate/src/transform/parse.js +20 -0
  479. package/dist/esm/bundled_modules/d3-interpolate/src/value.js +24 -0
  480. package/dist/esm/bundled_modules/d3-interpolate/src/zoom.js +73 -0
  481. package/dist/esm/bundled_modules/d3-path/src/path.js +154 -0
  482. package/dist/esm/bundled_modules/d3-quadtree/src/add.js +86 -0
  483. package/dist/esm/bundled_modules/d3-quadtree/src/cover.js +45 -0
  484. package/dist/esm/bundled_modules/d3-quadtree/src/data.js +9 -0
  485. package/dist/esm/bundled_modules/d3-quadtree/src/extent.js +7 -0
  486. package/dist/esm/bundled_modules/d3-quadtree/src/find.js +72 -0
  487. package/dist/esm/bundled_modules/d3-quadtree/src/quad.js +9 -0
  488. package/dist/esm/bundled_modules/d3-quadtree/src/quadtree.js +75 -0
  489. package/dist/esm/bundled_modules/d3-quadtree/src/remove.js +64 -0
  490. package/dist/esm/bundled_modules/d3-quadtree/src/root.js +5 -0
  491. package/dist/esm/bundled_modules/d3-quadtree/src/size.js +9 -0
  492. package/dist/esm/bundled_modules/d3-quadtree/src/visit.js +18 -0
  493. package/dist/esm/bundled_modules/d3-quadtree/src/visitAfter.js +23 -0
  494. package/dist/esm/bundled_modules/d3-quadtree/src/x.js +9 -0
  495. package/dist/esm/bundled_modules/d3-quadtree/src/y.js +9 -0
  496. package/dist/esm/bundled_modules/d3-scale/src/constant.js +7 -0
  497. package/dist/esm/bundled_modules/d3-scale/src/continuous.js +129 -0
  498. package/dist/esm/bundled_modules/d3-scale/src/diverging.js +108 -0
  499. package/dist/esm/bundled_modules/d3-scale/src/identity.js +30 -0
  500. package/dist/esm/bundled_modules/d3-scale/src/init.js +28 -0
  501. package/dist/esm/bundled_modules/d3-scale/src/linear.js +72 -0
  502. package/dist/esm/bundled_modules/d3-scale/src/log.js +143 -0
  503. package/dist/esm/bundled_modules/d3-scale/src/nice.js +20 -0
  504. package/dist/esm/bundled_modules/d3-scale/src/number.js +5 -0
  505. package/dist/esm/bundled_modules/d3-scale/src/ordinal.js +48 -0
  506. package/dist/esm/bundled_modules/d3-scale/src/pow.js +52 -0
  507. package/dist/esm/bundled_modules/d3-scale/src/quantile.js +61 -0
  508. package/dist/esm/bundled_modules/d3-scale/src/quantize.js +58 -0
  509. package/dist/esm/bundled_modules/d3-scale/src/sequential.js +110 -0
  510. package/dist/esm/bundled_modules/d3-scale/src/symlog.js +37 -0
  511. package/dist/esm/bundled_modules/d3-scale/src/threshold.js +41 -0
  512. package/dist/esm/bundled_modules/d3-scale/src/tickFormat.js +35 -0
  513. package/dist/esm/bundled_modules/d3-scale/src/time.js +80 -0
  514. package/dist/esm/bundled_modules/d3-scale/src/utcTime.js +17 -0
  515. package/dist/esm/bundled_modules/d3-scale-chromatic/src/categorical/Accent.js +5 -0
  516. package/dist/esm/bundled_modules/d3-scale-chromatic/src/categorical/Dark2.js +5 -0
  517. package/dist/esm/bundled_modules/d3-scale-chromatic/src/categorical/Paired.js +5 -0
  518. package/dist/esm/bundled_modules/d3-scale-chromatic/src/categorical/Pastel1.js +5 -0
  519. package/dist/esm/bundled_modules/d3-scale-chromatic/src/categorical/Pastel2.js +5 -0
  520. package/dist/esm/bundled_modules/d3-scale-chromatic/src/categorical/Set1.js +5 -0
  521. package/dist/esm/bundled_modules/d3-scale-chromatic/src/categorical/Set2.js +5 -0
  522. package/dist/esm/bundled_modules/d3-scale-chromatic/src/categorical/Set3.js +5 -0
  523. package/dist/esm/bundled_modules/d3-scale-chromatic/src/categorical/category10.js +5 -0
  524. package/dist/esm/bundled_modules/d3-scale-chromatic/src/categorical/observable10.js +5 -0
  525. package/dist/esm/bundled_modules/d3-scale-chromatic/src/colors.js +7 -0
  526. package/dist/esm/bundled_modules/d3-shape/src/arc.js +270 -0
  527. package/dist/esm/bundled_modules/d3-shape/src/area.js +114 -0
  528. package/dist/esm/bundled_modules/d3-shape/src/array.js +7 -0
  529. package/dist/esm/bundled_modules/d3-shape/src/constant.js +7 -0
  530. package/dist/esm/bundled_modules/d3-shape/src/curve/basis.js +53 -0
  531. package/dist/esm/bundled_modules/d3-shape/src/curve/basisClosed.js +54 -0
  532. package/dist/esm/bundled_modules/d3-shape/src/curve/basisOpen.js +41 -0
  533. package/dist/esm/bundled_modules/d3-shape/src/curve/bundle.js +58 -0
  534. package/dist/esm/bundled_modules/d3-shape/src/curve/cardinal.js +63 -0
  535. package/dist/esm/bundled_modules/d3-shape/src/curve/cardinalClosed.js +63 -0
  536. package/dist/esm/bundled_modules/d3-shape/src/curve/cardinalOpen.js +51 -0
  537. package/dist/esm/bundled_modules/d3-shape/src/curve/catmullRom.js +90 -0
  538. package/dist/esm/bundled_modules/d3-shape/src/curve/catmullRomClosed.js +76 -0
  539. package/dist/esm/bundled_modules/d3-shape/src/curve/catmullRomOpen.js +64 -0
  540. package/dist/esm/bundled_modules/d3-shape/src/curve/linear.js +33 -0
  541. package/dist/esm/bundled_modules/d3-shape/src/curve/linearClosed.js +27 -0
  542. package/dist/esm/bundled_modules/d3-shape/src/curve/monotone.js +106 -0
  543. package/dist/esm/bundled_modules/d3-shape/src/curve/natural.js +67 -0
  544. package/dist/esm/bundled_modules/d3-shape/src/curve/step.js +55 -0
  545. package/dist/esm/bundled_modules/d3-shape/src/line.js +60 -0
  546. package/dist/esm/bundled_modules/d3-shape/src/math.js +22 -0
  547. package/dist/esm/bundled_modules/d3-shape/src/noop.js +3 -0
  548. package/dist/esm/bundled_modules/d3-shape/src/path.js +21 -0
  549. package/dist/esm/bundled_modules/d3-shape/src/point.js +9 -0
  550. package/dist/esm/bundled_modules/d3-shape/src/symbol/circle.js +11 -0
  551. package/dist/esm/bundled_modules/d3-shape/src/symbol.js +34 -0
  552. package/dist/esm/bundled_modules/d3-time/src/day.js +37 -0
  553. package/dist/esm/bundled_modules/d3-time/src/duration.js +9 -0
  554. package/dist/esm/bundled_modules/d3-time/src/hour.js +28 -0
  555. package/dist/esm/bundled_modules/d3-time/src/interval.js +71 -0
  556. package/dist/esm/bundled_modules/d3-time/src/millisecond.js +27 -0
  557. package/dist/esm/bundled_modules/d3-time/src/minute.js +28 -0
  558. package/dist/esm/bundled_modules/d3-time/src/month.js +29 -0
  559. package/dist/esm/bundled_modules/d3-time/src/second.js +16 -0
  560. package/dist/esm/bundled_modules/d3-time/src/ticks.js +59 -0
  561. package/dist/esm/bundled_modules/d3-time/src/week.js +58 -0
  562. package/dist/esm/bundled_modules/d3-time/src/year.js +51 -0
  563. package/dist/esm/bundled_modules/d3-time-format/src/defaultLocale.js +29 -0
  564. package/dist/esm/bundled_modules/d3-time-format/src/locale.js +690 -0
  565. package/dist/esm/bundled_modules/d3-timer/src/interval.js +19 -0
  566. package/dist/esm/bundled_modules/d3-timer/src/timer.js +112 -0
  567. package/dist/esm/bundled_modules/delaunator/index.js +481 -0
  568. package/dist/esm/bundled_modules/internmap/src/index.js +63 -0
  569. package/dist/esm/bundled_modules/json-stringify-pretty-compact/index.js +100 -0
  570. package/dist/esm/bundled_modules/robust-predicates/esm/orient2d.js +182 -0
  571. package/dist/esm/bundled_modules/robust-predicates/esm/util.js +88 -0
  572. package/dist/esm/bundled_modules/topojson-client/src/feature.js +72 -0
  573. package/dist/esm/bundled_modules/topojson-client/src/identity.js +5 -0
  574. package/dist/esm/bundled_modules/topojson-client/src/mesh.js +55 -0
  575. package/dist/esm/bundled_modules/topojson-client/src/reverse.js +6 -0
  576. package/dist/esm/bundled_modules/topojson-client/src/stitch.js +75 -0
  577. package/dist/esm/bundled_modules/topojson-client/src/transform.js +21 -0
  578. package/dist/esm/bundled_modules/vega/build/vega.module.js +38 -0
  579. package/dist/esm/bundled_modules/vega-canvas/build/vega-canvas.browser.js +14 -0
  580. package/dist/esm/bundled_modules/vega-crossfilter/build/vega-crossfilter.js +673 -0
  581. package/dist/esm/bundled_modules/vega-dataflow/build/vega-dataflow.js +2080 -0
  582. package/dist/esm/bundled_modules/vega-embed/build/embed.js +2932 -0
  583. package/dist/esm/bundled_modules/vega-encode/build/vega-encode.js +952 -0
  584. package/dist/esm/bundled_modules/vega-event-selector/build/vega-event-selector.js +190 -0
  585. package/dist/esm/bundled_modules/vega-expression/build/vega-expression.js +1597 -0
  586. package/dist/esm/bundled_modules/vega-force/build/vega-force.js +293 -0
  587. package/dist/esm/bundled_modules/vega-format/build/vega-format.js +191 -0
  588. package/dist/esm/bundled_modules/vega-functions/build/vega-functions.js +779 -0
  589. package/dist/esm/bundled_modules/vega-geo/build/vega-geo.js +1322 -0
  590. package/dist/esm/bundled_modules/vega-hierarchy/build/vega-hierarchy.js +572 -0
  591. package/dist/esm/bundled_modules/vega-interpreter/build/vega-interpreter.js +308 -0
  592. package/dist/esm/bundled_modules/vega-label/build/vega-label.js +874 -0
  593. package/dist/esm/bundled_modules/vega-lite/build/index.js +20110 -0
  594. package/dist/esm/bundled_modules/vega-loader/build/vega-loader.browser.js +328 -0
  595. package/dist/esm/bundled_modules/vega-parser/build/vega-parser.js +3783 -0
  596. package/dist/esm/bundled_modules/vega-projection/build/vega-projection.js +86 -0
  597. package/dist/esm/bundled_modules/vega-regression/build/vega-regression.js +233 -0
  598. package/dist/esm/bundled_modules/vega-runtime/build/vega-runtime.js +586 -0
  599. package/dist/esm/bundled_modules/vega-scale/build/vega-scale.js +799 -0
  600. package/dist/esm/bundled_modules/vega-scenegraph/build/vega-scenegraph.js +4982 -0
  601. package/dist/esm/bundled_modules/vega-schema-url-parser/dist/parser.modern.js +3 -0
  602. package/dist/esm/bundled_modules/vega-selections/build/vega-selection.js +336 -0
  603. package/dist/esm/bundled_modules/vega-statistics/build/vega-statistics.js +1157 -0
  604. package/dist/esm/bundled_modules/vega-themes/build/index.js +837 -0
  605. package/dist/esm/bundled_modules/vega-time/build/vega-time.js +314 -0
  606. package/dist/esm/bundled_modules/vega-tooltip/build/index.js +339 -0
  607. package/dist/esm/bundled_modules/vega-transforms/build/vega-transforms.js +3740 -0
  608. package/dist/esm/bundled_modules/vega-util/build/vega-util.js +753 -0
  609. package/dist/esm/bundled_modules/vega-view/build/vega-view.js +1304 -0
  610. package/dist/esm/bundled_modules/vega-view-transforms/build/vega-view-transforms.js +1306 -0
  611. package/dist/esm/bundled_modules/vega-voronoi/build/vega-voronoi.js +78 -0
  612. package/dist/esm/bundled_modules/vega-wordcloud/build/vega-wordcloud.js +538 -0
  613. package/dist/esm/unstable/extras/chart/BarChart.js +40 -0
  614. package/dist/esm/unstable/extras/chart/Chart.js +96 -0
  615. package/dist/esm/unstable/extras/chart/DistributionChart.js +82 -0
  616. package/dist/esm/unstable/extras/chart/DonutChart.js +41 -0
  617. package/dist/esm/unstable/extras/chart/LineChart.js +43 -0
  618. package/dist/esm/unstable/extras/chart/PieChart.js +37 -0
  619. package/dist/esm/unstable/extras/chart/TimelineChart.js +46 -0
  620. package/dist/esm/unstable/extras/chart/index.js +8 -0
  621. package/dist/types/unstable/extras/chart/BarChart.d.ts +16 -0
  622. package/dist/types/unstable/extras/chart/Chart.d.ts +33 -0
  623. package/dist/types/unstable/extras/chart/DistributionChart.d.ts +18 -0
  624. package/dist/types/unstable/extras/chart/DonutChart.d.ts +16 -0
  625. package/dist/types/unstable/extras/chart/LineChart.d.ts +16 -0
  626. package/dist/types/unstable/extras/chart/PieChart.d.ts +14 -0
  627. package/dist/types/unstable/extras/chart/TimelineChart.d.ts +15 -0
  628. package/dist/types/unstable/extras/chart/index.d.ts +15 -0
  629. package/package.json +1 -1
@@ -0,0 +1,5040 @@
1
+ 'use strict';
2
+
3
+ var vegaUtil = require('../../vega-util/build/vega-util.js');
4
+ var vegaCanvas_browser = require('../../vega-canvas/build/vega-canvas.browser.js');
5
+ var vegaLoader_browser = require('../../vega-loader/build/vega-loader.browser.js');
6
+ var vegaScale = require('../../vega-scale/build/vega-scale.js');
7
+ var arc$2 = require('../../d3-shape/src/arc.js');
8
+ var area$2 = require('../../d3-shape/src/area.js');
9
+ var line$2 = require('../../d3-shape/src/line.js');
10
+ var symbol$2 = require('../../d3-shape/src/symbol.js');
11
+ var path$3 = require('../../d3-path/src/path.js');
12
+ var step = require('../../d3-shape/src/curve/step.js');
13
+ var natural = require('../../d3-shape/src/curve/natural.js');
14
+ var monotone = require('../../d3-shape/src/curve/monotone.js');
15
+ var linearClosed = require('../../d3-shape/src/curve/linearClosed.js');
16
+ var linear = require('../../d3-shape/src/curve/linear.js');
17
+ var catmullRomOpen = require('../../d3-shape/src/curve/catmullRomOpen.js');
18
+ var catmullRomClosed = require('../../d3-shape/src/curve/catmullRomClosed.js');
19
+ var catmullRom = require('../../d3-shape/src/curve/catmullRom.js');
20
+ var cardinalClosed = require('../../d3-shape/src/curve/cardinalClosed.js');
21
+ var cardinalOpen = require('../../d3-shape/src/curve/cardinalOpen.js');
22
+ var cardinal = require('../../d3-shape/src/curve/cardinal.js');
23
+ var bundle$1 = require('../../d3-shape/src/curve/bundle.js');
24
+ var basisOpen = require('../../d3-shape/src/curve/basisOpen.js');
25
+ var basisClosed = require('../../d3-shape/src/curve/basisClosed.js');
26
+ var basis = require('../../d3-shape/src/curve/basis.js');
27
+
28
+ let gradient_id = 0;
29
+ function resetSVGGradientId() {
30
+ gradient_id = 0;
31
+ }
32
+ const patternPrefix = 'p_';
33
+ function isGradient(value) {
34
+ return value && value.gradient;
35
+ }
36
+ function gradientRef(g, defs, base) {
37
+ const type = g.gradient;
38
+ let id = g.id,
39
+ prefix = type === 'radial' ? patternPrefix : '';
40
+
41
+ // check id, assign default values as needed
42
+ if (!id) {
43
+ id = g.id = 'gradient_' + gradient_id++;
44
+ if (type === 'radial') {
45
+ g.x1 = get(g.x1, 0.5);
46
+ g.y1 = get(g.y1, 0.5);
47
+ g.r1 = get(g.r1, 0);
48
+ g.x2 = get(g.x2, 0.5);
49
+ g.y2 = get(g.y2, 0.5);
50
+ g.r2 = get(g.r2, 0.5);
51
+ prefix = patternPrefix;
52
+ } else {
53
+ g.x1 = get(g.x1, 0);
54
+ g.y1 = get(g.y1, 0);
55
+ g.x2 = get(g.x2, 1);
56
+ g.y2 = get(g.y2, 0);
57
+ }
58
+ }
59
+
60
+ // register definition
61
+ defs[id] = g;
62
+
63
+ // return url reference
64
+ return 'url(' + (base || '') + '#' + prefix + id + ')';
65
+ }
66
+ function get(val, def) {
67
+ return val != null ? val : def;
68
+ }
69
+ function Gradient (p0, p1) {
70
+ var stops = [],
71
+ gradient;
72
+ return gradient = {
73
+ gradient: 'linear',
74
+ x1: p0 ? p0[0] : 0,
75
+ y1: p0 ? p0[1] : 0,
76
+ x2: p1 ? p1[0] : 1,
77
+ y2: p1 ? p1[1] : 0,
78
+ stops: stops,
79
+ stop: function (offset, color) {
80
+ stops.push({
81
+ offset: offset,
82
+ color: color
83
+ });
84
+ return gradient;
85
+ }
86
+ };
87
+ }
88
+
89
+ const lookup = {
90
+ 'basis': {
91
+ curve: basis.default
92
+ },
93
+ 'basis-closed': {
94
+ curve: basisClosed.default
95
+ },
96
+ 'basis-open': {
97
+ curve: basisOpen.default
98
+ },
99
+ 'bundle': {
100
+ curve: bundle$1.default,
101
+ tension: 'beta',
102
+ value: 0.85
103
+ },
104
+ 'cardinal': {
105
+ curve: cardinal.default,
106
+ tension: 'tension',
107
+ value: 0
108
+ },
109
+ 'cardinal-open': {
110
+ curve: cardinalOpen.default,
111
+ tension: 'tension',
112
+ value: 0
113
+ },
114
+ 'cardinal-closed': {
115
+ curve: cardinalClosed.default,
116
+ tension: 'tension',
117
+ value: 0
118
+ },
119
+ 'catmull-rom': {
120
+ curve: catmullRom.default,
121
+ tension: 'alpha',
122
+ value: 0.5
123
+ },
124
+ 'catmull-rom-closed': {
125
+ curve: catmullRomClosed.default,
126
+ tension: 'alpha',
127
+ value: 0.5
128
+ },
129
+ 'catmull-rom-open': {
130
+ curve: catmullRomOpen.default,
131
+ tension: 'alpha',
132
+ value: 0.5
133
+ },
134
+ 'linear': {
135
+ curve: linear.default
136
+ },
137
+ 'linear-closed': {
138
+ curve: linearClosed.default
139
+ },
140
+ 'monotone': {
141
+ horizontal: monotone.monotoneY,
142
+ vertical: monotone.monotoneX
143
+ },
144
+ 'natural': {
145
+ curve: natural.default
146
+ },
147
+ 'step': {
148
+ curve: step.default
149
+ },
150
+ 'step-after': {
151
+ curve: step.stepAfter
152
+ },
153
+ 'step-before': {
154
+ curve: step.stepBefore
155
+ }
156
+ };
157
+ function curves(type, orientation, tension) {
158
+ var entry = vegaUtil.hasOwnProperty(lookup, type) && lookup[type],
159
+ curve = null;
160
+ if (entry) {
161
+ curve = entry.curve || entry[orientation || 'vertical'];
162
+ if (entry.tension && tension != null) {
163
+ curve = curve[entry.tension](tension);
164
+ }
165
+ }
166
+ return curve;
167
+ }
168
+
169
+ const paramCounts = {
170
+ m: 2,
171
+ l: 2,
172
+ h: 1,
173
+ v: 1,
174
+ z: 0,
175
+ c: 6,
176
+ s: 4,
177
+ q: 4,
178
+ t: 2,
179
+ a: 7
180
+ };
181
+ const commandPattern = /[mlhvzcsqta]([^mlhvzcsqta]+|$)/gi;
182
+ const numberPattern = /^[+-]?(([0-9]*\.[0-9]+)|([0-9]+\.)|([0-9]+))([eE][+-]?[0-9]+)?/;
183
+ const spacePattern = /^((\s+,?\s*)|(,\s*))/;
184
+ const flagPattern = /^[01]/;
185
+ function parse(path) {
186
+ const commands = [];
187
+ const matches = path.match(commandPattern) || [];
188
+ matches.forEach(str => {
189
+ let cmd = str[0];
190
+ const type = cmd.toLowerCase();
191
+
192
+ // parse parameters
193
+ const paramCount = paramCounts[type];
194
+ const params = parseParams(type, paramCount, str.slice(1).trim());
195
+ const count = params.length;
196
+
197
+ // error checking based on parameter count
198
+ if (count < paramCount || count && count % paramCount !== 0) {
199
+ throw Error('Invalid SVG path, incorrect parameter count');
200
+ }
201
+
202
+ // register the command
203
+ commands.push([cmd, ...params.slice(0, paramCount)]);
204
+
205
+ // exit now if we're done, also handles zero-param 'z'
206
+ if (count === paramCount) {
207
+ return;
208
+ }
209
+
210
+ // handle implicit line-to
211
+ if (type === 'm') {
212
+ cmd = cmd === 'M' ? 'L' : 'l';
213
+ }
214
+
215
+ // repeat command when given extended param list
216
+ for (let i = paramCount; i < count; i += paramCount) {
217
+ commands.push([cmd, ...params.slice(i, i + paramCount)]);
218
+ }
219
+ });
220
+ return commands;
221
+ }
222
+ function parseParams(type, paramCount, segment) {
223
+ const params = [];
224
+ for (let index = 0; paramCount && index < segment.length;) {
225
+ for (let i = 0; i < paramCount; ++i) {
226
+ const pattern = type === 'a' && (i === 3 || i === 4) ? flagPattern : numberPattern;
227
+ const match = segment.slice(index).match(pattern);
228
+ if (match === null) {
229
+ throw Error('Invalid SVG path, incorrect parameter type');
230
+ }
231
+ index += match[0].length;
232
+ params.push(+match[0]);
233
+ const ws = segment.slice(index).match(spacePattern);
234
+ if (ws !== null) {
235
+ index += ws[0].length;
236
+ }
237
+ }
238
+ }
239
+ return params;
240
+ }
241
+
242
+ const DegToRad = Math.PI / 180;
243
+ const Epsilon = 1e-14;
244
+ const HalfPi = Math.PI / 2;
245
+ const Tau = Math.PI * 2;
246
+ const HalfSqrt3 = Math.sqrt(3) / 2;
247
+
248
+ var segmentCache = {};
249
+ var bezierCache = {};
250
+ var join = [].join;
251
+
252
+ // Copied from Inkscape svgtopdf, thanks!
253
+ function segments(x, y, rx, ry, large, sweep, rotateX, ox, oy) {
254
+ const key = join.call(arguments);
255
+ if (segmentCache[key]) {
256
+ return segmentCache[key];
257
+ }
258
+ const th = rotateX * DegToRad;
259
+ const sin_th = Math.sin(th);
260
+ const cos_th = Math.cos(th);
261
+ rx = Math.abs(rx);
262
+ ry = Math.abs(ry);
263
+ const px = cos_th * (ox - x) * 0.5 + sin_th * (oy - y) * 0.5;
264
+ const py = cos_th * (oy - y) * 0.5 - sin_th * (ox - x) * 0.5;
265
+ let pl = px * px / (rx * rx) + py * py / (ry * ry);
266
+ if (pl > 1) {
267
+ pl = Math.sqrt(pl);
268
+ rx *= pl;
269
+ ry *= pl;
270
+ }
271
+ const a00 = cos_th / rx;
272
+ const a01 = sin_th / rx;
273
+ const a10 = -sin_th / ry;
274
+ const a11 = cos_th / ry;
275
+ const x0 = a00 * ox + a01 * oy;
276
+ const y0 = a10 * ox + a11 * oy;
277
+ const x1 = a00 * x + a01 * y;
278
+ const y1 = a10 * x + a11 * y;
279
+ const d = (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0);
280
+ let sfactor_sq = 1 / d - 0.25;
281
+ if (sfactor_sq < 0) sfactor_sq = 0;
282
+ let sfactor = Math.sqrt(sfactor_sq);
283
+ if (sweep == large) sfactor = -sfactor;
284
+ const xc = 0.5 * (x0 + x1) - sfactor * (y1 - y0);
285
+ const yc = 0.5 * (y0 + y1) + sfactor * (x1 - x0);
286
+ const th0 = Math.atan2(y0 - yc, x0 - xc);
287
+ const th1 = Math.atan2(y1 - yc, x1 - xc);
288
+ let th_arc = th1 - th0;
289
+ if (th_arc < 0 && sweep === 1) {
290
+ th_arc += Tau;
291
+ } else if (th_arc > 0 && sweep === 0) {
292
+ th_arc -= Tau;
293
+ }
294
+ const segs = Math.ceil(Math.abs(th_arc / (HalfPi + 0.001)));
295
+ const result = [];
296
+ for (let i = 0; i < segs; ++i) {
297
+ const th2 = th0 + i * th_arc / segs;
298
+ const th3 = th0 + (i + 1) * th_arc / segs;
299
+ result[i] = [xc, yc, th2, th3, rx, ry, sin_th, cos_th];
300
+ }
301
+ return segmentCache[key] = result;
302
+ }
303
+ function bezier(params) {
304
+ const key = join.call(params);
305
+ if (bezierCache[key]) {
306
+ return bezierCache[key];
307
+ }
308
+ var cx = params[0],
309
+ cy = params[1],
310
+ th0 = params[2],
311
+ th1 = params[3],
312
+ rx = params[4],
313
+ ry = params[5],
314
+ sin_th = params[6],
315
+ cos_th = params[7];
316
+ const a00 = cos_th * rx;
317
+ const a01 = -sin_th * ry;
318
+ const a10 = sin_th * rx;
319
+ const a11 = cos_th * ry;
320
+ const cos_th0 = Math.cos(th0);
321
+ const sin_th0 = Math.sin(th0);
322
+ const cos_th1 = Math.cos(th1);
323
+ const sin_th1 = Math.sin(th1);
324
+ const th_half = 0.5 * (th1 - th0);
325
+ const sin_th_h2 = Math.sin(th_half * 0.5);
326
+ const t = 8 / 3 * sin_th_h2 * sin_th_h2 / Math.sin(th_half);
327
+ const x1 = cx + cos_th0 - t * sin_th0;
328
+ const y1 = cy + sin_th0 + t * cos_th0;
329
+ const x3 = cx + cos_th1;
330
+ const y3 = cy + sin_th1;
331
+ const x2 = x3 + t * sin_th1;
332
+ const y2 = y3 - t * cos_th1;
333
+ return bezierCache[key] = [a00 * x1 + a01 * y1, a10 * x1 + a11 * y1, a00 * x2 + a01 * y2, a10 * x2 + a11 * y2, a00 * x3 + a01 * y3, a10 * x3 + a11 * y3];
334
+ }
335
+
336
+ const temp = ['l', 0, 0, 0, 0, 0, 0, 0];
337
+ function scale$1(current, sX, sY) {
338
+ const c = temp[0] = current[0];
339
+ if (c === 'a' || c === 'A') {
340
+ temp[1] = sX * current[1];
341
+ temp[2] = sY * current[2];
342
+ temp[3] = current[3];
343
+ temp[4] = current[4];
344
+ temp[5] = current[5];
345
+ temp[6] = sX * current[6];
346
+ temp[7] = sY * current[7];
347
+ } else if (c === 'h' || c === 'H') {
348
+ temp[1] = sX * current[1];
349
+ } else if (c === 'v' || c === 'V') {
350
+ temp[1] = sY * current[1];
351
+ } else {
352
+ for (var i = 1, n = current.length; i < n; ++i) {
353
+ temp[i] = (i % 2 == 1 ? sX : sY) * current[i];
354
+ }
355
+ }
356
+ return temp;
357
+ }
358
+ function pathRender (context, path, l, t, sX, sY) {
359
+ var current,
360
+ // current instruction
361
+ previous = null,
362
+ x = 0,
363
+ // current x
364
+ y = 0,
365
+ // current y
366
+ controlX = 0,
367
+ // current control point x
368
+ controlY = 0,
369
+ // current control point y
370
+ tempX,
371
+ tempY,
372
+ tempControlX,
373
+ tempControlY,
374
+ anchorX = 0,
375
+ anchorY = 0;
376
+ if (l == null) l = 0;
377
+ if (t == null) t = 0;
378
+ if (sX == null) sX = 1;
379
+ if (sY == null) sY = sX;
380
+ if (context.beginPath) context.beginPath();
381
+ for (var i = 0, len = path.length; i < len; ++i) {
382
+ current = path[i];
383
+ if (sX !== 1 || sY !== 1) {
384
+ current = scale$1(current, sX, sY);
385
+ }
386
+ switch (current[0]) {
387
+ // first letter
388
+
389
+ case 'l':
390
+ // lineto, relative
391
+ x += current[1];
392
+ y += current[2];
393
+ context.lineTo(x + l, y + t);
394
+ break;
395
+ case 'L':
396
+ // lineto, absolute
397
+ x = current[1];
398
+ y = current[2];
399
+ context.lineTo(x + l, y + t);
400
+ break;
401
+ case 'h':
402
+ // horizontal lineto, relative
403
+ x += current[1];
404
+ context.lineTo(x + l, y + t);
405
+ break;
406
+ case 'H':
407
+ // horizontal lineto, absolute
408
+ x = current[1];
409
+ context.lineTo(x + l, y + t);
410
+ break;
411
+ case 'v':
412
+ // vertical lineto, relative
413
+ y += current[1];
414
+ context.lineTo(x + l, y + t);
415
+ break;
416
+ case 'V':
417
+ // verical lineto, absolute
418
+ y = current[1];
419
+ context.lineTo(x + l, y + t);
420
+ break;
421
+ case 'm':
422
+ // moveTo, relative
423
+ x += current[1];
424
+ y += current[2];
425
+ anchorX = x;
426
+ anchorY = y;
427
+ context.moveTo(x + l, y + t);
428
+ break;
429
+ case 'M':
430
+ // moveTo, absolute
431
+ x = current[1];
432
+ y = current[2];
433
+ anchorX = x;
434
+ anchorY = y;
435
+ context.moveTo(x + l, y + t);
436
+ break;
437
+ case 'c':
438
+ // bezierCurveTo, relative
439
+ tempX = x + current[5];
440
+ tempY = y + current[6];
441
+ controlX = x + current[3];
442
+ controlY = y + current[4];
443
+ context.bezierCurveTo(x + current[1] + l,
444
+ // x1
445
+ y + current[2] + t,
446
+ // y1
447
+ controlX + l,
448
+ // x2
449
+ controlY + t,
450
+ // y2
451
+ tempX + l, tempY + t);
452
+ x = tempX;
453
+ y = tempY;
454
+ break;
455
+ case 'C':
456
+ // bezierCurveTo, absolute
457
+ x = current[5];
458
+ y = current[6];
459
+ controlX = current[3];
460
+ controlY = current[4];
461
+ context.bezierCurveTo(current[1] + l, current[2] + t, controlX + l, controlY + t, x + l, y + t);
462
+ break;
463
+ case 's':
464
+ // shorthand cubic bezierCurveTo, relative
465
+ // transform to absolute x,y
466
+ tempX = x + current[3];
467
+ tempY = y + current[4];
468
+ // calculate reflection of previous control points
469
+ controlX = 2 * x - controlX;
470
+ controlY = 2 * y - controlY;
471
+ context.bezierCurveTo(controlX + l, controlY + t, x + current[1] + l, y + current[2] + t, tempX + l, tempY + t);
472
+
473
+ // set control point to 2nd one of this command
474
+ // the first control point is assumed to be the reflection of
475
+ // the second control point on the previous command relative
476
+ // to the current point.
477
+ controlX = x + current[1];
478
+ controlY = y + current[2];
479
+ x = tempX;
480
+ y = tempY;
481
+ break;
482
+ case 'S':
483
+ // shorthand cubic bezierCurveTo, absolute
484
+ tempX = current[3];
485
+ tempY = current[4];
486
+ // calculate reflection of previous control points
487
+ controlX = 2 * x - controlX;
488
+ controlY = 2 * y - controlY;
489
+ context.bezierCurveTo(controlX + l, controlY + t, current[1] + l, current[2] + t, tempX + l, tempY + t);
490
+ x = tempX;
491
+ y = tempY;
492
+ // set control point to 2nd one of this command
493
+ // the first control point is assumed to be the reflection of
494
+ // the second control point on the previous command relative
495
+ // to the current point.
496
+ controlX = current[1];
497
+ controlY = current[2];
498
+ break;
499
+ case 'q':
500
+ // quadraticCurveTo, relative
501
+ // transform to absolute x,y
502
+ tempX = x + current[3];
503
+ tempY = y + current[4];
504
+ controlX = x + current[1];
505
+ controlY = y + current[2];
506
+ context.quadraticCurveTo(controlX + l, controlY + t, tempX + l, tempY + t);
507
+ x = tempX;
508
+ y = tempY;
509
+ break;
510
+ case 'Q':
511
+ // quadraticCurveTo, absolute
512
+ tempX = current[3];
513
+ tempY = current[4];
514
+ context.quadraticCurveTo(current[1] + l, current[2] + t, tempX + l, tempY + t);
515
+ x = tempX;
516
+ y = tempY;
517
+ controlX = current[1];
518
+ controlY = current[2];
519
+ break;
520
+ case 't':
521
+ // shorthand quadraticCurveTo, relative
522
+
523
+ // transform to absolute x,y
524
+ tempX = x + current[1];
525
+ tempY = y + current[2];
526
+ if (previous[0].match(/[QqTt]/) === null) {
527
+ // If there is no previous command or if the previous command was not a Q, q, T or t,
528
+ // assume the control point is coincident with the current point
529
+ controlX = x;
530
+ controlY = y;
531
+ } else if (previous[0] === 't') {
532
+ // calculate reflection of previous control points for t
533
+ controlX = 2 * x - tempControlX;
534
+ controlY = 2 * y - tempControlY;
535
+ } else if (previous[0] === 'q') {
536
+ // calculate reflection of previous control points for q
537
+ controlX = 2 * x - controlX;
538
+ controlY = 2 * y - controlY;
539
+ }
540
+ tempControlX = controlX;
541
+ tempControlY = controlY;
542
+ context.quadraticCurveTo(controlX + l, controlY + t, tempX + l, tempY + t);
543
+ x = tempX;
544
+ y = tempY;
545
+ controlX = x + current[1];
546
+ controlY = y + current[2];
547
+ break;
548
+ case 'T':
549
+ tempX = current[1];
550
+ tempY = current[2];
551
+
552
+ // calculate reflection of previous control points
553
+ controlX = 2 * x - controlX;
554
+ controlY = 2 * y - controlY;
555
+ context.quadraticCurveTo(controlX + l, controlY + t, tempX + l, tempY + t);
556
+ x = tempX;
557
+ y = tempY;
558
+ break;
559
+ case 'a':
560
+ drawArc(context, x + l, y + t, [current[1], current[2], current[3], current[4], current[5], current[6] + x + l, current[7] + y + t]);
561
+ x += current[6];
562
+ y += current[7];
563
+ break;
564
+ case 'A':
565
+ drawArc(context, x + l, y + t, [current[1], current[2], current[3], current[4], current[5], current[6] + l, current[7] + t]);
566
+ x = current[6];
567
+ y = current[7];
568
+ break;
569
+ case 'z':
570
+ case 'Z':
571
+ x = anchorX;
572
+ y = anchorY;
573
+ context.closePath();
574
+ break;
575
+ }
576
+ previous = current;
577
+ }
578
+ }
579
+ function drawArc(context, x, y, coords) {
580
+ const seg = segments(coords[5],
581
+ // end x
582
+ coords[6],
583
+ // end y
584
+ coords[0],
585
+ // radius x
586
+ coords[1],
587
+ // radius y
588
+ coords[3],
589
+ // large flag
590
+ coords[4],
591
+ // sweep flag
592
+ coords[2],
593
+ // rotation
594
+ x, y);
595
+ for (let i = 0; i < seg.length; ++i) {
596
+ const bez = bezier(seg[i]);
597
+ context.bezierCurveTo(bez[0], bez[1], bez[2], bez[3], bez[4], bez[5]);
598
+ }
599
+ }
600
+
601
+ const Tan30 = 0.5773502691896257;
602
+ const builtins = {
603
+ 'circle': {
604
+ draw: function (context, size) {
605
+ const r = Math.sqrt(size) / 2;
606
+ context.moveTo(r, 0);
607
+ context.arc(0, 0, r, 0, Tau);
608
+ }
609
+ },
610
+ 'cross': {
611
+ draw: function (context, size) {
612
+ var r = Math.sqrt(size) / 2,
613
+ s = r / 2.5;
614
+ context.moveTo(-r, -s);
615
+ context.lineTo(-r, s);
616
+ context.lineTo(-s, s);
617
+ context.lineTo(-s, r);
618
+ context.lineTo(s, r);
619
+ context.lineTo(s, s);
620
+ context.lineTo(r, s);
621
+ context.lineTo(r, -s);
622
+ context.lineTo(s, -s);
623
+ context.lineTo(s, -r);
624
+ context.lineTo(-s, -r);
625
+ context.lineTo(-s, -s);
626
+ context.closePath();
627
+ }
628
+ },
629
+ 'diamond': {
630
+ draw: function (context, size) {
631
+ const r = Math.sqrt(size) / 2;
632
+ context.moveTo(-r, 0);
633
+ context.lineTo(0, -r);
634
+ context.lineTo(r, 0);
635
+ context.lineTo(0, r);
636
+ context.closePath();
637
+ }
638
+ },
639
+ 'square': {
640
+ draw: function (context, size) {
641
+ var w = Math.sqrt(size),
642
+ x = -w / 2;
643
+ context.rect(x, x, w, w);
644
+ }
645
+ },
646
+ 'arrow': {
647
+ draw: function (context, size) {
648
+ var r = Math.sqrt(size) / 2,
649
+ s = r / 7,
650
+ t = r / 2.5,
651
+ v = r / 8;
652
+ context.moveTo(-s, r);
653
+ context.lineTo(s, r);
654
+ context.lineTo(s, -v);
655
+ context.lineTo(t, -v);
656
+ context.lineTo(0, -r);
657
+ context.lineTo(-t, -v);
658
+ context.lineTo(-s, -v);
659
+ context.closePath();
660
+ }
661
+ },
662
+ 'wedge': {
663
+ draw: function (context, size) {
664
+ var r = Math.sqrt(size) / 2,
665
+ h = HalfSqrt3 * r,
666
+ o = h - r * Tan30,
667
+ b = r / 4;
668
+ context.moveTo(0, -h - o);
669
+ context.lineTo(-b, h - o);
670
+ context.lineTo(b, h - o);
671
+ context.closePath();
672
+ }
673
+ },
674
+ 'triangle': {
675
+ draw: function (context, size) {
676
+ var r = Math.sqrt(size) / 2,
677
+ h = HalfSqrt3 * r,
678
+ o = h - r * Tan30;
679
+ context.moveTo(0, -h - o);
680
+ context.lineTo(-r, h - o);
681
+ context.lineTo(r, h - o);
682
+ context.closePath();
683
+ }
684
+ },
685
+ 'triangle-up': {
686
+ draw: function (context, size) {
687
+ var r = Math.sqrt(size) / 2,
688
+ h = HalfSqrt3 * r;
689
+ context.moveTo(0, -h);
690
+ context.lineTo(-r, h);
691
+ context.lineTo(r, h);
692
+ context.closePath();
693
+ }
694
+ },
695
+ 'triangle-down': {
696
+ draw: function (context, size) {
697
+ var r = Math.sqrt(size) / 2,
698
+ h = HalfSqrt3 * r;
699
+ context.moveTo(0, h);
700
+ context.lineTo(-r, -h);
701
+ context.lineTo(r, -h);
702
+ context.closePath();
703
+ }
704
+ },
705
+ 'triangle-right': {
706
+ draw: function (context, size) {
707
+ var r = Math.sqrt(size) / 2,
708
+ h = HalfSqrt3 * r;
709
+ context.moveTo(h, 0);
710
+ context.lineTo(-h, -r);
711
+ context.lineTo(-h, r);
712
+ context.closePath();
713
+ }
714
+ },
715
+ 'triangle-left': {
716
+ draw: function (context, size) {
717
+ var r = Math.sqrt(size) / 2,
718
+ h = HalfSqrt3 * r;
719
+ context.moveTo(-h, 0);
720
+ context.lineTo(h, -r);
721
+ context.lineTo(h, r);
722
+ context.closePath();
723
+ }
724
+ },
725
+ 'stroke': {
726
+ draw: function (context, size) {
727
+ const r = Math.sqrt(size) / 2;
728
+ context.moveTo(-r, 0);
729
+ context.lineTo(r, 0);
730
+ }
731
+ }
732
+ };
733
+ function symbols(_) {
734
+ return vegaUtil.hasOwnProperty(builtins, _) ? builtins[_] : customSymbol(_);
735
+ }
736
+ var custom = {};
737
+ function customSymbol(path) {
738
+ if (!vegaUtil.hasOwnProperty(custom, path)) {
739
+ const parsed = parse(path);
740
+ custom[path] = {
741
+ draw: function (context, size) {
742
+ pathRender(context, parsed, 0, 0, Math.sqrt(size) / 2);
743
+ }
744
+ };
745
+ }
746
+ return custom[path];
747
+ }
748
+
749
+ // See http://spencermortensen.com/articles/bezier-circle/
750
+ const C = 0.448084975506; // C = 1 - c
751
+
752
+ function rectangleX(d) {
753
+ return d.x;
754
+ }
755
+ function rectangleY(d) {
756
+ return d.y;
757
+ }
758
+ function rectangleWidth(d) {
759
+ return d.width;
760
+ }
761
+ function rectangleHeight(d) {
762
+ return d.height;
763
+ }
764
+ function number(_) {
765
+ return typeof _ === 'function' ? _ : () => +_;
766
+ }
767
+ function clamp(value, min, max) {
768
+ return Math.max(min, Math.min(value, max));
769
+ }
770
+ function vg_rect () {
771
+ var x = rectangleX,
772
+ y = rectangleY,
773
+ width = rectangleWidth,
774
+ height = rectangleHeight,
775
+ crTL = number(0),
776
+ crTR = crTL,
777
+ crBL = crTL,
778
+ crBR = crTL,
779
+ context = null;
780
+ function rectangle(_, x0, y0) {
781
+ var buffer,
782
+ x1 = x0 != null ? x0 : +x.call(this, _),
783
+ y1 = y0 != null ? y0 : +y.call(this, _),
784
+ w = +width.call(this, _),
785
+ h = +height.call(this, _),
786
+ s = Math.min(w, h) / 2,
787
+ tl = clamp(+crTL.call(this, _), 0, s),
788
+ tr = clamp(+crTR.call(this, _), 0, s),
789
+ bl = clamp(+crBL.call(this, _), 0, s),
790
+ br = clamp(+crBR.call(this, _), 0, s);
791
+ if (!context) context = buffer = path$3.path();
792
+ if (tl <= 0 && tr <= 0 && bl <= 0 && br <= 0) {
793
+ context.rect(x1, y1, w, h);
794
+ } else {
795
+ var x2 = x1 + w,
796
+ y2 = y1 + h;
797
+ context.moveTo(x1 + tl, y1);
798
+ context.lineTo(x2 - tr, y1);
799
+ context.bezierCurveTo(x2 - C * tr, y1, x2, y1 + C * tr, x2, y1 + tr);
800
+ context.lineTo(x2, y2 - br);
801
+ context.bezierCurveTo(x2, y2 - C * br, x2 - C * br, y2, x2 - br, y2);
802
+ context.lineTo(x1 + bl, y2);
803
+ context.bezierCurveTo(x1 + C * bl, y2, x1, y2 - C * bl, x1, y2 - bl);
804
+ context.lineTo(x1, y1 + tl);
805
+ context.bezierCurveTo(x1, y1 + C * tl, x1 + C * tl, y1, x1 + tl, y1);
806
+ context.closePath();
807
+ }
808
+ if (buffer) {
809
+ context = null;
810
+ return buffer + '' || null;
811
+ }
812
+ }
813
+ rectangle.x = function (_) {
814
+ if (arguments.length) {
815
+ x = number(_);
816
+ return rectangle;
817
+ } else {
818
+ return x;
819
+ }
820
+ };
821
+ rectangle.y = function (_) {
822
+ if (arguments.length) {
823
+ y = number(_);
824
+ return rectangle;
825
+ } else {
826
+ return y;
827
+ }
828
+ };
829
+ rectangle.width = function (_) {
830
+ if (arguments.length) {
831
+ width = number(_);
832
+ return rectangle;
833
+ } else {
834
+ return width;
835
+ }
836
+ };
837
+ rectangle.height = function (_) {
838
+ if (arguments.length) {
839
+ height = number(_);
840
+ return rectangle;
841
+ } else {
842
+ return height;
843
+ }
844
+ };
845
+ rectangle.cornerRadius = function (tl, tr, br, bl) {
846
+ if (arguments.length) {
847
+ crTL = number(tl);
848
+ crTR = tr != null ? number(tr) : crTL;
849
+ crBR = br != null ? number(br) : crTL;
850
+ crBL = bl != null ? number(bl) : crTR;
851
+ return rectangle;
852
+ } else {
853
+ return crTL;
854
+ }
855
+ };
856
+ rectangle.context = function (_) {
857
+ if (arguments.length) {
858
+ context = _ == null ? null : _;
859
+ return rectangle;
860
+ } else {
861
+ return context;
862
+ }
863
+ };
864
+ return rectangle;
865
+ }
866
+
867
+ function vg_trail () {
868
+ var x,
869
+ y,
870
+ size,
871
+ defined,
872
+ context = null,
873
+ ready,
874
+ x1,
875
+ y1,
876
+ r1;
877
+ function point(x2, y2, w2) {
878
+ const r2 = w2 / 2;
879
+ if (ready) {
880
+ var ux = y1 - y2,
881
+ uy = x2 - x1;
882
+ if (ux || uy) {
883
+ // get normal vector
884
+ var ud = Math.hypot(ux, uy),
885
+ rx = (ux /= ud) * r1,
886
+ ry = (uy /= ud) * r1,
887
+ t = Math.atan2(uy, ux);
888
+
889
+ // draw segment
890
+ context.moveTo(x1 - rx, y1 - ry);
891
+ context.lineTo(x2 - ux * r2, y2 - uy * r2);
892
+ context.arc(x2, y2, r2, t - Math.PI, t);
893
+ context.lineTo(x1 + rx, y1 + ry);
894
+ context.arc(x1, y1, r1, t, t + Math.PI);
895
+ } else {
896
+ context.arc(x2, y2, r2, 0, Tau);
897
+ }
898
+ context.closePath();
899
+ } else {
900
+ ready = 1;
901
+ }
902
+ x1 = x2;
903
+ y1 = y2;
904
+ r1 = r2;
905
+ }
906
+ function trail(data) {
907
+ var i,
908
+ n = data.length,
909
+ d,
910
+ defined0 = false,
911
+ buffer;
912
+ if (context == null) context = buffer = path$3.path();
913
+ for (i = 0; i <= n; ++i) {
914
+ if (!(i < n && defined(d = data[i], i, data)) === defined0) {
915
+ if (defined0 = !defined0) ready = 0;
916
+ }
917
+ if (defined0) point(+x(d, i, data), +y(d, i, data), +size(d, i, data));
918
+ }
919
+ if (buffer) {
920
+ context = null;
921
+ return buffer + '' || null;
922
+ }
923
+ }
924
+ trail.x = function (_) {
925
+ if (arguments.length) {
926
+ x = _;
927
+ return trail;
928
+ } else {
929
+ return x;
930
+ }
931
+ };
932
+ trail.y = function (_) {
933
+ if (arguments.length) {
934
+ y = _;
935
+ return trail;
936
+ } else {
937
+ return y;
938
+ }
939
+ };
940
+ trail.size = function (_) {
941
+ if (arguments.length) {
942
+ size = _;
943
+ return trail;
944
+ } else {
945
+ return size;
946
+ }
947
+ };
948
+ trail.defined = function (_) {
949
+ if (arguments.length) {
950
+ defined = _;
951
+ return trail;
952
+ } else {
953
+ return defined;
954
+ }
955
+ };
956
+ trail.context = function (_) {
957
+ if (arguments.length) {
958
+ if (_ == null) {
959
+ context = null;
960
+ } else {
961
+ context = _;
962
+ }
963
+ return trail;
964
+ } else {
965
+ return context;
966
+ }
967
+ };
968
+ return trail;
969
+ }
970
+
971
+ function value$1(a, b) {
972
+ return a != null ? a : b;
973
+ }
974
+ const x = item => item.x || 0,
975
+ y = item => item.y || 0,
976
+ w = item => item.width || 0,
977
+ h = item => item.height || 0,
978
+ xw = item => (item.x || 0) + (item.width || 0),
979
+ yh = item => (item.y || 0) + (item.height || 0),
980
+ sa = item => item.startAngle || 0,
981
+ ea = item => item.endAngle || 0,
982
+ pa = item => item.padAngle || 0,
983
+ ir = item => item.innerRadius || 0,
984
+ or = item => item.outerRadius || 0,
985
+ cr = item => item.cornerRadius || 0,
986
+ tl = item => value$1(item.cornerRadiusTopLeft, item.cornerRadius) || 0,
987
+ tr = item => value$1(item.cornerRadiusTopRight, item.cornerRadius) || 0,
988
+ br = item => value$1(item.cornerRadiusBottomRight, item.cornerRadius) || 0,
989
+ bl = item => value$1(item.cornerRadiusBottomLeft, item.cornerRadius) || 0,
990
+ sz = item => value$1(item.size, 64),
991
+ ts = item => item.size || 1,
992
+ def = item => !(item.defined === false),
993
+ type = item => symbols(item.shape || 'circle');
994
+ const arcShape = arc$2.default().startAngle(sa).endAngle(ea).padAngle(pa).innerRadius(ir).outerRadius(or).cornerRadius(cr),
995
+ areavShape = area$2.default().x(x).y1(y).y0(yh).defined(def),
996
+ areahShape = area$2.default().y(y).x1(x).x0(xw).defined(def),
997
+ lineShape = line$2.default().x(x).y(y).defined(def),
998
+ rectShape = vg_rect().x(x).y(y).width(w).height(h).cornerRadius(tl, tr, br, bl),
999
+ symbolShape = symbol$2.default().type(type).size(sz),
1000
+ trailShape = vg_trail().x(x).y(y).defined(def).size(ts);
1001
+ function hasCornerRadius(item) {
1002
+ return item.cornerRadius || item.cornerRadiusTopLeft || item.cornerRadiusTopRight || item.cornerRadiusBottomRight || item.cornerRadiusBottomLeft;
1003
+ }
1004
+ function arc$1(context, item) {
1005
+ return arcShape.context(context)(item);
1006
+ }
1007
+ function area$1(context, items) {
1008
+ const item = items[0],
1009
+ interp = item.interpolate || 'linear';
1010
+ return (item.orient === 'horizontal' ? areahShape : areavShape).curve(curves(interp, item.orient, item.tension)).context(context)(items);
1011
+ }
1012
+ function line$1(context, items) {
1013
+ const item = items[0],
1014
+ interp = item.interpolate || 'linear';
1015
+ return lineShape.curve(curves(interp, item.orient, item.tension)).context(context)(items);
1016
+ }
1017
+ function rectangle(context, item, x, y) {
1018
+ return rectShape.context(context)(item, x, y);
1019
+ }
1020
+ function shape$1(context, item) {
1021
+ return (item.mark.shape || item.shape).context(context)(item);
1022
+ }
1023
+ function symbol$1(context, item) {
1024
+ return symbolShape.context(context)(item);
1025
+ }
1026
+ function trail$1(context, items) {
1027
+ return trailShape.context(context)(items);
1028
+ }
1029
+
1030
+ var clip_id = 1;
1031
+ function resetSVGClipId() {
1032
+ clip_id = 1;
1033
+ }
1034
+ function clip$1 (renderer, item, size) {
1035
+ var clip = item.clip,
1036
+ defs = renderer._defs,
1037
+ id = item.clip_id || (item.clip_id = 'clip' + clip_id++),
1038
+ c = defs.clipping[id] || (defs.clipping[id] = {
1039
+ id: id
1040
+ });
1041
+ if (vegaUtil.isFunction(clip)) {
1042
+ c.path = clip(null);
1043
+ } else if (hasCornerRadius(size)) {
1044
+ c.path = rectangle(null, size, 0, 0);
1045
+ } else {
1046
+ c.width = size.width || 0;
1047
+ c.height = size.height || 0;
1048
+ }
1049
+ return 'url(#' + id + ')';
1050
+ }
1051
+
1052
+ function Bounds(b) {
1053
+ this.clear();
1054
+ if (b) this.union(b);
1055
+ }
1056
+ Bounds.prototype = {
1057
+ clone() {
1058
+ return new Bounds(this);
1059
+ },
1060
+ clear() {
1061
+ this.x1 = +Number.MAX_VALUE;
1062
+ this.y1 = +Number.MAX_VALUE;
1063
+ this.x2 = -Number.MAX_VALUE;
1064
+ this.y2 = -Number.MAX_VALUE;
1065
+ return this;
1066
+ },
1067
+ empty() {
1068
+ return this.x1 === +Number.MAX_VALUE && this.y1 === +Number.MAX_VALUE && this.x2 === -Number.MAX_VALUE && this.y2 === -Number.MAX_VALUE;
1069
+ },
1070
+ equals(b) {
1071
+ return this.x1 === b.x1 && this.y1 === b.y1 && this.x2 === b.x2 && this.y2 === b.y2;
1072
+ },
1073
+ set(x1, y1, x2, y2) {
1074
+ if (x2 < x1) {
1075
+ this.x2 = x1;
1076
+ this.x1 = x2;
1077
+ } else {
1078
+ this.x1 = x1;
1079
+ this.x2 = x2;
1080
+ }
1081
+ if (y2 < y1) {
1082
+ this.y2 = y1;
1083
+ this.y1 = y2;
1084
+ } else {
1085
+ this.y1 = y1;
1086
+ this.y2 = y2;
1087
+ }
1088
+ return this;
1089
+ },
1090
+ add(x, y) {
1091
+ if (x < this.x1) this.x1 = x;
1092
+ if (y < this.y1) this.y1 = y;
1093
+ if (x > this.x2) this.x2 = x;
1094
+ if (y > this.y2) this.y2 = y;
1095
+ return this;
1096
+ },
1097
+ expand(d) {
1098
+ this.x1 -= d;
1099
+ this.y1 -= d;
1100
+ this.x2 += d;
1101
+ this.y2 += d;
1102
+ return this;
1103
+ },
1104
+ round() {
1105
+ this.x1 = Math.floor(this.x1);
1106
+ this.y1 = Math.floor(this.y1);
1107
+ this.x2 = Math.ceil(this.x2);
1108
+ this.y2 = Math.ceil(this.y2);
1109
+ return this;
1110
+ },
1111
+ scale(s) {
1112
+ this.x1 *= s;
1113
+ this.y1 *= s;
1114
+ this.x2 *= s;
1115
+ this.y2 *= s;
1116
+ return this;
1117
+ },
1118
+ translate(dx, dy) {
1119
+ this.x1 += dx;
1120
+ this.x2 += dx;
1121
+ this.y1 += dy;
1122
+ this.y2 += dy;
1123
+ return this;
1124
+ },
1125
+ rotate(angle, x, y) {
1126
+ const p = this.rotatedPoints(angle, x, y);
1127
+ return this.clear().add(p[0], p[1]).add(p[2], p[3]).add(p[4], p[5]).add(p[6], p[7]);
1128
+ },
1129
+ rotatedPoints(angle, x, y) {
1130
+ var {
1131
+ x1,
1132
+ y1,
1133
+ x2,
1134
+ y2
1135
+ } = this,
1136
+ cos = Math.cos(angle),
1137
+ sin = Math.sin(angle),
1138
+ cx = x - x * cos + y * sin,
1139
+ cy = y - x * sin - y * cos;
1140
+ return [cos * x1 - sin * y1 + cx, sin * x1 + cos * y1 + cy, cos * x1 - sin * y2 + cx, sin * x1 + cos * y2 + cy, cos * x2 - sin * y1 + cx, sin * x2 + cos * y1 + cy, cos * x2 - sin * y2 + cx, sin * x2 + cos * y2 + cy];
1141
+ },
1142
+ union(b) {
1143
+ if (b.x1 < this.x1) this.x1 = b.x1;
1144
+ if (b.y1 < this.y1) this.y1 = b.y1;
1145
+ if (b.x2 > this.x2) this.x2 = b.x2;
1146
+ if (b.y2 > this.y2) this.y2 = b.y2;
1147
+ return this;
1148
+ },
1149
+ intersect(b) {
1150
+ if (b.x1 > this.x1) this.x1 = b.x1;
1151
+ if (b.y1 > this.y1) this.y1 = b.y1;
1152
+ if (b.x2 < this.x2) this.x2 = b.x2;
1153
+ if (b.y2 < this.y2) this.y2 = b.y2;
1154
+ return this;
1155
+ },
1156
+ encloses(b) {
1157
+ return b && this.x1 <= b.x1 && this.x2 >= b.x2 && this.y1 <= b.y1 && this.y2 >= b.y2;
1158
+ },
1159
+ alignsWith(b) {
1160
+ return b && (this.x1 == b.x1 || this.x2 == b.x2 || this.y1 == b.y1 || this.y2 == b.y2);
1161
+ },
1162
+ intersects(b) {
1163
+ return b && !(this.x2 < b.x1 || this.x1 > b.x2 || this.y2 < b.y1 || this.y1 > b.y2);
1164
+ },
1165
+ contains(x, y) {
1166
+ return !(x < this.x1 || x > this.x2 || y < this.y1 || y > this.y2);
1167
+ },
1168
+ width() {
1169
+ return this.x2 - this.x1;
1170
+ },
1171
+ height() {
1172
+ return this.y2 - this.y1;
1173
+ }
1174
+ };
1175
+
1176
+ function Item(mark) {
1177
+ this.mark = mark;
1178
+ this.bounds = this.bounds || new Bounds();
1179
+ }
1180
+
1181
+ function GroupItem(mark) {
1182
+ Item.call(this, mark);
1183
+ this.items = this.items || [];
1184
+ }
1185
+ vegaUtil.inherits(GroupItem, Item);
1186
+
1187
+ class ResourceLoader {
1188
+ constructor(customLoader) {
1189
+ this._pending = 0;
1190
+ this._loader = customLoader || vegaLoader_browser.loader();
1191
+ }
1192
+ pending() {
1193
+ return this._pending;
1194
+ }
1195
+ sanitizeURL(uri) {
1196
+ const loader = this;
1197
+ increment(loader);
1198
+ return loader._loader.sanitize(uri, {
1199
+ context: 'href'
1200
+ }).then(opt => {
1201
+ decrement(loader);
1202
+ return opt;
1203
+ }).catch(() => {
1204
+ decrement(loader);
1205
+ return null;
1206
+ });
1207
+ }
1208
+ loadImage(uri) {
1209
+ const loader = this,
1210
+ Image = vegaCanvas_browser.image();
1211
+ increment(loader);
1212
+ return loader._loader.sanitize(uri, {
1213
+ context: 'image'
1214
+ }).then(opt => {
1215
+ const url = opt.href;
1216
+ if (!url || !Image) throw {
1217
+ url: url
1218
+ };
1219
+ const img = new Image();
1220
+
1221
+ // set crossOrigin only if cors is defined; empty string sets anonymous mode
1222
+ // https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/crossOrigin
1223
+ const cors = vegaUtil.hasOwnProperty(opt, 'crossOrigin') ? opt.crossOrigin : 'anonymous';
1224
+ if (cors != null) img.crossOrigin = cors;
1225
+
1226
+ // attempt to load image resource
1227
+ img.onload = () => decrement(loader);
1228
+ img.onerror = () => decrement(loader);
1229
+ img.src = url;
1230
+ return img;
1231
+ }).catch(e => {
1232
+ decrement(loader);
1233
+ return {
1234
+ complete: false,
1235
+ width: 0,
1236
+ height: 0,
1237
+ src: e && e.url || ''
1238
+ };
1239
+ });
1240
+ }
1241
+ ready() {
1242
+ const loader = this;
1243
+ return new Promise(accept => {
1244
+ function poll(value) {
1245
+ if (!loader.pending()) accept(value);else setTimeout(() => {
1246
+ poll(true);
1247
+ }, 10);
1248
+ }
1249
+ poll(false);
1250
+ });
1251
+ }
1252
+ }
1253
+ function increment(loader) {
1254
+ loader._pending += 1;
1255
+ }
1256
+ function decrement(loader) {
1257
+ loader._pending -= 1;
1258
+ }
1259
+
1260
+ function boundStroke (bounds, item, miter) {
1261
+ if (item.stroke && item.opacity !== 0 && item.strokeOpacity !== 0) {
1262
+ const sw = item.strokeWidth != null ? +item.strokeWidth : 1;
1263
+ bounds.expand(sw + (miter ? miterAdjustment(item, sw) : 0));
1264
+ }
1265
+ return bounds;
1266
+ }
1267
+ function miterAdjustment(item, strokeWidth) {
1268
+ // TODO: more sophisticated adjustment? Or miter support in boundContext?
1269
+ return item.strokeJoin && item.strokeJoin !== 'miter' ? 0 : strokeWidth;
1270
+ }
1271
+
1272
+ const circleThreshold = Tau - 1e-8;
1273
+ let bounds, lx, ly, rot, ma, mb, mc, md;
1274
+ const add = (x, y) => bounds.add(x, y);
1275
+ const addL = (x, y) => add(lx = x, ly = y);
1276
+ const addX = x => add(x, bounds.y1);
1277
+ const addY = y => add(bounds.x1, y);
1278
+ const px = (x, y) => ma * x + mc * y;
1279
+ const py = (x, y) => mb * x + md * y;
1280
+ const addp = (x, y) => add(px(x, y), py(x, y));
1281
+ const addpL = (x, y) => addL(px(x, y), py(x, y));
1282
+ function boundContext (_, deg) {
1283
+ bounds = _;
1284
+ if (deg) {
1285
+ rot = deg * DegToRad;
1286
+ ma = md = Math.cos(rot);
1287
+ mb = Math.sin(rot);
1288
+ mc = -mb;
1289
+ } else {
1290
+ ma = md = 1;
1291
+ rot = mb = mc = 0;
1292
+ }
1293
+ return context$1;
1294
+ }
1295
+ const context$1 = {
1296
+ beginPath() {},
1297
+ closePath() {},
1298
+ moveTo: addpL,
1299
+ lineTo: addpL,
1300
+ rect(x, y, w, h) {
1301
+ if (rot) {
1302
+ addp(x + w, y);
1303
+ addp(x + w, y + h);
1304
+ addp(x, y + h);
1305
+ addpL(x, y);
1306
+ } else {
1307
+ add(x + w, y + h);
1308
+ addL(x, y);
1309
+ }
1310
+ },
1311
+ quadraticCurveTo(x1, y1, x2, y2) {
1312
+ const px1 = px(x1, y1),
1313
+ py1 = py(x1, y1),
1314
+ px2 = px(x2, y2),
1315
+ py2 = py(x2, y2);
1316
+ quadExtrema(lx, px1, px2, addX);
1317
+ quadExtrema(ly, py1, py2, addY);
1318
+ addL(px2, py2);
1319
+ },
1320
+ bezierCurveTo(x1, y1, x2, y2, x3, y3) {
1321
+ const px1 = px(x1, y1),
1322
+ py1 = py(x1, y1),
1323
+ px2 = px(x2, y2),
1324
+ py2 = py(x2, y2),
1325
+ px3 = px(x3, y3),
1326
+ py3 = py(x3, y3);
1327
+ cubicExtrema(lx, px1, px2, px3, addX);
1328
+ cubicExtrema(ly, py1, py2, py3, addY);
1329
+ addL(px3, py3);
1330
+ },
1331
+ arc(cx, cy, r, sa, ea, ccw) {
1332
+ sa += rot;
1333
+ ea += rot;
1334
+
1335
+ // store last point on path
1336
+ lx = r * Math.cos(ea) + cx;
1337
+ ly = r * Math.sin(ea) + cy;
1338
+ if (Math.abs(ea - sa) > circleThreshold) {
1339
+ // treat as full circle
1340
+ add(cx - r, cy - r);
1341
+ add(cx + r, cy + r);
1342
+ } else {
1343
+ const update = a => add(r * Math.cos(a) + cx, r * Math.sin(a) + cy);
1344
+ let s, i;
1345
+
1346
+ // sample end points
1347
+ update(sa);
1348
+ update(ea);
1349
+
1350
+ // sample interior points aligned with 90 degrees
1351
+ if (ea !== sa) {
1352
+ sa = sa % Tau;
1353
+ if (sa < 0) sa += Tau;
1354
+ ea = ea % Tau;
1355
+ if (ea < 0) ea += Tau;
1356
+ if (ea < sa) {
1357
+ ccw = !ccw; // flip direction
1358
+ s = sa;
1359
+ sa = ea;
1360
+ ea = s; // swap end-points
1361
+ }
1362
+ if (ccw) {
1363
+ ea -= Tau;
1364
+ s = sa - sa % HalfPi;
1365
+ for (i = 0; i < 4 && s > ea; ++i, s -= HalfPi) update(s);
1366
+ } else {
1367
+ s = sa - sa % HalfPi + HalfPi;
1368
+ for (i = 0; i < 4 && s < ea; ++i, s = s + HalfPi) update(s);
1369
+ }
1370
+ }
1371
+ }
1372
+ }
1373
+ };
1374
+ function quadExtrema(x0, x1, x2, cb) {
1375
+ const t = (x0 - x1) / (x0 + x2 - 2 * x1);
1376
+ if (0 < t && t < 1) cb(x0 + (x1 - x0) * t);
1377
+ }
1378
+ function cubicExtrema(x0, x1, x2, x3, cb) {
1379
+ const a = x3 - x0 + 3 * x1 - 3 * x2,
1380
+ b = x0 + x2 - 2 * x1,
1381
+ c = x0 - x1;
1382
+ let t0 = 0,
1383
+ t1 = 0,
1384
+ r;
1385
+
1386
+ // solve for parameter t
1387
+ if (Math.abs(a) > Epsilon) {
1388
+ // quadratic equation
1389
+ r = b * b + c * a;
1390
+ if (r >= 0) {
1391
+ r = Math.sqrt(r);
1392
+ t0 = (-b + r) / a;
1393
+ t1 = (-b - r) / a;
1394
+ }
1395
+ } else {
1396
+ // linear equation
1397
+ t0 = 0.5 * c / b;
1398
+ }
1399
+
1400
+ // calculate position
1401
+ if (0 < t0 && t0 < 1) cb(cubic(t0, x0, x1, x2, x3));
1402
+ if (0 < t1 && t1 < 1) cb(cubic(t1, x0, x1, x2, x3));
1403
+ }
1404
+ function cubic(t, x0, x1, x2, x3) {
1405
+ const s = 1 - t,
1406
+ s2 = s * s,
1407
+ t2 = t * t;
1408
+ return s2 * s * x0 + 3 * s2 * t * x1 + 3 * s * t2 * x2 + t2 * t * x3;
1409
+ }
1410
+
1411
+ var context = (context = vegaCanvas_browser.canvas(1, 1)) ? context.getContext('2d') : null;
1412
+
1413
+ const b = new Bounds();
1414
+ function intersectPath(draw) {
1415
+ return function (item, brush) {
1416
+ // rely on (inaccurate) bounds intersection if no context
1417
+ if (!context) return true;
1418
+
1419
+ // add path to offscreen graphics context
1420
+ draw(context, item);
1421
+
1422
+ // get bounds intersection region
1423
+ b.clear().union(item.bounds).intersect(brush).round();
1424
+ const {
1425
+ x1,
1426
+ y1,
1427
+ x2,
1428
+ y2
1429
+ } = b;
1430
+
1431
+ // iterate over intersection region
1432
+ // perform fine grained inclusion test
1433
+ for (let y = y1; y <= y2; ++y) {
1434
+ for (let x = x1; x <= x2; ++x) {
1435
+ if (context.isPointInPath(x, y)) {
1436
+ return true;
1437
+ }
1438
+ }
1439
+ }
1440
+
1441
+ // false if no hits in intersection region
1442
+ return false;
1443
+ };
1444
+ }
1445
+ function intersectPoint(item, box) {
1446
+ return box.contains(item.x || 0, item.y || 0);
1447
+ }
1448
+ function intersectRect(item, box) {
1449
+ const x = item.x || 0,
1450
+ y = item.y || 0,
1451
+ w = item.width || 0,
1452
+ h = item.height || 0;
1453
+ return box.intersects(b.set(x, y, x + w, y + h));
1454
+ }
1455
+ function intersectRule(item, box) {
1456
+ const x = item.x || 0,
1457
+ y = item.y || 0,
1458
+ x2 = item.x2 != null ? item.x2 : x,
1459
+ y2 = item.y2 != null ? item.y2 : y;
1460
+ return intersectBoxLine(box, x, y, x2, y2);
1461
+ }
1462
+ function intersectBoxLine(box, x, y, u, v) {
1463
+ const {
1464
+ x1,
1465
+ y1,
1466
+ x2,
1467
+ y2
1468
+ } = box,
1469
+ dx = u - x,
1470
+ dy = v - y;
1471
+ let t0 = 0,
1472
+ t1 = 1,
1473
+ p,
1474
+ q,
1475
+ r,
1476
+ e;
1477
+ for (e = 0; e < 4; ++e) {
1478
+ if (e === 0) {
1479
+ p = -dx;
1480
+ q = -(x1 - x);
1481
+ }
1482
+ if (e === 1) {
1483
+ p = dx;
1484
+ q = x2 - x;
1485
+ }
1486
+ if (e === 2) {
1487
+ p = -dy;
1488
+ q = -(y1 - y);
1489
+ }
1490
+ if (e === 3) {
1491
+ p = dy;
1492
+ q = y2 - y;
1493
+ }
1494
+ if (Math.abs(p) < 1e-10 && q < 0) return false;
1495
+ r = q / p;
1496
+ if (p < 0) {
1497
+ if (r > t1) return false;else if (r > t0) t0 = r;
1498
+ } else if (p > 0) {
1499
+ if (r < t0) return false;else if (r < t1) t1 = r;
1500
+ }
1501
+ }
1502
+ return true;
1503
+ }
1504
+
1505
+ function blend (context, item) {
1506
+ context.globalCompositeOperation = item.blend || 'source-over';
1507
+ }
1508
+
1509
+ function value (value, dflt) {
1510
+ return value == null ? dflt : value;
1511
+ }
1512
+
1513
+ function addStops(gradient, stops) {
1514
+ const n = stops.length;
1515
+ for (let i = 0; i < n; ++i) {
1516
+ gradient.addColorStop(stops[i].offset, stops[i].color);
1517
+ }
1518
+ return gradient;
1519
+ }
1520
+ function gradient (context, spec, bounds) {
1521
+ const w = bounds.width(),
1522
+ h = bounds.height();
1523
+ let gradient;
1524
+ if (spec.gradient === 'radial') {
1525
+ gradient = context.createRadialGradient(bounds.x1 + value(spec.x1, 0.5) * w, bounds.y1 + value(spec.y1, 0.5) * h, Math.max(w, h) * value(spec.r1, 0), bounds.x1 + value(spec.x2, 0.5) * w, bounds.y1 + value(spec.y2, 0.5) * h, Math.max(w, h) * value(spec.r2, 0.5));
1526
+ } else {
1527
+ // linear gradient
1528
+ const x1 = value(spec.x1, 0),
1529
+ y1 = value(spec.y1, 0),
1530
+ x2 = value(spec.x2, 1),
1531
+ y2 = value(spec.y2, 0);
1532
+ if (x1 === x2 || y1 === y2 || w === h) {
1533
+ // axis aligned: use normal gradient
1534
+ gradient = context.createLinearGradient(bounds.x1 + x1 * w, bounds.y1 + y1 * h, bounds.x1 + x2 * w, bounds.y1 + y2 * h);
1535
+ } else {
1536
+ // not axis aligned: render gradient into a pattern (#2365)
1537
+ // this allows us to use normalized bounding box coordinates
1538
+ const image = vegaCanvas_browser.canvas(Math.ceil(w), Math.ceil(h)),
1539
+ ictx = image.getContext('2d');
1540
+ ictx.scale(w, h);
1541
+ ictx.fillStyle = addStops(ictx.createLinearGradient(x1, y1, x2, y2), spec.stops);
1542
+ ictx.fillRect(0, 0, w, h);
1543
+ return context.createPattern(image, 'no-repeat');
1544
+ }
1545
+ }
1546
+ return addStops(gradient, spec.stops);
1547
+ }
1548
+
1549
+ function color (context, item, value) {
1550
+ return isGradient(value) ? gradient(context, value, item.bounds) : value;
1551
+ }
1552
+
1553
+ function fill (context, item, opacity) {
1554
+ opacity *= item.fillOpacity == null ? 1 : item.fillOpacity;
1555
+ if (opacity > 0) {
1556
+ context.globalAlpha = opacity;
1557
+ context.fillStyle = color(context, item, item.fill);
1558
+ return true;
1559
+ } else {
1560
+ return false;
1561
+ }
1562
+ }
1563
+
1564
+ var Empty = [];
1565
+ function stroke (context, item, opacity) {
1566
+ var lw = (lw = item.strokeWidth) != null ? lw : 1;
1567
+ if (lw <= 0) return false;
1568
+ opacity *= item.strokeOpacity == null ? 1 : item.strokeOpacity;
1569
+ if (opacity > 0) {
1570
+ context.globalAlpha = opacity;
1571
+ context.strokeStyle = color(context, item, item.stroke);
1572
+ context.lineWidth = lw;
1573
+ context.lineCap = item.strokeCap || 'butt';
1574
+ context.lineJoin = item.strokeJoin || 'miter';
1575
+ context.miterLimit = item.strokeMiterLimit || 10;
1576
+ if (context.setLineDash) {
1577
+ context.setLineDash(item.strokeDash || Empty);
1578
+ context.lineDashOffset = item.strokeDashOffset || 0;
1579
+ }
1580
+ return true;
1581
+ } else {
1582
+ return false;
1583
+ }
1584
+ }
1585
+
1586
+ function compare(a, b) {
1587
+ return a.zindex - b.zindex || a.index - b.index;
1588
+ }
1589
+ function zorder(scene) {
1590
+ if (!scene.zdirty) return scene.zitems;
1591
+ var items = scene.items,
1592
+ output = [],
1593
+ item,
1594
+ i,
1595
+ n;
1596
+ for (i = 0, n = items.length; i < n; ++i) {
1597
+ item = items[i];
1598
+ item.index = i;
1599
+ if (item.zindex) output.push(item);
1600
+ }
1601
+ scene.zdirty = false;
1602
+ return scene.zitems = output.sort(compare);
1603
+ }
1604
+ function visit(scene, visitor) {
1605
+ var items = scene.items,
1606
+ i,
1607
+ n;
1608
+ if (!items || !items.length) return;
1609
+ const zitems = zorder(scene);
1610
+ if (zitems && zitems.length) {
1611
+ for (i = 0, n = items.length; i < n; ++i) {
1612
+ if (!items[i].zindex) visitor(items[i]);
1613
+ }
1614
+ items = zitems;
1615
+ }
1616
+ for (i = 0, n = items.length; i < n; ++i) {
1617
+ visitor(items[i]);
1618
+ }
1619
+ }
1620
+ function pickVisit(scene, visitor) {
1621
+ var items = scene.items,
1622
+ hit,
1623
+ i;
1624
+ if (!items || !items.length) return null;
1625
+ const zitems = zorder(scene);
1626
+ if (zitems && zitems.length) items = zitems;
1627
+ for (i = items.length; --i >= 0;) {
1628
+ if (hit = visitor(items[i])) return hit;
1629
+ }
1630
+ if (items === zitems) {
1631
+ for (items = scene.items, i = items.length; --i >= 0;) {
1632
+ if (!items[i].zindex) {
1633
+ if (hit = visitor(items[i])) return hit;
1634
+ }
1635
+ }
1636
+ }
1637
+ return null;
1638
+ }
1639
+
1640
+ function drawAll(path) {
1641
+ return function (context, scene, bounds) {
1642
+ visit(scene, item => {
1643
+ if (!bounds || bounds.intersects(item.bounds)) {
1644
+ drawPath(path, context, item, item);
1645
+ }
1646
+ });
1647
+ };
1648
+ }
1649
+ function drawOne(path) {
1650
+ return function (context, scene, bounds) {
1651
+ if (scene.items.length && (!bounds || bounds.intersects(scene.bounds))) {
1652
+ drawPath(path, context, scene.items[0], scene.items);
1653
+ }
1654
+ };
1655
+ }
1656
+ function drawPath(path, context, item, items) {
1657
+ var opacity = item.opacity == null ? 1 : item.opacity;
1658
+ if (opacity === 0) return;
1659
+ if (path(context, items)) return;
1660
+ blend(context, item);
1661
+ if (item.fill && fill(context, item, opacity)) {
1662
+ context.fill();
1663
+ }
1664
+ if (item.stroke && stroke(context, item, opacity)) {
1665
+ context.stroke();
1666
+ }
1667
+ }
1668
+
1669
+ function pick$1(test) {
1670
+ test = test || vegaUtil.truthy;
1671
+ return function (context, scene, x, y, gx, gy) {
1672
+ x *= context.pixelRatio;
1673
+ y *= context.pixelRatio;
1674
+ return pickVisit(scene, item => {
1675
+ const b = item.bounds;
1676
+ // first hit test against bounding box
1677
+ if (b && !b.contains(gx, gy) || !b) return;
1678
+ // if in bounding box, perform more careful test
1679
+ if (test(context, item, x, y, gx, gy)) return item;
1680
+ });
1681
+ };
1682
+ }
1683
+ function hitPath(path, filled) {
1684
+ return function (context, o, x, y) {
1685
+ var item = Array.isArray(o) ? o[0] : o,
1686
+ fill = filled == null ? item.fill : filled,
1687
+ stroke = item.stroke && context.isPointInStroke,
1688
+ lw,
1689
+ lc;
1690
+ if (stroke) {
1691
+ lw = item.strokeWidth;
1692
+ lc = item.strokeCap;
1693
+ context.lineWidth = lw != null ? lw : 1;
1694
+ context.lineCap = lc != null ? lc : 'butt';
1695
+ }
1696
+ return path(context, o) ? false : fill && context.isPointInPath(x, y) || stroke && context.isPointInStroke(x, y);
1697
+ };
1698
+ }
1699
+ function pickPath(path) {
1700
+ return pick$1(hitPath(path));
1701
+ }
1702
+
1703
+ function translate(x, y) {
1704
+ return 'translate(' + x + ',' + y + ')';
1705
+ }
1706
+ function rotate(a) {
1707
+ return 'rotate(' + a + ')';
1708
+ }
1709
+ function scale(scaleX, scaleY) {
1710
+ return 'scale(' + scaleX + ',' + scaleY + ')';
1711
+ }
1712
+ function translateItem(item) {
1713
+ return translate(item.x || 0, item.y || 0);
1714
+ }
1715
+ function rotateItem(item) {
1716
+ return translate(item.x || 0, item.y || 0) + (item.angle ? ' ' + rotate(item.angle) : '');
1717
+ }
1718
+ function transformItem(item) {
1719
+ return translate(item.x || 0, item.y || 0) + (item.angle ? ' ' + rotate(item.angle) : '') + (item.scaleX || item.scaleY ? ' ' + scale(item.scaleX || 1, item.scaleY || 1) : '');
1720
+ }
1721
+
1722
+ function markItemPath (type, shape, isect) {
1723
+ function attr(emit, item) {
1724
+ emit('transform', rotateItem(item));
1725
+ emit('d', shape(null, item));
1726
+ }
1727
+ function bound(bounds, item) {
1728
+ shape(boundContext(bounds, item.angle), item);
1729
+ return boundStroke(bounds, item).translate(item.x || 0, item.y || 0);
1730
+ }
1731
+ function draw(context, item) {
1732
+ var x = item.x || 0,
1733
+ y = item.y || 0,
1734
+ a = item.angle || 0;
1735
+ context.translate(x, y);
1736
+ if (a) context.rotate(a *= DegToRad);
1737
+ context.beginPath();
1738
+ shape(context, item);
1739
+ if (a) context.rotate(-a);
1740
+ context.translate(-x, -y);
1741
+ }
1742
+ return {
1743
+ type: type,
1744
+ tag: 'path',
1745
+ nested: false,
1746
+ attr: attr,
1747
+ bound: bound,
1748
+ draw: drawAll(draw),
1749
+ pick: pickPath(draw),
1750
+ isect: isect || intersectPath(draw)
1751
+ };
1752
+ }
1753
+
1754
+ var arc = markItemPath('arc', arc$1);
1755
+
1756
+ function pickArea(a, p) {
1757
+ var v = a[0].orient === 'horizontal' ? p[1] : p[0],
1758
+ z = a[0].orient === 'horizontal' ? 'y' : 'x',
1759
+ i = a.length,
1760
+ min = +Infinity,
1761
+ hit,
1762
+ d;
1763
+ while (--i >= 0) {
1764
+ if (a[i].defined === false) continue;
1765
+ d = Math.abs(a[i][z] - v);
1766
+ if (d < min) {
1767
+ min = d;
1768
+ hit = a[i];
1769
+ }
1770
+ }
1771
+ return hit;
1772
+ }
1773
+ function pickLine(a, p) {
1774
+ var t = Math.pow(a[0].strokeWidth || 1, 2),
1775
+ i = a.length,
1776
+ dx,
1777
+ dy,
1778
+ dd;
1779
+ while (--i >= 0) {
1780
+ if (a[i].defined === false) continue;
1781
+ dx = a[i].x - p[0];
1782
+ dy = a[i].y - p[1];
1783
+ dd = dx * dx + dy * dy;
1784
+ if (dd < t) return a[i];
1785
+ }
1786
+ return null;
1787
+ }
1788
+ function pickTrail(a, p) {
1789
+ var i = a.length,
1790
+ dx,
1791
+ dy,
1792
+ dd;
1793
+ while (--i >= 0) {
1794
+ if (a[i].defined === false) continue;
1795
+ dx = a[i].x - p[0];
1796
+ dy = a[i].y - p[1];
1797
+ dd = dx * dx + dy * dy;
1798
+ dx = a[i].size || 1;
1799
+ if (dd < dx * dx) return a[i];
1800
+ }
1801
+ return null;
1802
+ }
1803
+
1804
+ function markMultiItemPath (type, shape, tip) {
1805
+ function attr(emit, item) {
1806
+ var items = item.mark.items;
1807
+ if (items.length) emit('d', shape(null, items));
1808
+ }
1809
+ function bound(bounds, mark) {
1810
+ var items = mark.items;
1811
+ if (items.length === 0) {
1812
+ return bounds;
1813
+ } else {
1814
+ shape(boundContext(bounds), items);
1815
+ return boundStroke(bounds, items[0]);
1816
+ }
1817
+ }
1818
+ function draw(context, items) {
1819
+ context.beginPath();
1820
+ shape(context, items);
1821
+ }
1822
+ const hit = hitPath(draw);
1823
+ function pick(context, scene, x, y, gx, gy) {
1824
+ var items = scene.items,
1825
+ b = scene.bounds;
1826
+ if (!items || !items.length || b && !b.contains(gx, gy)) {
1827
+ return null;
1828
+ }
1829
+ x *= context.pixelRatio;
1830
+ y *= context.pixelRatio;
1831
+ return hit(context, items, x, y) ? items[0] : null;
1832
+ }
1833
+ return {
1834
+ type: type,
1835
+ tag: 'path',
1836
+ nested: true,
1837
+ attr: attr,
1838
+ bound: bound,
1839
+ draw: drawOne(draw),
1840
+ pick: pick,
1841
+ isect: intersectPoint,
1842
+ tip: tip
1843
+ };
1844
+ }
1845
+
1846
+ var area = markMultiItemPath('area', area$1, pickArea);
1847
+
1848
+ function clip (context, scene) {
1849
+ var clip = scene.clip;
1850
+ context.save();
1851
+ if (vegaUtil.isFunction(clip)) {
1852
+ context.beginPath();
1853
+ clip(context);
1854
+ context.clip();
1855
+ } else {
1856
+ clipGroup(context, scene.group);
1857
+ }
1858
+ }
1859
+ function clipGroup(context, group) {
1860
+ context.beginPath();
1861
+ hasCornerRadius(group) ? rectangle(context, group, 0, 0) : context.rect(0, 0, group.width || 0, group.height || 0);
1862
+ context.clip();
1863
+ }
1864
+
1865
+ function offset$1(item) {
1866
+ const sw = value(item.strokeWidth, 1);
1867
+ return item.strokeOffset != null ? item.strokeOffset : item.stroke && sw > 0.5 && sw < 1.5 ? 0.5 - Math.abs(sw - 1) : 0;
1868
+ }
1869
+ function attr$5(emit, item) {
1870
+ emit('transform', translateItem(item));
1871
+ }
1872
+ function emitRectangle(emit, item) {
1873
+ const off = offset$1(item);
1874
+ emit('d', rectangle(null, item, off, off));
1875
+ }
1876
+ function background(emit, item) {
1877
+ emit('class', 'background');
1878
+ emit('aria-hidden', true);
1879
+ emitRectangle(emit, item);
1880
+ }
1881
+ function foreground(emit, item) {
1882
+ emit('class', 'foreground');
1883
+ emit('aria-hidden', true);
1884
+ if (item.strokeForeground) {
1885
+ emitRectangle(emit, item);
1886
+ } else {
1887
+ emit('d', '');
1888
+ }
1889
+ }
1890
+ function content(emit, item, renderer) {
1891
+ const url = item.clip ? clip$1(renderer, item, item) : null;
1892
+ emit('clip-path', url);
1893
+ }
1894
+ function bound$5(bounds, group) {
1895
+ if (!group.clip && group.items) {
1896
+ const items = group.items,
1897
+ m = items.length;
1898
+ for (let j = 0; j < m; ++j) {
1899
+ bounds.union(items[j].bounds);
1900
+ }
1901
+ }
1902
+ if ((group.clip || group.width || group.height) && !group.noBound) {
1903
+ bounds.add(0, 0).add(group.width || 0, group.height || 0);
1904
+ }
1905
+ boundStroke(bounds, group);
1906
+ return bounds.translate(group.x || 0, group.y || 0);
1907
+ }
1908
+ function rectanglePath(context, group, x, y) {
1909
+ const off = offset$1(group);
1910
+ context.beginPath();
1911
+ rectangle(context, group, (x || 0) + off, (y || 0) + off);
1912
+ }
1913
+ const hitBackground = hitPath(rectanglePath);
1914
+ const hitForeground = hitPath(rectanglePath, false);
1915
+ const hitCorner = hitPath(rectanglePath, true);
1916
+ function draw$4(context, scene, bounds, markTypes) {
1917
+ visit(scene, group => {
1918
+ const gx = group.x || 0,
1919
+ gy = group.y || 0,
1920
+ fore = group.strokeForeground,
1921
+ opacity = group.opacity == null ? 1 : group.opacity;
1922
+
1923
+ // draw group background
1924
+ if ((group.stroke || group.fill) && opacity) {
1925
+ rectanglePath(context, group, gx, gy);
1926
+ blend(context, group);
1927
+ if (group.fill && fill(context, group, opacity)) {
1928
+ context.fill();
1929
+ }
1930
+ if (group.stroke && !fore && stroke(context, group, opacity)) {
1931
+ context.stroke();
1932
+ }
1933
+ }
1934
+
1935
+ // setup graphics context, set clip and bounds
1936
+ context.save();
1937
+ context.translate(gx, gy);
1938
+ if (group.clip) clipGroup(context, group);
1939
+ if (bounds) bounds.translate(-gx, -gy);
1940
+
1941
+ // draw group contents
1942
+ visit(group, item => {
1943
+ if (item.marktype === 'group' || markTypes == null || markTypes.includes(item.marktype)) {
1944
+ this.draw(context, item, bounds, markTypes);
1945
+ }
1946
+ });
1947
+
1948
+ // restore graphics context
1949
+ if (bounds) bounds.translate(gx, gy);
1950
+ context.restore();
1951
+
1952
+ // draw group foreground
1953
+ if (fore && group.stroke && opacity) {
1954
+ rectanglePath(context, group, gx, gy);
1955
+ blend(context, group);
1956
+ if (stroke(context, group, opacity)) {
1957
+ context.stroke();
1958
+ }
1959
+ }
1960
+ });
1961
+ }
1962
+ function pick(context, scene, x, y, gx, gy) {
1963
+ if (scene.bounds && !scene.bounds.contains(gx, gy) || !scene.items) {
1964
+ return null;
1965
+ }
1966
+ const cx = x * context.pixelRatio,
1967
+ cy = y * context.pixelRatio;
1968
+ return pickVisit(scene, group => {
1969
+ let hit, dx, dy;
1970
+
1971
+ // first hit test bounding box
1972
+ const b = group.bounds;
1973
+ if (b && !b.contains(gx, gy)) return;
1974
+
1975
+ // passed bounds check, test rectangular clip
1976
+ dx = group.x || 0;
1977
+ dy = group.y || 0;
1978
+ const dw = dx + (group.width || 0),
1979
+ dh = dy + (group.height || 0),
1980
+ c = group.clip;
1981
+ if (c && (gx < dx || gx > dw || gy < dy || gy > dh)) return;
1982
+
1983
+ // adjust coordinate system
1984
+ context.save();
1985
+ context.translate(dx, dy);
1986
+ dx = gx - dx;
1987
+ dy = gy - dy;
1988
+
1989
+ // test background for rounded corner clip
1990
+ if (c && hasCornerRadius(group) && !hitCorner(context, group, cx, cy)) {
1991
+ context.restore();
1992
+ return null;
1993
+ }
1994
+ const fore = group.strokeForeground,
1995
+ ix = scene.interactive !== false;
1996
+
1997
+ // hit test against group foreground
1998
+ if (ix && fore && group.stroke && hitForeground(context, group, cx, cy)) {
1999
+ context.restore();
2000
+ return group;
2001
+ }
2002
+
2003
+ // hit test against contained marks
2004
+ hit = pickVisit(group, mark => pickMark(mark, dx, dy) ? this.pick(mark, x, y, dx, dy) : null);
2005
+
2006
+ // hit test against group background
2007
+ if (!hit && ix && (group.fill || !fore && group.stroke) && hitBackground(context, group, cx, cy)) {
2008
+ hit = group;
2009
+ }
2010
+
2011
+ // restore state and return
2012
+ context.restore();
2013
+ return hit || null;
2014
+ });
2015
+ }
2016
+ function pickMark(mark, x, y) {
2017
+ return (mark.interactive !== false || mark.marktype === 'group') && mark.bounds && mark.bounds.contains(x, y);
2018
+ }
2019
+ var group = {
2020
+ type: 'group',
2021
+ tag: 'g',
2022
+ nested: false,
2023
+ attr: attr$5,
2024
+ bound: bound$5,
2025
+ draw: draw$4,
2026
+ pick: pick,
2027
+ isect: intersectRect,
2028
+ content: content,
2029
+ background: background,
2030
+ foreground: foreground
2031
+ };
2032
+
2033
+ var metadata = {
2034
+ 'xmlns': 'http://www.w3.org/2000/svg',
2035
+ 'xmlns:xlink': 'http://www.w3.org/1999/xlink',
2036
+ 'version': '1.1'
2037
+ };
2038
+
2039
+ function getImage(item, renderer) {
2040
+ var image = item.image;
2041
+ if (!image || item.url && item.url !== image.url) {
2042
+ image = {
2043
+ complete: false,
2044
+ width: 0,
2045
+ height: 0
2046
+ };
2047
+ renderer.loadImage(item.url).then(image => {
2048
+ item.image = image;
2049
+ item.image.url = item.url;
2050
+ });
2051
+ }
2052
+ return image;
2053
+ }
2054
+ function imageWidth(item, image) {
2055
+ return item.width != null ? item.width : !image || !image.width ? 0 : item.aspect !== false && item.height ? item.height * image.width / image.height : image.width;
2056
+ }
2057
+ function imageHeight(item, image) {
2058
+ return item.height != null ? item.height : !image || !image.height ? 0 : item.aspect !== false && item.width ? item.width * image.height / image.width : image.height;
2059
+ }
2060
+ function imageXOffset(align, w) {
2061
+ return align === 'center' ? w / 2 : align === 'right' ? w : 0;
2062
+ }
2063
+ function imageYOffset(baseline, h) {
2064
+ return baseline === 'middle' ? h / 2 : baseline === 'bottom' ? h : 0;
2065
+ }
2066
+ function attr$4(emit, item, renderer) {
2067
+ const img = getImage(item, renderer),
2068
+ w = imageWidth(item, img),
2069
+ h = imageHeight(item, img),
2070
+ x = (item.x || 0) - imageXOffset(item.align, w),
2071
+ y = (item.y || 0) - imageYOffset(item.baseline, h),
2072
+ i = !img.src && img.toDataURL ? img.toDataURL() : img.src || '';
2073
+ emit('href', i, metadata['xmlns:xlink'], 'xlink:href');
2074
+ emit('transform', translate(x, y));
2075
+ emit('width', w);
2076
+ emit('height', h);
2077
+ emit('preserveAspectRatio', item.aspect === false ? 'none' : 'xMidYMid');
2078
+ }
2079
+ function bound$4(bounds, item) {
2080
+ const img = item.image,
2081
+ w = imageWidth(item, img),
2082
+ h = imageHeight(item, img),
2083
+ x = (item.x || 0) - imageXOffset(item.align, w),
2084
+ y = (item.y || 0) - imageYOffset(item.baseline, h);
2085
+ return bounds.set(x, y, x + w, y + h);
2086
+ }
2087
+ function draw$3(context, scene, bounds) {
2088
+ visit(scene, item => {
2089
+ if (bounds && !bounds.intersects(item.bounds)) return; // bounds check
2090
+
2091
+ const img = getImage(item, this);
2092
+ let w = imageWidth(item, img);
2093
+ let h = imageHeight(item, img);
2094
+ if (w === 0 || h === 0) return; // early exit
2095
+
2096
+ let x = (item.x || 0) - imageXOffset(item.align, w),
2097
+ y = (item.y || 0) - imageYOffset(item.baseline, h),
2098
+ opacity,
2099
+ ar0,
2100
+ ar1,
2101
+ t;
2102
+ if (item.aspect !== false) {
2103
+ ar0 = img.width / img.height;
2104
+ ar1 = item.width / item.height;
2105
+ if (ar0 === ar0 && ar1 === ar1 && ar0 !== ar1) {
2106
+ if (ar1 < ar0) {
2107
+ t = w / ar0;
2108
+ y += (h - t) / 2;
2109
+ h = t;
2110
+ } else {
2111
+ t = h * ar0;
2112
+ x += (w - t) / 2;
2113
+ w = t;
2114
+ }
2115
+ }
2116
+ }
2117
+ if (img.complete || img.toDataURL) {
2118
+ blend(context, item);
2119
+ context.globalAlpha = (opacity = item.opacity) != null ? opacity : 1;
2120
+ context.imageSmoothingEnabled = item.smooth !== false;
2121
+ context.drawImage(img, x, y, w, h);
2122
+ }
2123
+ });
2124
+ }
2125
+ var image = {
2126
+ type: 'image',
2127
+ tag: 'image',
2128
+ nested: false,
2129
+ attr: attr$4,
2130
+ bound: bound$4,
2131
+ draw: draw$3,
2132
+ pick: pick$1(),
2133
+ isect: vegaUtil.truthy,
2134
+ // bounds check is sufficient
2135
+ get: getImage,
2136
+ xOffset: imageXOffset,
2137
+ yOffset: imageYOffset
2138
+ };
2139
+
2140
+ var line = markMultiItemPath('line', line$1, pickLine);
2141
+
2142
+ function attr$3(emit, item) {
2143
+ var sx = item.scaleX || 1,
2144
+ sy = item.scaleY || 1;
2145
+ if (sx !== 1 || sy !== 1) {
2146
+ emit('vector-effect', 'non-scaling-stroke');
2147
+ }
2148
+ emit('transform', transformItem(item));
2149
+ emit('d', item.path);
2150
+ }
2151
+ function path$1(context, item) {
2152
+ var path = item.path;
2153
+ if (path == null) return true;
2154
+ var x = item.x || 0,
2155
+ y = item.y || 0,
2156
+ sx = item.scaleX || 1,
2157
+ sy = item.scaleY || 1,
2158
+ a = (item.angle || 0) * DegToRad,
2159
+ cache = item.pathCache;
2160
+ if (!cache || cache.path !== path) {
2161
+ (item.pathCache = cache = parse(path)).path = path;
2162
+ }
2163
+ if (a && context.rotate && context.translate) {
2164
+ context.translate(x, y);
2165
+ context.rotate(a);
2166
+ pathRender(context, cache, 0, 0, sx, sy);
2167
+ context.rotate(-a);
2168
+ context.translate(-x, -y);
2169
+ } else {
2170
+ pathRender(context, cache, x, y, sx, sy);
2171
+ }
2172
+ }
2173
+ function bound$3(bounds, item) {
2174
+ return path$1(boundContext(bounds, item.angle), item) ? bounds.set(0, 0, 0, 0) : boundStroke(bounds, item, true);
2175
+ }
2176
+ var path$2 = {
2177
+ type: 'path',
2178
+ tag: 'path',
2179
+ nested: false,
2180
+ attr: attr$3,
2181
+ bound: bound$3,
2182
+ draw: drawAll(path$1),
2183
+ pick: pickPath(path$1),
2184
+ isect: intersectPath(path$1)
2185
+ };
2186
+
2187
+ function attr$2(emit, item) {
2188
+ emit('d', rectangle(null, item));
2189
+ }
2190
+ function bound$2(bounds, item) {
2191
+ var x, y;
2192
+ return boundStroke(bounds.set(x = item.x || 0, y = item.y || 0, x + item.width || 0, y + item.height || 0), item);
2193
+ }
2194
+ function draw$2(context, item) {
2195
+ context.beginPath();
2196
+ rectangle(context, item);
2197
+ }
2198
+ var rect = {
2199
+ type: 'rect',
2200
+ tag: 'path',
2201
+ nested: false,
2202
+ attr: attr$2,
2203
+ bound: bound$2,
2204
+ draw: drawAll(draw$2),
2205
+ pick: pickPath(draw$2),
2206
+ isect: intersectRect
2207
+ };
2208
+
2209
+ function attr$1(emit, item) {
2210
+ emit('transform', translateItem(item));
2211
+ emit('x2', item.x2 != null ? item.x2 - (item.x || 0) : 0);
2212
+ emit('y2', item.y2 != null ? item.y2 - (item.y || 0) : 0);
2213
+ }
2214
+ function bound$1(bounds, item) {
2215
+ var x1, y1;
2216
+ return boundStroke(bounds.set(x1 = item.x || 0, y1 = item.y || 0, item.x2 != null ? item.x2 : x1, item.y2 != null ? item.y2 : y1), item);
2217
+ }
2218
+ function path(context, item, opacity) {
2219
+ var x1, y1, x2, y2;
2220
+ if (item.stroke && stroke(context, item, opacity)) {
2221
+ x1 = item.x || 0;
2222
+ y1 = item.y || 0;
2223
+ x2 = item.x2 != null ? item.x2 : x1;
2224
+ y2 = item.y2 != null ? item.y2 : y1;
2225
+ context.beginPath();
2226
+ context.moveTo(x1, y1);
2227
+ context.lineTo(x2, y2);
2228
+ return true;
2229
+ }
2230
+ return false;
2231
+ }
2232
+ function draw$1(context, scene, bounds) {
2233
+ visit(scene, item => {
2234
+ if (bounds && !bounds.intersects(item.bounds)) return; // bounds check
2235
+ var opacity = item.opacity == null ? 1 : item.opacity;
2236
+ if (opacity && path(context, item, opacity)) {
2237
+ blend(context, item);
2238
+ context.stroke();
2239
+ }
2240
+ });
2241
+ }
2242
+ function hit$1(context, item, x, y) {
2243
+ if (!context.isPointInStroke) return false;
2244
+ return path(context, item, 1) && context.isPointInStroke(x, y);
2245
+ }
2246
+ var rule = {
2247
+ type: 'rule',
2248
+ tag: 'line',
2249
+ nested: false,
2250
+ attr: attr$1,
2251
+ bound: bound$1,
2252
+ draw: draw$1,
2253
+ pick: pick$1(hit$1),
2254
+ isect: intersectRule
2255
+ };
2256
+
2257
+ var shape = markItemPath('shape', shape$1);
2258
+
2259
+ var symbol = markItemPath('symbol', symbol$1, intersectPoint);
2260
+
2261
+ // memoize text width measurement
2262
+ const widthCache = vegaUtil.lruCache();
2263
+ var textMetrics = {
2264
+ height: fontSize,
2265
+ measureWidth: measureWidth,
2266
+ estimateWidth: estimateWidth,
2267
+ width: estimateWidth,
2268
+ canvas: useCanvas
2269
+ };
2270
+ useCanvas(true);
2271
+ function useCanvas(use) {
2272
+ textMetrics.width = use && context ? measureWidth : estimateWidth;
2273
+ }
2274
+
2275
+ // make simple estimate if no canvas is available
2276
+ function estimateWidth(item, text) {
2277
+ return _estimateWidth(textValue(item, text), fontSize(item));
2278
+ }
2279
+ function _estimateWidth(text, currentFontHeight) {
2280
+ return ~~(0.8 * text.length * currentFontHeight);
2281
+ }
2282
+
2283
+ // measure text width if canvas is available
2284
+ function measureWidth(item, text) {
2285
+ return fontSize(item) <= 0 || !(text = textValue(item, text)) ? 0 : _measureWidth(text, font(item));
2286
+ }
2287
+ function _measureWidth(text, currentFont) {
2288
+ const key = `(${currentFont}) ${text}`;
2289
+ let width = widthCache.get(key);
2290
+ if (width === undefined) {
2291
+ context.font = currentFont;
2292
+ width = context.measureText(text).width;
2293
+ widthCache.set(key, width);
2294
+ }
2295
+ return width;
2296
+ }
2297
+ function fontSize(item) {
2298
+ return item.fontSize != null ? +item.fontSize || 0 : 11;
2299
+ }
2300
+ function lineHeight(item) {
2301
+ return item.lineHeight != null ? item.lineHeight : fontSize(item) + 2;
2302
+ }
2303
+ function lineArray(_) {
2304
+ return vegaUtil.isArray(_) ? _.length > 1 ? _ : _[0] : _;
2305
+ }
2306
+ function textLines(item) {
2307
+ return lineArray(item.lineBreak && item.text && !vegaUtil.isArray(item.text) ? item.text.split(item.lineBreak) : item.text);
2308
+ }
2309
+ function multiLineOffset(item) {
2310
+ const tl = textLines(item);
2311
+ return (vegaUtil.isArray(tl) ? tl.length - 1 : 0) * lineHeight(item);
2312
+ }
2313
+ function textValue(item, line) {
2314
+ const text = line == null ? '' : (line + '').trim();
2315
+ return item.limit > 0 && text.length ? truncate(item, text) : text;
2316
+ }
2317
+ function widthGetter(item) {
2318
+ if (textMetrics.width === measureWidth) {
2319
+ // we are using canvas
2320
+ const currentFont = font(item);
2321
+ return text => _measureWidth(text, currentFont);
2322
+ } else if (textMetrics.width === estimateWidth) {
2323
+ // we are relying on estimates
2324
+ const currentFontHeight = fontSize(item);
2325
+ return text => _estimateWidth(text, currentFontHeight);
2326
+ } else {
2327
+ // User defined textMetrics.width function in use (e.g. vl-convert)
2328
+ return text => textMetrics.width(item, text);
2329
+ }
2330
+ }
2331
+ function truncate(item, text) {
2332
+ var limit = +item.limit,
2333
+ width = widthGetter(item);
2334
+ if (width(text) < limit) return text;
2335
+ var ellipsis = item.ellipsis || '\u2026',
2336
+ rtl = item.dir === 'rtl',
2337
+ lo = 0,
2338
+ hi = text.length,
2339
+ mid;
2340
+ limit -= width(ellipsis);
2341
+ if (rtl) {
2342
+ while (lo < hi) {
2343
+ mid = lo + hi >>> 1;
2344
+ if (width(text.slice(mid)) > limit) lo = mid + 1;else hi = mid;
2345
+ }
2346
+ return ellipsis + text.slice(lo);
2347
+ } else {
2348
+ while (lo < hi) {
2349
+ mid = 1 + (lo + hi >>> 1);
2350
+ if (width(text.slice(0, mid)) < limit) lo = mid;else hi = mid - 1;
2351
+ }
2352
+ return text.slice(0, lo) + ellipsis;
2353
+ }
2354
+ }
2355
+ function fontFamily(item, quote) {
2356
+ var font = item.font;
2357
+ return (quote && font ? String(font).replace(/"/g, '\'') : font) || 'sans-serif';
2358
+ }
2359
+ function font(item, quote) {
2360
+ return '' + (item.fontStyle ? item.fontStyle + ' ' : '') + (item.fontVariant ? item.fontVariant + ' ' : '') + (item.fontWeight ? item.fontWeight + ' ' : '') + fontSize(item) + 'px ' + fontFamily(item, quote);
2361
+ }
2362
+ function offset(item) {
2363
+ // perform our own font baseline calculation
2364
+ // why? not all browsers support SVG 1.1 'alignment-baseline' :(
2365
+ // this also ensures consistent layout across renderers
2366
+ var baseline = item.baseline,
2367
+ h = fontSize(item);
2368
+ return Math.round(baseline === 'top' ? 0.79 * h : baseline === 'middle' ? 0.30 * h : baseline === 'bottom' ? -0.21 * h : baseline === 'line-top' ? 0.29 * h + 0.5 * lineHeight(item) : baseline === 'line-bottom' ? 0.29 * h - 0.5 * lineHeight(item) : 0);
2369
+ }
2370
+
2371
+ const textAlign = {
2372
+ 'left': 'start',
2373
+ 'center': 'middle',
2374
+ 'right': 'end'
2375
+ };
2376
+ const tempBounds = new Bounds();
2377
+ function anchorPoint(item) {
2378
+ var x = item.x || 0,
2379
+ y = item.y || 0,
2380
+ r = item.radius || 0,
2381
+ t;
2382
+ if (r) {
2383
+ t = (item.theta || 0) - HalfPi;
2384
+ x += r * Math.cos(t);
2385
+ y += r * Math.sin(t);
2386
+ }
2387
+ tempBounds.x1 = x;
2388
+ tempBounds.y1 = y;
2389
+ return tempBounds;
2390
+ }
2391
+ function attr(emit, item) {
2392
+ var dx = item.dx || 0,
2393
+ dy = (item.dy || 0) + offset(item),
2394
+ p = anchorPoint(item),
2395
+ x = p.x1,
2396
+ y = p.y1,
2397
+ a = item.angle || 0,
2398
+ t;
2399
+ emit('text-anchor', textAlign[item.align] || 'start');
2400
+ if (a) {
2401
+ t = translate(x, y) + ' ' + rotate(a);
2402
+ if (dx || dy) t += ' ' + translate(dx, dy);
2403
+ } else {
2404
+ t = translate(x + dx, y + dy);
2405
+ }
2406
+ emit('transform', t);
2407
+ }
2408
+ function bound(bounds, item, mode) {
2409
+ var h = textMetrics.height(item),
2410
+ a = item.align,
2411
+ p = anchorPoint(item),
2412
+ x = p.x1,
2413
+ y = p.y1,
2414
+ dx = item.dx || 0,
2415
+ dy = (item.dy || 0) + offset(item) - Math.round(0.8 * h),
2416
+ // use 4/5 offset
2417
+ tl = textLines(item),
2418
+ w;
2419
+
2420
+ // get dimensions
2421
+ if (vegaUtil.isArray(tl)) {
2422
+ // multi-line text
2423
+ h += lineHeight(item) * (tl.length - 1);
2424
+ w = tl.reduce((w, t) => Math.max(w, textMetrics.width(item, t)), 0);
2425
+ } else {
2426
+ // single-line text
2427
+ w = textMetrics.width(item, tl);
2428
+ }
2429
+
2430
+ // horizontal alignment
2431
+ if (a === 'center') {
2432
+ dx -= w / 2;
2433
+ } else if (a === 'right') {
2434
+ dx -= w;
2435
+ } else ;
2436
+ bounds.set(dx += x, dy += y, dx + w, dy + h);
2437
+ if (item.angle && !mode) {
2438
+ bounds.rotate(item.angle * DegToRad, x, y);
2439
+ } else if (mode === 2) {
2440
+ return bounds.rotatedPoints(item.angle * DegToRad, x, y);
2441
+ }
2442
+ return bounds;
2443
+ }
2444
+ function draw(context, scene, bounds) {
2445
+ visit(scene, item => {
2446
+ var opacity = item.opacity == null ? 1 : item.opacity,
2447
+ p,
2448
+ x,
2449
+ y,
2450
+ i,
2451
+ lh,
2452
+ tl,
2453
+ str;
2454
+ if (bounds && !bounds.intersects(item.bounds) ||
2455
+ // bounds check
2456
+ opacity === 0 || item.fontSize <= 0 || item.text == null || item.text.length === 0) return;
2457
+ context.font = font(item);
2458
+ context.textAlign = item.align || 'left';
2459
+ p = anchorPoint(item);
2460
+ x = p.x1, y = p.y1;
2461
+ if (item.angle) {
2462
+ context.save();
2463
+ context.translate(x, y);
2464
+ context.rotate(item.angle * DegToRad);
2465
+ x = y = 0; // reset x, y
2466
+ }
2467
+ x += item.dx || 0;
2468
+ y += (item.dy || 0) + offset(item);
2469
+ tl = textLines(item);
2470
+ blend(context, item);
2471
+ if (vegaUtil.isArray(tl)) {
2472
+ lh = lineHeight(item);
2473
+ for (i = 0; i < tl.length; ++i) {
2474
+ str = textValue(item, tl[i]);
2475
+ if (item.fill && fill(context, item, opacity)) {
2476
+ context.fillText(str, x, y);
2477
+ }
2478
+ if (item.stroke && stroke(context, item, opacity)) {
2479
+ context.strokeText(str, x, y);
2480
+ }
2481
+ y += lh;
2482
+ }
2483
+ } else {
2484
+ str = textValue(item, tl);
2485
+ if (item.fill && fill(context, item, opacity)) {
2486
+ context.fillText(str, x, y);
2487
+ }
2488
+ if (item.stroke && stroke(context, item, opacity)) {
2489
+ context.strokeText(str, x, y);
2490
+ }
2491
+ }
2492
+ if (item.angle) context.restore();
2493
+ });
2494
+ }
2495
+ function hit(context, item, x, y, gx, gy) {
2496
+ if (item.fontSize <= 0) return false;
2497
+ if (!item.angle) return true; // bounds sufficient if no rotation
2498
+
2499
+ // project point into space of unrotated bounds
2500
+ var p = anchorPoint(item),
2501
+ ax = p.x1,
2502
+ ay = p.y1,
2503
+ b = bound(tempBounds, item, 1),
2504
+ a = -item.angle * DegToRad,
2505
+ cos = Math.cos(a),
2506
+ sin = Math.sin(a),
2507
+ px = cos * gx - sin * gy + (ax - cos * ax + sin * ay),
2508
+ py = sin * gx + cos * gy + (ay - sin * ax - cos * ay);
2509
+ return b.contains(px, py);
2510
+ }
2511
+ function intersectText(item, box) {
2512
+ const p = bound(tempBounds, item, 2);
2513
+ return intersectBoxLine(box, p[0], p[1], p[2], p[3]) || intersectBoxLine(box, p[0], p[1], p[4], p[5]) || intersectBoxLine(box, p[4], p[5], p[6], p[7]) || intersectBoxLine(box, p[2], p[3], p[6], p[7]);
2514
+ }
2515
+ var text = {
2516
+ type: 'text',
2517
+ tag: 'text',
2518
+ nested: false,
2519
+ attr: attr,
2520
+ bound: bound,
2521
+ draw: draw,
2522
+ pick: pick$1(hit),
2523
+ isect: intersectText
2524
+ };
2525
+
2526
+ var trail = markMultiItemPath('trail', trail$1, pickTrail);
2527
+
2528
+ var Marks = {
2529
+ arc: arc,
2530
+ area: area,
2531
+ group: group,
2532
+ image: image,
2533
+ line: line,
2534
+ path: path$2,
2535
+ rect: rect,
2536
+ rule: rule,
2537
+ shape: shape,
2538
+ symbol: symbol,
2539
+ text: text,
2540
+ trail: trail
2541
+ };
2542
+
2543
+ function boundItem (item, func, opt) {
2544
+ var type = Marks[item.mark.marktype],
2545
+ bound = func || type.bound;
2546
+ if (type.nested) item = item.mark;
2547
+ return bound(item.bounds || (item.bounds = new Bounds()), item, opt);
2548
+ }
2549
+
2550
+ var DUMMY = {
2551
+ mark: null
2552
+ };
2553
+ function boundMark (mark, bounds, opt) {
2554
+ var type = Marks[mark.marktype],
2555
+ bound = type.bound,
2556
+ items = mark.items,
2557
+ hasItems = items && items.length,
2558
+ i,
2559
+ n,
2560
+ item,
2561
+ b;
2562
+ if (type.nested) {
2563
+ if (hasItems) {
2564
+ item = items[0];
2565
+ } else {
2566
+ // no items, fake it
2567
+ DUMMY.mark = mark;
2568
+ item = DUMMY;
2569
+ }
2570
+ b = boundItem(item, bound, opt);
2571
+ bounds = bounds && bounds.union(b) || b;
2572
+ return bounds;
2573
+ }
2574
+ bounds = bounds || mark.bounds && mark.bounds.clear() || new Bounds();
2575
+ if (hasItems) {
2576
+ for (i = 0, n = items.length; i < n; ++i) {
2577
+ bounds.union(boundItem(items[i], bound, opt));
2578
+ }
2579
+ }
2580
+ return mark.bounds = bounds;
2581
+ }
2582
+
2583
+ const keys = ['marktype', 'name', 'role', 'interactive', 'clip', 'items', 'zindex', 'x', 'y', 'width', 'height', 'align', 'baseline',
2584
+ // layout
2585
+ 'fill', 'fillOpacity', 'opacity', 'blend',
2586
+ // fill
2587
+ 'stroke', 'strokeOpacity', 'strokeWidth', 'strokeCap',
2588
+ // stroke
2589
+ 'strokeDash', 'strokeDashOffset',
2590
+ // stroke dash
2591
+ 'strokeForeground', 'strokeOffset',
2592
+ // group
2593
+ 'startAngle', 'endAngle', 'innerRadius', 'outerRadius',
2594
+ // arc
2595
+ 'cornerRadius', 'padAngle',
2596
+ // arc, rect
2597
+ 'cornerRadiusTopLeft', 'cornerRadiusTopRight',
2598
+ // rect, group
2599
+ 'cornerRadiusBottomLeft', 'cornerRadiusBottomRight', 'interpolate', 'tension', 'orient', 'defined',
2600
+ // area, line
2601
+ 'url', 'aspect', 'smooth',
2602
+ // image
2603
+ 'path', 'scaleX', 'scaleY',
2604
+ // path
2605
+ 'x2', 'y2',
2606
+ // rule
2607
+ 'size', 'shape',
2608
+ // symbol
2609
+ 'text', 'angle', 'theta', 'radius', 'dir', 'dx', 'dy',
2610
+ // text
2611
+ 'ellipsis', 'limit', 'lineBreak', 'lineHeight', 'font', 'fontSize', 'fontWeight', 'fontStyle', 'fontVariant',
2612
+ // font
2613
+ 'description', 'aria', 'ariaRole', 'ariaRoleDescription' // aria
2614
+ ];
2615
+ function sceneToJSON(scene, indent) {
2616
+ return JSON.stringify(scene, keys, indent);
2617
+ }
2618
+ function sceneFromJSON(json) {
2619
+ const scene = typeof json === 'string' ? JSON.parse(json) : json;
2620
+ return initialize(scene);
2621
+ }
2622
+ function initialize(scene) {
2623
+ var type = scene.marktype,
2624
+ items = scene.items,
2625
+ parent,
2626
+ i,
2627
+ n;
2628
+ if (items) {
2629
+ for (i = 0, n = items.length; i < n; ++i) {
2630
+ parent = type ? 'mark' : 'group';
2631
+ items[i][parent] = scene;
2632
+ if (items[i].zindex) items[i][parent].zdirty = true;
2633
+ if ('group' === (type || parent)) initialize(items[i]);
2634
+ }
2635
+ }
2636
+ if (type) boundMark(scene);
2637
+ return scene;
2638
+ }
2639
+
2640
+ class Scenegraph {
2641
+ constructor(scene) {
2642
+ if (arguments.length) {
2643
+ this.root = sceneFromJSON(scene);
2644
+ } else {
2645
+ this.root = createMark({
2646
+ marktype: 'group',
2647
+ name: 'root',
2648
+ role: 'frame'
2649
+ });
2650
+ this.root.items = [new GroupItem(this.root)];
2651
+ }
2652
+ }
2653
+ toJSON(indent) {
2654
+ return sceneToJSON(this.root, indent || 0);
2655
+ }
2656
+ mark(markdef, group, index) {
2657
+ group = group || this.root.items[0];
2658
+ const mark = createMark(markdef, group);
2659
+ group.items[index] = mark;
2660
+ if (mark.zindex) mark.group.zdirty = true;
2661
+ return mark;
2662
+ }
2663
+ }
2664
+ function createMark(def, group) {
2665
+ const mark = {
2666
+ bounds: new Bounds(),
2667
+ clip: !!def.clip,
2668
+ group: group,
2669
+ interactive: def.interactive === false ? false : true,
2670
+ items: [],
2671
+ marktype: def.marktype,
2672
+ name: def.name || undefined,
2673
+ role: def.role || undefined,
2674
+ zindex: def.zindex || 0
2675
+ };
2676
+
2677
+ // add accessibility properties if defined
2678
+ if (def.aria != null) {
2679
+ mark.aria = def.aria;
2680
+ }
2681
+ if (def.description) {
2682
+ mark.description = def.description;
2683
+ }
2684
+ return mark;
2685
+ }
2686
+
2687
+ // create a new DOM element
2688
+ function domCreate(doc, tag, ns) {
2689
+ if (!doc && typeof document !== 'undefined' && document.createElement) {
2690
+ doc = document;
2691
+ }
2692
+ return doc ? ns ? doc.createElementNS(ns, tag) : doc.createElement(tag) : null;
2693
+ }
2694
+
2695
+ // find first child element with matching tag
2696
+ function domFind(el, tag) {
2697
+ tag = tag.toLowerCase();
2698
+ var nodes = el.childNodes,
2699
+ i = 0,
2700
+ n = nodes.length;
2701
+ for (; i < n; ++i) if (nodes[i].tagName.toLowerCase() === tag) {
2702
+ return nodes[i];
2703
+ }
2704
+ }
2705
+
2706
+ // retrieve child element at given index
2707
+ // create & insert if doesn't exist or if tags do not match
2708
+ function domChild(el, index, tag, ns) {
2709
+ var a = el.childNodes[index],
2710
+ b;
2711
+ if (!a || a.tagName.toLowerCase() !== tag.toLowerCase()) {
2712
+ b = a || null;
2713
+ a = domCreate(el.ownerDocument, tag, ns);
2714
+ el.insertBefore(a, b);
2715
+ }
2716
+ return a;
2717
+ }
2718
+
2719
+ // remove all child elements at or above the given index
2720
+ function domClear(el, index) {
2721
+ var nodes = el.childNodes,
2722
+ curr = nodes.length;
2723
+ while (curr > index) el.removeChild(nodes[--curr]);
2724
+ return el;
2725
+ }
2726
+
2727
+ // generate css class name for mark
2728
+ function cssClass(mark) {
2729
+ return 'mark-' + mark.marktype + (mark.role ? ' role-' + mark.role : '') + (mark.name ? ' ' + mark.name : '');
2730
+ }
2731
+
2732
+ function point (event, el) {
2733
+ const rect = el.getBoundingClientRect();
2734
+ return [event.clientX - rect.left - (el.clientLeft || 0), event.clientY - rect.top - (el.clientTop || 0)];
2735
+ }
2736
+
2737
+ function resolveItem (item, event, el, origin) {
2738
+ var mark = item && item.mark,
2739
+ mdef,
2740
+ p;
2741
+ if (mark && (mdef = Marks[mark.marktype]).tip) {
2742
+ p = point(event, el);
2743
+ p[0] -= origin[0];
2744
+ p[1] -= origin[1];
2745
+ while (item = item.mark.group) {
2746
+ p[0] -= item.x || 0;
2747
+ p[1] -= item.y || 0;
2748
+ }
2749
+ item = mdef.tip(mark.items, p);
2750
+ }
2751
+ return item;
2752
+ }
2753
+
2754
+ class Handler {
2755
+ /**
2756
+ * Create a new Handler instance.
2757
+ * @param {object} [customLoader] - Optional loader instance for
2758
+ * href URL sanitization. If not specified, a standard loader
2759
+ * instance will be generated.
2760
+ * @param {function} [customTooltip] - Optional tooltip handler
2761
+ * function for custom tooltip display.
2762
+ * @constructor
2763
+ */
2764
+ constructor(customLoader, customTooltip) {
2765
+ this._active = null;
2766
+ this._handlers = {};
2767
+ this._loader = customLoader || vegaLoader_browser.loader();
2768
+ this._tooltip = customTooltip || defaultTooltip;
2769
+ }
2770
+
2771
+ /**
2772
+ * Initialize a new Handler instance.
2773
+ * @param {DOMElement} el - The containing DOM element for the display.
2774
+ * @param {Array<number>} origin - The origin of the display, in pixels.
2775
+ * The coordinate system will be translated to this point.
2776
+ * @param {object} [obj] - Optional context object that should serve as
2777
+ * the "this" context for event callbacks.
2778
+ * @return {Handler} - This handler instance.
2779
+ */
2780
+ initialize(el, origin, obj) {
2781
+ this._el = el;
2782
+ this._obj = obj || null;
2783
+ return this.origin(origin);
2784
+ }
2785
+
2786
+ /**
2787
+ * Returns the parent container element for a visualization.
2788
+ * @return {DOMElement} - The containing DOM element.
2789
+ */
2790
+ element() {
2791
+ return this._el;
2792
+ }
2793
+
2794
+ /**
2795
+ * Returns the scene element (e.g., canvas or SVG) of the visualization
2796
+ * Subclasses must override if the first child is not the scene element.
2797
+ * @return {DOMElement} - The scene (e.g., canvas or SVG) element.
2798
+ */
2799
+ canvas() {
2800
+ return this._el && this._el.firstChild;
2801
+ }
2802
+
2803
+ /**
2804
+ * Get / set the origin coordinates of the visualization.
2805
+ */
2806
+ origin(origin) {
2807
+ if (arguments.length) {
2808
+ this._origin = origin || [0, 0];
2809
+ return this;
2810
+ } else {
2811
+ return this._origin.slice();
2812
+ }
2813
+ }
2814
+
2815
+ /**
2816
+ * Get / set the scenegraph root.
2817
+ */
2818
+ scene(scene) {
2819
+ if (!arguments.length) return this._scene;
2820
+ this._scene = scene;
2821
+ return this;
2822
+ }
2823
+
2824
+ /**
2825
+ * Add an event handler. Subclasses should override this method.
2826
+ */
2827
+ on(/*type, handler*/) {}
2828
+
2829
+ /**
2830
+ * Remove an event handler. Subclasses should override this method.
2831
+ */
2832
+ off(/*type, handler*/) {}
2833
+
2834
+ /**
2835
+ * Utility method for finding the array index of an event handler.
2836
+ * @param {Array} h - An array of registered event handlers.
2837
+ * @param {string} type - The event type.
2838
+ * @param {function} handler - The event handler instance to find.
2839
+ * @return {number} - The handler's array index or -1 if not registered.
2840
+ */
2841
+ _handlerIndex(h, type, handler) {
2842
+ for (let i = h ? h.length : 0; --i >= 0;) {
2843
+ if (h[i].type === type && (!handler || h[i].handler === handler)) {
2844
+ return i;
2845
+ }
2846
+ }
2847
+ return -1;
2848
+ }
2849
+
2850
+ /**
2851
+ * Returns an array with registered event handlers.
2852
+ * @param {string} [type] - The event type to query. Any annotations
2853
+ * are ignored; for example, for the argument "click.foo", ".foo" will
2854
+ * be ignored and the method returns all "click" handlers. If type is
2855
+ * null or unspecified, this method returns handlers for all types.
2856
+ * @return {Array} - A new array containing all registered event handlers.
2857
+ */
2858
+ handlers(type) {
2859
+ const h = this._handlers,
2860
+ a = [];
2861
+ if (type) {
2862
+ a.push(...h[this.eventName(type)]);
2863
+ } else {
2864
+ for (const k in h) {
2865
+ a.push(...h[k]);
2866
+ }
2867
+ }
2868
+ return a;
2869
+ }
2870
+
2871
+ /**
2872
+ * Parses an event name string to return the specific event type.
2873
+ * For example, given "click.foo" returns "click"
2874
+ * @param {string} name - The input event type string.
2875
+ * @return {string} - A string with the event type only.
2876
+ */
2877
+ eventName(name) {
2878
+ const i = name.indexOf('.');
2879
+ return i < 0 ? name : name.slice(0, i);
2880
+ }
2881
+
2882
+ /**
2883
+ * Handle hyperlink navigation in response to an item.href value.
2884
+ * @param {Event} event - The event triggering hyperlink navigation.
2885
+ * @param {Item} item - The scenegraph item.
2886
+ * @param {string} href - The URL to navigate to.
2887
+ */
2888
+ handleHref(event, item, href) {
2889
+ this._loader.sanitize(href, {
2890
+ context: 'href'
2891
+ }).then(opt => {
2892
+ const e = new MouseEvent(event.type, event),
2893
+ a = domCreate(null, 'a');
2894
+ for (const name in opt) a.setAttribute(name, opt[name]);
2895
+ a.dispatchEvent(e);
2896
+ }).catch(() => {});
2897
+ }
2898
+
2899
+ /**
2900
+ * Handle tooltip display in response to an item.tooltip value.
2901
+ * @param {Event} event - The event triggering tooltip display.
2902
+ * @param {Item} item - The scenegraph item.
2903
+ * @param {boolean} show - A boolean flag indicating whether
2904
+ * to show or hide a tooltip for the given item.
2905
+ */
2906
+ handleTooltip(event, item, show) {
2907
+ if (item && item.tooltip != null) {
2908
+ item = resolveItem(item, event, this.canvas(), this._origin);
2909
+ const value = show && item && item.tooltip || null;
2910
+ this._tooltip.call(this._obj, this, event, item, value);
2911
+ }
2912
+ }
2913
+
2914
+ /**
2915
+ * Returns the size of a scenegraph item and its position relative
2916
+ * to the viewport.
2917
+ * @param {Item} item - The scenegraph item.
2918
+ * @return {object} - A bounding box object (compatible with the
2919
+ * DOMRect type) consisting of x, y, width, heigh, top, left,
2920
+ * right, and bottom properties.
2921
+ */
2922
+ getItemBoundingClientRect(item) {
2923
+ const el = this.canvas();
2924
+ if (!el) return;
2925
+ const rect = el.getBoundingClientRect(),
2926
+ origin = this._origin,
2927
+ bounds = item.bounds,
2928
+ width = bounds.width(),
2929
+ height = bounds.height();
2930
+ let x = bounds.x1 + origin[0] + rect.left,
2931
+ y = bounds.y1 + origin[1] + rect.top;
2932
+
2933
+ // translate coordinate for each parent group
2934
+ while (item.mark && (item = item.mark.group)) {
2935
+ x += item.x || 0;
2936
+ y += item.y || 0;
2937
+ }
2938
+
2939
+ // return DOMRect-compatible bounding box
2940
+ return {
2941
+ x,
2942
+ y,
2943
+ width,
2944
+ height,
2945
+ left: x,
2946
+ top: y,
2947
+ right: x + width,
2948
+ bottom: y + height
2949
+ };
2950
+ }
2951
+ }
2952
+
2953
+ // The default tooltip display handler.
2954
+ // Sets the HTML title attribute on the visualization container.
2955
+ function defaultTooltip(handler, event, item, value) {
2956
+ handler.element().setAttribute('title', value || '');
2957
+ }
2958
+
2959
+ class Renderer {
2960
+ /**
2961
+ * Create a new Renderer instance.
2962
+ * @param {object} [loader] - Optional loader instance for
2963
+ * image and href URL sanitization. If not specified, a
2964
+ * standard loader instance will be generated.
2965
+ * @constructor
2966
+ */
2967
+ constructor(loader) {
2968
+ this._el = null;
2969
+ this._bgcolor = null;
2970
+ this._loader = new ResourceLoader(loader);
2971
+ }
2972
+
2973
+ /**
2974
+ * Initialize a new Renderer instance.
2975
+ * @param {DOMElement} el - The containing DOM element for the display.
2976
+ * @param {number} width - The coordinate width of the display, in pixels.
2977
+ * @param {number} height - The coordinate height of the display, in pixels.
2978
+ * @param {Array<number>} origin - The origin of the display, in pixels.
2979
+ * The coordinate system will be translated to this point.
2980
+ * @param {number} [scaleFactor=1] - Optional scaleFactor by which to multiply
2981
+ * the width and height to determine the final pixel size.
2982
+ * @return {Renderer} - This renderer instance.
2983
+ */
2984
+ initialize(el, width, height, origin, scaleFactor) {
2985
+ this._el = el;
2986
+ return this.resize(width, height, origin, scaleFactor);
2987
+ }
2988
+
2989
+ /**
2990
+ * Returns the parent container element for a visualization.
2991
+ * @return {DOMElement} - The containing DOM element.
2992
+ */
2993
+ element() {
2994
+ return this._el;
2995
+ }
2996
+
2997
+ /**
2998
+ * Returns the scene element (e.g., canvas or SVG) of the visualization
2999
+ * Subclasses must override if the first child is not the scene element.
3000
+ * @return {DOMElement} - The scene (e.g., canvas or SVG) element.
3001
+ */
3002
+ canvas() {
3003
+ return this._el && this._el.firstChild;
3004
+ }
3005
+
3006
+ /**
3007
+ * Get / set the background color.
3008
+ */
3009
+ background(bgcolor) {
3010
+ if (arguments.length === 0) return this._bgcolor;
3011
+ this._bgcolor = bgcolor;
3012
+ return this;
3013
+ }
3014
+
3015
+ /**
3016
+ * Resize the display.
3017
+ * @param {number} width - The new coordinate width of the display, in pixels.
3018
+ * @param {number} height - The new coordinate height of the display, in pixels.
3019
+ * @param {Array<number>} origin - The new origin of the display, in pixels.
3020
+ * The coordinate system will be translated to this point.
3021
+ * @param {number} [scaleFactor=1] - Optional scaleFactor by which to multiply
3022
+ * the width and height to determine the final pixel size.
3023
+ * @return {Renderer} - This renderer instance;
3024
+ */
3025
+ resize(width, height, origin, scaleFactor) {
3026
+ this._width = width;
3027
+ this._height = height;
3028
+ this._origin = origin || [0, 0];
3029
+ this._scale = scaleFactor || 1;
3030
+ return this;
3031
+ }
3032
+
3033
+ /**
3034
+ * Report a dirty item whose bounds should be redrawn.
3035
+ * This base class method does nothing. Subclasses that perform
3036
+ * incremental should implement this method.
3037
+ * @param {Item} item - The dirty item whose bounds should be redrawn.
3038
+ */
3039
+ dirty(/*item*/) {}
3040
+
3041
+ /**
3042
+ * Render an input scenegraph, potentially with a set of dirty items.
3043
+ * This method will perform an immediate rendering with available resources.
3044
+ * The renderer may also need to perform image loading to perform a complete
3045
+ * render. This process can lead to asynchronous re-rendering of the scene
3046
+ * after this method returns. To receive notification when rendering is
3047
+ * complete, use the renderAsync method instead.
3048
+ * @param {object} scene - The root mark of a scenegraph to render.
3049
+ * @param {Array} markTypes - Array of the mark types to render.
3050
+ * If undefined, render all mark types
3051
+ * @return {Renderer} - This renderer instance.
3052
+ */
3053
+ render(scene, markTypes) {
3054
+ const r = this;
3055
+
3056
+ // bind arguments into a render call, and cache it
3057
+ // this function may be subsequently called for async redraw
3058
+ r._call = function () {
3059
+ r._render(scene, markTypes);
3060
+ };
3061
+
3062
+ // invoke the renderer
3063
+ r._call();
3064
+
3065
+ // clear the cached call for garbage collection
3066
+ // async redraws will stash their own copy
3067
+ r._call = null;
3068
+ return r;
3069
+ }
3070
+
3071
+ /**
3072
+ * Internal rendering method. Renderer subclasses should override this
3073
+ * method to actually perform rendering.
3074
+ * @param {object} scene - The root mark of a scenegraph to render.
3075
+ * @param {Array} markTypes - Array of the mark types to render.
3076
+ * If undefined, render all mark types
3077
+ */
3078
+ _render(/*scene, markTypes*/
3079
+ ) {
3080
+ // subclasses to override
3081
+ }
3082
+
3083
+ /**
3084
+ * Asynchronous rendering method. Similar to render, but returns a Promise
3085
+ * that resolves when all rendering is completed. Sometimes a renderer must
3086
+ * perform image loading to get a complete rendering. The returned
3087
+ * Promise will not resolve until this process completes.
3088
+ * @param {object} scene - The root mark of a scenegraph to render.
3089
+ * @param {Array} markTypes - Array of the mark types to render.
3090
+ * If undefined, render all mark types
3091
+ * @return {Promise} - A Promise that resolves when rendering is complete.
3092
+ */
3093
+ renderAsync(scene, markTypes) {
3094
+ const r = this.render(scene, markTypes);
3095
+ return this._ready ? this._ready.then(() => r) : Promise.resolve(r);
3096
+ }
3097
+
3098
+ /**
3099
+ * Internal method for asynchronous resource loading.
3100
+ * Proxies method calls to the ImageLoader, and tracks loading
3101
+ * progress to invoke a re-render once complete.
3102
+ * @param {string} method - The method name to invoke on the ImageLoader.
3103
+ * @param {string} uri - The URI for the requested resource.
3104
+ * @return {Promise} - A Promise that resolves to the requested resource.
3105
+ */
3106
+ _load(method, uri) {
3107
+ var r = this,
3108
+ p = r._loader[method](uri);
3109
+ if (!r._ready) {
3110
+ // re-render the scene when loading completes
3111
+ const call = r._call;
3112
+ r._ready = r._loader.ready().then(redraw => {
3113
+ if (redraw) call();
3114
+ r._ready = null;
3115
+ });
3116
+ }
3117
+ return p;
3118
+ }
3119
+
3120
+ /**
3121
+ * Sanitize a URL to include as a hyperlink in the rendered scene.
3122
+ * This method proxies a call to ImageLoader.sanitizeURL, but also tracks
3123
+ * image loading progress and invokes a re-render once complete.
3124
+ * @param {string} uri - The URI string to sanitize.
3125
+ * @return {Promise} - A Promise that resolves to the sanitized URL.
3126
+ */
3127
+ sanitizeURL(uri) {
3128
+ return this._load('sanitizeURL', uri);
3129
+ }
3130
+
3131
+ /**
3132
+ * Requests an image to include in the rendered scene.
3133
+ * This method proxies a call to ImageLoader.loadImage, but also tracks
3134
+ * image loading progress and invokes a re-render once complete.
3135
+ * @param {string} uri - The URI string of the image.
3136
+ * @return {Promise} - A Promise that resolves to the loaded Image.
3137
+ */
3138
+ loadImage(uri) {
3139
+ return this._load('loadImage', uri);
3140
+ }
3141
+ }
3142
+
3143
+ const KeyDownEvent = 'keydown';
3144
+ const KeyPressEvent = 'keypress';
3145
+ const KeyUpEvent = 'keyup';
3146
+ const DragEnterEvent = 'dragenter';
3147
+ const DragLeaveEvent = 'dragleave';
3148
+ const DragOverEvent = 'dragover';
3149
+ const PointerDownEvent = 'pointerdown';
3150
+ const PointerUpEvent = 'pointerup';
3151
+ const PointerMoveEvent = 'pointermove';
3152
+ const PointerOutEvent = 'pointerout';
3153
+ const PointerOverEvent = 'pointerover';
3154
+ const MouseDownEvent = 'mousedown';
3155
+ const MouseUpEvent = 'mouseup';
3156
+ const MouseMoveEvent = 'mousemove';
3157
+ const MouseOutEvent = 'mouseout';
3158
+ const MouseOverEvent = 'mouseover';
3159
+ const ClickEvent = 'click';
3160
+ const DoubleClickEvent = 'dblclick';
3161
+ const WheelEvent = 'wheel';
3162
+ const MouseWheelEvent = 'mousewheel';
3163
+ const TouchStartEvent = 'touchstart';
3164
+ const TouchMoveEvent = 'touchmove';
3165
+ const TouchEndEvent = 'touchend';
3166
+ const Events = [KeyDownEvent, KeyPressEvent, KeyUpEvent, DragEnterEvent, DragLeaveEvent, DragOverEvent, PointerDownEvent, PointerUpEvent, PointerMoveEvent, PointerOutEvent, PointerOverEvent, MouseDownEvent, MouseUpEvent, MouseMoveEvent, MouseOutEvent, MouseOverEvent, ClickEvent, DoubleClickEvent, WheelEvent, MouseWheelEvent, TouchStartEvent, TouchMoveEvent, TouchEndEvent];
3167
+ const TooltipShowEvent = PointerMoveEvent;
3168
+ const TooltipHideEvent = MouseOutEvent;
3169
+ const HrefEvent = ClickEvent;
3170
+
3171
+ class CanvasHandler extends Handler {
3172
+ constructor(loader, tooltip) {
3173
+ super(loader, tooltip);
3174
+ this._down = null;
3175
+ this._touch = null;
3176
+ this._first = true;
3177
+ this._events = {};
3178
+
3179
+ // supported events
3180
+ this.events = Events;
3181
+ this.pointermove = move([PointerMoveEvent, MouseMoveEvent], [PointerOverEvent, MouseOverEvent], [PointerOutEvent, MouseOutEvent]);
3182
+ this.dragover = move([DragOverEvent], [DragEnterEvent], [DragLeaveEvent]), this.pointerout = inactive([PointerOutEvent, MouseOutEvent]);
3183
+ this.dragleave = inactive([DragLeaveEvent]);
3184
+ }
3185
+ initialize(el, origin, obj) {
3186
+ this._canvas = el && domFind(el, 'canvas');
3187
+
3188
+ // add minimal events required for proper state management
3189
+ [ClickEvent, MouseDownEvent, PointerDownEvent, PointerMoveEvent, PointerOutEvent, DragLeaveEvent].forEach(type => eventListenerCheck(this, type));
3190
+ return super.initialize(el, origin, obj);
3191
+ }
3192
+
3193
+ // return the backing canvas instance
3194
+ canvas() {
3195
+ return this._canvas;
3196
+ }
3197
+
3198
+ // retrieve the current canvas context
3199
+ context() {
3200
+ return this._canvas.getContext('2d');
3201
+ }
3202
+
3203
+ // to keep old versions of firefox happy
3204
+ DOMMouseScroll(evt) {
3205
+ this.fire(MouseWheelEvent, evt);
3206
+ }
3207
+ pointerdown(evt) {
3208
+ this._down = this._active;
3209
+ this.fire(PointerDownEvent, evt);
3210
+ }
3211
+ mousedown(evt) {
3212
+ this._down = this._active;
3213
+ this.fire(MouseDownEvent, evt);
3214
+ }
3215
+ click(evt) {
3216
+ if (this._down === this._active) {
3217
+ this.fire(ClickEvent, evt);
3218
+ this._down = null;
3219
+ }
3220
+ }
3221
+ touchstart(evt) {
3222
+ this._touch = this.pickEvent(evt.changedTouches[0]);
3223
+ if (this._first) {
3224
+ this._active = this._touch;
3225
+ this._first = false;
3226
+ }
3227
+ this.fire(TouchStartEvent, evt, true);
3228
+ }
3229
+ touchmove(evt) {
3230
+ this.fire(TouchMoveEvent, evt, true);
3231
+ }
3232
+ touchend(evt) {
3233
+ this.fire(TouchEndEvent, evt, true);
3234
+ this._touch = null;
3235
+ }
3236
+
3237
+ // fire an event
3238
+ fire(type, evt, touch) {
3239
+ const a = touch ? this._touch : this._active,
3240
+ h = this._handlers[type];
3241
+
3242
+ // set event type relative to scenegraph items
3243
+ evt.vegaType = type;
3244
+
3245
+ // handle hyperlinks and tooltips first
3246
+ if (type === HrefEvent && a && a.href) {
3247
+ this.handleHref(evt, a, a.href);
3248
+ } else if (type === TooltipShowEvent || type === TooltipHideEvent) {
3249
+ this.handleTooltip(evt, a, type !== TooltipHideEvent);
3250
+ }
3251
+
3252
+ // invoke all registered handlers
3253
+ if (h) {
3254
+ for (let i = 0, len = h.length; i < len; ++i) {
3255
+ h[i].handler.call(this._obj, evt, a);
3256
+ }
3257
+ }
3258
+ }
3259
+
3260
+ // add an event handler
3261
+ on(type, handler) {
3262
+ const name = this.eventName(type),
3263
+ h = this._handlers,
3264
+ i = this._handlerIndex(h[name], type, handler);
3265
+ if (i < 0) {
3266
+ eventListenerCheck(this, type);
3267
+ (h[name] || (h[name] = [])).push({
3268
+ type: type,
3269
+ handler: handler
3270
+ });
3271
+ }
3272
+ return this;
3273
+ }
3274
+
3275
+ // remove an event handler
3276
+ off(type, handler) {
3277
+ const name = this.eventName(type),
3278
+ h = this._handlers[name],
3279
+ i = this._handlerIndex(h, type, handler);
3280
+ if (i >= 0) {
3281
+ h.splice(i, 1);
3282
+ }
3283
+ return this;
3284
+ }
3285
+ pickEvent(evt) {
3286
+ const p = point(evt, this._canvas),
3287
+ o = this._origin;
3288
+ return this.pick(this._scene, p[0], p[1], p[0] - o[0], p[1] - o[1]);
3289
+ }
3290
+
3291
+ // find the scenegraph item at the current pointer position
3292
+ // x, y -- the absolute x, y pointer coordinates on the canvas element
3293
+ // gx, gy -- the relative coordinates within the current group
3294
+ pick(scene, x, y, gx, gy) {
3295
+ const g = this.context(),
3296
+ mark = Marks[scene.marktype];
3297
+ return mark.pick.call(this, g, scene, x, y, gx, gy);
3298
+ }
3299
+ }
3300
+ const eventBundle = type => type === TouchStartEvent || type === TouchMoveEvent || type === TouchEndEvent ? [TouchStartEvent, TouchMoveEvent, TouchEndEvent] : [type];
3301
+
3302
+ // lazily add listeners to the canvas as needed
3303
+ function eventListenerCheck(handler, type) {
3304
+ eventBundle(type).forEach(_ => addEventListener(handler, _));
3305
+ }
3306
+ function addEventListener(handler, type) {
3307
+ const canvas = handler.canvas();
3308
+ if (canvas && !handler._events[type]) {
3309
+ handler._events[type] = 1;
3310
+ canvas.addEventListener(type, handler[type] ? evt => handler[type](evt) : evt => handler.fire(type, evt));
3311
+ }
3312
+ }
3313
+ function fireAll(handler, types, event) {
3314
+ types.forEach(type => handler.fire(type, event));
3315
+ }
3316
+ function move(moveEvents, overEvents, outEvents) {
3317
+ return function (evt) {
3318
+ const a = this._active,
3319
+ p = this.pickEvent(evt);
3320
+ if (p === a) {
3321
+ // active item and picked item are the same
3322
+ fireAll(this, moveEvents, evt); // fire move
3323
+ } else {
3324
+ // active item and picked item are different
3325
+ if (!a || !a.exit) {
3326
+ // fire out for prior active item
3327
+ // suppress if active item was removed from scene
3328
+ fireAll(this, outEvents, evt);
3329
+ }
3330
+ this._active = p; // set new active item
3331
+ fireAll(this, overEvents, evt); // fire over for new active item
3332
+ fireAll(this, moveEvents, evt); // fire move for new active item
3333
+ }
3334
+ };
3335
+ }
3336
+ function inactive(types) {
3337
+ return function (evt) {
3338
+ fireAll(this, types, evt);
3339
+ this._active = null;
3340
+ };
3341
+ }
3342
+
3343
+ function devicePixelRatio() {
3344
+ return typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;
3345
+ }
3346
+ function resize (canvas, width, height, origin, scaleFactor, opt) {
3347
+ const inDOM = typeof HTMLElement !== 'undefined' && canvas instanceof HTMLElement && canvas.parentNode != null,
3348
+ context = canvas.getContext('2d'),
3349
+ ratio = inDOM ? devicePixelRatio() : scaleFactor;
3350
+ canvas.width = width * ratio;
3351
+ canvas.height = height * ratio;
3352
+ for (const key in opt) {
3353
+ context[key] = opt[key];
3354
+ }
3355
+ if (inDOM && ratio !== 1) {
3356
+ canvas.style.width = width + 'px';
3357
+ canvas.style.height = height + 'px';
3358
+ }
3359
+ context.pixelRatio = ratio;
3360
+ context.setTransform(ratio, 0, 0, ratio, ratio * origin[0], ratio * origin[1]);
3361
+ return canvas;
3362
+ }
3363
+
3364
+ class CanvasRenderer extends Renderer {
3365
+ constructor(loader) {
3366
+ super(loader);
3367
+ this._options = {};
3368
+ this._redraw = false;
3369
+ this._dirty = new Bounds();
3370
+ this._tempb = new Bounds();
3371
+ }
3372
+ initialize(el, width, height, origin, scaleFactor, options) {
3373
+ this._options = options || {};
3374
+ this._canvas = this._options.externalContext ? null : vegaCanvas_browser.canvas(1, 1, this._options.type); // instantiate a small canvas
3375
+
3376
+ if (el && this._canvas) {
3377
+ domClear(el, 0).appendChild(this._canvas);
3378
+ this._canvas.setAttribute('class', 'marks');
3379
+ }
3380
+
3381
+ // this method will invoke resize to size the canvas appropriately
3382
+ return super.initialize(el, width, height, origin, scaleFactor);
3383
+ }
3384
+ resize(width, height, origin, scaleFactor) {
3385
+ super.resize(width, height, origin, scaleFactor);
3386
+ if (this._canvas) {
3387
+ // configure canvas size and transform
3388
+ resize(this._canvas, this._width, this._height, this._origin, this._scale, this._options.context);
3389
+ } else {
3390
+ // external context needs to be scaled and positioned to origin
3391
+ const ctx = this._options.externalContext;
3392
+ if (!ctx) vegaUtil.error('CanvasRenderer is missing a valid canvas or context');
3393
+ ctx.scale(this._scale, this._scale);
3394
+ ctx.translate(this._origin[0], this._origin[1]);
3395
+ }
3396
+ this._redraw = true;
3397
+ return this;
3398
+ }
3399
+ canvas() {
3400
+ return this._canvas;
3401
+ }
3402
+ context() {
3403
+ return this._options.externalContext || (this._canvas ? this._canvas.getContext('2d') : null);
3404
+ }
3405
+ dirty(item) {
3406
+ const b = this._tempb.clear().union(item.bounds);
3407
+ let g = item.mark.group;
3408
+ while (g) {
3409
+ b.translate(g.x || 0, g.y || 0);
3410
+ g = g.mark.group;
3411
+ }
3412
+ this._dirty.union(b);
3413
+ }
3414
+ _render(scene, markTypes) {
3415
+ const g = this.context(),
3416
+ o = this._origin,
3417
+ w = this._width,
3418
+ h = this._height,
3419
+ db = this._dirty,
3420
+ vb = viewBounds(o, w, h);
3421
+
3422
+ // setup
3423
+ g.save();
3424
+ const b = this._redraw || db.empty() ? (this._redraw = false, vb.expand(1)) : clipToBounds(g, vb.intersect(db), o);
3425
+ this.clear(-o[0], -o[1], w, h);
3426
+
3427
+ // render
3428
+ this.draw(g, scene, b, markTypes);
3429
+
3430
+ // takedown
3431
+ g.restore();
3432
+ db.clear();
3433
+ return this;
3434
+ }
3435
+ draw(ctx, scene, bounds, markTypes) {
3436
+ if (scene.marktype !== 'group' && markTypes != null && !markTypes.includes(scene.marktype)) {
3437
+ return;
3438
+ }
3439
+ const mark = Marks[scene.marktype];
3440
+ if (scene.clip) clip(ctx, scene);
3441
+ mark.draw.call(this, ctx, scene, bounds, markTypes);
3442
+ if (scene.clip) ctx.restore();
3443
+ }
3444
+ clear(x, y, w, h) {
3445
+ const opt = this._options,
3446
+ g = this.context();
3447
+ if (opt.type !== 'pdf' && !opt.externalContext) {
3448
+ // calling clear rect voids vector output in pdf mode
3449
+ // and could remove external context content (#2615)
3450
+ g.clearRect(x, y, w, h);
3451
+ }
3452
+ if (this._bgcolor != null) {
3453
+ g.fillStyle = this._bgcolor;
3454
+ g.fillRect(x, y, w, h);
3455
+ }
3456
+ }
3457
+ }
3458
+ const viewBounds = (origin, width, height) => new Bounds().set(0, 0, width, height).translate(-origin[0], -origin[1]);
3459
+ function clipToBounds(g, b, origin) {
3460
+ // expand bounds by 1 pixel, then round to pixel boundaries
3461
+ b.expand(1).round();
3462
+
3463
+ // align to base pixel grid in case of non-integer scaling (#2425)
3464
+ if (g.pixelRatio % 1) {
3465
+ b.scale(g.pixelRatio).round().scale(1 / g.pixelRatio);
3466
+ }
3467
+
3468
+ // to avoid artifacts translate if origin has fractional pixels
3469
+ b.translate(-(origin[0] % 1), -(origin[1] % 1));
3470
+
3471
+ // set clip path
3472
+ g.beginPath();
3473
+ g.rect(b.x1, b.y1, b.width(), b.height());
3474
+ g.clip();
3475
+ return b;
3476
+ }
3477
+
3478
+ class SVGHandler extends Handler {
3479
+ constructor(loader, tooltip) {
3480
+ super(loader, tooltip);
3481
+ const h = this;
3482
+ h._hrefHandler = listener(h, (evt, item) => {
3483
+ if (item && item.href) h.handleHref(evt, item, item.href);
3484
+ });
3485
+ h._tooltipHandler = listener(h, (evt, item) => {
3486
+ h.handleTooltip(evt, item, evt.type !== TooltipHideEvent);
3487
+ });
3488
+ }
3489
+ initialize(el, origin, obj) {
3490
+ let svg = this._svg;
3491
+ if (svg) {
3492
+ svg.removeEventListener(HrefEvent, this._hrefHandler);
3493
+ svg.removeEventListener(TooltipShowEvent, this._tooltipHandler);
3494
+ svg.removeEventListener(TooltipHideEvent, this._tooltipHandler);
3495
+ }
3496
+ this._svg = svg = el && domFind(el, 'svg');
3497
+ if (svg) {
3498
+ svg.addEventListener(HrefEvent, this._hrefHandler);
3499
+ svg.addEventListener(TooltipShowEvent, this._tooltipHandler);
3500
+ svg.addEventListener(TooltipHideEvent, this._tooltipHandler);
3501
+ }
3502
+ return super.initialize(el, origin, obj);
3503
+ }
3504
+ canvas() {
3505
+ return this._svg;
3506
+ }
3507
+
3508
+ // add an event handler
3509
+ on(type, handler) {
3510
+ const name = this.eventName(type),
3511
+ h = this._handlers,
3512
+ i = this._handlerIndex(h[name], type, handler);
3513
+ if (i < 0) {
3514
+ const x = {
3515
+ type,
3516
+ handler,
3517
+ listener: listener(this, handler)
3518
+ };
3519
+ (h[name] || (h[name] = [])).push(x);
3520
+ if (this._svg) {
3521
+ this._svg.addEventListener(name, x.listener);
3522
+ }
3523
+ }
3524
+ return this;
3525
+ }
3526
+
3527
+ // remove an event handler
3528
+ off(type, handler) {
3529
+ const name = this.eventName(type),
3530
+ h = this._handlers[name],
3531
+ i = this._handlerIndex(h, type, handler);
3532
+ if (i >= 0) {
3533
+ if (this._svg) {
3534
+ this._svg.removeEventListener(name, h[i].listener);
3535
+ }
3536
+ h.splice(i, 1);
3537
+ }
3538
+ return this;
3539
+ }
3540
+ }
3541
+
3542
+ // wrap an event listener for the SVG DOM
3543
+ const listener = (context, handler) => evt => {
3544
+ let item = evt.target.__data__;
3545
+ item = Array.isArray(item) ? item[0] : item;
3546
+ evt.vegaType = evt.type;
3547
+ handler.call(context._obj, evt, item);
3548
+ };
3549
+
3550
+ const ARIA_HIDDEN = 'aria-hidden';
3551
+ const ARIA_LABEL = 'aria-label';
3552
+ const ARIA_ROLE = 'role';
3553
+ const ARIA_ROLEDESCRIPTION = 'aria-roledescription';
3554
+ const GRAPHICS_OBJECT = 'graphics-object';
3555
+ const GRAPHICS_SYMBOL = 'graphics-symbol';
3556
+ const bundle = (role, roledesc, label) => ({
3557
+ [ARIA_ROLE]: role,
3558
+ [ARIA_ROLEDESCRIPTION]: roledesc,
3559
+ [ARIA_LABEL]: label || undefined
3560
+ });
3561
+
3562
+ // these roles are covered by related roles
3563
+ // we can ignore them, no need to generate attributes
3564
+ const AriaIgnore = vegaUtil.toSet(['axis-domain', 'axis-grid', 'axis-label', 'axis-tick', 'axis-title', 'legend-band', 'legend-entry', 'legend-gradient', 'legend-label', 'legend-title', 'legend-symbol', 'title']);
3565
+
3566
+ // aria attribute generators for guide roles
3567
+ const AriaGuides = {
3568
+ 'axis': {
3569
+ desc: 'axis',
3570
+ caption: axisCaption
3571
+ },
3572
+ 'legend': {
3573
+ desc: 'legend',
3574
+ caption: legendCaption
3575
+ },
3576
+ 'title-text': {
3577
+ desc: 'title',
3578
+ caption: item => `Title text '${titleCaption(item)}'`
3579
+ },
3580
+ 'title-subtitle': {
3581
+ desc: 'subtitle',
3582
+ caption: item => `Subtitle text '${titleCaption(item)}'`
3583
+ }
3584
+ };
3585
+
3586
+ // aria properties generated for mark item encoding channels
3587
+ const AriaEncode = {
3588
+ ariaRole: ARIA_ROLE,
3589
+ ariaRoleDescription: ARIA_ROLEDESCRIPTION,
3590
+ description: ARIA_LABEL
3591
+ };
3592
+ function ariaItemAttributes(emit, item) {
3593
+ const hide = item.aria === false;
3594
+ emit(ARIA_HIDDEN, hide || undefined);
3595
+ if (hide || item.description == null) {
3596
+ for (const prop in AriaEncode) {
3597
+ emit(AriaEncode[prop], undefined);
3598
+ }
3599
+ } else {
3600
+ const type = item.mark.marktype;
3601
+ emit(ARIA_LABEL, item.description);
3602
+ emit(ARIA_ROLE, item.ariaRole || (type === 'group' ? GRAPHICS_OBJECT : GRAPHICS_SYMBOL));
3603
+ emit(ARIA_ROLEDESCRIPTION, item.ariaRoleDescription || `${type} mark`);
3604
+ }
3605
+ }
3606
+ function ariaMarkAttributes(mark) {
3607
+ return mark.aria === false ? {
3608
+ [ARIA_HIDDEN]: true
3609
+ } : AriaIgnore[mark.role] ? null : AriaGuides[mark.role] ? ariaGuide(mark, AriaGuides[mark.role]) : ariaMark(mark);
3610
+ }
3611
+ function ariaMark(mark) {
3612
+ const type = mark.marktype;
3613
+ const recurse = type === 'group' || type === 'text' || mark.items.some(_ => _.description != null && _.aria !== false);
3614
+ return bundle(recurse ? GRAPHICS_OBJECT : GRAPHICS_SYMBOL, `${type} mark container`, mark.description);
3615
+ }
3616
+ function ariaGuide(mark, opt) {
3617
+ try {
3618
+ const item = mark.items[0],
3619
+ caption = opt.caption || (() => '');
3620
+ return bundle(opt.role || GRAPHICS_SYMBOL, opt.desc, item.description || caption(item));
3621
+ } catch (err) {
3622
+ return null;
3623
+ }
3624
+ }
3625
+ function titleCaption(item) {
3626
+ return vegaUtil.array(item.text).join(' ');
3627
+ }
3628
+ function axisCaption(item) {
3629
+ const datum = item.datum,
3630
+ orient = item.orient,
3631
+ title = datum.title ? extractTitle(item) : null,
3632
+ ctx = item.context,
3633
+ scale = ctx.scales[datum.scale].value,
3634
+ locale = ctx.dataflow.locale(),
3635
+ type = scale.type,
3636
+ xy = orient === 'left' || orient === 'right' ? 'Y' : 'X';
3637
+ return `${xy}-axis` + (title ? ` titled '${title}'` : '') + ` for a ${vegaScale.isDiscrete(type) ? 'discrete' : type} scale` + ` with ${vegaScale.domainCaption(locale, scale, item)}`;
3638
+ }
3639
+ function legendCaption(item) {
3640
+ const datum = item.datum,
3641
+ title = datum.title ? extractTitle(item) : null,
3642
+ type = `${datum.type || ''} legend`.trim(),
3643
+ scales = datum.scales,
3644
+ props = Object.keys(scales),
3645
+ ctx = item.context,
3646
+ scale = ctx.scales[scales[props[0]]].value,
3647
+ locale = ctx.dataflow.locale();
3648
+ return capitalize(type) + (title ? ` titled '${title}'` : '') + ` for ${channelCaption(props)}` + ` with ${vegaScale.domainCaption(locale, scale, item)}`;
3649
+ }
3650
+ function extractTitle(item) {
3651
+ try {
3652
+ return vegaUtil.array(vegaUtil.peek(item.items).items[0].text).join(' ');
3653
+ } catch (err) {
3654
+ return null;
3655
+ }
3656
+ }
3657
+ function channelCaption(props) {
3658
+ props = props.map(p => p + (p === 'fill' || p === 'stroke' ? ' color' : ''));
3659
+ return props.length < 2 ? props[0] : props.slice(0, -1).join(', ') + ' and ' + vegaUtil.peek(props);
3660
+ }
3661
+ function capitalize(s) {
3662
+ return s.length ? s[0].toUpperCase() + s.slice(1) : s;
3663
+ }
3664
+
3665
+ const innerText = val => (val + '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
3666
+ const attrText = val => innerText(val).replace(/"/g, '&quot;').replace(/\t/g, '&#x9;').replace(/\n/g, '&#xA;').replace(/\r/g, '&#xD;');
3667
+ function markup() {
3668
+ let buf = '',
3669
+ outer = '',
3670
+ inner = '';
3671
+ const stack = [],
3672
+ clear = () => outer = inner = '',
3673
+ push = tag => {
3674
+ if (outer) {
3675
+ buf += `${outer}>${inner}`;
3676
+ clear();
3677
+ }
3678
+ stack.push(tag);
3679
+ },
3680
+ attr = (name, value) => {
3681
+ if (value != null) outer += ` ${name}="${attrText(value)}"`;
3682
+ return m;
3683
+ },
3684
+ m = {
3685
+ open(tag, ...attrs) {
3686
+ push(tag);
3687
+ outer = '<' + tag;
3688
+ for (const set of attrs) {
3689
+ for (const key in set) attr(key, set[key]);
3690
+ }
3691
+ return m;
3692
+ },
3693
+ close() {
3694
+ const tag = stack.pop();
3695
+ if (outer) {
3696
+ buf += outer + (inner ? `>${inner}</${tag}>` : '/>');
3697
+ } else {
3698
+ buf += `</${tag}>`;
3699
+ }
3700
+ clear();
3701
+ return m;
3702
+ },
3703
+ attr,
3704
+ text: t => (inner += innerText(t), m),
3705
+ toString: () => buf
3706
+ };
3707
+ return m;
3708
+ }
3709
+ const serializeXML = node => _serialize(markup(), node) + '';
3710
+ function _serialize(m, node) {
3711
+ m.open(node.tagName);
3712
+ if (node.hasAttributes()) {
3713
+ const attrs = node.attributes,
3714
+ n = attrs.length;
3715
+ for (let i = 0; i < n; ++i) {
3716
+ m.attr(attrs[i].name, attrs[i].value);
3717
+ }
3718
+ }
3719
+ if (node.hasChildNodes()) {
3720
+ const children = node.childNodes;
3721
+ for (const child of children) {
3722
+ child.nodeType === 3 // text node
3723
+ ? m.text(child.nodeValue) : _serialize(m, child);
3724
+ }
3725
+ }
3726
+ return m.close();
3727
+ }
3728
+
3729
+ const stylesAttr = {
3730
+ fill: 'fill',
3731
+ fillOpacity: 'fill-opacity',
3732
+ stroke: 'stroke',
3733
+ strokeOpacity: 'stroke-opacity',
3734
+ strokeWidth: 'stroke-width',
3735
+ strokeCap: 'stroke-linecap',
3736
+ strokeJoin: 'stroke-linejoin',
3737
+ strokeDash: 'stroke-dasharray',
3738
+ strokeDashOffset: 'stroke-dashoffset',
3739
+ strokeMiterLimit: 'stroke-miterlimit',
3740
+ opacity: 'opacity'
3741
+ };
3742
+ const stylesCss = {
3743
+ blend: 'mix-blend-mode'
3744
+ };
3745
+
3746
+ // ensure miter limit default is consistent with canvas (#2498)
3747
+ const rootAttributes = {
3748
+ 'fill': 'none',
3749
+ 'stroke-miterlimit': 10
3750
+ };
3751
+
3752
+ const RootIndex = 0,
3753
+ xmlns = 'http://www.w3.org/2000/xmlns/',
3754
+ svgns = metadata.xmlns;
3755
+ class SVGRenderer extends Renderer {
3756
+ constructor(loader) {
3757
+ super(loader);
3758
+ this._dirtyID = 0;
3759
+ this._dirty = [];
3760
+ this._svg = null;
3761
+ this._root = null;
3762
+ this._defs = null;
3763
+ }
3764
+
3765
+ /**
3766
+ * Initialize a new SVGRenderer instance.
3767
+ * @param {DOMElement} el - The containing DOM element for the display.
3768
+ * @param {number} width - The coordinate width of the display, in pixels.
3769
+ * @param {number} height - The coordinate height of the display, in pixels.
3770
+ * @param {Array<number>} origin - The origin of the display, in pixels.
3771
+ * The coordinate system will be translated to this point.
3772
+ * @param {number} [scaleFactor=1] - Optional scaleFactor by which to multiply
3773
+ * the width and height to determine the final pixel size.
3774
+ * @return {SVGRenderer} - This renderer instance.
3775
+ */
3776
+ initialize(el, width, height, origin, scaleFactor) {
3777
+ // create the svg definitions cache
3778
+ this._defs = {};
3779
+ this._clearDefs();
3780
+ if (el) {
3781
+ this._svg = domChild(el, 0, 'svg', svgns);
3782
+ this._svg.setAttributeNS(xmlns, 'xmlns', svgns);
3783
+ this._svg.setAttributeNS(xmlns, 'xmlns:xlink', metadata['xmlns:xlink']);
3784
+ this._svg.setAttribute('version', metadata['version']);
3785
+ this._svg.setAttribute('class', 'marks');
3786
+ domClear(el, 1);
3787
+
3788
+ // set the svg root group
3789
+ this._root = domChild(this._svg, RootIndex, 'g', svgns);
3790
+ setAttributes(this._root, rootAttributes);
3791
+
3792
+ // ensure no additional child elements
3793
+ domClear(this._svg, RootIndex + 1);
3794
+ }
3795
+
3796
+ // set background color if defined
3797
+ this.background(this._bgcolor);
3798
+ return super.initialize(el, width, height, origin, scaleFactor);
3799
+ }
3800
+
3801
+ /**
3802
+ * Get / set the background color.
3803
+ */
3804
+ background(bgcolor) {
3805
+ if (arguments.length && this._svg) {
3806
+ this._svg.style.setProperty('background-color', bgcolor);
3807
+ }
3808
+ return super.background(...arguments);
3809
+ }
3810
+
3811
+ /**
3812
+ * Resize the display.
3813
+ * @param {number} width - The new coordinate width of the display, in pixels.
3814
+ * @param {number} height - The new coordinate height of the display, in pixels.
3815
+ * @param {Array<number>} origin - The new origin of the display, in pixels.
3816
+ * The coordinate system will be translated to this point.
3817
+ * @param {number} [scaleFactor=1] - Optional scaleFactor by which to multiply
3818
+ * the width and height to determine the final pixel size.
3819
+ * @return {SVGRenderer} - This renderer instance;
3820
+ */
3821
+ resize(width, height, origin, scaleFactor) {
3822
+ super.resize(width, height, origin, scaleFactor);
3823
+ if (this._svg) {
3824
+ setAttributes(this._svg, {
3825
+ width: this._width * this._scale,
3826
+ height: this._height * this._scale,
3827
+ viewBox: `0 0 ${this._width} ${this._height}`
3828
+ });
3829
+ this._root.setAttribute('transform', `translate(${this._origin})`);
3830
+ }
3831
+ this._dirty = [];
3832
+ return this;
3833
+ }
3834
+
3835
+ /**
3836
+ * Returns the SVG element of the visualization.
3837
+ * @return {DOMElement} - The SVG element.
3838
+ */
3839
+ canvas() {
3840
+ return this._svg;
3841
+ }
3842
+
3843
+ /**
3844
+ * Returns an SVG text string for the rendered content,
3845
+ * or null if this renderer is currently headless.
3846
+ */
3847
+ svg() {
3848
+ const svg = this._svg,
3849
+ bg = this._bgcolor;
3850
+ if (!svg) return null;
3851
+ let node;
3852
+ if (bg) {
3853
+ svg.removeAttribute('style');
3854
+ node = domChild(svg, RootIndex, 'rect', svgns);
3855
+ setAttributes(node, {
3856
+ width: this._width,
3857
+ height: this._height,
3858
+ fill: bg
3859
+ });
3860
+ }
3861
+ const text = serializeXML(svg);
3862
+ if (bg) {
3863
+ svg.removeChild(node);
3864
+ this._svg.style.setProperty('background-color', bg);
3865
+ }
3866
+ return text;
3867
+ }
3868
+
3869
+ /**
3870
+ * Internal rendering method.
3871
+ * @param {object} scene - The root mark of a scenegraph to render.
3872
+ * @param {Array} markTypes - Array of the mark types to render.
3873
+ * If undefined, render all mark types
3874
+ */
3875
+ _render(scene, markTypes) {
3876
+ // perform spot updates and re-render markup
3877
+ if (this._dirtyCheck()) {
3878
+ if (this._dirtyAll) this._clearDefs();
3879
+ this.mark(this._root, scene, undefined, markTypes);
3880
+ domClear(this._root, 1);
3881
+ }
3882
+ this.defs();
3883
+ this._dirty = [];
3884
+ ++this._dirtyID;
3885
+ return this;
3886
+ }
3887
+
3888
+ // -- Manage rendering of items marked as dirty --
3889
+
3890
+ /**
3891
+ * Flag a mark item as dirty.
3892
+ * @param {Item} item - The mark item.
3893
+ */
3894
+ dirty(item) {
3895
+ if (item.dirty !== this._dirtyID) {
3896
+ item.dirty = this._dirtyID;
3897
+ this._dirty.push(item);
3898
+ }
3899
+ }
3900
+
3901
+ /**
3902
+ * Check if a mark item is considered dirty.
3903
+ * @param {Item} item - The mark item.
3904
+ */
3905
+ isDirty(item) {
3906
+ return this._dirtyAll || !item._svg || !item._svg.ownerSVGElement || item.dirty === this._dirtyID;
3907
+ }
3908
+
3909
+ /**
3910
+ * Internal method to check dirty status and, if possible,
3911
+ * make targetted updates without a full rendering pass.
3912
+ */
3913
+ _dirtyCheck() {
3914
+ this._dirtyAll = true;
3915
+ const items = this._dirty;
3916
+ if (!items.length || !this._dirtyID) return true;
3917
+ const id = ++this._dirtyID;
3918
+ let item, mark, type, mdef, i, n, o;
3919
+ for (i = 0, n = items.length; i < n; ++i) {
3920
+ item = items[i];
3921
+ mark = item.mark;
3922
+ if (mark.marktype !== type) {
3923
+ // memoize mark instance lookup
3924
+ type = mark.marktype;
3925
+ mdef = Marks[type];
3926
+ }
3927
+ if (mark.zdirty && mark.dirty !== id) {
3928
+ this._dirtyAll = false;
3929
+ dirtyParents(item, id);
3930
+ mark.items.forEach(i => {
3931
+ i.dirty = id;
3932
+ });
3933
+ }
3934
+ if (mark.zdirty) continue; // handle in standard drawing pass
3935
+
3936
+ if (item.exit) {
3937
+ // EXIT
3938
+ if (mdef.nested && mark.items.length) {
3939
+ // if nested mark with remaining points, update instead
3940
+ o = mark.items[0];
3941
+ if (o._svg) this._update(mdef, o._svg, o);
3942
+ } else if (item._svg) {
3943
+ // otherwise remove from DOM
3944
+ o = item._svg.parentNode;
3945
+ if (o) o.removeChild(item._svg);
3946
+ }
3947
+ item._svg = null;
3948
+ continue;
3949
+ }
3950
+ item = mdef.nested ? mark.items[0] : item;
3951
+ if (item._update === id) continue; // already visited
3952
+
3953
+ if (!item._svg || !item._svg.ownerSVGElement) {
3954
+ // ENTER
3955
+ this._dirtyAll = false;
3956
+ dirtyParents(item, id);
3957
+ } else {
3958
+ // IN-PLACE UPDATE
3959
+ this._update(mdef, item._svg, item);
3960
+ }
3961
+ item._update = id;
3962
+ }
3963
+ return !this._dirtyAll;
3964
+ }
3965
+
3966
+ // -- Construct & maintain scenegraph to SVG mapping ---
3967
+
3968
+ /**
3969
+ * Render a set of mark items.
3970
+ * @param {SVGElement} el - The parent element in the SVG tree.
3971
+ * @param {object} scene - The mark parent to render.
3972
+ * @param {SVGElement} prev - The previous sibling in the SVG tree.
3973
+ * @param {Array} markTypes - Array of the mark types to render.
3974
+ * If undefined, render all mark types
3975
+ */
3976
+ mark(el, scene, prev, markTypes) {
3977
+ if (!this.isDirty(scene)) {
3978
+ return scene._svg;
3979
+ }
3980
+ const svg = this._svg,
3981
+ markType = scene.marktype,
3982
+ mdef = Marks[markType],
3983
+ events = scene.interactive === false ? 'none' : null,
3984
+ isGroup = mdef.tag === 'g';
3985
+ const parent = bind(scene, el, prev, 'g', svg);
3986
+ if (markType !== 'group' && markTypes != null && !markTypes.includes(markType)) {
3987
+ domClear(parent, 0);
3988
+ return scene._svg;
3989
+ }
3990
+ parent.setAttribute('class', cssClass(scene));
3991
+
3992
+ // apply aria attributes to parent container element
3993
+ const aria = ariaMarkAttributes(scene);
3994
+ for (const key in aria) setAttribute(parent, key, aria[key]);
3995
+ if (!isGroup) {
3996
+ setAttribute(parent, 'pointer-events', events);
3997
+ }
3998
+ setAttribute(parent, 'clip-path', scene.clip ? clip$1(this, scene, scene.group) : null);
3999
+ let sibling = null,
4000
+ i = 0;
4001
+ const process = item => {
4002
+ const dirty = this.isDirty(item),
4003
+ node = bind(item, parent, sibling, mdef.tag, svg);
4004
+ if (dirty) {
4005
+ this._update(mdef, node, item);
4006
+ if (isGroup) recurse(this, node, item, markTypes);
4007
+ }
4008
+ sibling = node;
4009
+ ++i;
4010
+ };
4011
+ if (mdef.nested) {
4012
+ if (scene.items.length) process(scene.items[0]);
4013
+ } else {
4014
+ visit(scene, process);
4015
+ }
4016
+ domClear(parent, i);
4017
+ return parent;
4018
+ }
4019
+
4020
+ /**
4021
+ * Update the attributes of an SVG element for a mark item.
4022
+ * @param {object} mdef - The mark definition object
4023
+ * @param {SVGElement} el - The SVG element.
4024
+ * @param {Item} item - The mark item.
4025
+ */
4026
+ _update(mdef, el, item) {
4027
+ // set dom element and values cache
4028
+ // provides access to emit method
4029
+ element = el;
4030
+ values = el.__values__;
4031
+
4032
+ // apply aria-specific properties
4033
+ ariaItemAttributes(emit, item);
4034
+
4035
+ // apply svg attributes
4036
+ mdef.attr(emit, item, this);
4037
+
4038
+ // some marks need special treatment
4039
+ const extra = mark_extras[mdef.type];
4040
+ if (extra) extra.call(this, mdef, el, item);
4041
+
4042
+ // apply svg style attributes
4043
+ // note: element state may have been modified by 'extra' method
4044
+ if (element) this.style(element, item);
4045
+ }
4046
+
4047
+ /**
4048
+ * Update the presentation attributes of an SVG element for a mark item.
4049
+ * @param {SVGElement} el - The SVG element.
4050
+ * @param {Item} item - The mark item.
4051
+ */
4052
+ style(el, item) {
4053
+ if (item == null) return;
4054
+ for (const prop in stylesAttr) {
4055
+ let value = prop === 'font' ? fontFamily(item) : item[prop];
4056
+ if (value === values[prop]) continue;
4057
+ const name = stylesAttr[prop];
4058
+ if (value == null) {
4059
+ el.removeAttribute(name);
4060
+ } else {
4061
+ if (isGradient(value)) {
4062
+ value = gradientRef(value, this._defs.gradient, href());
4063
+ }
4064
+ el.setAttribute(name, value + '');
4065
+ }
4066
+ values[prop] = value;
4067
+ }
4068
+ for (const prop in stylesCss) {
4069
+ setStyle(el, stylesCss[prop], item[prop]);
4070
+ }
4071
+ }
4072
+
4073
+ /**
4074
+ * Render SVG defs, as needed.
4075
+ * Must be called *after* marks have been processed to ensure the
4076
+ * collected state is current and accurate.
4077
+ */
4078
+ defs() {
4079
+ const svg = this._svg,
4080
+ defs = this._defs;
4081
+ let el = defs.el,
4082
+ index = 0;
4083
+ for (const id in defs.gradient) {
4084
+ if (!el) defs.el = el = domChild(svg, RootIndex + 1, 'defs', svgns);
4085
+ index = updateGradient(el, defs.gradient[id], index);
4086
+ }
4087
+ for (const id in defs.clipping) {
4088
+ if (!el) defs.el = el = domChild(svg, RootIndex + 1, 'defs', svgns);
4089
+ index = updateClipping(el, defs.clipping[id], index);
4090
+ }
4091
+
4092
+ // clean-up
4093
+ if (el) {
4094
+ index === 0 ? (svg.removeChild(el), defs.el = null) : domClear(el, index);
4095
+ }
4096
+ }
4097
+
4098
+ /**
4099
+ * Clear defs caches.
4100
+ */
4101
+ _clearDefs() {
4102
+ const def = this._defs;
4103
+ def.gradient = {};
4104
+ def.clipping = {};
4105
+ }
4106
+ }
4107
+
4108
+ // mark ancestor chain with a dirty id
4109
+ function dirtyParents(item, id) {
4110
+ for (; item && item.dirty !== id; item = item.mark.group) {
4111
+ item.dirty = id;
4112
+ if (item.mark && item.mark.dirty !== id) {
4113
+ item.mark.dirty = id;
4114
+ } else return;
4115
+ }
4116
+ }
4117
+
4118
+ // update gradient definitions
4119
+ function updateGradient(el, grad, index) {
4120
+ let i, n, stop;
4121
+ if (grad.gradient === 'radial') {
4122
+ // SVG radial gradients automatically transform to normalized bbox
4123
+ // coordinates, in a way that is cumbersome to replicate in canvas.
4124
+ // We wrap the radial gradient in a pattern element, allowing us to
4125
+ // maintain a circular gradient that matches what canvas provides.
4126
+ let pt = domChild(el, index++, 'pattern', svgns);
4127
+ setAttributes(pt, {
4128
+ id: patternPrefix + grad.id,
4129
+ viewBox: '0,0,1,1',
4130
+ width: '100%',
4131
+ height: '100%',
4132
+ preserveAspectRatio: 'xMidYMid slice'
4133
+ });
4134
+ pt = domChild(pt, 0, 'rect', svgns);
4135
+ setAttributes(pt, {
4136
+ width: 1,
4137
+ height: 1,
4138
+ fill: `url(${href()}#${grad.id})`
4139
+ });
4140
+ el = domChild(el, index++, 'radialGradient', svgns);
4141
+ setAttributes(el, {
4142
+ id: grad.id,
4143
+ fx: grad.x1,
4144
+ fy: grad.y1,
4145
+ fr: grad.r1,
4146
+ cx: grad.x2,
4147
+ cy: grad.y2,
4148
+ r: grad.r2
4149
+ });
4150
+ } else {
4151
+ el = domChild(el, index++, 'linearGradient', svgns);
4152
+ setAttributes(el, {
4153
+ id: grad.id,
4154
+ x1: grad.x1,
4155
+ x2: grad.x2,
4156
+ y1: grad.y1,
4157
+ y2: grad.y2
4158
+ });
4159
+ }
4160
+ for (i = 0, n = grad.stops.length; i < n; ++i) {
4161
+ stop = domChild(el, i, 'stop', svgns);
4162
+ stop.setAttribute('offset', grad.stops[i].offset);
4163
+ stop.setAttribute('stop-color', grad.stops[i].color);
4164
+ }
4165
+ domClear(el, i);
4166
+ return index;
4167
+ }
4168
+
4169
+ // update clipping path definitions
4170
+ function updateClipping(el, clip, index) {
4171
+ let mask;
4172
+ el = domChild(el, index, 'clipPath', svgns);
4173
+ el.setAttribute('id', clip.id);
4174
+ if (clip.path) {
4175
+ mask = domChild(el, 0, 'path', svgns);
4176
+ mask.setAttribute('d', clip.path);
4177
+ } else {
4178
+ mask = domChild(el, 0, 'rect', svgns);
4179
+ setAttributes(mask, {
4180
+ x: 0,
4181
+ y: 0,
4182
+ width: clip.width,
4183
+ height: clip.height
4184
+ });
4185
+ }
4186
+ domClear(el, 1);
4187
+ return index + 1;
4188
+ }
4189
+
4190
+ // Recursively process group contents.
4191
+ function recurse(renderer, el, group, markTypes) {
4192
+ // child 'g' element is second to last among children (path, g, path)
4193
+ // other children here are foreground and background path elements
4194
+ el = el.lastChild.previousSibling;
4195
+ let prev,
4196
+ idx = 0;
4197
+ visit(group, item => {
4198
+ prev = renderer.mark(el, item, prev, markTypes);
4199
+ ++idx;
4200
+ });
4201
+
4202
+ // remove any extraneous DOM elements
4203
+ domClear(el, 1 + idx);
4204
+ }
4205
+
4206
+ // Bind a scenegraph item to an SVG DOM element.
4207
+ // Create new SVG elements as needed.
4208
+ function bind(item, el, sibling, tag, svg) {
4209
+ let node = item._svg,
4210
+ doc;
4211
+
4212
+ // create a new dom node if needed
4213
+ if (!node) {
4214
+ doc = el.ownerDocument;
4215
+ node = domCreate(doc, tag, svgns);
4216
+ item._svg = node;
4217
+ if (item.mark) {
4218
+ node.__data__ = item;
4219
+ node.__values__ = {
4220
+ fill: 'default'
4221
+ };
4222
+
4223
+ // if group, create background, content, and foreground elements
4224
+ if (tag === 'g') {
4225
+ const bg = domCreate(doc, 'path', svgns);
4226
+ node.appendChild(bg);
4227
+ bg.__data__ = item;
4228
+ const cg = domCreate(doc, 'g', svgns);
4229
+ node.appendChild(cg);
4230
+ cg.__data__ = item;
4231
+ const fg = domCreate(doc, 'path', svgns);
4232
+ node.appendChild(fg);
4233
+ fg.__data__ = item;
4234
+ fg.__values__ = {
4235
+ fill: 'default'
4236
+ };
4237
+ }
4238
+ }
4239
+ }
4240
+
4241
+ // (re-)insert if (a) not contained in SVG or (b) sibling order has changed
4242
+ if (node.ownerSVGElement !== svg || siblingCheck(node, sibling)) {
4243
+ el.insertBefore(node, sibling ? sibling.nextSibling : el.firstChild);
4244
+ }
4245
+ return node;
4246
+ }
4247
+
4248
+ // check if two nodes are ordered siblings
4249
+ function siblingCheck(node, sibling) {
4250
+ return node.parentNode && node.parentNode.childNodes.length > 1 && node.previousSibling != sibling; // treat null/undefined the same
4251
+ }
4252
+
4253
+ // -- Set attributes & styles on SVG elements ---
4254
+
4255
+ let element = null,
4256
+ // temp var for current SVG element
4257
+ values = null; // temp var for current values hash
4258
+
4259
+ // Extra configuration for certain mark types
4260
+ const mark_extras = {
4261
+ group(mdef, el, item) {
4262
+ const fg = element = el.childNodes[2];
4263
+ values = fg.__values__;
4264
+ mdef.foreground(emit, item, this);
4265
+ values = el.__values__; // use parent's values hash
4266
+ element = el.childNodes[1];
4267
+ mdef.content(emit, item, this);
4268
+ const bg = element = el.childNodes[0];
4269
+ mdef.background(emit, item, this);
4270
+ const value = item.mark.interactive === false ? 'none' : null;
4271
+ if (value !== values.events) {
4272
+ setAttribute(fg, 'pointer-events', value);
4273
+ setAttribute(bg, 'pointer-events', value);
4274
+ values.events = value;
4275
+ }
4276
+ if (item.strokeForeground && item.stroke) {
4277
+ const fill = item.fill;
4278
+ setAttribute(fg, 'display', null);
4279
+
4280
+ // set style of background
4281
+ this.style(bg, item);
4282
+ setAttribute(bg, 'stroke', null);
4283
+
4284
+ // set style of foreground
4285
+ if (fill) item.fill = null;
4286
+ values = fg.__values__;
4287
+ this.style(fg, item);
4288
+ if (fill) item.fill = fill;
4289
+
4290
+ // leave element null to prevent downstream styling
4291
+ element = null;
4292
+ } else {
4293
+ // ensure foreground is ignored
4294
+ setAttribute(fg, 'display', 'none');
4295
+ }
4296
+ },
4297
+ image(mdef, el, item) {
4298
+ if (item.smooth === false) {
4299
+ setStyle(el, 'image-rendering', 'optimizeSpeed');
4300
+ setStyle(el, 'image-rendering', 'pixelated');
4301
+ } else {
4302
+ setStyle(el, 'image-rendering', null);
4303
+ }
4304
+ },
4305
+ text(mdef, el, item) {
4306
+ const tl = textLines(item);
4307
+ let key, value, doc, lh;
4308
+ if (vegaUtil.isArray(tl)) {
4309
+ // multi-line text
4310
+ value = tl.map(_ => textValue(item, _));
4311
+ key = value.join('\n'); // content cache key
4312
+
4313
+ if (key !== values.text) {
4314
+ domClear(el, 0);
4315
+ doc = el.ownerDocument;
4316
+ lh = lineHeight(item);
4317
+ value.forEach((t, i) => {
4318
+ const ts = domCreate(doc, 'tspan', svgns);
4319
+ ts.__data__ = item; // data binding
4320
+ ts.textContent = t;
4321
+ if (i) {
4322
+ ts.setAttribute('x', 0);
4323
+ ts.setAttribute('dy', lh);
4324
+ }
4325
+ el.appendChild(ts);
4326
+ });
4327
+ values.text = key;
4328
+ }
4329
+ } else {
4330
+ // single-line text
4331
+ value = textValue(item, tl);
4332
+ if (value !== values.text) {
4333
+ el.textContent = value;
4334
+ values.text = value;
4335
+ }
4336
+ }
4337
+ setAttribute(el, 'font-family', fontFamily(item));
4338
+ setAttribute(el, 'font-size', fontSize(item) + 'px');
4339
+ setAttribute(el, 'font-style', item.fontStyle);
4340
+ setAttribute(el, 'font-variant', item.fontVariant);
4341
+ setAttribute(el, 'font-weight', item.fontWeight);
4342
+ }
4343
+ };
4344
+ function emit(name, value, ns) {
4345
+ // early exit if value is unchanged
4346
+ if (value === values[name]) return;
4347
+
4348
+ // use appropriate method given namespace (ns)
4349
+ if (ns) {
4350
+ setAttributeNS(element, name, value, ns);
4351
+ } else {
4352
+ setAttribute(element, name, value);
4353
+ }
4354
+
4355
+ // note current value for future comparison
4356
+ values[name] = value;
4357
+ }
4358
+ function setStyle(el, name, value) {
4359
+ if (value !== values[name]) {
4360
+ if (value == null) {
4361
+ el.style.removeProperty(name);
4362
+ } else {
4363
+ el.style.setProperty(name, value + '');
4364
+ }
4365
+ values[name] = value;
4366
+ }
4367
+ }
4368
+ function setAttributes(el, attrs) {
4369
+ for (const key in attrs) {
4370
+ setAttribute(el, key, attrs[key]);
4371
+ }
4372
+ }
4373
+ function setAttribute(el, name, value) {
4374
+ if (value != null) {
4375
+ // if value is provided, update DOM attribute
4376
+ el.setAttribute(name, value);
4377
+ } else {
4378
+ // else remove DOM attribute
4379
+ el.removeAttribute(name);
4380
+ }
4381
+ }
4382
+ function setAttributeNS(el, name, value, ns) {
4383
+ if (value != null) {
4384
+ // if value is provided, update DOM attribute
4385
+ el.setAttributeNS(ns, name, value);
4386
+ } else {
4387
+ // else remove DOM attribute
4388
+ el.removeAttributeNS(ns, name);
4389
+ }
4390
+ }
4391
+ function href() {
4392
+ let loc;
4393
+ return typeof window === 'undefined' ? '' : (loc = window.location).hash ? loc.href.slice(0, -loc.hash.length) : loc.href;
4394
+ }
4395
+
4396
+ class SVGStringRenderer extends Renderer {
4397
+ constructor(loader) {
4398
+ super(loader);
4399
+ this._text = null;
4400
+ this._defs = {
4401
+ gradient: {},
4402
+ clipping: {}
4403
+ };
4404
+ }
4405
+
4406
+ /**
4407
+ * Returns the rendered SVG text string,
4408
+ * or null if rendering has not yet occurred.
4409
+ */
4410
+ svg() {
4411
+ return this._text;
4412
+ }
4413
+
4414
+ /**
4415
+ * Internal rendering method.
4416
+ * @param {object} scene - The root mark of a scenegraph to render.
4417
+ */
4418
+ _render(scene) {
4419
+ const m = markup();
4420
+
4421
+ // svg tag
4422
+ m.open('svg', vegaUtil.extend({}, metadata, {
4423
+ class: 'marks',
4424
+ width: this._width * this._scale,
4425
+ height: this._height * this._scale,
4426
+ viewBox: `0 0 ${this._width} ${this._height}`
4427
+ }));
4428
+
4429
+ // background, if defined
4430
+ const bg = this._bgcolor;
4431
+ if (bg && bg !== 'transparent' && bg !== 'none') {
4432
+ m.open('rect', {
4433
+ width: this._width,
4434
+ height: this._height,
4435
+ fill: bg
4436
+ }).close();
4437
+ }
4438
+
4439
+ // root content group
4440
+ m.open('g', rootAttributes, {
4441
+ transform: 'translate(' + this._origin + ')'
4442
+ });
4443
+ this.mark(m, scene);
4444
+ m.close(); // </g>
4445
+
4446
+ // defs
4447
+ this.defs(m);
4448
+
4449
+ // get SVG text string
4450
+ this._text = m.close() + '';
4451
+ return this;
4452
+ }
4453
+
4454
+ /**
4455
+ * Render a set of mark items.
4456
+ * @param {object} m - The markup context.
4457
+ * @param {object} scene - The mark parent to render.
4458
+ */
4459
+ mark(m, scene) {
4460
+ const mdef = Marks[scene.marktype],
4461
+ tag = mdef.tag,
4462
+ attrList = [ariaItemAttributes, mdef.attr];
4463
+
4464
+ // render opening group tag
4465
+ m.open('g', {
4466
+ 'class': cssClass(scene),
4467
+ 'clip-path': scene.clip ? clip$1(this, scene, scene.group) : null
4468
+ }, ariaMarkAttributes(scene), {
4469
+ 'pointer-events': tag !== 'g' && scene.interactive === false ? 'none' : null
4470
+ });
4471
+
4472
+ // render contained elements
4473
+ const process = item => {
4474
+ const href = this.href(item);
4475
+ if (href) m.open('a', href);
4476
+ m.open(tag, this.attr(scene, item, attrList, tag !== 'g' ? tag : null));
4477
+ if (tag === 'text') {
4478
+ const tl = textLines(item);
4479
+ if (vegaUtil.isArray(tl)) {
4480
+ // multi-line text
4481
+ const attrs = {
4482
+ x: 0,
4483
+ dy: lineHeight(item)
4484
+ };
4485
+ for (let i = 0; i < tl.length; ++i) {
4486
+ m.open('tspan', i ? attrs : null).text(textValue(item, tl[i])).close();
4487
+ }
4488
+ } else {
4489
+ // single-line text
4490
+ m.text(textValue(item, tl));
4491
+ }
4492
+ } else if (tag === 'g') {
4493
+ const fore = item.strokeForeground,
4494
+ fill = item.fill,
4495
+ stroke = item.stroke;
4496
+ if (fore && stroke) {
4497
+ item.stroke = null;
4498
+ }
4499
+ m.open('path', this.attr(scene, item, mdef.background, 'bgrect')).close();
4500
+
4501
+ // recurse for group content
4502
+ m.open('g', this.attr(scene, item, mdef.content));
4503
+ visit(item, scene => this.mark(m, scene));
4504
+ m.close();
4505
+ if (fore && stroke) {
4506
+ if (fill) item.fill = null;
4507
+ item.stroke = stroke;
4508
+ m.open('path', this.attr(scene, item, mdef.foreground, 'bgrect')).close();
4509
+ if (fill) item.fill = fill;
4510
+ } else {
4511
+ m.open('path', this.attr(scene, item, mdef.foreground, 'bgfore')).close();
4512
+ }
4513
+ }
4514
+ m.close(); // </tag>
4515
+ if (href) m.close(); // </a>
4516
+ };
4517
+ if (mdef.nested) {
4518
+ if (scene.items && scene.items.length) process(scene.items[0]);
4519
+ } else {
4520
+ visit(scene, process);
4521
+ }
4522
+
4523
+ // render closing group tag
4524
+ return m.close(); // </g>
4525
+ }
4526
+
4527
+ /**
4528
+ * Get href attributes for a hyperlinked mark item.
4529
+ * @param {Item} item - The mark item.
4530
+ */
4531
+ href(item) {
4532
+ const href = item.href;
4533
+ let attr;
4534
+ if (href) {
4535
+ if (attr = this._hrefs && this._hrefs[href]) {
4536
+ return attr;
4537
+ } else {
4538
+ this.sanitizeURL(href).then(attr => {
4539
+ // rewrite to use xlink namespace
4540
+ attr['xlink:href'] = attr.href;
4541
+ attr.href = null;
4542
+ (this._hrefs || (this._hrefs = {}))[href] = attr;
4543
+ });
4544
+ }
4545
+ }
4546
+ return null;
4547
+ }
4548
+
4549
+ /**
4550
+ * Get an object of SVG attributes for a mark item.
4551
+ * @param {object} scene - The mark parent.
4552
+ * @param {Item} item - The mark item.
4553
+ * @param {array|function} attrs - One or more attribute emitters.
4554
+ * @param {string} tag - The tag being rendered.
4555
+ */
4556
+ attr(scene, item, attrs, tag) {
4557
+ const object = {},
4558
+ emit = (name, value, ns, prefixed) => {
4559
+ object[prefixed || name] = value;
4560
+ };
4561
+
4562
+ // apply mark specific attributes
4563
+ if (Array.isArray(attrs)) {
4564
+ attrs.forEach(fn => fn(emit, item, this));
4565
+ } else {
4566
+ attrs(emit, item, this);
4567
+ }
4568
+
4569
+ // apply style attributes
4570
+ if (tag) {
4571
+ style(object, item, scene, tag, this._defs);
4572
+ }
4573
+ return object;
4574
+ }
4575
+
4576
+ /**
4577
+ * Render SVG defs, as needed.
4578
+ * Must be called *after* marks have been processed to ensure the
4579
+ * collected state is current and accurate.
4580
+ * @param {object} m - The markup context.
4581
+ */
4582
+ defs(m) {
4583
+ const gradient = this._defs.gradient,
4584
+ clipping = this._defs.clipping,
4585
+ count = Object.keys(gradient).length + Object.keys(clipping).length;
4586
+ if (count === 0) return; // nothing to do
4587
+
4588
+ m.open('defs');
4589
+ for (const id in gradient) {
4590
+ const def = gradient[id],
4591
+ stops = def.stops;
4592
+ if (def.gradient === 'radial') {
4593
+ // SVG radial gradients automatically transform to normalized bbox
4594
+ // coordinates, in a way that is cumbersome to replicate in canvas.
4595
+ // We wrap the radial gradient in a pattern element, allowing us to
4596
+ // maintain a circular gradient that matches what canvas provides.
4597
+
4598
+ m.open('pattern', {
4599
+ id: patternPrefix + id,
4600
+ viewBox: '0,0,1,1',
4601
+ width: '100%',
4602
+ height: '100%',
4603
+ preserveAspectRatio: 'xMidYMid slice'
4604
+ });
4605
+ m.open('rect', {
4606
+ width: '1',
4607
+ height: '1',
4608
+ fill: 'url(#' + id + ')'
4609
+ }).close();
4610
+ m.close(); // </pattern>
4611
+
4612
+ m.open('radialGradient', {
4613
+ id: id,
4614
+ fx: def.x1,
4615
+ fy: def.y1,
4616
+ fr: def.r1,
4617
+ cx: def.x2,
4618
+ cy: def.y2,
4619
+ r: def.r2
4620
+ });
4621
+ } else {
4622
+ m.open('linearGradient', {
4623
+ id: id,
4624
+ x1: def.x1,
4625
+ x2: def.x2,
4626
+ y1: def.y1,
4627
+ y2: def.y2
4628
+ });
4629
+ }
4630
+ for (let i = 0; i < stops.length; ++i) {
4631
+ m.open('stop', {
4632
+ offset: stops[i].offset,
4633
+ 'stop-color': stops[i].color
4634
+ }).close();
4635
+ }
4636
+ m.close();
4637
+ }
4638
+ for (const id in clipping) {
4639
+ const def = clipping[id];
4640
+ m.open('clipPath', {
4641
+ id: id
4642
+ });
4643
+ if (def.path) {
4644
+ m.open('path', {
4645
+ d: def.path
4646
+ }).close();
4647
+ } else {
4648
+ m.open('rect', {
4649
+ x: 0,
4650
+ y: 0,
4651
+ width: def.width,
4652
+ height: def.height
4653
+ }).close();
4654
+ }
4655
+ m.close();
4656
+ }
4657
+ m.close();
4658
+ }
4659
+ }
4660
+
4661
+ // Helper function for attr for style presentation attributes
4662
+ function style(s, item, scene, tag, defs) {
4663
+ let styleList;
4664
+ if (item == null) return s;
4665
+ if (tag === 'bgrect' && scene.interactive === false) {
4666
+ s['pointer-events'] = 'none';
4667
+ }
4668
+ if (tag === 'bgfore') {
4669
+ if (scene.interactive === false) {
4670
+ s['pointer-events'] = 'none';
4671
+ }
4672
+ s.display = 'none';
4673
+ if (item.fill !== null) return s;
4674
+ }
4675
+ if (tag === 'image' && item.smooth === false) {
4676
+ styleList = ['image-rendering: optimizeSpeed;', 'image-rendering: pixelated;'];
4677
+ }
4678
+ if (tag === 'text') {
4679
+ s['font-family'] = fontFamily(item);
4680
+ s['font-size'] = fontSize(item) + 'px';
4681
+ s['font-style'] = item.fontStyle;
4682
+ s['font-variant'] = item.fontVariant;
4683
+ s['font-weight'] = item.fontWeight;
4684
+ }
4685
+ for (const prop in stylesAttr) {
4686
+ let value = item[prop];
4687
+ const name = stylesAttr[prop];
4688
+ if (value === 'transparent' && (name === 'fill' || name === 'stroke')) ; else if (value != null) {
4689
+ if (isGradient(value)) {
4690
+ value = gradientRef(value, defs.gradient, '');
4691
+ }
4692
+ s[name] = value;
4693
+ }
4694
+ }
4695
+ for (const prop in stylesCss) {
4696
+ const value = item[prop];
4697
+ if (value != null) {
4698
+ styleList = styleList || [];
4699
+ styleList.push(`${stylesCss[prop]}: ${value};`);
4700
+ }
4701
+ }
4702
+ if (styleList) {
4703
+ s.style = styleList.join(' ');
4704
+ }
4705
+ return s;
4706
+ }
4707
+
4708
+ /**
4709
+ * @typedef {Object} HybridRendererOptions
4710
+ *
4711
+ * @property {string[]} [svgMarkTypes=['text']] - An array of SVG mark types to render
4712
+ * in the SVG layer. All other mark types
4713
+ * will be rendered in the Canvas layer.
4714
+ * @property {boolean} [svgOnTop=true] - Flag to determine if SVG should be rendered on top.
4715
+ * @property {boolean} [debug=false] - Flag to enable or disable debugging mode. When true,
4716
+ * the top layer will be stacked below the bottom layer
4717
+ * rather than overlaid on top.
4718
+ */
4719
+
4720
+ /** @type {HybridRendererOptions} */
4721
+ const OPTS = {
4722
+ svgMarkTypes: ['text'],
4723
+ svgOnTop: true,
4724
+ debug: false
4725
+ };
4726
+
4727
+ /**
4728
+ * Configure the HybridRenderer
4729
+ *
4730
+ * @param {HybridRendererOptions} options - HybridRenderer configuration options.
4731
+ */
4732
+ function setHybridRendererOptions(options) {
4733
+ OPTS['svgMarkTypes'] = options.svgMarkTypes ?? ['text'];
4734
+ OPTS['svgOnTop'] = options.svgOnTop ?? true;
4735
+ OPTS['debug'] = options.debug ?? false;
4736
+ }
4737
+ class HybridRenderer extends Renderer {
4738
+ constructor(loader) {
4739
+ super(loader);
4740
+ this._svgRenderer = new SVGRenderer(loader);
4741
+ this._canvasRenderer = new CanvasRenderer(loader);
4742
+ }
4743
+
4744
+ /**
4745
+ * Initialize a new HybridRenderer instance.
4746
+ * @param {DOMElement} el - The containing DOM element for the display.
4747
+ * @param {number} width - The coordinate width of the display, in pixels.
4748
+ * @param {number} height - The coordinate height of the display, in pixels.
4749
+ * @param {Array<number>} origin - The origin of the display, in pixels.
4750
+ * The coordinate system will be translated to this point.
4751
+ * @param {number} [scaleFactor=1] - Optional scaleFactor by which to multiply
4752
+ * the width and height to determine the final pixel size.
4753
+ * @return {HybridRenderer} - This renderer instance.
4754
+ */
4755
+ initialize(el, width, height, origin, scaleFactor) {
4756
+ this._root_el = domChild(el, 0, 'div');
4757
+ const bottomEl = domChild(this._root_el, 0, 'div');
4758
+ const topEl = domChild(this._root_el, 1, 'div');
4759
+ this._root_el.style.position = 'relative';
4760
+
4761
+ // Set position absolute to overlay svg on top of canvas
4762
+ if (!OPTS.debug) {
4763
+ bottomEl.style.height = '100%';
4764
+ topEl.style.position = 'absolute';
4765
+ topEl.style.top = '0';
4766
+ topEl.style.left = '0';
4767
+ topEl.style.height = '100%';
4768
+ topEl.style.width = '100%';
4769
+ }
4770
+ this._svgEl = OPTS.svgOnTop ? topEl : bottomEl;
4771
+ this._canvasEl = OPTS.svgOnTop ? bottomEl : topEl;
4772
+
4773
+ // pointer-events to none on SVG layer so that canvas gets all events
4774
+ this._svgEl.style.pointerEvents = 'none';
4775
+ this._canvasRenderer.initialize(this._canvasEl, width, height, origin, scaleFactor);
4776
+ this._svgRenderer.initialize(this._svgEl, width, height, origin, scaleFactor);
4777
+ return super.initialize(el, width, height, origin, scaleFactor);
4778
+ }
4779
+
4780
+ /**
4781
+ * Flag a mark item as dirty.
4782
+ * @param {Item} item - The mark item.
4783
+ */
4784
+ dirty(item) {
4785
+ if (OPTS.svgMarkTypes.includes(item.mark.marktype)) {
4786
+ this._svgRenderer.dirty(item);
4787
+ } else {
4788
+ this._canvasRenderer.dirty(item);
4789
+ }
4790
+ return this;
4791
+ }
4792
+
4793
+ /**
4794
+ * Internal rendering method.
4795
+ * @param {object} scene - The root mark of a scenegraph to render.
4796
+ * @param {Array} markTypes - Array of the mark types to render.
4797
+ * If undefined, render all mark types
4798
+ */
4799
+ _render(scene, markTypes) {
4800
+ const allMarkTypes = markTypes ?? ['arc', 'area', 'image', 'line', 'path', 'rect', 'rule', 'shape', 'symbol', 'text', 'trail'];
4801
+ const canvasMarkTypes = allMarkTypes.filter(m => !OPTS.svgMarkTypes.includes(m));
4802
+ this._svgRenderer.render(scene, OPTS.svgMarkTypes);
4803
+ this._canvasRenderer.render(scene, canvasMarkTypes);
4804
+ }
4805
+
4806
+ /**
4807
+ * Resize the display.
4808
+ * @param {number} width - The new coordinate width of the display, in pixels.
4809
+ * @param {number} height - The new coordinate height of the display, in pixels.
4810
+ * @param {Array<number>} origin - The new origin of the display, in pixels.
4811
+ * The coordinate system will be translated to this point.
4812
+ * @param {number} [scaleFactor=1] - Optional scaleFactor by which to multiply
4813
+ * the width and height to determine the final pixel size.
4814
+ * @return {SVGRenderer} - This renderer instance;
4815
+ */
4816
+ resize(width, height, origin, scaleFactor) {
4817
+ super.resize(width, height, origin, scaleFactor);
4818
+ this._svgRenderer.resize(width, height, origin, scaleFactor);
4819
+ this._canvasRenderer.resize(width, height, origin, scaleFactor);
4820
+ return this;
4821
+ }
4822
+ background(bgcolor) {
4823
+ // Propagate background color to lower canvas renderer
4824
+ if (OPTS.svgOnTop) {
4825
+ this._canvasRenderer.background(bgcolor);
4826
+ } else {
4827
+ this._svgRenderer.background(bgcolor);
4828
+ }
4829
+ return this;
4830
+ }
4831
+ }
4832
+
4833
+ class HybridHandler extends CanvasHandler {
4834
+ constructor(loader, tooltip) {
4835
+ super(loader, tooltip);
4836
+ }
4837
+ initialize(el, origin, obj) {
4838
+ const canvas = domChild(domChild(el, 0, 'div'), OPTS.svgOnTop ? 0 : 1, 'div');
4839
+ return super.initialize(canvas, origin, obj);
4840
+ }
4841
+ }
4842
+
4843
+ const Canvas = 'canvas';
4844
+ const Hybrid = 'hybrid';
4845
+ const PNG = 'png';
4846
+ const SVG = 'svg';
4847
+ const None = 'none';
4848
+ const RenderType = {
4849
+ Canvas: Canvas,
4850
+ PNG: PNG,
4851
+ SVG: SVG,
4852
+ Hybrid: Hybrid,
4853
+ None: None
4854
+ };
4855
+ const modules = {};
4856
+ modules[Canvas] = modules[PNG] = {
4857
+ renderer: CanvasRenderer,
4858
+ headless: CanvasRenderer,
4859
+ handler: CanvasHandler
4860
+ };
4861
+ modules[SVG] = {
4862
+ renderer: SVGRenderer,
4863
+ headless: SVGStringRenderer,
4864
+ handler: SVGHandler
4865
+ };
4866
+ modules[Hybrid] = {
4867
+ renderer: HybridRenderer,
4868
+ headless: HybridRenderer,
4869
+ handler: HybridHandler
4870
+ };
4871
+ modules[None] = {};
4872
+ function renderModule(name, _) {
4873
+ name = String(name || '').toLowerCase();
4874
+ if (arguments.length > 1) {
4875
+ modules[name] = _;
4876
+ return this;
4877
+ } else {
4878
+ return modules[name];
4879
+ }
4880
+ }
4881
+
4882
+ function intersect(scene, bounds, filter) {
4883
+ const hits = [],
4884
+ // intersection results
4885
+ box = new Bounds().union(bounds),
4886
+ // defensive copy
4887
+ type = scene.marktype;
4888
+ return type ? intersectMark(scene, box, filter, hits) : type === 'group' ? intersectGroup(scene, box, filter, hits) : vegaUtil.error('Intersect scene must be mark node or group item.');
4889
+ }
4890
+ function intersectMark(mark, box, filter, hits) {
4891
+ if (visitMark(mark, box, filter)) {
4892
+ const items = mark.items,
4893
+ type = mark.marktype,
4894
+ n = items.length;
4895
+ let i = 0;
4896
+ if (type === 'group') {
4897
+ for (; i < n; ++i) {
4898
+ intersectGroup(items[i], box, filter, hits);
4899
+ }
4900
+ } else {
4901
+ for (const test = Marks[type].isect; i < n; ++i) {
4902
+ const item = items[i];
4903
+ if (intersectItem(item, box, test)) hits.push(item);
4904
+ }
4905
+ }
4906
+ }
4907
+ return hits;
4908
+ }
4909
+ function visitMark(mark, box, filter) {
4910
+ // process if bounds intersect and if
4911
+ // (1) mark is a group mark (so we must recurse), or
4912
+ // (2) mark is interactive and passes filter
4913
+ return mark.bounds && box.intersects(mark.bounds) && (mark.marktype === 'group' || mark.interactive !== false && (!filter || filter(mark)));
4914
+ }
4915
+ function intersectGroup(group, box, filter, hits) {
4916
+ // test intersect against group
4917
+ // skip groups by default unless filter says otherwise
4918
+ if (filter && filter(group.mark) && intersectItem(group, box, Marks.group.isect)) {
4919
+ hits.push(group);
4920
+ }
4921
+
4922
+ // recursively test children marks
4923
+ // translate box to group coordinate space
4924
+ const marks = group.items,
4925
+ n = marks && marks.length;
4926
+ if (n) {
4927
+ const x = group.x || 0,
4928
+ y = group.y || 0;
4929
+ box.translate(-x, -y);
4930
+ for (let i = 0; i < n; ++i) {
4931
+ intersectMark(marks[i], box, filter, hits);
4932
+ }
4933
+ box.translate(x, y);
4934
+ }
4935
+ return hits;
4936
+ }
4937
+ function intersectItem(item, box, test) {
4938
+ // test bounds enclosure, bounds intersection, then detailed test
4939
+ const bounds = item.bounds;
4940
+ return box.encloses(bounds) || box.intersects(bounds) && test(item, box);
4941
+ }
4942
+
4943
+ const clipBounds = new Bounds();
4944
+ function boundClip (mark) {
4945
+ const clip = mark.clip;
4946
+ if (vegaUtil.isFunction(clip)) {
4947
+ clip(boundContext(clipBounds.clear()));
4948
+ } else if (clip) {
4949
+ clipBounds.set(0, 0, mark.group.width, mark.group.height);
4950
+ } else return;
4951
+ mark.bounds.intersect(clipBounds);
4952
+ }
4953
+
4954
+ const TOLERANCE = 1e-9;
4955
+ function sceneEqual(a, b, key) {
4956
+ return a === b ? true : key === 'path' ? pathEqual(a, b) : a instanceof Date && b instanceof Date ? +a === +b : vegaUtil.isNumber(a) && vegaUtil.isNumber(b) ? Math.abs(a - b) <= TOLERANCE : !a || !b || !vegaUtil.isObject(a) && !vegaUtil.isObject(b) ? a == b : objectEqual(a, b);
4957
+ }
4958
+ function pathEqual(a, b) {
4959
+ return sceneEqual(parse(a), parse(b));
4960
+ }
4961
+ function objectEqual(a, b) {
4962
+ var ka = Object.keys(a),
4963
+ kb = Object.keys(b),
4964
+ key,
4965
+ i;
4966
+ if (ka.length !== kb.length) return false;
4967
+ ka.sort();
4968
+ kb.sort();
4969
+ for (i = ka.length - 1; i >= 0; i--) {
4970
+ if (ka[i] != kb[i]) return false;
4971
+ }
4972
+ for (i = ka.length - 1; i >= 0; i--) {
4973
+ key = ka[i];
4974
+ if (!sceneEqual(a[key], b[key], key)) return false;
4975
+ }
4976
+ return typeof a === typeof b;
4977
+ }
4978
+
4979
+ function resetSVGDefIds() {
4980
+ resetSVGClipId();
4981
+ resetSVGGradientId();
4982
+ }
4983
+
4984
+ exports.path = path$3.path;
4985
+ exports.Bounds = Bounds;
4986
+ exports.CanvasHandler = CanvasHandler;
4987
+ exports.CanvasRenderer = CanvasRenderer;
4988
+ exports.Gradient = Gradient;
4989
+ exports.GroupItem = GroupItem;
4990
+ exports.Handler = Handler;
4991
+ exports.HybridHandler = HybridHandler;
4992
+ exports.HybridRenderer = HybridRenderer;
4993
+ exports.Item = Item;
4994
+ exports.Marks = Marks;
4995
+ exports.RenderType = RenderType;
4996
+ exports.Renderer = Renderer;
4997
+ exports.ResourceLoader = ResourceLoader;
4998
+ exports.SVGHandler = SVGHandler;
4999
+ exports.SVGRenderer = SVGRenderer;
5000
+ exports.SVGStringRenderer = SVGStringRenderer;
5001
+ exports.Scenegraph = Scenegraph;
5002
+ exports.boundClip = boundClip;
5003
+ exports.boundContext = boundContext;
5004
+ exports.boundItem = boundItem;
5005
+ exports.boundMark = boundMark;
5006
+ exports.boundStroke = boundStroke;
5007
+ exports.domChild = domChild;
5008
+ exports.domClear = domClear;
5009
+ exports.domCreate = domCreate;
5010
+ exports.domFind = domFind;
5011
+ exports.font = font;
5012
+ exports.fontFamily = fontFamily;
5013
+ exports.fontSize = fontSize;
5014
+ exports.intersect = intersect;
5015
+ exports.intersectBoxLine = intersectBoxLine;
5016
+ exports.intersectPath = intersectPath;
5017
+ exports.intersectPoint = intersectPoint;
5018
+ exports.intersectRule = intersectRule;
5019
+ exports.lineHeight = lineHeight;
5020
+ exports.markup = markup;
5021
+ exports.multiLineOffset = multiLineOffset;
5022
+ exports.pathCurves = curves;
5023
+ exports.pathEqual = pathEqual;
5024
+ exports.pathParse = parse;
5025
+ exports.pathRectangle = vg_rect;
5026
+ exports.pathRender = pathRender;
5027
+ exports.pathSymbols = symbols;
5028
+ exports.pathTrail = vg_trail;
5029
+ exports.point = point;
5030
+ exports.renderModule = renderModule;
5031
+ exports.resetSVGDefIds = resetSVGDefIds;
5032
+ exports.sceneEqual = sceneEqual;
5033
+ exports.sceneFromJSON = sceneFromJSON;
5034
+ exports.scenePickVisit = pickVisit;
5035
+ exports.sceneToJSON = sceneToJSON;
5036
+ exports.sceneVisit = visit;
5037
+ exports.sceneZOrder = zorder;
5038
+ exports.serializeXML = serializeXML;
5039
+ exports.setHybridRendererOptions = setHybridRendererOptions;
5040
+ exports.textMetrics = textMetrics;