From a135b6930b20973fbe3b2729891dc02fb52f4a1c Mon Sep 17 00:00:00 2001
From: Atul Varma
Date: Sat, 13 Feb 2021 21:13:04 -0500
Subject: [PATCH] Add checkbox toggle to show specs.
---
lib/bounding-box.ts | 2 +-
lib/browser-main.tsx | 106 +++++++++++++++++++++++++++++++++++++++++--
2 files changed, 102 insertions(+), 6 deletions(-)
diff --git a/lib/bounding-box.ts b/lib/bounding-box.ts
index 1195edb..5553e26 100644
--- a/lib/bounding-box.ts
+++ b/lib/bounding-box.ts
@@ -28,7 +28,7 @@ export function getBoundingBoxCenter(bbox: Bbox): Point {
};
}
-function dilateBoundingBox(bbox: Bbox, amount: number): Bbox {
+export function dilateBoundingBox(bbox: Bbox, amount: number): Bbox {
return {
minX: bbox.minX - amount,
maxX: bbox.maxX + amount,
diff --git a/lib/browser-main.tsx b/lib/browser-main.tsx
index f641925..9cdf388 100644
--- a/lib/browser-main.tsx
+++ b/lib/browser-main.tsx
@@ -1,7 +1,10 @@
import React, { useState } from "react";
import ReactDOM from "react-dom";
-import { getBoundingBoxSize } from "./bounding-box";
+import { Point } from "../vendor/bezier-js";
+import { Bbox, dilateBoundingBox, getBoundingBoxSize } from "./bounding-box";
import { FILL_REPLACEMENT_COLOR, STROKE_REPLACEMENT_COLOR } from "./colors";
+import * as colors from "./colors";
+import { Specs } from "./specs";
import _SvgVocabulary from "./svg-vocabulary.json";
import type { SvgSymbolData, SvgSymbolElement } from "./vocabulary";
@@ -19,6 +22,7 @@ if (!appEl) {
type SvgSymbolContext = {
stroke: string;
fill: string;
+ showSpecs: boolean;
};
type SvgSymbolProps = {
@@ -56,19 +60,101 @@ function reactifySvgSymbolElement(
);
}
+const ATTACHMENT_POINT_RADIUS = 20;
+
+const AttachmentPoints: React.FC<{ color: string; points: Point[] }> = (
+ props
+) => (
+ <>
+ {props.points.map((p, i) => (
+
+ ))}
+ >
+);
+
+const BoundingBoxes: React.FC<{ fill: string; bboxes: Bbox[] }> = (props) => (
+ <>
+ {props.bboxes.map((b, i) => {
+ const [width, height] = getBoundingBoxSize(b);
+ return (
+
+ );
+ })}
+ >
+);
+
+const SvgSymbolSpecs: React.FC<{ specs: Specs }> = ({ specs }) => {
+ return (
+ <>
+ {specs.tail && (
+
+ )}
+ {specs.leg && (
+
+ )}
+ {specs.arm && (
+
+ )}
+ {specs.horn && (
+
+ )}
+ {specs.crown && (
+
+ )}
+ {specs.nesting && (
+
+ )}
+ >
+ );
+};
+
+const BBOX_DILATION = 50;
+
const SvgSymbol: React.FC = (props) => {
const d = props.data;
+ const bbox = dilateBoundingBox(d.bbox, BBOX_DILATION);
const scale = props.scale || 1;
- const [width, height] = getBoundingBoxSize(d.bbox);
+ const [width, height] = getBoundingBoxSize(bbox);
return (
);
};
@@ -76,6 +162,7 @@ const SvgSymbol: React.FC = (props) => {
const App: React.FC<{}> = () => {
const [stroke, setStroke] = useState("#000000");
const [fill, setFill] = useState("#ffffff");
+ const [showSpecs, setShowSpecs] = useState(false);
return (
<>
@@ -94,7 +181,15 @@ const App: React.FC<{}> = () => {
value={fill}
onChange={(e) => setFill(e.target.value)}
id="fill"
- />
+ />{" "}
+
{SvgVocabulary.map((symbolData) => (
= () => {
scale={0.25}
stroke={stroke}
fill={fill}
+ showSpecs={showSpecs}
/>