Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/hiccup-canvas/src/draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
__restoreState,
} from "./internal/state.js";
import { line, lines } from "./line.js";
import { packedLines } from "./packed-lines.js";
import { packedPoints } from "./packed-points.js";
import { path } from "./path.js";
import { points } from "./points.js";
Expand Down Expand Up @@ -69,6 +70,9 @@ export const draw = (
case "lines":
lines(ctx, attribs, shape[2]);
break;
case "packedLines":
packedLines(ctx, attribs, origAttribs, shape[2]);
break;
case "hline":
line(ctx, attribs, [-1e6, shape[2]], [1e6, shape[2]]);
break;
Expand Down
25 changes: 25 additions & 0 deletions packages/hiccup-canvas/src/packed-lines.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { IObjectOf } from "@thi.ng/api";

export const packedPoints = (
ctx: CanvasRenderingContext2D,
attribs: IObjectOf<any>,
opts: IObjectOf<any>,
pts: ArrayLike<number>
) => {
if (attribs.stroke === "none") return;
const { start, cstride, estride } = {
start: 0,
cstride: 1,
estride: 2,
...opts,
};
let num =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 4 locations. Consider refactoring.

opts && opts.num != null
? opts.num
: ((pts.length - start) / estride) | 0;
ctx.beginPath();
for (let i = start + estride; num-- > 1; i += estride) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

ctx.lineTo(pts[i], pts[i + cstride]);
}
ctx.stroke();
};