vega2ol 1.1.3 ā 1.1.5
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/main.js +13 -0
- package/dist/tests/test-basic.js +16 -0
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -51,6 +51,7 @@ const FUNCTION_MAPPING = {
|
|
|
51
51
|
atan: "atan",
|
|
52
52
|
atan2: "atan",
|
|
53
53
|
clamp: "clamp",
|
|
54
|
+
rgb: "rgb",
|
|
54
55
|
};
|
|
55
56
|
/**
|
|
56
57
|
* Custom error class for Vega2OL transpilation errors
|
|
@@ -210,6 +211,18 @@ class VegaToOLVisitor {
|
|
|
210
211
|
throw new Vega2OLError(`indexof is only supported in the pattern 'indexof(array, value) != -1' (or '== -1'), ` +
|
|
211
212
|
`it cannot be used as a standalone expression in OpenLayers`);
|
|
212
213
|
}
|
|
214
|
+
// rgb(r, g, b[, opacity]) ā OL ['color', r, g, b, a].
|
|
215
|
+
if (funcName.toLowerCase() === "rgb" &&
|
|
216
|
+
(args.length === 3 || args.length === 4)) {
|
|
217
|
+
const [r, g, b, a] = args;
|
|
218
|
+
return [
|
|
219
|
+
"color",
|
|
220
|
+
this.visit(r),
|
|
221
|
+
this.visit(g),
|
|
222
|
+
this.visit(b),
|
|
223
|
+
a ? this.visit(a) : 1,
|
|
224
|
+
];
|
|
225
|
+
}
|
|
213
226
|
const olFunc = FUNCTION_MAPPING[funcName.toLowerCase()];
|
|
214
227
|
if (!olFunc) {
|
|
215
228
|
throw new Vega2OLError(`Unsupported function: ${funcName}`);
|
package/dist/tests/test-basic.js
CHANGED
|
@@ -170,6 +170,22 @@ async function runTests() {
|
|
|
170
170
|
passed++;
|
|
171
171
|
else
|
|
172
172
|
failed++;
|
|
173
|
+
if (assertEqual(await vega2ol("rgb(255, 0, 0)"), ["color", 255, 0, 0, 1], "rgb() with 3 numeric literals, default opacity"))
|
|
174
|
+
passed++;
|
|
175
|
+
else
|
|
176
|
+
failed++;
|
|
177
|
+
if (assertEqual(await vega2ol("rgb(255, 0, 0, 0.5)"), ["color", 255, 0, 0, 0.5], "rgb() with explicit opacity"))
|
|
178
|
+
passed++;
|
|
179
|
+
else
|
|
180
|
+
failed++;
|
|
181
|
+
if (assertEqual(await vega2ol("rgb(datum.r, datum.g, datum.b)"), ["color", ["get", "r"], ["get", "g"], ["get", "b"], 1], "rgb() with dynamic field args, default opacity"))
|
|
182
|
+
passed++;
|
|
183
|
+
else
|
|
184
|
+
failed++;
|
|
185
|
+
if (assertEqual(await vega2ol("rgb(sqrt(50), 0, 0, 0.5)"), ["color", ["sqrt", 50], 0, 0, 0.5], "rgb() with nested function call as a channel arg"))
|
|
186
|
+
passed++;
|
|
187
|
+
else
|
|
188
|
+
failed++;
|
|
173
189
|
// Test 10: Real-world example - Color mapping
|
|
174
190
|
console.log("\nš Real-world Examples");
|
|
175
191
|
if (assertEqual(await vega2ol("datum.population > 1000000 ? '#FF0000' : datum.population > 500000 ? '#FFA500' : '#FFFF00'"), [
|