@opendata-ai/openchart-engine 8.0.0-rc.22 → 8.0.0-rc.24

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.js CHANGED
@@ -11044,6 +11044,40 @@ function validateMarkRenderMode(spec, errors) {
11044
11044
  });
11045
11045
  }
11046
11046
  }
11047
+ var MAX_PLAUSIBLE_POINT_RADIUS = 50;
11048
+ function pointSizeError(path2, value2) {
11049
+ const radius = Math.max(1, Math.round(Math.sqrt(value2 / Math.PI)));
11050
+ return {
11051
+ message: `Spec error: ${path2} is a radius in pixels, and ${value2} would draw a ${Math.round(value2 * 2)}px-wide circle. This usually means the value was written in Vega-Lite's units, where point size is an area in px^2.`,
11052
+ path: path2,
11053
+ code: "INVALID_VALUE",
11054
+ suggestion: `Point sizes are radii in px (default 5, typical 2-12). For the dot a Vega-Lite size of ${value2} draws, use ${radius} (r = sqrt(area / pi)).`
11055
+ };
11056
+ }
11057
+ function validatePointSize(spec, errors) {
11058
+ const markType = typeof spec.mark === "string" ? spec.mark : spec.mark?.type;
11059
+ if (markType !== "point") return;
11060
+ if (spec.mark && typeof spec.mark === "object") {
11061
+ const size = spec.mark.size;
11062
+ if (typeof size === "number" && size > MAX_PLAUSIBLE_POINT_RADIUS) {
11063
+ errors.push(pointSizeError("mark.size", size));
11064
+ }
11065
+ }
11066
+ const sizeEnc = spec.encoding && typeof spec.encoding === "object" ? spec.encoding.size : void 0;
11067
+ if (!sizeEnc || typeof sizeEnc !== "object") return;
11068
+ if (typeof sizeEnc.value === "number" && sizeEnc.value > MAX_PLAUSIBLE_POINT_RADIUS) {
11069
+ errors.push(pointSizeError("encoding.size.value", sizeEnc.value));
11070
+ }
11071
+ const range3 = sizeEnc.scale && typeof sizeEnc.scale === "object" ? sizeEnc.scale.range : void 0;
11072
+ if (Array.isArray(range3)) {
11073
+ const worst = range3.find(
11074
+ (entry) => typeof entry === "number" && entry > MAX_PLAUSIBLE_POINT_RADIUS
11075
+ );
11076
+ if (typeof worst === "number") {
11077
+ errors.push(pointSizeError("encoding.size.scale.range", worst));
11078
+ }
11079
+ }
11080
+ }
11047
11081
  function validateChartSpec(spec, errors) {
11048
11082
  const markType = typeof spec.mark === "string" ? spec.mark : spec.mark?.type;
11049
11083
  if (!Array.isArray(spec.data)) {
@@ -11150,6 +11184,7 @@ function validateChartSpec(spec, errors) {
11150
11184
  validateCalendarSpec(spec, errors);
11151
11185
  }
11152
11186
  validateMarkRenderMode(spec, errors);
11187
+ validatePointSize(spec, errors);
11153
11188
  if (Array.isArray(spec.transform)) {
11154
11189
  const transforms = spec.transform;
11155
11190
  for (let i = 0; i < transforms.length; i++) {