Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
76 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Path } from '../../geometry' | ||
|
||
/** | ||
* Normalizes marker's path data by translate the center | ||
* of an arbitrary path at <0 + offset,0>. | ||
*/ | ||
export function normalizeMarker( | ||
d: string, | ||
offset: { x?: number; y?: number }, | ||
): string | ||
export function normalizeMarker( | ||
d: string, | ||
offsetX?: number, | ||
offsetY?: number, | ||
): string | ||
export function normalizeMarker( | ||
d: string, | ||
offset1?: number | { x?: number; y?: number }, | ||
offset2?: number, | ||
) { | ||
let offsetX: number | undefined | ||
let offsetY: number | undefined | ||
if (typeof offset1 === 'object') { | ||
offsetX = offset1.x | ||
offsetY = offset1.y | ||
} else { | ||
offsetX = offset1 | ||
offsetY = offset2 | ||
} | ||
|
||
const path = Path.parse(Path.normalize(d)) | ||
const bbox = path.bbox() | ||
if (bbox) { | ||
let ty = -bbox.height / 2 - bbox.y | ||
let tx = -bbox.width / 2 - bbox.x | ||
if (typeof offsetX === 'number') { | ||
tx -= offsetX | ||
} | ||
if (typeof offsetY === 'number') { | ||
ty -= offsetY | ||
} | ||
|
||
path.translate(tx, ty) | ||
} | ||
|
||
return path.serialize() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters