Urgent.News

What's breaking now, across thousands of outlets.

Tech

What React Flow Doesn't Do For You: Building a Diagram Editor With Domain Rules

I built a diagram editor for genograms. If you have not run into the term: a genogram is a diagram of a family that records more than descent. It uses standardized shapes for people and a set of line conventions for relationships, including emotional ones like closeness, distance, and conflict. The obvious library choice was React Flow ( @xyflow/react ). It is a good fit and I would choose it…

Building a diagram editor with domain rules in React Flow demanded more than just the library's basic features. While React Flow provided a canvas for panning, zooming, and viewport controls, along with a node/edge data model and selection/dragging capabilities, it did not inherently support the domain-specific rules necessary for a comprehensive genogram editor.

Node rendering rules were one area where React Flow fell short. Genograms employ specialized shapes to represent individuals, encoding gender and health status within them. Custom node components utilizing SVG graphics were required to accurately render these elements within the React Flow canvas.

Edge routing rules presented another challenge. Family relationships in genograms differ from mere connections. Partnerships are depicted with horizontal lines, while children descend from a midpoint on these lines. The midpoint shifts whenever partnerships are added or removed, necessitating edge geometry that adapts to the surrounding nodes rather than being stored directly per node pair.

By utilizing custom edge components and defining edge types based on the domain model, React Flow could render these relationships correctly.

React Flow did not inherently distinguish between emotional and structural relationships in genograms. Emotional relationships required distinct line conventions, such as triple lines for close connections, zigzag lines for conflict, and dotted lines for distant relationships. Each line type necessitated a different edge component with specific path geometry and legend entries. This domain-specific classification of edges became the responsibility of the developer, rather than a feature provided by React Flow.

To enhance the user experience, a legend was implemented within the editor. The legend clarified the meaning behind each line convention used in the diagram, ensuring users understood the symbolism behind dashed, zigzag, and dotted lines. Creating a comprehensive legend required domain knowledge and careful consideration of the notation employed in genograms.

Persistence posed an additional design challenge. Two storage modes were implemented: local projects using IndexedDB and cloud projects utilizing a different storage mechanism. Handling concurrent saves and ensuring data integrity required careful serialization of writes, preventing conflicts and race conditions. The autosave functionality was debounced, allowing for efficient storage updates without overloading the system.

The export feature presented its own set of complexities, requiring the conversion of DOM elements representing nodes into a printable image format while maintaining the fidelity of the original design. Computing the bounding box, determining an appropriate scale factor, generating filenames, and handling nodes that fall outside the computed bounds were all considerations in the export process.

One of the most time-consuming aspects of building the genogram editor was ensuring the integrity and consistency of the domain model. The editor had to validate and migrate projects across different versions, safeguarding against schema changes and ensuring a seamless user experience. Proper error handling and migration strategies were implemented to gracefully handle scenarios where older projects were loaded or saved with incompatible schemas.

The export feature required meticulous attention to detail, ensuring that the exported image accurately represented the diagram's layout, connections, and domain-specific conventions.

In summary, while React Flow provided a solid foundation for building a diagram editor, creating a domain-specific genogram editor demanded careful consideration of node rendering rules, edge routing rules, legend consistency, persistence strategies, and validation processes. By addressing these domain-specific requirements and implementing robust design patterns, a professional-grade editor capable of capturing the nuances of genograms could be achieved using React Flow as the underlying framework.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

I made a small website to check Codex reset

Hi, I made this small website because I often go X to check if Codex reset. But I found many posts use the word “reset”, and maybe they talk about different thing. Sometimes it is personal reset time.

Small Calculator, Three Bugs: Input Parsing, Unit Drift, and Stale Results

A calculator with two inputs and one output is the "hello world" of interactive UI. It is also a small minefield. These are three defects I hit while building bidirectional CPM ↔ CPC conversion, and…

  • Bug 1: Percentage drift in CTR calculation due to treating CTR as percentage
  • Bug 2: Validation allowing empty fields treated as zero instead of leaving blank
  • Bug 3: Stale results displayed after invalid form submission

Normalize Units at the Boundary, or Ship a 12x Bug

A user types 3 into a depth field. The label says inches. Your formula assumes feet. You just shipped a 12x error, and nothing in the type system noticed, because both values are number .

  • User inputs depth in inches, but formula assumes feet
  • Convert all inputs to a single internal unit at boundary
  • Validate unit and number, reject unknown or non-positive values

A No-Repeat Random Draw Looks Trivial Until Round 70

Drawing numbers without repeats sounds like a beginner exercise. It is also a place where a lot of shipped code has a real defect.

  • Naive rejection sampling inefficient as pool shrinks
  • Check operation O(n) complexity leads to loops
  • Directly select from remaining set for constant time

More from Friday 25 September →