@jbrowse/render-core 5.0.0-beta.1 → 5.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/RenderCanvas.d.ts +2 -2
- package/esm/RenderLifecycleMixin.d.ts +52 -20
- package/esm/RenderLifecycleMixin.js +89 -23
- package/esm/canvas2dUtils.d.ts +90 -23
- package/esm/canvas2dUtils.js +119 -36
- package/esm/colorRampLut.d.ts +5 -5
- package/esm/colorRampLut.js +6 -6
- package/esm/computePipeline.d.ts +14 -0
- package/esm/computePipeline.js +62 -0
- package/esm/contractReports.d.ts +54 -0
- package/esm/contractReports.js +112 -0
- package/esm/coverageBand.d.ts +13 -8
- package/esm/coverageBand.js +15 -5
- package/esm/coverageBandBuffers.d.ts +2 -9
- package/esm/coverageBandBuffers.js +1 -13
- package/esm/createRenderingBackend.d.ts +14 -18
- package/esm/createRenderingBackend.js +4 -2
- package/esm/displayPhase.d.ts +83 -104
- package/esm/displayPhase.js +42 -82
- package/esm/encodeMemo.d.ts +14 -0
- package/esm/encodeMemo.js +48 -0
- package/esm/gpuContextLostError.d.ts +30 -0
- package/esm/gpuContextLostError.js +40 -0
- package/esm/gpuDevice.d.ts +29 -10
- package/esm/gpuDevice.js +35 -16
- package/esm/graphicsCapabilities.d.ts +27 -19
- package/esm/graphicsCapabilities.js +40 -18
- package/esm/hal/createHal.d.ts +4 -5
- package/esm/hal/createHal.js +14 -4
- package/esm/hal/deviceGpuCache.d.ts +25 -30
- package/esm/hal/deviceGpuCache.js +88 -97
- package/esm/hal/gpuHalBase.d.ts +5 -4
- package/esm/hal/gpuHalBase.js +25 -14
- package/esm/hal/index.d.ts +2 -2
- package/esm/hal/index.js +1 -1
- package/esm/hal/mockHal.d.ts +15 -10
- package/esm/hal/mockHal.js +31 -18
- package/esm/hal/oomReporter.d.ts +7 -0
- package/esm/hal/oomReporter.js +10 -0
- package/esm/hal/passIds.d.ts +8 -7
- package/esm/hal/passIds.js +11 -10
- package/esm/hal/regionRegistry.d.ts +0 -1
- package/esm/hal/regionRegistry.js +3 -15
- package/esm/hal/types.d.ts +55 -18
- package/esm/hal/webgl2Hal.d.ts +23 -6
- package/esm/hal/webgl2Hal.js +161 -155
- package/esm/hal/webgpuHal.d.ts +29 -13
- package/esm/hal/webgpuHal.js +221 -153
- package/esm/installUpload.d.ts +16 -3
- package/esm/installUpload.js +13 -41
- package/esm/instanceCache.d.ts +10 -7
- package/esm/instanceCache.js +14 -15
- package/esm/instancePass.d.ts +2 -1
- package/esm/mapUploadSync.d.ts +2 -10
- package/esm/mapUploadSync.js +2 -3
- package/esm/marks/barMark.d.ts +30 -0
- package/esm/marks/barMark.js +149 -0
- package/esm/marks/colorFill.d.ts +17 -0
- package/esm/marks/colorFill.js +26 -0
- package/esm/marks/drawAgainstHit.d.ts +113 -0
- package/esm/marks/drawAgainstHit.js +407 -0
- package/esm/marks/ellipseDistance.d.ts +10 -0
- package/esm/marks/ellipseDistance.js +136 -0
- package/esm/marks/glyphPaint.d.ts +36 -0
- package/esm/marks/glyphPaint.js +77 -0
- package/esm/marks/index.d.ts +33 -0
- package/esm/marks/index.js +20 -0
- package/esm/marks/lineMark.d.ts +37 -0
- package/esm/marks/lineMark.js +416 -0
- package/esm/marks/linkMark.d.ts +76 -0
- package/esm/marks/linkMark.js +585 -0
- package/esm/marks/markBackend.d.ts +118 -0
- package/esm/marks/markBackend.js +196 -0
- package/esm/marks/markHit.d.ts +32 -0
- package/esm/marks/markHit.js +61 -0
- package/esm/marks/markInk.d.ts +18 -0
- package/esm/marks/markInk.js +71 -0
- package/esm/marks/markPaint.d.ts +14 -0
- package/esm/marks/markPaint.js +32 -0
- package/esm/marks/markPlan.d.ts +25 -0
- package/esm/marks/markPlan.js +20 -0
- package/esm/marks/markRamp.d.ts +72 -0
- package/esm/marks/markRamp.js +197 -0
- package/esm/marks/nearestMarkHit.d.ts +55 -0
- package/esm/marks/nearestMarkHit.js +158 -0
- package/esm/marks/pathRecorder.d.ts +14 -0
- package/esm/marks/pathRecorder.js +80 -0
- package/esm/marks/pointMark.d.ts +42 -0
- package/esm/marks/pointMark.js +125 -0
- package/esm/marks/rowLane.d.ts +39 -0
- package/esm/marks/rowLane.js +41 -0
- package/esm/marks/rowSpanIndex.d.ts +29 -0
- package/esm/marks/rowSpanIndex.js +141 -0
- package/esm/marks/rowTable.d.ts +41 -0
- package/esm/marks/rowTable.js +75 -0
- package/esm/marks/ruleMark.d.ts +21 -0
- package/esm/marks/ruleMark.js +91 -0
- package/esm/marks/spanMark.d.ts +42 -0
- package/esm/marks/spanMark.js +81 -0
- package/esm/marks/types.d.ts +261 -0
- package/esm/marks/types.js +175 -0
- package/esm/marks/valueScale.d.ts +23 -0
- package/esm/marks/valueScale.js +11 -0
- package/esm/namedReactions.d.ts +3 -4
- package/esm/namedReactions.js +3 -4
- package/esm/perRegionRenderingBackend.d.ts +21 -3
- package/esm/perRegionRenderingBackend.js +37 -3
- package/esm/regionDataMap.d.ts +2 -2
- package/esm/regionDataMap.js +25 -23
- package/esm/renderBlock.d.ts +14 -0
- package/esm/renderBlock.js +25 -0
- package/esm/renderingBackendBase.d.ts +20 -14
- package/esm/renderingBackendBase.js +12 -7
- package/esm/scoreScale.d.ts +27 -0
- package/esm/scoreScale.js +88 -0
- package/esm/shaders/barMark.generated.d.ts +3 -0
- package/esm/shaders/barMark.generated.js +7 -0
- package/esm/shaders/barMark.glsl.generated.d.ts +2 -0
- package/esm/shaders/barMark.glsl.generated.js +4 -0
- package/esm/shaders/barMark.iface.generated.d.ts +90 -0
- package/esm/shaders/barMark.iface.generated.js +205 -0
- package/esm/shaders/barMark.wgsl.generated.d.ts +1 -0
- package/esm/shaders/barMark.wgsl.generated.js +3 -0
- package/esm/shaders/capsule.js.generated.d.ts +1 -0
- package/esm/shaders/capsule.js.generated.js +11 -0
- package/esm/shaders/clipStrip.generated.d.ts +2 -0
- package/esm/shaders/clipStrip.generated.js +4 -0
- package/esm/shaders/clipStrip.js.generated.d.ts +1 -0
- package/esm/shaders/clipStrip.js.generated.js +21 -0
- package/esm/shaders/colorRampLut.js.generated.d.ts +1 -0
- package/esm/shaders/colorRampLut.js.generated.js +17 -0
- package/esm/shaders/coverageBar.generated.d.ts +2 -3
- package/esm/shaders/coverageBar.generated.js +4 -3
- package/esm/shaders/coverageBar.glsl.generated.d.ts +2 -0
- package/esm/shaders/coverageBar.glsl.generated.js +4 -0
- package/esm/shaders/coverageBar.iface.generated.js +1 -1
- package/esm/shaders/coverageBar.wgsl.generated.d.ts +1 -0
- package/esm/shaders/coverageBar.wgsl.generated.js +3 -0
- package/esm/shaders/coverageClip.generated.d.ts +3 -0
- package/esm/shaders/coverageClip.generated.js +7 -0
- package/esm/shaders/coverageClip.glsl.generated.d.ts +2 -0
- package/esm/shaders/coverageClip.glsl.generated.js +4 -0
- package/esm/shaders/coverageClip.iface.generated.d.ts +85 -0
- package/esm/shaders/coverageClip.iface.generated.js +114 -0
- package/esm/shaders/coverageClip.wgsl.generated.d.ts +1 -0
- package/esm/shaders/coverageClip.wgsl.generated.js +3 -0
- package/esm/shaders/coverageIndicator.generated.d.ts +2 -3
- package/esm/shaders/coverageIndicator.generated.js +4 -3
- package/esm/shaders/coverageIndicator.glsl.generated.d.ts +2 -0
- package/esm/shaders/coverageIndicator.glsl.generated.js +4 -0
- package/esm/shaders/coverageIndicator.iface.generated.js +1 -1
- package/esm/shaders/coverageIndicator.wgsl.generated.d.ts +1 -0
- package/esm/shaders/coverageIndicator.wgsl.generated.js +3 -0
- package/esm/shaders/coverageInterbase.generated.d.ts +2 -3
- package/esm/shaders/coverageInterbase.generated.js +4 -3
- package/esm/shaders/coverageInterbase.glsl.generated.d.ts +2 -0
- package/esm/shaders/coverageInterbase.glsl.generated.js +4 -0
- package/esm/shaders/coverageInterbase.iface.generated.js +1 -1
- package/esm/shaders/coverageInterbase.wgsl.generated.d.ts +1 -0
- package/esm/shaders/coverageInterbase.wgsl.generated.js +3 -0
- package/esm/shaders/coverageMod.generated.d.ts +2 -3
- package/esm/shaders/coverageMod.generated.js +4 -3
- package/esm/shaders/coverageMod.glsl.generated.d.ts +2 -0
- package/esm/shaders/coverageMod.glsl.generated.js +4 -0
- package/esm/shaders/coverageMod.iface.generated.js +1 -1
- package/esm/shaders/coverageMod.wgsl.generated.d.ts +1 -0
- package/esm/shaders/coverageMod.wgsl.generated.js +3 -0
- package/esm/shaders/coverageSnp.generated.d.ts +2 -3
- package/esm/shaders/coverageSnp.generated.js +4 -3
- package/esm/shaders/coverageSnp.glsl.generated.d.ts +2 -0
- package/esm/shaders/coverageSnp.glsl.generated.js +4 -0
- package/esm/shaders/coverageSnp.iface.generated.js +1 -1
- package/esm/shaders/coverageSnp.wgsl.generated.d.ts +1 -0
- package/esm/shaders/coverageSnp.wgsl.generated.js +3 -0
- package/esm/shaders/curveDistance.js.generated.d.ts +5 -0
- package/esm/shaders/curveDistance.js.generated.js +87 -0
- package/esm/shaders/hpmath.js.generated.d.ts +2 -1
- package/esm/shaders/hpmath.js.generated.js +5 -2
- package/esm/shaders/lineCenterMark.generated.d.ts +3 -0
- package/esm/shaders/lineCenterMark.generated.js +7 -0
- package/esm/shaders/lineCenterMark.glsl.generated.d.ts +2 -0
- package/esm/shaders/lineCenterMark.glsl.generated.js +4 -0
- package/esm/shaders/lineCenterMark.iface.generated.d.ts +104 -0
- package/esm/shaders/lineCenterMark.iface.generated.js +237 -0
- package/esm/shaders/lineCenterMark.wgsl.generated.d.ts +1 -0
- package/esm/shaders/lineCenterMark.wgsl.generated.js +3 -0
- package/esm/shaders/lineCommon.generated.d.ts +2 -0
- package/esm/shaders/lineCommon.generated.js +4 -0
- package/esm/shaders/lineStepMark.generated.d.ts +3 -0
- package/esm/shaders/lineStepMark.generated.js +7 -0
- package/esm/shaders/lineStepMark.glsl.generated.d.ts +2 -0
- package/esm/shaders/lineStepMark.glsl.generated.js +4 -0
- package/esm/shaders/lineStepMark.iface.generated.d.ts +98 -0
- package/esm/shaders/lineStepMark.iface.generated.js +225 -0
- package/esm/shaders/lineStepMark.wgsl.generated.d.ts +1 -0
- package/esm/shaders/lineStepMark.wgsl.generated.js +3 -0
- package/esm/shaders/linkMark.consts.generated.d.ts +14 -0
- package/esm/shaders/linkMark.consts.generated.js +16 -0
- package/esm/shaders/linkMark.generated.d.ts +4 -0
- package/esm/shaders/linkMark.generated.js +8 -0
- package/esm/shaders/linkMark.glsl.generated.d.ts +2 -0
- package/esm/shaders/linkMark.glsl.generated.js +4 -0
- package/esm/shaders/linkMark.iface.generated.d.ts +142 -0
- package/esm/shaders/linkMark.iface.generated.js +1829 -0
- package/esm/shaders/linkMark.js.generated.d.ts +7 -0
- package/esm/shaders/linkMark.js.generated.js +159 -0
- package/esm/shaders/linkMark.wgsl.generated.d.ts +1 -0
- package/esm/shaders/linkMark.wgsl.generated.js +3 -0
- package/esm/shaders/markColor.generated.d.ts +9 -0
- package/esm/shaders/markColor.generated.js +11 -0
- package/esm/shaders/pointGlyph.js.generated.d.ts +2 -0
- package/esm/shaders/pointGlyph.js.generated.js +15 -0
- package/esm/shaders/pointMark.consts.generated.d.ts +7 -0
- package/esm/shaders/pointMark.consts.generated.js +9 -0
- package/esm/shaders/pointMark.generated.d.ts +4 -0
- package/esm/shaders/pointMark.generated.js +8 -0
- package/esm/shaders/pointMark.glsl.generated.d.ts +2 -0
- package/esm/shaders/pointMark.glsl.generated.js +4 -0
- package/esm/shaders/pointMark.iface.generated.d.ts +98 -0
- package/esm/shaders/pointMark.iface.generated.js +219 -0
- package/esm/shaders/pointMark.js.generated.d.ts +3 -0
- package/esm/shaders/pointMark.js.generated.js +93 -0
- package/esm/shaders/pointMark.wgsl.generated.d.ts +1 -0
- package/esm/shaders/pointMark.wgsl.generated.js +3 -0
- package/esm/shaders/rowRect.generated.d.ts +0 -1
- package/esm/shaders/rowRect.generated.js +0 -1
- package/esm/shaders/rowTable.generated.d.ts +1 -0
- package/esm/shaders/rowTable.generated.js +3 -0
- package/esm/shaders/rowTable.js.generated.d.ts +5 -0
- package/esm/shaders/rowTable.js.generated.js +29 -0
- package/esm/shaders/scoreScale.generated.d.ts +2 -0
- package/esm/shaders/scoreScale.generated.js +4 -0
- package/esm/shaders/scoreScale.js.generated.d.ts +1 -0
- package/esm/shaders/scoreScale.js.generated.js +50 -23
- package/esm/shaders/spanMark.generated.d.ts +3 -0
- package/esm/shaders/spanMark.generated.js +7 -0
- package/esm/shaders/spanMark.glsl.generated.d.ts +2 -0
- package/esm/shaders/spanMark.glsl.generated.js +4 -0
- package/esm/shaders/spanMark.iface.generated.d.ts +81 -0
- package/esm/shaders/spanMark.iface.generated.js +215 -0
- package/esm/shaders/spanMark.wgsl.generated.d.ts +1 -0
- package/esm/shaders/spanMark.wgsl.generated.js +3 -0
- package/esm/sharedBackendKey.d.ts +18 -0
- package/esm/{keyedRenderingBackend.js → sharedBackendKey.js} +5 -0
- package/esm/slangPass.d.ts +18 -11
- package/esm/slangPass.js +12 -4
- package/esm/useGraphicsCapabilities.d.ts +1 -1
- package/esm/useGraphicsCapabilities.js +1 -1
- package/esm/useRenderingBackend.d.ts +13 -13
- package/esm/useRenderingBackend.js +58 -20
- package/esm/webgpuUtils.d.ts +3 -11
- package/esm/webgpuUtils.js +12 -33
- package/package.json +32 -7
- package/src/shaders/antialias.slang +46 -0
- package/src/shaders/arcHull.test.ts +267 -0
- package/src/shaders/barMark.generated.ts +11 -0
- package/src/shaders/barMark.glsl.generated.ts +6 -0
- package/src/shaders/barMark.iface.generated.ts +285 -0
- package/src/shaders/barMark.slang +167 -0
- package/src/shaders/barMark.wgsl.generated.ts +4 -0
- package/src/shaders/capsule.js.generated.ts +14 -0
- package/src/shaders/capsule.slang +12 -4
- package/src/shaders/clipStrip.generated.ts +6 -0
- package/src/shaders/clipStrip.js.generated.ts +22 -0
- package/src/shaders/clipStrip.slang +34 -0
- package/src/shaders/clipStrip.test.ts +39 -0
- package/src/shaders/colorPack.slang +5 -1
- package/src/shaders/colorRampLut.js.generated.ts +22 -0
- package/src/shaders/colorRampLut.slang +15 -1
- package/src/shaders/coverageBand.slang +64 -32
- package/src/shaders/coverageBar.generated.ts +6 -5
- package/src/shaders/coverageBar.glsl.generated.ts +6 -0
- package/src/shaders/coverageBar.iface.generated.ts +1 -1
- package/src/shaders/coverageBar.slang +10 -10
- package/src/shaders/coverageBar.wgsl.generated.ts +4 -0
- package/src/shaders/coverageClip.generated.ts +11 -0
- package/src/shaders/coverageClip.glsl.generated.ts +6 -0
- package/src/shaders/coverageClip.iface.generated.ts +172 -0
- package/src/shaders/coverageClip.slang +38 -0
- package/src/shaders/coverageClip.wgsl.generated.ts +4 -0
- package/src/shaders/coverageIndicator.generated.ts +6 -5
- package/src/shaders/coverageIndicator.glsl.generated.ts +6 -0
- package/src/shaders/coverageIndicator.iface.generated.ts +1 -1
- package/src/shaders/coverageIndicator.wgsl.generated.ts +4 -0
- package/src/shaders/coverageInterbase.generated.ts +6 -5
- package/src/shaders/coverageInterbase.glsl.generated.ts +6 -0
- package/src/shaders/coverageInterbase.iface.generated.ts +1 -1
- package/src/shaders/coverageInterbase.wgsl.generated.ts +4 -0
- package/src/shaders/coverageMod.generated.ts +6 -5
- package/src/shaders/coverageMod.glsl.generated.ts +6 -0
- package/src/shaders/coverageMod.iface.generated.ts +1 -1
- package/src/shaders/coverageMod.wgsl.generated.ts +4 -0
- package/src/shaders/coverageSnp.generated.ts +6 -5
- package/src/shaders/coverageSnp.glsl.generated.ts +6 -0
- package/src/shaders/coverageSnp.iface.generated.ts +1 -1
- package/src/shaders/coverageSnp.wgsl.generated.ts +4 -0
- package/src/shaders/curveDistance.js.generated.ts +91 -0
- package/src/shaders/curveDistance.slang +265 -0
- package/src/shaders/hpClampFloor.test.ts +87 -0
- package/src/shaders/hpmath.js.generated.ts +6 -2
- package/src/shaders/hpmath.slang +100 -48
- package/src/shaders/insetValueScale.test.ts +67 -0
- package/src/shaders/lineCenterMark.generated.ts +11 -0
- package/src/shaders/lineCenterMark.glsl.generated.ts +6 -0
- package/src/shaders/lineCenterMark.iface.generated.ts +328 -0
- package/src/shaders/lineCenterMark.slang +127 -0
- package/src/shaders/lineCenterMark.wgsl.generated.ts +4 -0
- package/src/shaders/lineCommon.generated.ts +6 -0
- package/src/shaders/lineCommon.slang +102 -0
- package/src/shaders/lineStepMark.generated.ts +11 -0
- package/src/shaders/lineStepMark.glsl.generated.ts +6 -0
- package/src/shaders/lineStepMark.iface.generated.ts +311 -0
- package/src/shaders/lineStepMark.slang +125 -0
- package/src/shaders/lineStepMark.wgsl.generated.ts +4 -0
- package/src/shaders/linkMark.consts.generated.ts +30 -0
- package/src/shaders/linkMark.generated.ts +12 -0
- package/src/shaders/linkMark.glsl.generated.ts +6 -0
- package/src/shaders/linkMark.iface.generated.ts +1954 -0
- package/src/shaders/linkMark.js.generated.ts +167 -0
- package/src/shaders/linkMark.slang +439 -0
- package/src/shaders/linkMark.wgsl.generated.ts +4 -0
- package/src/shaders/markColor.generated.ts +20 -0
- package/src/shaders/markColor.slang +128 -0
- package/src/shaders/pointGlyph.js.generated.ts +20 -0
- package/src/shaders/pointGlyph.slang +23 -7
- package/src/shaders/pointGlyphPad.test.ts +242 -0
- package/src/shaders/pointMark.consts.generated.ts +16 -0
- package/src/shaders/pointMark.generated.ts +12 -0
- package/src/shaders/pointMark.glsl.generated.ts +6 -0
- package/src/shaders/pointMark.iface.generated.ts +304 -0
- package/src/shaders/pointMark.js.generated.ts +99 -0
- package/src/shaders/pointMark.slang +227 -0
- package/src/shaders/pointMark.wgsl.generated.ts +4 -0
- package/src/shaders/rowRect.generated.ts +0 -2
- package/src/shaders/rowRect.slang +39 -58
- package/src/shaders/rowTable.generated.ts +4 -0
- package/src/shaders/rowTable.js.generated.ts +37 -0
- package/src/shaders/rowTable.slang +98 -0
- package/src/shaders/scoreScale.generated.ts +6 -0
- package/src/shaders/scoreScale.js.generated.ts +48 -23
- package/src/shaders/scoreScale.slang +49 -55
- package/src/shaders/sdEllipse.test.ts +211 -0
- package/src/shaders/spanMark.generated.ts +11 -0
- package/src/shaders/spanMark.glsl.generated.ts +6 -0
- package/src/shaders/spanMark.iface.generated.ts +289 -0
- package/src/shaders/spanMark.slang +77 -0
- package/src/shaders/spanMark.wgsl.generated.ts +4 -0
- package/src/shaders/valueScale.slang +26 -0
- package/src/shaders/wideCircleLeg.test.ts +85 -0
- package/esm/globalRenderingBackend.d.ts +0 -90
- package/esm/globalRenderingBackend.js +0 -53
- package/esm/keyedRenderingBackend.d.ts +0 -41
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
import { getDpr } from '../canvas2dUtils.js';
|
|
2
|
+
import { SCALE_TYPE_LOG } from '../scoreScale.js';
|
|
3
|
+
import { distToWideCirclePx } from '../shaders/curveDistance.js.generated.js';
|
|
4
|
+
import { LINK_CURVE_SEGMENTS, LINK_ELSEWHERE, LINK_FAR_SCREEN_WIDTHS, LINK_FOOT_PX, LINK_MAX_REGIONS, LINK_NO_REGION, LINK_NO_SIZE, LINK_LINE_MIN_PX, LINK_SHAPE_ARC, LINK_SHAPE_DOME, LINK_SHAPE_LINE, LINK_SIZE_CONSTANT, LINK_SIZE_SCALED, LINK_STEM_PX, } from '../shaders/linkMark.consts.generated.js';
|
|
5
|
+
import * as shader from '../shaders/linkMark.generated.js';
|
|
6
|
+
import { linkApexPx, linkBaseYPx, linkFootDir, linkFootLenPx, linkRadiiPx, linkStrokeWidthPx, linkValuePx, } from '../shaders/linkMark.js.generated.js';
|
|
7
|
+
import { slangPass } from '../slangPass.js';
|
|
8
|
+
import { abgrToCssRgba } from './colorFill.js';
|
|
9
|
+
import { ellipseNearest } from './ellipseDistance.js';
|
|
10
|
+
import { nearestInk } from './markHit.js';
|
|
11
|
+
import { colorBits, paintColors, rampUniforms } from './markRamp.js';
|
|
12
|
+
import { bandHeightPx, rowColor, rowLane, rowSlot, rowTableKeys, rowTableTextures, } from './rowLane.js';
|
|
13
|
+
import { valueScaleUniforms } from './valueScale.js';
|
|
14
|
+
export const LINK_FOOT_FORWARD = 1;
|
|
15
|
+
export const LINK_FOOT_REVERSE = 2;
|
|
16
|
+
/** The `feet` lane's value for a tick at each foot, by genomic direction. */
|
|
17
|
+
export function linkFeet(xDir, x2Dir) {
|
|
18
|
+
const bits = (d) => d > 0 ? LINK_FOOT_FORWARD : d < 0 ? LINK_FOOT_REVERSE : 0;
|
|
19
|
+
return bits(xDir) | (bits(x2Dir) << 2);
|
|
20
|
+
}
|
|
21
|
+
const KIND_ELLIPSE = 0;
|
|
22
|
+
const KIND_CIRCLE = 1;
|
|
23
|
+
const KIND_STEM = 2;
|
|
24
|
+
const KIND_NONE = 3;
|
|
25
|
+
const KIND_LINE = 4;
|
|
26
|
+
// The painter's leg polyline: enough segments that the chord sagitta on any
|
|
27
|
+
// leg the band can show is under a pixel.
|
|
28
|
+
const LEG_SEGMENTS = 32;
|
|
29
|
+
function linkFrame(block, frame, params) {
|
|
30
|
+
const band = bandHeightPx(params, frame.canvasHeight);
|
|
31
|
+
const { valueScaleType, valueSymlogConstant } = valueScaleUniforms(params);
|
|
32
|
+
const { sizeScale } = params;
|
|
33
|
+
return {
|
|
34
|
+
band,
|
|
35
|
+
rowOffsetPx: params.rowOffsetPx ?? 0,
|
|
36
|
+
table: params.rowTable,
|
|
37
|
+
reverse: params.reverse ? 1 : 0,
|
|
38
|
+
ySign: params.reverse ? -1 : 1,
|
|
39
|
+
stemPx: params.stemPx ?? LINK_STEM_PX,
|
|
40
|
+
reach: Math.max(band - (params.insetPx ?? 0), 0),
|
|
41
|
+
screenW: frame.canvasWidth,
|
|
42
|
+
regions: params.regions,
|
|
43
|
+
own: block.displayedRegionIndex,
|
|
44
|
+
dpr: getDpr(),
|
|
45
|
+
scaleType: valueScaleType,
|
|
46
|
+
symlogConstant: valueSymlogConstant,
|
|
47
|
+
domainMin: params.domain[0],
|
|
48
|
+
domainMax: params.domain[1],
|
|
49
|
+
insetPx: params.insetPx ?? 0,
|
|
50
|
+
shape: linkShapeCode(params.linkShape),
|
|
51
|
+
valued: params.valued ? 1 : 0,
|
|
52
|
+
sizeMode: sizeScale ? LINK_SIZE_SCALED : LINK_SIZE_CONSTANT,
|
|
53
|
+
sizePx: params.sizePx,
|
|
54
|
+
sizeDomainMin: sizeScale?.domain[0] ?? 0,
|
|
55
|
+
sizeDomainMax: sizeScale?.domain[1] ?? 1,
|
|
56
|
+
sizeScaleType: sizeScale?.scale === 'log' ? SCALE_TYPE_LOG : 0,
|
|
57
|
+
sizeRangeMin: sizeScale?.range[0] ?? params.sizePx,
|
|
58
|
+
sizeRangeMax: sizeScale?.range[1] ?? params.sizePx,
|
|
59
|
+
kind: KIND_STEM,
|
|
60
|
+
xPx: 0,
|
|
61
|
+
x2Px: 0,
|
|
62
|
+
baseY: 0,
|
|
63
|
+
rx: 0,
|
|
64
|
+
ry: 0,
|
|
65
|
+
legHeight: 0,
|
|
66
|
+
legSweep: 0,
|
|
67
|
+
strokePx: 0,
|
|
68
|
+
footPx: params.footPx ?? LINK_FOOT_PX,
|
|
69
|
+
xPadPx: Math.max(params.sizePx, sizeScale?.range[0] ?? 0, sizeScale?.range[1] ?? 0, 1.5 / getDpr()) /
|
|
70
|
+
2 +
|
|
71
|
+
LINK_LINE_MIN_PX / 2,
|
|
72
|
+
foot1Dir: 0,
|
|
73
|
+
foot1Len: 0,
|
|
74
|
+
foot2Dir: 0,
|
|
75
|
+
foot2Len: 0,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
// A straight line's strip needs one segment; a curve's, the full count.
|
|
79
|
+
function curveSegments(params) {
|
|
80
|
+
return params.linkShape === 'line' ? 1 : LINK_CURVE_SEGMENTS;
|
|
81
|
+
}
|
|
82
|
+
// The curve's strip, then the two feet's six vertices each.
|
|
83
|
+
const FOOT_STRIP_VERTS = 12;
|
|
84
|
+
function linkShapeCode(shape) {
|
|
85
|
+
return shape === 'arc'
|
|
86
|
+
? LINK_SHAPE_ARC
|
|
87
|
+
: shape === 'line'
|
|
88
|
+
? LINK_SHAPE_LINE
|
|
89
|
+
: LINK_SHAPE_DOME;
|
|
90
|
+
}
|
|
91
|
+
function regionPx(regions, index, bp) {
|
|
92
|
+
const r = regions[index];
|
|
93
|
+
return r.anchorPx + (bp - r.anchorBp) * r.signedPxPerBp;
|
|
94
|
+
}
|
|
95
|
+
// Whether instance `i`'s ink can reach [lo, hi] horizontally, off its two feet
|
|
96
|
+
// alone: every shape's ink lies between them, padded by half the widest stroke,
|
|
97
|
+
// a foot's length, and half a `line`'s shortest length. Two table lookups, so
|
|
98
|
+
// a scan over tens of thousands of instances places only those it could hit.
|
|
99
|
+
function reachesX(c, g, i, lo, hi) {
|
|
100
|
+
const region = c.x2Region[i];
|
|
101
|
+
if (region === LINK_ELSEWHERE) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
const x = regionPx(g.regions, g.own, c.x[i]);
|
|
105
|
+
const x2 = region < g.regions.length && region < LINK_MAX_REGIONS
|
|
106
|
+
? regionPx(g.regions, region, c.x2[i])
|
|
107
|
+
: x;
|
|
108
|
+
const pad = g.xPadPx + (c.feet?.[i] ? g.footPx : 0);
|
|
109
|
+
return x2 > x
|
|
110
|
+
? x2 + pad >= lo && x - pad <= hi
|
|
111
|
+
: x + pad >= lo && x2 - pad <= hi;
|
|
112
|
+
}
|
|
113
|
+
function sizeOf(c, i) {
|
|
114
|
+
const v = c.size?.[i];
|
|
115
|
+
return v !== undefined && Number.isFinite(v) ? v : LINK_NO_SIZE;
|
|
116
|
+
}
|
|
117
|
+
// A foot's tick through its own region: the genomic direction mirrored where
|
|
118
|
+
// the region draws right to left, and held short of the region's edge.
|
|
119
|
+
function footOn(region, x, genomicDir, footPx) {
|
|
120
|
+
const dir = genomicDir * Math.sign(region.signedPxPerBp);
|
|
121
|
+
const len = linkFootLenPx(x, dir, region.leftPx ?? -Infinity, region.rightPx ?? Infinity, footPx);
|
|
122
|
+
return dir !== 0 && len > 0 ? { dir, len } : { dir: 0, len: 0 };
|
|
123
|
+
}
|
|
124
|
+
function placeFeet(c, g, i) {
|
|
125
|
+
const feet = c.feet?.[i] ?? 0;
|
|
126
|
+
const placed = g.kind !== KIND_STEM && g.kind !== KIND_NONE;
|
|
127
|
+
const one = feet === 0 || g.kind === KIND_NONE
|
|
128
|
+
? { dir: 0, len: 0 }
|
|
129
|
+
: footOn(g.regions[g.own], g.xPx, linkFootDir(feet, 0), g.footPx);
|
|
130
|
+
const two = feet === 0 || !placed
|
|
131
|
+
? { dir: 0, len: 0 }
|
|
132
|
+
: footOn(g.regions[c.x2Region[i]], g.x2Px, linkFootDir(feet, 2), g.footPx);
|
|
133
|
+
g.foot1Dir = one.dir;
|
|
134
|
+
g.foot1Len = one.len;
|
|
135
|
+
g.foot2Dir = two.dir;
|
|
136
|
+
g.foot2Len = two.len;
|
|
137
|
+
}
|
|
138
|
+
function placeLink(c, g, i) {
|
|
139
|
+
placeCurve(c, g, i);
|
|
140
|
+
placeFeet(c, g, i);
|
|
141
|
+
}
|
|
142
|
+
function placeCurve(c, g, i) {
|
|
143
|
+
const slot = rowSlot(c.row, i, g.table);
|
|
144
|
+
if (slot === undefined) {
|
|
145
|
+
g.kind = KIND_NONE;
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const { regions } = g;
|
|
149
|
+
g.strokePx = linkStrokeWidthPx(sizeOf(c, i), g.sizeMode, g.sizePx, g.sizeDomainMin, g.sizeDomainMax, g.sizeScaleType, g.sizeRangeMin, g.sizeRangeMax, g.dpr);
|
|
150
|
+
g.baseY = linkBaseYPx(g.rowOffsetPx, g.band, slot, g.reverse);
|
|
151
|
+
g.xPx = regionPx(regions, g.own, c.x[i]);
|
|
152
|
+
const region = c.x2Region[i];
|
|
153
|
+
if (region === LINK_ELSEWHERE) {
|
|
154
|
+
g.kind = KIND_NONE;
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (region >= regions.length || region >= LINK_MAX_REGIONS) {
|
|
158
|
+
g.kind = KIND_STEM;
|
|
159
|
+
g.x2Px = g.xPx;
|
|
160
|
+
g.rx = 0;
|
|
161
|
+
g.ry = g.stemPx;
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
g.x2Px = regionPx(regions, region, c.x2[i]);
|
|
165
|
+
const pairHalf = Math.abs(g.x2Px - g.xPx) / 2;
|
|
166
|
+
const valuePx = linkValuePx(c.y ? c.y[i] : 0, g.domainMin, g.domainMax, g.band, g.scaleType, g.insetPx, g.symlogConstant);
|
|
167
|
+
const apex = linkApexPx(pairHalf, g.reach, g.shape, g.valued, valuePx);
|
|
168
|
+
if (g.shape === LINK_SHAPE_LINE) {
|
|
169
|
+
g.kind = KIND_LINE;
|
|
170
|
+
g.rx = Math.max(2 * pairHalf, LINK_LINE_MIN_PX);
|
|
171
|
+
g.ry = apex;
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const [rx, ry] = linkRadiiPx(pairHalf, apex, g.screenW);
|
|
175
|
+
g.rx = rx;
|
|
176
|
+
g.ry = ry;
|
|
177
|
+
if (2 * pairHalf > LINK_FAR_SCREEN_WIDTHS * g.screenW) {
|
|
178
|
+
g.kind = KIND_CIRCLE;
|
|
179
|
+
g.legSweep = Math.asin(Math.min(1, Math.max(0, (g.reach + g.strokePx / 2) / Math.max(rx, 1e-6))));
|
|
180
|
+
g.legHeight = rx * Math.sin(g.legSweep);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
g.kind = KIND_ELLIPSE;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function sizeLane(c) {
|
|
187
|
+
const lane = new Float32Array(c.count);
|
|
188
|
+
for (let i = 0; i < c.count; i++) {
|
|
189
|
+
lane[i] = sizeOf(c, i);
|
|
190
|
+
}
|
|
191
|
+
return lane;
|
|
192
|
+
}
|
|
193
|
+
const NO_VALUES = new Float32Array(0);
|
|
194
|
+
const NO_FEET = new Uint8Array(0);
|
|
195
|
+
// The region table the uniform writer takes, mutated in place per write so a
|
|
196
|
+
// frame allocates nothing per block.
|
|
197
|
+
const TABLE = Array.from({ length: LINK_MAX_REGIONS }, () => [0, 0, 0, 0]);
|
|
198
|
+
function writeEntry(entry, { anchorPx, anchorBp, signedPxPerBp }) {
|
|
199
|
+
const lo = anchorBp % 4096;
|
|
200
|
+
entry[0] = anchorPx;
|
|
201
|
+
entry[1] = anchorBp - lo;
|
|
202
|
+
entry[2] = lo;
|
|
203
|
+
entry[3] = signedPxPerBp;
|
|
204
|
+
return entry;
|
|
205
|
+
}
|
|
206
|
+
const OWN = [0, 0, 0, 0];
|
|
207
|
+
function tableEntry(region) {
|
|
208
|
+
return region ? writeEntry(OWN, region) : OWN.fill(0);
|
|
209
|
+
}
|
|
210
|
+
// Past float32's reach, so an unbounded edge never shortens a foot.
|
|
211
|
+
const UNBOUNDED_PX = 1e30;
|
|
212
|
+
const SPANS = Array.from({ length: LINK_MAX_REGIONS / 2 }, () => [0, 0, 0, 0]);
|
|
213
|
+
const OWN_SPAN = [0, 0, 0, 0];
|
|
214
|
+
function writeSpan(entry, at, region) {
|
|
215
|
+
entry[at] = region?.leftPx ?? -UNBOUNDED_PX;
|
|
216
|
+
entry[at + 1] = region?.rightPx ?? UNBOUNDED_PX;
|
|
217
|
+
return entry;
|
|
218
|
+
}
|
|
219
|
+
function fillTable(regions) {
|
|
220
|
+
const n = Math.min(regions.length, LINK_MAX_REGIONS);
|
|
221
|
+
for (let i = 0; i < n; i++) {
|
|
222
|
+
writeEntry(TABLE[i], regions[i]);
|
|
223
|
+
writeSpan(SPANS[i >> 1], (i & 1) === 0 ? 0 : 2, regions[i]);
|
|
224
|
+
}
|
|
225
|
+
return n;
|
|
226
|
+
}
|
|
227
|
+
// Canvas y of a point `up` px from the baseline on the drawn side.
|
|
228
|
+
function yAt(g, up) {
|
|
229
|
+
return g.baseY - g.ySign * up;
|
|
230
|
+
}
|
|
231
|
+
function lineStart(g) {
|
|
232
|
+
return (g.xPx + g.x2Px) / 2 - g.rx / 2;
|
|
233
|
+
}
|
|
234
|
+
// The visible part of a far circle's leg rising from `footX`, in canvas px,
|
|
235
|
+
// built from the foot outward with the half-angle identity as the shader
|
|
236
|
+
// does, so a radius past 1e6 px cancels nothing.
|
|
237
|
+
function legPoints(g, footX, legDir) {
|
|
238
|
+
const points = [];
|
|
239
|
+
for (let k = 0; k <= LEG_SEGMENTS; k++) {
|
|
240
|
+
const b = (k / LEG_SEGMENTS) * g.legSweep;
|
|
241
|
+
const sh = Math.sin(b / 2);
|
|
242
|
+
points.push({
|
|
243
|
+
x: footX + legDir * (-2 * g.rx * sh * sh),
|
|
244
|
+
y: yAt(g, Math.sin(b) * g.rx),
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
return points;
|
|
248
|
+
}
|
|
249
|
+
function tracePath(ctx, g) {
|
|
250
|
+
const { baseY } = g;
|
|
251
|
+
if (g.kind === KIND_STEM) {
|
|
252
|
+
ctx.moveTo(g.xPx, baseY);
|
|
253
|
+
ctx.lineTo(g.xPx, yAt(g, g.stemPx));
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (g.kind === KIND_LINE) {
|
|
257
|
+
const x = lineStart(g);
|
|
258
|
+
const y = yAt(g, g.ry);
|
|
259
|
+
ctx.moveTo(x, y);
|
|
260
|
+
ctx.lineTo(x + g.rx, y);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
const left = Math.min(g.xPx, g.x2Px);
|
|
264
|
+
const right = Math.max(g.xPx, g.x2Px);
|
|
265
|
+
if (g.kind === KIND_CIRCLE) {
|
|
266
|
+
for (const [footX, legDir] of [
|
|
267
|
+
[right, 1],
|
|
268
|
+
[left, -1],
|
|
269
|
+
]) {
|
|
270
|
+
const points = legPoints(g, footX, legDir);
|
|
271
|
+
ctx.moveTo(points[0].x, points[0].y);
|
|
272
|
+
for (let k = 1; k < points.length; k++) {
|
|
273
|
+
ctx.lineTo(points[k].x, points[k].y);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const mid = (left + right) / 2;
|
|
279
|
+
if (g.reverse) {
|
|
280
|
+
ctx.moveTo(mid + g.rx, baseY);
|
|
281
|
+
ctx.ellipse(mid, baseY, g.rx, g.ry, 0, 0, Math.PI);
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
ctx.moveTo(mid - g.rx, baseY);
|
|
285
|
+
ctx.ellipse(mid, baseY, g.rx, g.ry, 0, Math.PI, 2 * Math.PI);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// The ticks, a half stroke inside the band so one on its edge draws whole.
|
|
289
|
+
function footSegments(g) {
|
|
290
|
+
const y = yAt(g, g.strokePx / 2);
|
|
291
|
+
const segments = [];
|
|
292
|
+
if (g.foot1Len > 0) {
|
|
293
|
+
segments.push({ from: g.xPx, to: g.xPx + g.foot1Dir * g.foot1Len, y });
|
|
294
|
+
}
|
|
295
|
+
if (g.foot2Len > 0) {
|
|
296
|
+
segments.push({ from: g.x2Px, to: g.x2Px + g.foot2Dir * g.foot2Len, y });
|
|
297
|
+
}
|
|
298
|
+
return segments;
|
|
299
|
+
}
|
|
300
|
+
const svgNumber = (n) => Math.round(n * 100) / 100;
|
|
301
|
+
// The curve and its feet as an SVG path, traced by the painter's own
|
|
302
|
+
// `tracePath`. Every arc starts where the path already stands.
|
|
303
|
+
function svgPathOf(g) {
|
|
304
|
+
const parts = [];
|
|
305
|
+
const point = (x, y) => `${svgNumber(x)} ${svgNumber(y)}`;
|
|
306
|
+
tracePath({
|
|
307
|
+
moveTo: (x, y) => parts.push(`M${point(x, y)}`),
|
|
308
|
+
lineTo: (x, y) => parts.push(`L${point(x, y)}`),
|
|
309
|
+
ellipse: (cx, cy, rx, ry, _rotation, from, to) => {
|
|
310
|
+
const large = Math.abs(to - from) > Math.PI ? 1 : 0;
|
|
311
|
+
const sweep = to > from ? 1 : 0;
|
|
312
|
+
const end = point(cx + rx * Math.cos(to), cy + ry * Math.sin(to));
|
|
313
|
+
parts.push(`A${svgNumber(rx)} ${svgNumber(ry)} 0 ${large} ${sweep} ${end}`);
|
|
314
|
+
},
|
|
315
|
+
}, g);
|
|
316
|
+
for (const { from, to, y } of footSegments(g)) {
|
|
317
|
+
parts.push(`M${point(from, y)}L${point(to, y)}`);
|
|
318
|
+
}
|
|
319
|
+
return parts.join('');
|
|
320
|
+
}
|
|
321
|
+
function footBox({ from, to, y }, half) {
|
|
322
|
+
const left = Math.min(from, to);
|
|
323
|
+
return {
|
|
324
|
+
left: left - half,
|
|
325
|
+
top: y - half,
|
|
326
|
+
width: Math.abs(to - from) + 2 * half,
|
|
327
|
+
height: 2 * half,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
function union(a, b) {
|
|
331
|
+
const left = Math.min(a.left, b.left);
|
|
332
|
+
const top = Math.min(a.top, b.top);
|
|
333
|
+
return {
|
|
334
|
+
left,
|
|
335
|
+
top,
|
|
336
|
+
width: Math.max(a.left + a.width, b.left + b.width) - left,
|
|
337
|
+
height: Math.max(a.top + a.height, b.top + b.height) - top,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
function dashes(g) {
|
|
341
|
+
return g.kind === KIND_LINE || g.kind === KIND_STEM;
|
|
342
|
+
}
|
|
343
|
+
// The box from the baseline to `rise` px off it, padded by `pad`.
|
|
344
|
+
function riseBox(g, left, width, rise, pad) {
|
|
345
|
+
const top = g.reverse ? g.baseY - pad : g.baseY - rise - pad;
|
|
346
|
+
return { left, top, width, height: rise + 2 * pad };
|
|
347
|
+
}
|
|
348
|
+
function inkBox(g) {
|
|
349
|
+
const curve = curveBox(g);
|
|
350
|
+
const half = g.strokePx / 2;
|
|
351
|
+
return curve
|
|
352
|
+
? footSegments(g).reduce((box, f) => union(box, footBox(f, half)), curve)
|
|
353
|
+
: undefined;
|
|
354
|
+
}
|
|
355
|
+
function curveBox(g) {
|
|
356
|
+
if (g.kind === KIND_NONE) {
|
|
357
|
+
return undefined;
|
|
358
|
+
}
|
|
359
|
+
const half = g.strokePx / 2;
|
|
360
|
+
if (g.kind === KIND_STEM) {
|
|
361
|
+
return riseBox(g, g.xPx - half, g.strokePx, g.stemPx, half);
|
|
362
|
+
}
|
|
363
|
+
if (g.kind === KIND_LINE) {
|
|
364
|
+
return {
|
|
365
|
+
left: lineStart(g) - half,
|
|
366
|
+
top: yAt(g, g.ry) - half,
|
|
367
|
+
width: g.rx + g.strokePx,
|
|
368
|
+
height: g.strokePx,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
const left = Math.min(g.xPx, g.x2Px);
|
|
372
|
+
const right = Math.max(g.xPx, g.x2Px);
|
|
373
|
+
const rise = g.kind === KIND_CIRCLE ? g.legHeight : g.ry;
|
|
374
|
+
return riseBox(g, left - half, right - left + g.strokePx, rise, half);
|
|
375
|
+
}
|
|
376
|
+
// The nearest point of the drawn curve to (px, py), in canvas px, and how far
|
|
377
|
+
// the cursor is from it. Measured with the curve rising above its baseline:
|
|
378
|
+
// under a reversed scale the cursor is reflected there and the answer back.
|
|
379
|
+
function nearestOnCurve(g, px, py) {
|
|
380
|
+
const flip = (y) => (g.reverse ? 2 * g.baseY - y : y);
|
|
381
|
+
const rising = nearestRising(g, px, flip(py));
|
|
382
|
+
let near = { ...rising, y: flip(rising.y) };
|
|
383
|
+
for (const { from, to, y } of footSegments(g)) {
|
|
384
|
+
const x = Math.min(Math.max(from, to), Math.max(Math.min(from, to), px));
|
|
385
|
+
const dist = Math.hypot(px - x, py - y);
|
|
386
|
+
if (dist < near.dist) {
|
|
387
|
+
near = { x, y, dist };
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return near;
|
|
391
|
+
}
|
|
392
|
+
function nearestRising(g, px, py) {
|
|
393
|
+
const { baseY } = g;
|
|
394
|
+
if (g.kind === KIND_STEM) {
|
|
395
|
+
const y = Math.min(baseY, Math.max(baseY - g.stemPx, py));
|
|
396
|
+
return { x: g.xPx, y, dist: Math.hypot(px - g.xPx, py - y) };
|
|
397
|
+
}
|
|
398
|
+
if (g.kind === KIND_LINE) {
|
|
399
|
+
const start = lineStart(g);
|
|
400
|
+
const x = Math.min(start + g.rx, Math.max(start, px));
|
|
401
|
+
const y = baseY - g.ry;
|
|
402
|
+
return { x, y, dist: Math.hypot(px - x, py - y) };
|
|
403
|
+
}
|
|
404
|
+
const left = Math.min(g.xPx, g.x2Px);
|
|
405
|
+
const right = Math.max(g.xPx, g.x2Px);
|
|
406
|
+
if (g.kind === KIND_CIRCLE) {
|
|
407
|
+
let best;
|
|
408
|
+
for (const [footX, legDir] of [
|
|
409
|
+
[right, 1],
|
|
410
|
+
[left, -1],
|
|
411
|
+
]) {
|
|
412
|
+
const dist = distToWideCirclePx((px - footX) * legDir, py - baseY, g.rx);
|
|
413
|
+
if (!best || dist < best.dist) {
|
|
414
|
+
// The nearest point of the whole circle, then held to the leg the
|
|
415
|
+
// painter drew: from the foot up to the band's reach.
|
|
416
|
+
const cx = footX - legDir * g.rx;
|
|
417
|
+
const vx = px - cx;
|
|
418
|
+
const vy = py - baseY;
|
|
419
|
+
const len = Math.hypot(vx, vy) || 1;
|
|
420
|
+
let x = cx + (vx / len) * g.rx;
|
|
421
|
+
let y = baseY + (vy / len) * g.rx;
|
|
422
|
+
if (y >= baseY) {
|
|
423
|
+
x = footX;
|
|
424
|
+
y = baseY;
|
|
425
|
+
}
|
|
426
|
+
else if (y < baseY - g.legHeight) {
|
|
427
|
+
const sh = Math.sin(g.legSweep / 2);
|
|
428
|
+
x = footX + legDir * (-2 * g.rx * sh * sh);
|
|
429
|
+
y = baseY - g.legHeight;
|
|
430
|
+
}
|
|
431
|
+
best = { x, y, dist: Math.hypot(px - x, py - y) };
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return best;
|
|
435
|
+
}
|
|
436
|
+
const mid = (left + right) / 2;
|
|
437
|
+
if (py > baseY) {
|
|
438
|
+
const x = px < mid ? left : right;
|
|
439
|
+
return { x, y: baseY, dist: Math.hypot(px - x, py - baseY) };
|
|
440
|
+
}
|
|
441
|
+
const near = ellipseNearest(px - mid, py - baseY, g.rx, g.ry);
|
|
442
|
+
return { x: mid + near.x, y: baseY + near.y, dist: near.dist };
|
|
443
|
+
}
|
|
444
|
+
export const linkMark = {
|
|
445
|
+
id: 'link',
|
|
446
|
+
spansView: true,
|
|
447
|
+
pass: {
|
|
448
|
+
...slangPass({ id: 'link', mod: shader }),
|
|
449
|
+
pack: c => shader.packInstances({
|
|
450
|
+
x: c.x,
|
|
451
|
+
x2: c.x2,
|
|
452
|
+
x2Region: c.x2Region,
|
|
453
|
+
y: c.y ?? (c.count === 0 ? NO_VALUES : new Float32Array(c.count)),
|
|
454
|
+
size: sizeLane(c),
|
|
455
|
+
color: colorBits(c, c.count),
|
|
456
|
+
row: rowLane(c.row, c.count),
|
|
457
|
+
feet: c.feet ?? (c.count === 0 ? NO_FEET : new Uint8Array(c.count)),
|
|
458
|
+
}, c.count),
|
|
459
|
+
},
|
|
460
|
+
writeUniforms(scratch, _clip, block, frame, params) {
|
|
461
|
+
const { sizeScale } = params;
|
|
462
|
+
shader.writeUniforms(scratch, {
|
|
463
|
+
canvasHeight: frame.canvasHeight,
|
|
464
|
+
devicePixelRatio: getDpr(),
|
|
465
|
+
rowHeight: bandHeightPx(params, frame.canvasHeight),
|
|
466
|
+
rowOffsetPx: params.rowOffsetPx ?? 0,
|
|
467
|
+
reverse: params.reverse ? 1 : 0,
|
|
468
|
+
stemPx: params.stemPx ?? LINK_STEM_PX,
|
|
469
|
+
dashPx: params.strokeDash?.[0] ?? 0,
|
|
470
|
+
gapPx: params.strokeDash?.[1] ?? 0,
|
|
471
|
+
footPx: params.footPx ?? LINK_FOOT_PX,
|
|
472
|
+
curveSegments: curveSegments(params),
|
|
473
|
+
insetPx: params.insetPx ?? 0,
|
|
474
|
+
domainMin: params.domain[0],
|
|
475
|
+
domainMax: params.domain[1],
|
|
476
|
+
...valueScaleUniforms(params),
|
|
477
|
+
...rampUniforms(params.colorScale),
|
|
478
|
+
valued: params.valued ? 1 : 0,
|
|
479
|
+
linkShape: linkShapeCode(params.linkShape),
|
|
480
|
+
sizeMode: sizeScale ? LINK_SIZE_SCALED : LINK_SIZE_CONSTANT,
|
|
481
|
+
sizeConstantPx: params.sizePx,
|
|
482
|
+
sizeDomainMin: sizeScale?.domain[0] ?? 0,
|
|
483
|
+
sizeDomainMax: sizeScale?.domain[1] ?? 1,
|
|
484
|
+
sizeScaleType: sizeScale?.scale === 'log' ? SCALE_TYPE_LOG : 0,
|
|
485
|
+
sizeRangeMin: sizeScale?.range[0] ?? params.sizePx,
|
|
486
|
+
sizeRangeMax: sizeScale?.range[1] ?? params.sizePx,
|
|
487
|
+
canvasWidth: frame.canvasWidth,
|
|
488
|
+
regionCount: fillTable(params.regions),
|
|
489
|
+
zero: 0,
|
|
490
|
+
ownEntry: tableEntry(params.regions[block.displayedRegionIndex]),
|
|
491
|
+
ownSpan: writeSpan(OWN_SPAN, 0, params.regions[block.displayedRegionIndex]),
|
|
492
|
+
regionTable: TABLE,
|
|
493
|
+
regionSpan: SPANS,
|
|
494
|
+
rowTableKeys: rowTableKeys(params),
|
|
495
|
+
});
|
|
496
|
+
},
|
|
497
|
+
textures: rowTableTextures,
|
|
498
|
+
paintsBlock(block, _frame, params) {
|
|
499
|
+
return params.regions[block.displayedRegionIndex] !== undefined;
|
|
500
|
+
},
|
|
501
|
+
verticesPerInstance(_frame, params) {
|
|
502
|
+
return (curveSegments(params) + 1) * 2 + FOOT_STRIP_VERTS;
|
|
503
|
+
},
|
|
504
|
+
paintBlock(ctx, channels, block, frame, params) {
|
|
505
|
+
const { count } = channels;
|
|
506
|
+
if (count === 0) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
const color = paintColors(channels, count, params.colorScale);
|
|
510
|
+
const g = linkFrame(block, frame, params);
|
|
511
|
+
const dash = params.strokeDash ? [...params.strokeDash] : [];
|
|
512
|
+
ctx.lineCap = 'butt';
|
|
513
|
+
for (let i = 0; i < count; i++) {
|
|
514
|
+
if (!reachesX(channels, g, i, 0, frame.canvasWidth)) {
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
placeLink(channels, g, i);
|
|
518
|
+
if (g.kind === KIND_NONE) {
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
ctx.lineWidth = g.strokePx;
|
|
522
|
+
ctx.strokeStyle = abgrToCssRgba(rowColor(color[i], channels.row, i, g.table));
|
|
523
|
+
ctx.setLineDash(dashes(g) ? dash : []);
|
|
524
|
+
ctx.beginPath();
|
|
525
|
+
tracePath(ctx, g);
|
|
526
|
+
ctx.stroke();
|
|
527
|
+
const feet = footSegments(g);
|
|
528
|
+
if (feet.length > 0) {
|
|
529
|
+
ctx.setLineDash([]);
|
|
530
|
+
ctx.beginPath();
|
|
531
|
+
for (const { from, to, y } of feet) {
|
|
532
|
+
ctx.moveTo(from, y);
|
|
533
|
+
ctx.lineTo(to, y);
|
|
534
|
+
}
|
|
535
|
+
ctx.stroke();
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
ctx.setLineDash([]);
|
|
539
|
+
},
|
|
540
|
+
// The box the stroke lies in, the curve's extent padded by half the stroke,
|
|
541
|
+
// which the sweep holds the painting to; a highlight strokes the curve
|
|
542
|
+
// itself. The hit test below is the curve's own.
|
|
543
|
+
ink(channels, block, frame, params, i) {
|
|
544
|
+
const g = linkFrame(block, frame, params);
|
|
545
|
+
placeLink(channels, g, i);
|
|
546
|
+
const box = inkBox(g);
|
|
547
|
+
return (box && {
|
|
548
|
+
...box,
|
|
549
|
+
stroke: {
|
|
550
|
+
d: svgPathOf(g),
|
|
551
|
+
widthPx: g.strokePx,
|
|
552
|
+
originX: 0,
|
|
553
|
+
originY: 0,
|
|
554
|
+
},
|
|
555
|
+
});
|
|
556
|
+
},
|
|
557
|
+
hitNearest(channels, block, frame, params, xPx, yPx, candidates, maxDistSq) {
|
|
558
|
+
const g = linkFrame(block, frame, params);
|
|
559
|
+
const reach = Math.sqrt(maxDistSq);
|
|
560
|
+
return nearestInk(candidates, maxDistSq, i => {
|
|
561
|
+
if (!reachesX(channels, g, i, xPx - reach, xPx + reach)) {
|
|
562
|
+
return undefined;
|
|
563
|
+
}
|
|
564
|
+
placeLink(channels, g, i);
|
|
565
|
+
const box = inkBox(g);
|
|
566
|
+
if (!box ||
|
|
567
|
+
xPx < box.left - reach ||
|
|
568
|
+
xPx > box.left + box.width + reach ||
|
|
569
|
+
yPx < box.top - reach ||
|
|
570
|
+
yPx > box.top + box.height + reach) {
|
|
571
|
+
return undefined;
|
|
572
|
+
}
|
|
573
|
+
const near = nearestOnCurve(g, xPx, yPx);
|
|
574
|
+
const half = g.strokePx / 2;
|
|
575
|
+
if (near.dist <= half) {
|
|
576
|
+
return { x: xPx, y: yPx, distSq: 0 };
|
|
577
|
+
}
|
|
578
|
+
const t = half / near.dist;
|
|
579
|
+
const x = near.x + (xPx - near.x) * t;
|
|
580
|
+
const y = near.y + (yPx - near.y) * t;
|
|
581
|
+
return { x, y, distSq: (xPx - x) ** 2 + (yPx - y) ** 2 };
|
|
582
|
+
});
|
|
583
|
+
},
|
|
584
|
+
};
|
|
585
|
+
export { LINK_ELSEWHERE, LINK_NO_REGION };
|