Skip to content

Commit c74c81d

Browse files
Copilotgatopeich
andauthored
Remove coerce.js function pass-through hack; fatal errors on unknown marker symbols (#11)
* Initial plan * Remove coerce.js function pass-through fix and raise fatal errors on unknown marker symbols Co-authored-by: gatopeich <7722268+gatopeich@users.noreply.github.com> Agent-Logs-Url: https://github.com/gatopeich/plotly.js/sessions/faf05e5d-fbbf-4670-97b3-f5ee6a9ec6a0 * Move error throwing inside lookupSymbol for better encapsulation Co-authored-by: gatopeich <7722268+gatopeich@users.noreply.github.com> Agent-Logs-Url: https://github.com/gatopeich/plotly.js/sessions/702780b7-60c8-481e-9550-f292fc6482c8 --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: gatopeich <7722268+gatopeich@users.noreply.github.com>
1 parent 6bbdb63 commit c74c81d

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

src/components/drawing/index.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ for(var _i = 0; _i < MAXSYMBOL; _i++) {
407407
* n = idx + (open ? 100 : 0) + (dot ? 200 : 0)
408408
* so lookupSymbol(100).n === 100, lookupSymbol('circle-open').n === 100, etc.
409409
* n is null for custom SVG paths (id assigned per-SVG by ensureSymbolDef).
410-
* Returns null for unrecognised input (callers should fall back to circle).
410+
* Throws an Error for unrecognised input.
411411
*/
412412
drawing.lookupSymbol = function (v) {
413413
// Raw SVG path — no deterministic n; ensureSymbolDef will assign a per-SVG id.
@@ -418,20 +418,20 @@ drawing.lookupSymbol = function (v) {
418418
var name, open = false, dot = false, idx;
419419
if (isNumeric(v)) {
420420
var n = Math.floor(Math.max(+v, 0));
421-
if (n >= 400) return null;
421+
if (n >= 400) throw new Error('Unknown marker symbol: ' + v);
422422
open = n % 200 >= 100;
423423
dot = n >= 200;
424424
idx = n % 100;
425-
if (idx >= MAXSYMBOL) return null;
425+
if (idx >= MAXSYMBOL) throw new Error('Unknown marker symbol: ' + v);
426426
name = drawing.symbolNames[idx];
427427
} else if (typeof v === 'string') {
428428
if (v.indexOf('-open') > 0) { open = true; v = v.replace('-open', ''); }
429429
if (v.indexOf('-dot') > 0) { dot = true; v = v.replace('-dot', ''); }
430430
idx = drawing.symbolNames.indexOf(v);
431-
if (idx < 0) return null;
431+
if (idx < 0) throw new Error('Unknown marker symbol: ' + v);
432432
name = v;
433433
} else {
434-
return null;
434+
throw new Error('Unknown marker symbol: ' + v);
435435
}
436436

437437
var symN = idx + (open ? 100 : 0) + (dot ? 200 : 0);
@@ -449,9 +449,7 @@ drawing.lookupSymbol = function (v) {
449449

450450
// sym.n already equals the legacy numeric encoding, so symbolNumber is a simple wrapper.
451451
drawing.symbolNumber = function (v) {
452-
var sym = drawing.lookupSymbol(v);
453-
if (!sym || !sym.name) return 0;
454-
return sym.n;
452+
return drawing.lookupSymbol(v).n;
455453
};
456454

457455
drawing.ensureSymbolDef = function (gd, sym) {
@@ -1000,7 +998,7 @@ drawing.singlePointStyle = function (d, sel, trace, fns, gd, pt) {
1000998
}
1001999

10021000
var symbolValue = d.mx || marker.symbol;
1003-
var sym = drawing.lookupSymbol(symbolValue) || drawing.lookupSymbol(0);
1001+
var sym = drawing.lookupSymbol(symbolValue);
10041002

10051003
// save if this marker is open (impacts color handling)
10061004
d.om = sym.open;
@@ -1605,7 +1603,12 @@ function applyBackoff(pt, start) {
16051603
var endMarkerSize = endMarker.size;
16061604
if (Lib.isArrayOrTypedArray(endMarkerSize)) endMarkerSize = endMarkerSize[endI];
16071605

1608-
b = endMarker ? ((drawing.lookupSymbol(endMarkerSymbol) || {}).backoff || 0) * endMarkerSize : 0;
1606+
if(endMarker) {
1607+
var endMarkerSym = drawing.lookupSymbol(endMarkerSymbol);
1608+
b = (endMarkerSym.backoff || 0) * endMarkerSize;
1609+
} else {
1610+
b = 0;
1611+
}
16091612
b += drawing.getMarkerStandoff(d[endI], trace) || 0;
16101613
}
16111614

src/lib/coerce.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ exports.valObjectMeta = {
6464
requiredOpts: ['values'],
6565
otherOpts: ['dflt', 'coerceNumber', 'arrayOk'],
6666
coerceFunction: function(v, propOut, dflt, opts) {
67-
// Allow functions to pass through (for custom marker symbols, etc.)
68-
if(typeof v === 'function') {
69-
propOut.set(v);
70-
return;
71-
}
7267
if(opts.coerceNumber) v = +v;
7368
if(opts.values.indexOf(v) === -1) propOut.set(dflt);
7469
else propOut.set(v);

0 commit comments

Comments
 (0)