From e7250f0bc05b1b06898e21e67158e1bb8c8c2583 Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Thu, 9 Jun 2022 17:36:55 +0200 Subject: [PATCH] feat(dev): Added path.noop/path.insop example --- markdown/dev/reference/api/path/insop/en.md | 31 ++++++++++++++++-- markdown/dev/reference/api/path/noop/en.md | 35 +++++++++++++++++++-- packages/examples/config/index.js | 1 + packages/examples/src/index.js | 2 ++ packages/examples/src/path_noop.js | 26 +++++++++++++++ 5 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 packages/examples/src/path_noop.js diff --git a/markdown/dev/reference/api/path/insop/en.md b/markdown/dev/reference/api/path/insop/en.md index a88e05d3aad..f6b18f2378c 100644 --- a/markdown/dev/reference/api/path/insop/en.md +++ b/markdown/dev/reference/api/path/insop/en.md @@ -6,6 +6,33 @@ title: insop() Path path.insop(string id, Path path) ``` -Injects a Path into the [`noop` operation](#noop) with id `id`. +Injects a Path into the [`noop` operation](/reference/api/path/noop) with id `id`. -Add example +This is often used to insert darts into a path + + +Example of the Path.noop() method + + +```js +points.left = new Point(10,10) +points.dartLeft = new Point(40, 10) +points.dartTip = new Point(50, 50) +points.dartRight = new Point(60, 10) +points.right = new Point(90, 10) + +paths.withoutDart = new Path() + .move(points.left) + .line(points.dartLeft) + .noop('dart') + .line(points.right) + +paths.withDart = paths.without + .insop( + 'dart', + new Path() + .line(points.dartTip) + .line(points.dartRight) + ) + .attr('style', 'stroke-width: 2px; stroke-opacity: 0.5; stroke: orange;') +``` diff --git a/markdown/dev/reference/api/path/noop/en.md b/markdown/dev/reference/api/path/noop/en.md index 67851f79241..43cebbcc421 100644 --- a/markdown/dev/reference/api/path/noop/en.md +++ b/markdown/dev/reference/api/path/noop/en.md @@ -6,7 +6,36 @@ title: noop() Path path.noop(string id) ``` -Adds a placeholder path opertion.\ -A `noop` operation does nothing, but is intended to be replaced later with [`Path.insop()`](#insop). +Adds a placeholder path operation. -Add example +A `noop` operation does nothing, but is intended to be replaced later +with [`Path.insop()`](/reference/api/path/insop). + +This is often used to insert darts into a path + + +Example of the Path.noop() method + + +```js +points.left = new Point(10,10) +points.dartLeft = new Point(40, 10) +points.dartTip = new Point(50, 50) +points.dartRight = new Point(60, 10) +points.right = new Point(90, 10) + +paths.withoutDart = new Path() + .move(points.left) + .line(points.dartLeft) + .noop('dart') + .line(points.right) + +paths.withDart = paths.without + .insop( + 'dart', + new Path() + .line(points.dartTip) + .line(points.dartRight) + ) + .attr('style', 'stroke-width: 2px; stroke-opacity: 0.5; stroke: orange;') +``` diff --git a/packages/examples/config/index.js b/packages/examples/config/index.js index b9d5205252d..dd13932902c 100644 --- a/packages/examples/config/index.js +++ b/packages/examples/config/index.js @@ -35,6 +35,7 @@ export default { 'path_intersectsy', 'path_join', 'path_length', + 'path_noop', 'path_offset', 'path_reverse', 'path_shiftalong', diff --git a/packages/examples/src/index.js b/packages/examples/src/index.js index d9e57759796..5194ac85d94 100644 --- a/packages/examples/src/index.js +++ b/packages/examples/src/index.js @@ -21,6 +21,7 @@ import draftPath_intersectsx from './path_intersectsx' import draftPath_intersectsy from './path_intersectsy' import draftPath_join from './path_join' import draftPath_length from './path_length' +import draftPath_noop from './path_noop' import draftPath_offset from './path_offset' import draftPath_reverse from './path_reverse' import draftPath_shiftalong from './path_shiftalong' @@ -120,6 +121,7 @@ let methods = { draftPath_intersectsy, draftPath_join, draftPath_length, + draftPath_noop, draftPath_offset, draftPath_reverse, draftPath_shiftalong, diff --git a/packages/examples/src/path_noop.js b/packages/examples/src/path_noop.js new file mode 100644 index 00000000000..3fa76cd3eba --- /dev/null +++ b/packages/examples/src/path_noop.js @@ -0,0 +1,26 @@ +export default (part) => { + let { Point, points, Path, paths, Snippet, snippets } = part.shorthand() + + points.left = new Point(10,10) + points.dartLeft = new Point(40, 10) + points.dartTip = new Point(50, 50) + points.dartRight = new Point(60, 10) + points.right = new Point(90, 10) + + paths.without = new Path() + .move(points.left) + .line(points.dartLeft) + .noop('dart') + .line(points.right) + + paths.withDart = paths.without + .insop( + 'dart', + new Path() + .line(points.dartTip) + .line(points.dartRight) + ) + .attr('style', 'stroke-width: 2px; stroke-opacity: 0.5; stroke: orange;') + + return part +}