gladly-plot 0.0.1

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.
@@ -0,0 +1,107 @@
1
+ import { LayerType } from "./LayerType.js"
2
+ import { AXES } from "./AxisRegistry.js"
3
+ import { registerLayerType } from "./LayerTypeRegistry.js"
4
+
5
+ export const scatterLayerType = new LayerType({
6
+ name: "scatter",
7
+
8
+ getAxisConfig: function(parameters) {
9
+ const { xData, yData, vData, xAxis, yAxis } = parameters
10
+ return {
11
+ xAxis,
12
+ xAxisQuantityKind: xData,
13
+ yAxis,
14
+ yAxisQuantityKind: yData,
15
+ colorAxisQuantityKinds: [vData],
16
+ }
17
+ },
18
+
19
+ vert: `
20
+ precision mediump float;
21
+ attribute float x;
22
+ attribute float y;
23
+ attribute float color_data;
24
+ uniform vec2 xDomain;
25
+ uniform vec2 yDomain;
26
+ uniform float xScaleType;
27
+ uniform float yScaleType;
28
+ varying float value;
29
+ void main() {
30
+ float nx = normalize_axis(x, xDomain, xScaleType);
31
+ float ny = normalize_axis(y, yDomain, yScaleType);
32
+ gl_Position = vec4(nx*2.0-1.0, ny*2.0-1.0, 0, 1);
33
+ gl_PointSize = 4.0;
34
+ value = color_data;
35
+ }
36
+ `,
37
+ frag: `
38
+ precision mediump float;
39
+ uniform int colorscale;
40
+ uniform vec2 color_range;
41
+ uniform float color_scale_type;
42
+ varying float value;
43
+ void main() {
44
+ gl_FragColor = map_color_s(colorscale, color_range, value, color_scale_type);
45
+ }
46
+ `,
47
+ schema: (data) => {
48
+ const dataProperties = data ? Object.keys(data) : []
49
+ return {
50
+ $schema: "https://json-schema.org/draft/2020-12/schema",
51
+ type: "object",
52
+ properties: {
53
+ xData: {
54
+ type: "string",
55
+ enum: dataProperties,
56
+ description: "Property name in data object for x coordinates"
57
+ },
58
+ yData: {
59
+ type: "string",
60
+ enum: dataProperties,
61
+ description: "Property name in data object for y coordinates"
62
+ },
63
+ vData: {
64
+ type: "string",
65
+ enum: dataProperties,
66
+ description: "Property name in data object for color values; also used as the color axis quantity kind"
67
+ },
68
+ xAxis: {
69
+ type: "string",
70
+ enum: AXES.filter(a => a.includes("x")),
71
+ default: "xaxis_bottom",
72
+ description: "Which x-axis to use for this layer"
73
+ },
74
+ yAxis: {
75
+ type: "string",
76
+ enum: AXES.filter(a => a.includes("y")),
77
+ default: "yaxis_left",
78
+ description: "Which y-axis to use for this layer"
79
+ }
80
+ },
81
+ required: ["xData", "yData", "vData"]
82
+ }
83
+ },
84
+ createLayer: function(parameters, data) {
85
+ const { xData, yData, vData } = parameters
86
+
87
+ const x = data[xData]
88
+ const y = data[yData]
89
+ const v = data[vData]
90
+
91
+ if (!x) throw new Error(`Data property '${xData}' not found in data object`)
92
+ if (!y) throw new Error(`Data property '${yData}' not found in data object`)
93
+ if (!v) throw new Error(`Data property '${vData}' not found in data object`)
94
+
95
+ return [{
96
+ attributes: { x, y, [vData]: v },
97
+ uniforms: {},
98
+ nameMap: {
99
+ [vData]: 'color_data',
100
+ [`colorscale_${vData}`]: 'colorscale',
101
+ [`color_range_${vData}`]: 'color_range',
102
+ [`color_scale_type_${vData}`]: 'color_scale_type',
103
+ },
104
+ }]
105
+ }
106
+ })
107
+ registerLayerType("scatter", scatterLayerType)
package/src/index.js ADDED
@@ -0,0 +1,21 @@
1
+ export { LayerType } from "./LayerType.js"
2
+ export { Layer } from "./Layer.js"
3
+ export { AxisRegistry, AXES } from "./AxisRegistry.js"
4
+ export { ColorAxisRegistry } from "./ColorAxisRegistry.js"
5
+ export { FilterAxisRegistry, buildFilterGlsl } from "./FilterAxisRegistry.js"
6
+ export { Plot } from "./Plot.js"
7
+ export { scatterLayerType } from "./ScatterLayer.js"
8
+ export { registerLayerType, getLayerType, getRegisteredLayerTypes } from "./LayerTypeRegistry.js"
9
+ export { registerAxisQuantityKind, getAxisQuantityKind, getRegisteredAxisQuantityKinds } from "./AxisQuantityKindRegistry.js"
10
+ export { registerColorscale, getRegisteredColorscales, getColorscaleIndex, buildColorGlsl } from "./ColorscaleRegistry.js"
11
+ export { Axis } from "./Axis.js"
12
+ export { linkAxes } from "./AxisLink.js"
13
+ export { Colorbar } from "./Colorbar.js"
14
+ export { colorbarLayerType } from "./ColorbarLayer.js"
15
+ export { Float } from "./Float.js"
16
+ export { Filterbar } from "./Filterbar.js"
17
+ export { filterbarLayerType } from "./FilterbarLayer.js"
18
+ export { FilterbarFloat } from "./FilterbarFloat.js"
19
+
20
+ // Register all matplotlib colorscales (side-effect import)
21
+ import "./MatplotlibColorscales.js"