PY-91

Place Coordinate Overlays without Changing Meaning

  • Medium
  • Plot Overlays
  • Python

Task

Write place_coordinate_overlays(records, width, height, render_overlay). Coordinates use data space: x grows from left to right through [0, width], and y grows from top to bottom through [0, height]. Width and height must be positive finite numbers.

Each record is a dictionary with a unique non-empty string id and one of these forms:

  • point: {"id", "kind", "x", "y"};
  • box: {"id", "kind", "x0", "y0", "x1", "y1"};
  • span: {"id", "kind", "x0", "x1"};
  • link: {"id", "kind", "x0", "y0", "x1", "y1"}.

Every coordinate must be finite and inside the declared bounds. A box must have x0 < x1 and y0 < y1; a span must have x0 < x1. Reject extra or missing keys.

After all records pass validation, call render_overlay(record_copy) once per record in input order. The supplied function returns an artist object. Return a new list containing one dictionary per overlay with exactly these keys:

id, kind, record, artist

record is the independent copy passed to the renderer. Do not partially render an invalid collection and do not change the input records.

Example

The renderer receives two copied records in that order. The returned mapping makes it possible to trace each visible artist back to query or match.

Your implementation

Do not print or ask for input. You do not need to import Matplotlib; the caller supplies the low-level renderer.