Skip to content

feat: line style (dashed, dotted, dash-dot) - #202

Merged
tbolis merged 1 commit into
release/1.1.0from
feat/line-style
Oct 30, 2026
Merged

tbolis merged 1 commit into
release/1.1.0from
feat/line-style

Conversation

@tbolis

@tbolis tbolis commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Summary

Adds the lineStyle property and the Types.LineStyle type: "solid" (the default), "dashed", "dotted" or "dash-dot".

  • The dashes and the dots follow lineWidth. A line thinner than 2 pixels has the pattern of one of 2, so that it is seen.
  • The pencil, line, arrow (its shaft), rectangle, rectangle label, circle and polygon draw it. The head of an arrow and the text box of a rectangle label are not dashed. The highlighter, the eraser and the laser pointer do not draw it.
  • The polygon in progress is shown in the style: its sides are dashed, its dots and the ring on the first vertex are not.
  • A change of lineStyle is for the next drawing, what is drawn already keeps its style.
  • It is saved by toJSON() and loaded by fromJSON() with the object (strokeDashArray and strokeLineCap).
  • The pencil and the highlighter share one brush, so the tools get setBrushStroke(): the highlighter takes the brush back to solid, and the style of the pencil is not left on it.
  • Showcase: the four styles as buttons in the Line section, disabled for the tools which do not draw a style.
  • README: a row in the properties table, a "Line style" section, and LineStyle in the exports. CHANGELOG: an entry under Added.

Checks

yarn format:check, yarn lint, yarn typecheck and yarn build pass. yarn test: 392 passing and 1 todo. The new tests are LineStyle.spec.tsx (each tool and each style, solid by default, a change of the property, toJSON() and fromJSON(), the arrow head, the brush and its reset by the highlighter, the polygon in progress) and the tests of lineStroke in utils.spec.ts. With the feature switched off 35 of them fail.

In headless Chrome, a page with fabric and the options the tools set: dashed, dotted (round dots) and dash-dot lines, rectangles and circles, at widths 1, 4 and 10.

Not checked: the showcase in a browser, a physical touch device, and browsers other than Chrome.

Notes for review

  • fix: an arrow is one undo step #201 (an arrow is one undo step) is open and also touches Arrow.ts, in other lines. A conflict, if any, is small.
  • lineStyle takes the names only. A custom dash array is not part of this.

The lineStyle property and the Types.LineStyle type: solid (the default),
dashed, dotted or dash-dot, with the dashes and the dots following
lineWidth. The pencil, line, arrow (its shaft), rectangle, rectangle
label, circle and polygon draw it, and the polygon in progress is shown
in it. The brush is shared by the tools, so the highlighter takes it back
to solid. The style is saved with the object by toJSON() and loaded by
fromJSON(). The showcase has the line styles in the Line section.
@tbolis
tbolis merged commit 19e31c7 into release/1.1.0 Oct 30, 2026
3 checks passed
@tbolis
tbolis deleted the feat/line-style branch October 30, 2026 15:38
This was referenced Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant