@genome-spy/core 0.30.0 → 0.30.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +16373 -0
- package/dist/index.js +43 -43
- package/package.json +10 -7
- package/src/data/collector.js +0 -183
- package/src/data/collector.test.js +0 -84
- package/src/data/dataFlow.js +0 -148
- package/src/data/dataFlow.test.js +0 -5
- package/src/data/facetNode.js +0 -17
- package/src/data/flow.test.js +0 -72
- package/src/data/flowBatch.d.ts +0 -40
- package/src/data/flowNode.js +0 -283
- package/src/data/flowNode.test.js +0 -50
- package/src/data/flowOptimizer.js +0 -123
- package/src/data/flowOptimizer.test.js +0 -193
- package/src/data/flowTestUtils.js +0 -63
- package/src/data/formats/fasta.js +0 -32
- package/src/data/formats/fasta.test.js +0 -27
- package/src/data/sources/dataSource.js +0 -22
- package/src/data/sources/dataSourceFactory.js +0 -24
- package/src/data/sources/dataUtils.js +0 -78
- package/src/data/sources/dynamicCallbackSource.js +0 -57
- package/src/data/sources/dynamicSource.js +0 -37
- package/src/data/sources/inlineSource.js +0 -67
- package/src/data/sources/inlineSource.test.js +0 -56
- package/src/data/sources/namedSource.js +0 -79
- package/src/data/sources/sequenceSource.js +0 -46
- package/src/data/sources/sequenceSource.test.js +0 -46
- package/src/data/sources/urlSource.js +0 -74
- package/src/data/transforms/aggregate.js +0 -70
- package/src/data/transforms/clone.js +0 -40
- package/src/data/transforms/clone.test.js +0 -11
- package/src/data/transforms/coverage.js +0 -187
- package/src/data/transforms/coverage.test.js +0 -123
- package/src/data/transforms/filter.js +0 -37
- package/src/data/transforms/filter.test.js +0 -18
- package/src/data/transforms/filterScoredLabels.js +0 -134
- package/src/data/transforms/flattenCompressedExons.js +0 -57
- package/src/data/transforms/flattenDelimited.js +0 -74
- package/src/data/transforms/flattenDelimited.test.js +0 -87
- package/src/data/transforms/flattenSequence.js +0 -39
- package/src/data/transforms/flattenSequence.test.js +0 -34
- package/src/data/transforms/formula.js +0 -39
- package/src/data/transforms/formula.test.js +0 -19
- package/src/data/transforms/identifier.js +0 -108
- package/src/data/transforms/identifier.test.js +0 -83
- package/src/data/transforms/linearizeGenomicCoordinate.js +0 -101
- package/src/data/transforms/measureText.js +0 -44
- package/src/data/transforms/pileup.js +0 -128
- package/src/data/transforms/pileup.test.js +0 -70
- package/src/data/transforms/project.js +0 -41
- package/src/data/transforms/project.test.js +0 -32
- package/src/data/transforms/regexExtract.js +0 -61
- package/src/data/transforms/regexExtract.test.js +0 -67
- package/src/data/transforms/regexFold.js +0 -141
- package/src/data/transforms/regexFold.test.js +0 -160
- package/src/data/transforms/sample.js +0 -101
- package/src/data/transforms/sample.test.js +0 -38
- package/src/data/transforms/stack.js +0 -137
- package/src/data/transforms/stack.test.js +0 -91
- package/src/data/transforms/transformFactory.js +0 -60
- package/src/embedApi.d.ts +0 -67
- package/src/encoder/accessor.js +0 -82
- package/src/encoder/accessor.test.js +0 -47
- package/src/encoder/encoder.js +0 -394
- package/src/encoder/encoder.test.js +0 -98
- package/src/fonts/Lato-Regular.json +0 -1267
- package/src/fonts/Lato-Regular.png +0 -0
- package/src/fonts/OFL.txt +0 -93
- package/src/fonts/README.md +0 -3
- package/src/fonts/bmFont.d.ts +0 -58
- package/src/fonts/bmFontManager.js +0 -357
- package/src/fonts/bmFontMetrics.js +0 -108
- package/src/genome/genome.js +0 -317
- package/src/genome/genome.test.js +0 -188
- package/src/genome/genomeStore.js +0 -54
- package/src/genome/locusFormat.js +0 -31
- package/src/genome/scaleIndex.d.ts +0 -38
- package/src/genome/scaleIndex.js +0 -166
- package/src/genome/scaleIndex.test.js +0 -78
- package/src/genome/scaleLocus.d.ts +0 -11
- package/src/genome/scaleLocus.js +0 -108
- package/src/genome/scaleLocus.test.js +0 -4
- package/src/genomeSpy.js +0 -785
- package/src/gl/arrayBuilder.js +0 -199
- package/src/gl/dataToVertices.js +0 -636
- package/src/gl/includes/common.glsl +0 -63
- package/src/gl/includes/picking.fragment.glsl +0 -1
- package/src/gl/includes/picking.vertex.glsl +0 -27
- package/src/gl/includes/sampleFacet.glsl +0 -107
- package/src/gl/includes/scales.glsl +0 -112
- package/src/gl/link.fragment.glsl +0 -18
- package/src/gl/link.vertex.glsl +0 -111
- package/src/gl/point.fragment.glsl +0 -123
- package/src/gl/point.vertex.glsl +0 -129
- package/src/gl/rect.fragment.glsl +0 -51
- package/src/gl/rect.vertex.glsl +0 -114
- package/src/gl/rule.fragment.glsl +0 -52
- package/src/gl/rule.vertex.glsl +0 -89
- package/src/gl/text.fragment.glsl +0 -31
- package/src/gl/text.vertex.glsl +0 -246
- package/src/gl/webGLHelper.js +0 -504
- package/src/img/bowtie.svg +0 -1
- package/src/img/genomespy-favicon.svg +0 -34
- package/src/index.html +0 -11
- package/src/index.js +0 -128
- package/src/marks/link.js +0 -175
- package/src/marks/mark.js +0 -975
- package/src/marks/markUtils.js +0 -125
- package/src/marks/pointMark.js +0 -251
- package/src/marks/rectMark.js +0 -241
- package/src/marks/rule.js +0 -250
- package/src/marks/text.js +0 -278
- package/src/node_modules/.vitest/results.json +0 -1
- package/src/scale/colorUtils.js +0 -184
- package/src/scale/glslScaleGenerator.js +0 -502
- package/src/scale/scale.js +0 -451
- package/src/scale/scale.test.js +0 -324
- package/src/scale/ticks.js +0 -203
- package/src/scale/ticks.test.js +0 -40
- package/src/singlePageApp.js +0 -13
- package/src/spec/axis.d.ts +0 -296
- package/src/spec/channel.d.ts +0 -430
- package/src/spec/data.d.ts +0 -196
- package/src/spec/font.d.ts +0 -15
- package/src/spec/genome.d.ts +0 -35
- package/src/spec/mark.d.ts +0 -429
- package/src/spec/root.d.ts +0 -17
- package/src/spec/sampleView.d.ts +0 -180
- package/src/spec/scale.d.ts +0 -273
- package/src/spec/title.d.ts +0 -102
- package/src/spec/tooltip.d.ts +0 -9
- package/src/spec/transform.d.ts +0 -479
- package/src/spec/view.d.ts +0 -201
- package/src/styles/genome-spy.scss +0 -153
- package/src/tooltip/dataTooltipHandler.js +0 -64
- package/src/tooltip/refseqGeneTooltipHandler.js +0 -78
- package/src/tooltip/tooltipHandler.ts +0 -12
- package/src/types/filetypes.d.ts +0 -14
- package/src/types/flatqueue.d.ts +0 -53
- package/src/types/glsl.d.ts +0 -4
- package/src/types/internmap.d.ts +0 -22
- package/src/types/object.d.ts +0 -21
- package/src/types/vega-loader.d.ts +0 -1
- package/src/types/vega-scale.d.ts +0 -60
- package/src/utils/addBaseUrl.js +0 -19
- package/src/utils/addBaseUrl.test.js +0 -22
- package/src/utils/animator.js +0 -83
- package/src/utils/arrayUtils.js +0 -61
- package/src/utils/binnedIndex.js +0 -167
- package/src/utils/binnedIndex.test.js +0 -155
- package/src/utils/clamp.js +0 -8
- package/src/utils/cloner.js +0 -34
- package/src/utils/cloner.test.js +0 -24
- package/src/utils/coalesce.js +0 -11
- package/src/utils/coalesce.test.js +0 -16
- package/src/utils/concatIterables.js +0 -26
- package/src/utils/concatIterables.test.js +0 -8
- package/src/utils/debounce.js +0 -37
- package/src/utils/domainArray.js +0 -216
- package/src/utils/domainArray.test.js +0 -130
- package/src/utils/eerp.js +0 -13
- package/src/utils/expression.js +0 -32
- package/src/utils/field.js +0 -28
- package/src/utils/formatObject.js +0 -31
- package/src/utils/indexer.js +0 -43
- package/src/utils/indexer.test.js +0 -47
- package/src/utils/inertia.js +0 -124
- package/src/utils/interactionEvent.js +0 -33
- package/src/utils/iterateNestedMaps.js +0 -21
- package/src/utils/iterateNestedMaps.test.js +0 -33
- package/src/utils/kWayMerge.js +0 -42
- package/src/utils/kWayMerge.test.js +0 -26
- package/src/utils/layout/flexLayout.js +0 -368
- package/src/utils/layout/flexLayout.test.js +0 -311
- package/src/utils/layout/grid.js +0 -95
- package/src/utils/layout/grid.test.js +0 -71
- package/src/utils/layout/padding.js +0 -120
- package/src/utils/layout/point.js +0 -23
- package/src/utils/layout/rectangle.js +0 -288
- package/src/utils/layout/rectangle.test.js +0 -172
- package/src/utils/mergeObjects.js +0 -99
- package/src/utils/mergeObjects.test.js +0 -42
- package/src/utils/numberExtractor.js +0 -24
- package/src/utils/numberExtractor.test.js +0 -6
- package/src/utils/point.js +0 -14
- package/src/utils/propertyCacher.js +0 -70
- package/src/utils/propertyCacher.test.js +0 -85
- package/src/utils/propertyCoalescer.js +0 -42
- package/src/utils/propertyCoalescer.test.js +0 -22
- package/src/utils/reservationMap.js +0 -103
- package/src/utils/reservationMap.test.js +0 -20
- package/src/utils/scaleNull.js +0 -19
- package/src/utils/setOperations.js +0 -75
- package/src/utils/smoothstep.js +0 -10
- package/src/utils/throttle.js +0 -34
- package/src/utils/topK.js +0 -76
- package/src/utils/topK.test.js +0 -64
- package/src/utils/transition.js +0 -74
- package/src/utils/ui/tooltip.js +0 -189
- package/src/utils/url.js +0 -22
- package/src/utils/variableTools.js +0 -24
- package/src/utils/variableTools.test.js +0 -13
- package/src/view/axisResolution.js +0 -140
- package/src/view/axisResolution.test.js +0 -201
- package/src/view/axisView.js +0 -747
- package/src/view/concatView.js +0 -45
- package/src/view/containerView.js +0 -159
- package/src/view/facetView.js +0 -491
- package/src/view/flowBuilder.js +0 -367
- package/src/view/flowBuilder.test.js +0 -125
- package/src/view/gridView.js +0 -786
- package/src/view/implicitRootView.js +0 -14
- package/src/view/importView.js +0 -19
- package/src/view/layerView.js +0 -74
- package/src/view/rendering.d.ts +0 -44
- package/src/view/renderingContext/compositeViewRenderingContext.js +0 -51
- package/src/view/renderingContext/deferredViewRenderingContext.js +0 -176
- package/src/view/renderingContext/layoutRecorderViewRenderingContext.js +0 -128
- package/src/view/renderingContext/simpleViewRenderingContext.js +0 -64
- package/src/view/renderingContext/svgViewRenderingContext.js +0 -125
- package/src/view/renderingContext/viewRenderingContext.js +0 -41
- package/src/view/scaleResolution.js +0 -797
- package/src/view/scaleResolution.test.js +0 -572
- package/src/view/scaleResolutionApi.d.ts +0 -40
- package/src/view/testUtils.js +0 -51
- package/src/view/title.js +0 -165
- package/src/view/unitView.js +0 -382
- package/src/view/view.js +0 -612
- package/src/view/view.test.js +0 -214
- package/src/view/viewContext.d.ts +0 -62
- package/src/view/viewFactory.js +0 -181
- package/src/view/viewFactory.test.js +0 -17
- package/src/view/viewUtils.js +0 -327
- package/src/view/zoom.js +0 -89
package/src/gl/rect.vertex.glsl
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The vertex position wrt the rectangle specified by (x, x2, y, y2).
|
|
3
|
-
* [0, 0] = [x, y], [1, 1] = [x2, y2].
|
|
4
|
-
* The x or y component may contain fractional values if the rectangle
|
|
5
|
-
* have been tessellated.
|
|
6
|
-
*/
|
|
7
|
-
in vec2 frac;
|
|
8
|
-
|
|
9
|
-
/** Minimum size (width, height) of the displayed rectangle in pixels */
|
|
10
|
-
uniform vec2 uMinSize;
|
|
11
|
-
|
|
12
|
-
/** Minimum opacity for the size size clamping */
|
|
13
|
-
uniform float uMinOpacity;
|
|
14
|
-
|
|
15
|
-
/** top-right, bottom-right, top-left, bottom-left */
|
|
16
|
-
uniform vec4 uCornerRadii;
|
|
17
|
-
|
|
18
|
-
out lowp vec4 vFillColor;
|
|
19
|
-
out lowp vec4 vStrokeColor;
|
|
20
|
-
out float vHalfStrokeWidth;
|
|
21
|
-
out vec4 vCornerRadii;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
#if defined(ROUNDED_CORNERS) || defined(STROKED)
|
|
25
|
-
/** Position for SDF-strokes */
|
|
26
|
-
out vec2 vPosInPixels;
|
|
27
|
-
#endif
|
|
28
|
-
|
|
29
|
-
/** Size of the rect in pixels */
|
|
30
|
-
out vec2 vHalfSizeInPixels;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Clamps the minimumSize and returns an opacity that reflects the amount of clamping.
|
|
34
|
-
*/
|
|
35
|
-
float clampMinSize(inout float pos, float frac, float size, float minSize) {
|
|
36
|
-
if (minSize > 0.0 && abs(size) < minSize) {
|
|
37
|
-
pos += (frac - 0.5) * (minSize * sign(size) - size);
|
|
38
|
-
return abs(size) / minSize;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return 1.0;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
void sort(inout float a, inout float b) {
|
|
45
|
-
if (a > b) {
|
|
46
|
-
float tmp = b;
|
|
47
|
-
b = a;
|
|
48
|
-
a = tmp;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
void main(void) {
|
|
53
|
-
vec2 normalizedMinSize = uMinSize / uViewportSize;
|
|
54
|
-
|
|
55
|
-
float x = getScaled_x();
|
|
56
|
-
float x2 = getScaled_x2();
|
|
57
|
-
float y = getScaled_y();
|
|
58
|
-
float y2 = getScaled_y2();
|
|
59
|
-
|
|
60
|
-
sort(x, x2);
|
|
61
|
-
sort(y, y2);
|
|
62
|
-
|
|
63
|
-
// Clamp x to prevent precision artifacts when the scale is zoomed very close.
|
|
64
|
-
// TODO: clamp y as well
|
|
65
|
-
float clampMargin = 1.0;
|
|
66
|
-
vec2 pos1 = vec2(clamp(x, 0.0 - clampMargin, 1.0 + clampMargin), y);
|
|
67
|
-
vec2 pos2 = vec2(clamp(x2, 0.0 - clampMargin, 1.0 + clampMargin), y2);
|
|
68
|
-
|
|
69
|
-
vec2 size = pos2 - pos1;
|
|
70
|
-
|
|
71
|
-
if (size.x <= 0.0 || size.y <= 0.0) {
|
|
72
|
-
// Early exit. May increase performance or not...
|
|
73
|
-
gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
vec2 pos = pos1 + frac * size;
|
|
78
|
-
|
|
79
|
-
size.y *= getSampleFacetHeight(pos);
|
|
80
|
-
|
|
81
|
-
// Clamp to minimum size, optionally compensate with opacity
|
|
82
|
-
float opaFactor = uViewOpacity * max(uMinOpacity,
|
|
83
|
-
clampMinSize(pos.x, frac.x, size.x, normalizedMinSize.x) *
|
|
84
|
-
clampMinSize(pos.y, frac.y, size.y, normalizedMinSize.y));
|
|
85
|
-
|
|
86
|
-
pos = applySampleFacet(pos);
|
|
87
|
-
|
|
88
|
-
#if defined(ROUNDED_CORNERS) || defined(STROKED)
|
|
89
|
-
// Add an extra pixel to stroke width to accommodate edge antialiasing
|
|
90
|
-
float aaPadding = 1.0 / uDevicePixelRatio;
|
|
91
|
-
float strokeWidth = getScaled_strokeWidth();
|
|
92
|
-
float strokeOpacity = getScaled_strokeOpacity() * opaFactor;
|
|
93
|
-
|
|
94
|
-
vec2 centeredFrac = frac - 0.5;
|
|
95
|
-
vec2 expand = centeredFrac * (strokeWidth + aaPadding) / uViewportSize;
|
|
96
|
-
pos += expand;
|
|
97
|
-
|
|
98
|
-
vec2 sizeInPixels = size * uViewportSize;
|
|
99
|
-
vPosInPixels = (centeredFrac + expand / size) * sizeInPixels;
|
|
100
|
-
|
|
101
|
-
vHalfSizeInPixels = sizeInPixels / 2.0;
|
|
102
|
-
|
|
103
|
-
vCornerRadii = min(uCornerRadii, min(vHalfSizeInPixels.x, vHalfSizeInPixels.y));
|
|
104
|
-
vHalfStrokeWidth = strokeWidth / 2.0;
|
|
105
|
-
vStrokeColor = vec4(getScaled_stroke() * strokeOpacity, strokeOpacity);
|
|
106
|
-
#endif
|
|
107
|
-
|
|
108
|
-
gl_Position = unitToNdc(pos);
|
|
109
|
-
|
|
110
|
-
float fillOpacity = getScaled_fillOpacity() * opaFactor;
|
|
111
|
-
vFillColor = vec4(getScaled_fill() * fillOpacity, fillOpacity);
|
|
112
|
-
|
|
113
|
-
setupPicking();
|
|
114
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
// Line ending
|
|
2
|
-
const int BUTT = 0;
|
|
3
|
-
const int SQUARE = 1;
|
|
4
|
-
const int ROUND = 2;
|
|
5
|
-
|
|
6
|
-
uniform sampler2D uDashTexture;
|
|
7
|
-
uniform float uDashTextureSize;
|
|
8
|
-
uniform float uStrokeDashOffset;
|
|
9
|
-
uniform lowp int uStrokeCap;
|
|
10
|
-
|
|
11
|
-
in vec4 vColor;
|
|
12
|
-
in float vSize;
|
|
13
|
-
|
|
14
|
-
/** Position on the rule along its length in pixels */
|
|
15
|
-
in vec2 vPosInPixels;
|
|
16
|
-
in float vNormalLengthInPixels;
|
|
17
|
-
|
|
18
|
-
out lowp vec4 fragColor;
|
|
19
|
-
|
|
20
|
-
void main(void) {
|
|
21
|
-
float dpr = uDevicePixelRatio;
|
|
22
|
-
|
|
23
|
-
float distanceFromEnd = -min(vPosInPixels[0], vPosInPixels[1]);
|
|
24
|
-
float distance; // from the rule centerline or end
|
|
25
|
-
if (distanceFromEnd > 0.0 && uStrokeCap == ROUND) {
|
|
26
|
-
// round cap
|
|
27
|
-
distance = length(vec2(distanceFromEnd, vNormalLengthInPixels));
|
|
28
|
-
} else {
|
|
29
|
-
distance = abs(vNormalLengthInPixels);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Use a signed distance field to implement edge antialiasing
|
|
33
|
-
float opacity = clamp(((vSize / 2.0 - distance) * dpr), -0.5, 0.5) + 0.5;
|
|
34
|
-
|
|
35
|
-
if (uDashTextureSize > 0.0) {
|
|
36
|
-
float pos = (vPosInPixels[0] + uStrokeDashOffset) * dpr;
|
|
37
|
-
float floored = floor(pos);
|
|
38
|
-
vec2 texelPositions = (floored + vec2(0.5, 1.5)) / dpr / uDashTextureSize;
|
|
39
|
-
|
|
40
|
-
// Do antialiasing
|
|
41
|
-
opacity *= mix(
|
|
42
|
-
texture(uDashTexture, vec2(texelPositions[0], 0)).r,
|
|
43
|
-
texture(uDashTexture, vec2(texelPositions[1], 0)).r,
|
|
44
|
-
clamp((pos - floored), 0.0, 1.0));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
fragColor = vColor * opacity;
|
|
48
|
-
|
|
49
|
-
if (uPickingEnabled) {
|
|
50
|
-
fragColor = vPickingColor;
|
|
51
|
-
}
|
|
52
|
-
}
|
package/src/gl/rule.vertex.glsl
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
// Line caps
|
|
2
|
-
const int BUTT = 0;
|
|
3
|
-
const int SQUARE = 1;
|
|
4
|
-
const int ROUND = 2;
|
|
5
|
-
|
|
6
|
-
/** Position along the rule */
|
|
7
|
-
in float pos;
|
|
8
|
-
|
|
9
|
-
/** Which side of the stroke: -0.5 or 0.5 */
|
|
10
|
-
in float side;
|
|
11
|
-
|
|
12
|
-
/** Minimum rule length in pixels */
|
|
13
|
-
uniform float uMinLength;
|
|
14
|
-
|
|
15
|
-
uniform mediump float uDashTextureSize;
|
|
16
|
-
uniform lowp int uStrokeCap;
|
|
17
|
-
|
|
18
|
-
out vec4 vColor;
|
|
19
|
-
|
|
20
|
-
/** Stroke width */
|
|
21
|
-
out float vSize;
|
|
22
|
-
|
|
23
|
-
/** The distance from the line center to the direction of normal in pixels */
|
|
24
|
-
out float vNormalLengthInPixels;
|
|
25
|
-
|
|
26
|
-
/** Distances from the line endings. Used for rendering the round caps and dashes */
|
|
27
|
-
out highp vec2 vPosInPixels;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
void main(void) {
|
|
31
|
-
float pixelSize = 1.0 / uDevicePixelRatio;
|
|
32
|
-
|
|
33
|
-
// Stroke width in pixels
|
|
34
|
-
float size = getScaled_size();
|
|
35
|
-
float opacity = getScaled_opacity() * uViewOpacity;
|
|
36
|
-
|
|
37
|
-
// Avoid artifacts in very thin lines by clamping the size and adjusting opacity respectively
|
|
38
|
-
if (size < pixelSize) {
|
|
39
|
-
opacity *= size / pixelSize;
|
|
40
|
-
size = pixelSize;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
vec2 a = applySampleFacet(vec2(getScaled_x(), getScaled_y()));
|
|
44
|
-
vec2 b = applySampleFacet(vec2(getScaled_x2(), getScaled_y2()));
|
|
45
|
-
|
|
46
|
-
vec2 tangent = b - a;
|
|
47
|
-
|
|
48
|
-
float offset = 0.0;
|
|
49
|
-
float relativeDiff = 0.0;
|
|
50
|
-
if (uMinLength > 0.0 || uStrokeCap != BUTT) {
|
|
51
|
-
float len = length(tangent * uViewportSize);
|
|
52
|
-
|
|
53
|
-
// Elongate to reach the minimum length.
|
|
54
|
-
// The length difference in pixels
|
|
55
|
-
float diff = max(0.0, uMinLength - len);
|
|
56
|
-
|
|
57
|
-
// Add line caps
|
|
58
|
-
if (uStrokeCap != BUTT) {
|
|
59
|
-
diff += size;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
relativeDiff = diff / len;
|
|
63
|
-
offset = relativeDiff * (pos - 0.5);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Apply caps and minimum length by spreading the vertices along the tangent
|
|
67
|
-
vec2 p = pos < 1.0
|
|
68
|
-
? a + tangent * (pos + offset)
|
|
69
|
-
: b + tangent * offset;
|
|
70
|
-
|
|
71
|
-
// Add an extra pixel to stroke width to accommodate edge antialiasing
|
|
72
|
-
float aaPadding = pixelSize;
|
|
73
|
-
|
|
74
|
-
// Extrude
|
|
75
|
-
vec2 normal = normalize(vec2(-tangent.y, tangent.x) / uViewportSize);
|
|
76
|
-
p += normal * side * (size + aaPadding) / uViewportSize;
|
|
77
|
-
|
|
78
|
-
gl_Position = unitToNdc(p);
|
|
79
|
-
|
|
80
|
-
vColor = vec4(getScaled_color() * opacity, opacity);
|
|
81
|
-
vSize = size;
|
|
82
|
-
vNormalLengthInPixels = side * (size + aaPadding);
|
|
83
|
-
|
|
84
|
-
// TODO: Here's a precision problem that breaks round caps when zoomed in enough
|
|
85
|
-
vPosInPixels = vec2(pos, (1.0 - pos)) * (1.0 + relativeDiff) * length(tangent * uViewportSize) -
|
|
86
|
-
vec2(uStrokeCap != BUTT ? size / 2.0 : 0.0);
|
|
87
|
-
|
|
88
|
-
setupPicking();
|
|
89
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
uniform sampler2D uTexture;
|
|
2
|
-
|
|
3
|
-
in vec2 vTexCoord;
|
|
4
|
-
in float vEdgeFadeOpacity;
|
|
5
|
-
in vec4 vColor;
|
|
6
|
-
in float vSlope;
|
|
7
|
-
|
|
8
|
-
out lowp vec4 fragColor;
|
|
9
|
-
|
|
10
|
-
float median(float r, float g, float b) {
|
|
11
|
-
return max(min(r, g), min(max(r, g), b));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
void main() {
|
|
15
|
-
// TODO: Really small text should fall back to normal (non-SDF) texture that can be mip-mapped.
|
|
16
|
-
// Currently small text has severe aliasing artifacts.
|
|
17
|
-
|
|
18
|
-
vec3 c = texture(uTexture, vTexCoord).rgb;
|
|
19
|
-
|
|
20
|
-
float sigDist = 1.0 - median(c.r, c.g, c.b);
|
|
21
|
-
float opa = clamp((sigDist - 0.5) * vSlope + 0.5, 0.0, 1.0);
|
|
22
|
-
|
|
23
|
-
// Raise to the power of 2.2 to do some cheap gamma correction
|
|
24
|
-
opa *= pow(clamp(vEdgeFadeOpacity, 0.0, 1.0), 2.2);
|
|
25
|
-
|
|
26
|
-
fragColor = vColor * opa;
|
|
27
|
-
|
|
28
|
-
if (uPickingEnabled) {
|
|
29
|
-
fragColor = vPickingColor;
|
|
30
|
-
}
|
|
31
|
-
}
|
package/src/gl/text.vertex.glsl
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
uniform float uSdfNumerator;
|
|
2
|
-
|
|
3
|
-
uniform vec2 uD; // dx & dy
|
|
4
|
-
|
|
5
|
-
in mediump vec2 vertexCoord;
|
|
6
|
-
in lowp vec2 textureCoord;
|
|
7
|
-
|
|
8
|
-
uniform vec4 uViewportEdgeFadeWidth;
|
|
9
|
-
uniform vec4 uViewportEdgeFadeDistance;
|
|
10
|
-
|
|
11
|
-
uniform bool uSqueeze;
|
|
12
|
-
uniform bool uLogoLetter;
|
|
13
|
-
|
|
14
|
-
// Width of the text (all letters)
|
|
15
|
-
in float width;
|
|
16
|
-
|
|
17
|
-
// x: -1, 0, 1 = left, center, right
|
|
18
|
-
// y: -1, 0, 1 = top, middle, bottom
|
|
19
|
-
uniform ivec2 uAlign;
|
|
20
|
-
|
|
21
|
-
#ifdef x2_DEFINED
|
|
22
|
-
uniform float uPaddingX;
|
|
23
|
-
uniform bool uFlushX;
|
|
24
|
-
#endif
|
|
25
|
-
|
|
26
|
-
#ifdef y2_DEFINED
|
|
27
|
-
uniform float uPaddingY;
|
|
28
|
-
uniform bool uFlushY;
|
|
29
|
-
#endif
|
|
30
|
-
|
|
31
|
-
out vec2 vTexCoord;
|
|
32
|
-
out vec4 vColor;
|
|
33
|
-
out float vSlope;
|
|
34
|
-
out float vEdgeFadeOpacity;
|
|
35
|
-
|
|
36
|
-
struct RangeResult {
|
|
37
|
-
float pos;
|
|
38
|
-
float scale;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
float minValue(vec4 v) {
|
|
42
|
-
return min(min(v.x, v.y), min(v.z, v.w));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
float maxValue(vec4 v) {
|
|
46
|
-
return max(max(v.x, v.y), max(v.z, v.w));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* All measures are in [0, 1]
|
|
51
|
-
*/
|
|
52
|
-
RangeResult positionInsideRange(float a, float b, float width, float padding,
|
|
53
|
-
int align, bool flush) {
|
|
54
|
-
float span = b - a;
|
|
55
|
-
float paddedWidth = width + 2.0 * padding;
|
|
56
|
-
|
|
57
|
-
// Is the text clearly outside the viewport
|
|
58
|
-
if (a > 1.0 || b < 0.0) {
|
|
59
|
-
return RangeResult(0.0, 0.0);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// How much extra space we have for adjusting the position so that the
|
|
63
|
-
// text stays inside the range.
|
|
64
|
-
float extra = max(0.0, span - paddedWidth);
|
|
65
|
-
|
|
66
|
-
float pos;
|
|
67
|
-
|
|
68
|
-
// Align the text and try to keep it inside the range and the viewport
|
|
69
|
-
if (align == 0) {
|
|
70
|
-
float centre = a + b;
|
|
71
|
-
|
|
72
|
-
if (flush) {
|
|
73
|
-
float leftOver = max(0.0, paddedWidth - centre);
|
|
74
|
-
centre += min(leftOver, extra);
|
|
75
|
-
|
|
76
|
-
float rightOver = max(0.0, paddedWidth + centre - 2.0);
|
|
77
|
-
centre -= min(rightOver, extra);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
pos = centre / 2.0;
|
|
81
|
-
|
|
82
|
-
} else if (align < 0) {
|
|
83
|
-
float edge = a;
|
|
84
|
-
|
|
85
|
-
if (flush) {
|
|
86
|
-
float over = max(0.0, -edge);
|
|
87
|
-
edge += min(over, extra);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
pos = edge + padding;
|
|
91
|
-
|
|
92
|
-
} else {
|
|
93
|
-
float edge = b;
|
|
94
|
-
|
|
95
|
-
if (flush) {
|
|
96
|
-
float over = max(0.0, edge - 1.0);
|
|
97
|
-
edge -= min(over, extra);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// TODO: If the text spans the whole viewport, try to keep it centered if possible.
|
|
101
|
-
|
|
102
|
-
pos = edge - padding;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// How the text should be scaled to make it fit inside the range (if it didn't fit).
|
|
106
|
-
float scale = clamp((span - padding) / paddedWidth, 0.0, 1.0);
|
|
107
|
-
|
|
108
|
-
// TODO: Fix padding in scale factor. Padding should stay constant
|
|
109
|
-
return RangeResult(pos, scale);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
vec2 calculateRotatedDimensions(float width, mat2 rotationMatrix) {
|
|
113
|
-
vec2 a = abs(rotationMatrix * vec2(width / 2.0, 0.5));
|
|
114
|
-
vec2 b = abs(rotationMatrix * vec2(width / 2.0, -0.5));
|
|
115
|
-
return vec2(max(a.x, b.x), max(a.y, b.y)) * 2.0;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/** Needed when using ranged text */
|
|
119
|
-
ivec2 fixAlignForAngle(ivec2 align, float angleInDegrees) {
|
|
120
|
-
float a = mod(angleInDegrees + 45.0, 360.0);
|
|
121
|
-
int x = align.x;
|
|
122
|
-
int y = -align.y;
|
|
123
|
-
|
|
124
|
-
// TODO: Optimize by avoiding branching
|
|
125
|
-
if (a < 90.0) {
|
|
126
|
-
return ivec2(x, y);
|
|
127
|
-
} else if (a < 180.0) {
|
|
128
|
-
return ivec2(y, -x);
|
|
129
|
-
} else if (a < 270.0) {
|
|
130
|
-
return ivec2(-x, y);
|
|
131
|
-
} else {
|
|
132
|
-
return ivec2(-y, x);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
void main(void) {
|
|
137
|
-
float opacity = getScaled_opacity() * uViewOpacity;
|
|
138
|
-
vec2 size = vec2(getScaled_size());
|
|
139
|
-
float x = getScaled_x();
|
|
140
|
-
float y = getScaled_y();
|
|
141
|
-
|
|
142
|
-
float scale = 1.0;
|
|
143
|
-
|
|
144
|
-
float angleInDegrees = getScaled_angle();
|
|
145
|
-
float angle = -angleInDegrees * PI / 180.0;
|
|
146
|
-
|
|
147
|
-
float sinTheta = sin(angle);
|
|
148
|
-
float cosTheta = cos(angle);
|
|
149
|
-
mat2 rotationMatrix = mat2(cosTheta, sinTheta, -sinTheta, cosTheta);
|
|
150
|
-
|
|
151
|
-
vec2 flushSize = calculateRotatedDimensions(width, rotationMatrix);
|
|
152
|
-
|
|
153
|
-
#if defined(x2_DEFINED) || defined(y2_DEFINED)
|
|
154
|
-
ivec2 align = fixAlignForAngle(uAlign, angleInDegrees);
|
|
155
|
-
#else
|
|
156
|
-
ivec2 align = uAlign;
|
|
157
|
-
#endif
|
|
158
|
-
|
|
159
|
-
#ifdef x2_DEFINED
|
|
160
|
-
float x2 = getScaled_x2();
|
|
161
|
-
|
|
162
|
-
if (uLogoLetter) {
|
|
163
|
-
size.x = (x2 - x) * uViewportSize.x;
|
|
164
|
-
x += (x2 - x) / 2.0;
|
|
165
|
-
|
|
166
|
-
} else {
|
|
167
|
-
float x2 = getScaled_x2();
|
|
168
|
-
RangeResult result = positionInsideRange(
|
|
169
|
-
min(x, x2), max(x, x2),
|
|
170
|
-
size.x * scale * flushSize.x / uViewportSize.x, uPaddingX / uViewportSize.x,
|
|
171
|
-
align.x, uFlushX);
|
|
172
|
-
|
|
173
|
-
x = result.pos;
|
|
174
|
-
scale *= result.scale;
|
|
175
|
-
}
|
|
176
|
-
#endif
|
|
177
|
-
|
|
178
|
-
// Position of the text origo
|
|
179
|
-
vec2 pos = applySampleFacet(vec2(x, y));
|
|
180
|
-
|
|
181
|
-
#ifdef y2_DEFINED
|
|
182
|
-
float y2 = getScaled_y2();
|
|
183
|
-
vec2 pos2 = applySampleFacet(vec2(x, y2));
|
|
184
|
-
|
|
185
|
-
if (uLogoLetter) {
|
|
186
|
-
size.y = (pos2.y - pos.y) * uViewportSize.y;
|
|
187
|
-
pos.y += (pos2.y - pos.y) / 2.0;
|
|
188
|
-
|
|
189
|
-
} else {
|
|
190
|
-
RangeResult result = positionInsideRange(
|
|
191
|
-
min(pos.y, pos2.y), max(pos.y, pos2.y),
|
|
192
|
-
size.y * scale * flushSize.y / uViewportSize.y, uPaddingY / uViewportSize.y,
|
|
193
|
-
align.y, uFlushY);
|
|
194
|
-
|
|
195
|
-
pos.y = result.pos;
|
|
196
|
-
scale *= result.scale;
|
|
197
|
-
}
|
|
198
|
-
#endif
|
|
199
|
-
|
|
200
|
-
if (scale < 1.0) {
|
|
201
|
-
if (uSqueeze) {
|
|
202
|
-
vec2 scaleFadeExtent = vec2(3.0, 6.0) / size;
|
|
203
|
-
|
|
204
|
-
if (scale < scaleFadeExtent[0]) {
|
|
205
|
-
gl_Position = vec4(0.0);
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
size *= scale;
|
|
210
|
-
opacity *= linearstep(scaleFadeExtent[0], scaleFadeExtent[1], scale);
|
|
211
|
-
|
|
212
|
-
} else if (scale < 1.0) {
|
|
213
|
-
// Eliminate the text
|
|
214
|
-
gl_Position = vec4(0.0);
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Position of the character vertex in relation to the text origo
|
|
220
|
-
vec2 charPos = rotationMatrix * (vertexCoord * size + uD);
|
|
221
|
-
|
|
222
|
-
// Position of the character vertex inside the unit viewport
|
|
223
|
-
vec2 unitPos = pos + charPos / uViewportSize;
|
|
224
|
-
|
|
225
|
-
gl_Position = unitToNdc(unitPos);
|
|
226
|
-
|
|
227
|
-
// Controls antialiasing of the SDF
|
|
228
|
-
vSlope = max(1.0, min(size.x, size.y) / uSdfNumerator);
|
|
229
|
-
|
|
230
|
-
vColor = vec4(getScaled_color() * opacity, opacity);
|
|
231
|
-
|
|
232
|
-
vTexCoord = textureCoord;
|
|
233
|
-
|
|
234
|
-
// Edge fading. The implementation is simplistic and fails with primitives that
|
|
235
|
-
// span the whole viewport. However, it works just fine with reasonable font sizes.
|
|
236
|
-
// x: top, y: right, z: bottom, w: left
|
|
237
|
-
if (maxValue(uViewportEdgeFadeDistance) > -pow(10.0, 10.0)) { // -Infinity would be nice
|
|
238
|
-
vEdgeFadeOpacity = minValue(
|
|
239
|
-
((vec4(1.0, 1.0, 0.0, 0.0) + vec4(-1.0, -1.0, 1.0, 1.0) * unitPos.yxyx) *
|
|
240
|
-
uViewportSize.yxyx - uViewportEdgeFadeDistance) / uViewportEdgeFadeWidth);
|
|
241
|
-
} else {
|
|
242
|
-
vEdgeFadeOpacity = 1.0;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
setupPicking();
|
|
246
|
-
}
|