@mark1russell7/visuals 0.3.5 → 0.3.6
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/README.md +86 -1
- package/build/graph.d.ts +451 -58
- package/build/graph.d.ts.map +1 -1
- package/build/graph.js +887 -20
- package/build/graph.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -474,7 +474,8 @@ stage?.refresh();
|
|
|
474
474
|
## A flat picture
|
|
475
475
|
|
|
476
476
|
The entry `/graph` is for a flat picture that a person moves and zooms, for example a graph of boxes and edges.
|
|
477
|
-
It has a stage on a canvas, and the
|
|
477
|
+
It has a stage on a canvas, and the content for a picture of a layout.
|
|
478
|
+
It has the maths of its camera, its pointers and its keys too. It imports no `three`.
|
|
478
479
|
|
|
479
480
|
```ts
|
|
480
481
|
import { aimRects, createPictureStage, type PictureContent } from "@mark1russell7/visuals/graph";
|
|
@@ -615,6 +616,90 @@ canvas.addEventListener("pointerup", (event) => {
|
|
|
615
616
|
- `frameRects` gets the bounds of groups of boxes, the largest group first. It takes the first group that a person can read.
|
|
616
617
|
- The zoom stays in `ZOOM_LIMITS`. Each function with a zoom takes different limits as a parameter.
|
|
617
618
|
|
|
619
|
+
## The picture of a layout
|
|
620
|
+
|
|
621
|
+
`createPictureContent` makes the content of a flat stage from a picture of `@mark1russell7/layout-contract`: its boxes, its routes and its labels.
|
|
622
|
+
A layout engine gives the picture. The content draws the picture, and it does not change it.
|
|
623
|
+
|
|
624
|
+
```ts
|
|
625
|
+
import { PICTURE_SCHEMA, pathOf, type LayoutPicture } from "@mark1russell7/layout-contract";
|
|
626
|
+
import { LIGHT_PICTURE_THEME, createPictureContent, createPictureStage, plainLooks } from "@mark1russell7/visuals/graph";
|
|
627
|
+
|
|
628
|
+
const picture: LayoutPicture = {
|
|
629
|
+
schema: PICTURE_SCHEMA,
|
|
630
|
+
boxes: [
|
|
631
|
+
{ id: "card", x: 0, y: 0, w: 200, h: 100 },
|
|
632
|
+
{ id: "row", parent: "card", x: 10, y: 30, w: 180, h: 25 },
|
|
633
|
+
{ id: "topic", x: 300, y: 20, w: 60, h: 60, shape: { kind: "circle", cx: 30, cy: 30, r: 30 } },
|
|
634
|
+
],
|
|
635
|
+
routes: [
|
|
636
|
+
{
|
|
637
|
+
id: "link",
|
|
638
|
+
source: "row",
|
|
639
|
+
target: "topic",
|
|
640
|
+
path: pathOf([
|
|
641
|
+
{ x: 190, y: 42 },
|
|
642
|
+
{ x: 300, y: 50 },
|
|
643
|
+
]),
|
|
644
|
+
},
|
|
645
|
+
],
|
|
646
|
+
labels: [{ id: "name", box: "card", x: 10, y: 6, w: 100, h: 18, lines: ["Card"], lineHeight: 18, font: "13px sans-serif" }],
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
const content = createPictureContent(picture, { looks: plainLooks({ end: { shape: "arrow", size: 8 } }) });
|
|
650
|
+
const stage = createPictureStage(document.body, {
|
|
651
|
+
content,
|
|
652
|
+
theme: LIGHT_PICTURE_THEME,
|
|
653
|
+
label: "A card and a topic",
|
|
654
|
+
onSelect: (record) => console.log(record?.id),
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
// A new layout gives a new picture. The stage shows it after a refresh.
|
|
658
|
+
content.setPicture({ ...picture, routes: [] });
|
|
659
|
+
stage?.refresh();
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
- The looks give the colors, the lines and the signs of each record. `plainLooks` gives the looks of a plain picture.
|
|
663
|
+
- `LIGHT_PICTURE_THEME` and `DARK_PICTURE_THEME` are the themes of the plain looks.
|
|
664
|
+
- A look gets the state of its record: its highlight, its focus level, the zoom, and if the box has children.
|
|
665
|
+
- A look of `undefined` hides a record. A hidden box takes its labels with it, and a person cannot point at it.
|
|
666
|
+
- A box is a rectangle with round corners, a circle, an ellipse or a polygon. Its look can add a ring off its border, and small signs.
|
|
667
|
+
- A route is a path of lines, curves and arcs. Its look can add an arrow or a dot at each end.
|
|
668
|
+
- A label has the lines and the place that the layout gives. The content breaks no line.
|
|
669
|
+
- In `plainLooks`, a text that is too small to read becomes bars. A text below `SMALLEST_BAR_LINE` pixels goes.
|
|
670
|
+
- At the zoom 1 or less, the lines and the signs keep their size on the screen. Above it, they grow with the boxes.
|
|
671
|
+
- The selected record and the records at it stay clear. Each other record has less color, and the colors change in a short time.
|
|
672
|
+
- `setFocus` sets the records of the focus from the page. The option `focus: "none"` stops the focus of the selection.
|
|
673
|
+
- A person points at the top box below the pointer. A box with no child comes before the box around it.
|
|
674
|
+
- The option `picks` tells which records a person can point at, for example the routes too.
|
|
675
|
+
- The content makes shapes only for the records in view.
|
|
676
|
+
- `setPicture` shows a different picture. Start `refresh` of the stage after it.
|
|
677
|
+
|
|
678
|
+
The parts of the content are pure functions. A test in Node.js examines a picture with no canvas:
|
|
679
|
+
|
|
680
|
+
```ts
|
|
681
|
+
import { LIGHT_PICTURE_THEME, focusOf, indexPicture, paintPicture, pickRecord, plainLooks } from "@mark1russell7/visuals/graph";
|
|
682
|
+
|
|
683
|
+
const index = indexPicture(picture);
|
|
684
|
+
pickRecord(index, { x: 50, y: 40 })?.id; // => "row"
|
|
685
|
+
|
|
686
|
+
// The focus of the row has the row, its card, the link and the topic.
|
|
687
|
+
const focus = focusOf(index, ["row"]);
|
|
688
|
+
const shapes = paintPicture(index, plainLooks(), LIGHT_PICTURE_THEME, { zoom: 1, highlight: () => 0, focus });
|
|
689
|
+
shapes.length; // => 5: the card, its name, the link, the row and the topic
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
| Function | What it gives |
|
|
693
|
+
| --- | --- |
|
|
694
|
+
| `indexPicture` | The tables of a picture: each record by its id, the children of each box, and the routes and the labels of each record. |
|
|
695
|
+
| `focusOf`, `boxFocus`, `routeFocus` | The focus of a list of records, and the focus level of a box or a route. `FOCUS_OPACITY` has the color share of each level. |
|
|
696
|
+
| `pickRecord`, `boxDistance` | The record at a point of the picture, and the distance from a point to the shape of a box. |
|
|
697
|
+
| `routeLine` | The path of a route as a line of points, with its bounds. |
|
|
698
|
+
| `plainLooks`, `lookUnit` | The looks of a plain picture, and the size of one unit of a look at a zoom. |
|
|
699
|
+
| `paintPicture` | The paint list of a picture: its shapes as plain data, in the order of the paint. |
|
|
700
|
+
| `drawShapes` | The drawing of a paint list on a 2D context, in the view of a camera. |
|
|
701
|
+
| `recordKey`, `boxState`, `routeState` | The key of a record for the function `fade` of a paint, and the state of a record for its look. |
|
|
702
|
+
|
|
618
703
|
## The camera maths
|
|
619
704
|
|
|
620
705
|
The entry `.` has pure functions. A page with no WebGL 2 and a test in Node.js use the same functions as the stage.
|