›
byrcsc/laravel-cartographer · 1.x
Detect diagrams that exceed hosted Mermaid character or edge limits.
Hosted Mermaid renderers cap how much they will draw. GitHub, GitLab, and the
Mermaid live editor all stop at 50,000 characters of diagram source
(maxTextSize) and 500 relationship edges (maxEdges). Past either one they
show "Maximum text size in diagram exceeded" where the diagram should be.
Cartographer warns you when a generated diagram crosses a limit, on the run that caused it rather than in a pull request.
WARN The diagram is 63,412 characters, over the 50,000 character limit
hosted Mermaid renderers enforce (maxTextSize). GitHub and GitLab
report "Maximum text size in diagram exceeded" instead of drawing it.
The file itself is valid Mermaid and was written unchanged. Shrink it
with --columns=keys or --columns=none, split it into groups under
[cartographer.groups], render it yourself with --format=svg, or raise
[cartographer.limits.max_text_size] if your renderer is configured for
more.This is the important half. The generated file is valid Mermaid at any size, and it is written unchanged whether or not it crossed a limit. A renderer you control can be configured to draw it, and the export formats do exactly that.
The warning never changes the exit code either. A run that trips it still
returns 0, and cartographer:check still passes on a file that is correct
but too big for GitHub. The limits describe a rendering environment, not a
defect in your schema, so failing on them would be failing on somebody else's
configuration.
| Limit | Measured on | Default |
|---|---|---|
max_text_size | Characters of raw Mermaid source, without the wrapper | 50000 |
max_edges | Relationship edges in the diagram | 500 |
Two details follow from that. Characters are counted with multibyte awareness,
matching how Mermaid measures maxTextSize, so a schema with non-ASCII table
or column names is measured the way the renderer will measure it. And the
Markdown wrapper is excluded, because the generation comment and the fence are
not part of what the renderer parses.
Each declared diagram is measured on its own. Splitting into groups is therefore a real fix rather than a way of moving the total around: a group that fits is drawn, whatever the full diagram measures.
php artisan cartographer:erd --columns=keyskeys keeps only PK, FK, and UK columns and usually halves the source on
a wide schema. --columns=none drops the column blocks entirely and halves it
again, leaving entity names and edges, which is the right shape for an
orientation diagram anyway.
This does nothing for maxEdges. Columns are not edges.
'groups' => [
'billing' => [App\Models\Invoice::class, App\Models\Payment::class],
'catalog' => [App\Models\Product::class, App\Models\Category::class],
],The structural answer, and the only one that helps both limits at once. Each group is a committed diagram of its own, measured on its own, and a relation leaving a group keeps its edge with the far entity drawn as an empty box. See diagrams per subsystem.
php artisan cartographer:erd --format=svgCartographer supplies the renderer configuration for an export and raises both limits far past anything a schema produces. An export succeeds on diagrams GitHub refuses to draw, and no size warning is printed for one. See exporting images.
php artisan cartographer:erd --models=Invoice,Payment --depth=1Seeds and depth render one subsystem instead of the whole application. Good for a one-off; groups are better for anything committed, because a group regenerates with every run and a remembered flag does not. See scoping a diagram.
php artisan cartographer:erd --exclude-relations=through,morphAimed squarely at maxEdges. through relations are shortcuts across an
intermediate model, so each one adds an edge the diagram already implies
through two others. Polymorphic relations fan out to every model that
participates.
If you render with your own Mermaid configuration and have raised its limits,
set the matching key to your number, or to null to switch that check off:
'limits' => [
'max_text_size' => 200000,
'max_edges' => null,
],Each key is independent, so you can switch off the edge check and keep the text
check. A value must be null or a positive integer:
ERROR [cartographer.limits.max_edges] must be null or a positive integer.Switch a limit off only when you know the renderer that will draw the file.
Setting both to null because the warning is noisy means the first person to
open the diagram on GitHub finds out instead of you.
--stdout prints the diagram and nothing else, so warnings are suppressed
along with the summary line. If you are piping a large diagram and want to know
whether it is over a limit, run once without --stdout.
limits keys beside every other
key.