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
7 changed files
with
130 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
import { Attr } from '../../definition' | ||
import { Path } from '../../geometry' | ||
import { normalize } from './util' | ||
import { Marker } from './index' | ||
|
||
export interface CrossMarkerOptions { | ||
export interface CrossMarkerOptions extends Attr.SimpleAttrs { | ||
size?: number | ||
width?: number | ||
height?: number | ||
offset?: number | ||
} | ||
|
||
export const cross: Marker.Definition<CrossMarkerOptions> = (options) => { | ||
const size = options.size || 10 | ||
const width = options.width || size | ||
const height = options.height || size | ||
export const cross: Marker.Definition<CrossMarkerOptions> = ({ | ||
size, | ||
width, | ||
height, | ||
offset, | ||
...attrs | ||
}) => { | ||
const s = size || 10 | ||
const w = width || s | ||
const h = height || s | ||
|
||
const path = new Path() | ||
path.moveTo(0, 0).lineTo(width, height).moveTo(0, height).lineTo(width, 0) | ||
path.moveTo(0, 0).lineTo(w, h).moveTo(0, h).lineTo(w, 0) | ||
|
||
return { | ||
...attrs, | ||
type: 'path', | ||
fill: 'none', | ||
d: normalize(path.serialize(), options.offset || -width / 2), | ||
d: normalize(path.serialize(), offset || -w / 2), | ||
} | ||
} |
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 |
---|---|---|
@@ -1,29 +1,37 @@ | ||
import { Attr } from '../../definition' | ||
import { Path } from '../../geometry' | ||
import { normalize } from './util' | ||
import { Marker } from './index' | ||
|
||
export interface DiamondMarkerOptions { | ||
export interface DiamondMarkerOptions extends Attr.SimpleAttrs { | ||
size?: number | ||
width?: number | ||
height?: number | ||
offset?: number | ||
} | ||
|
||
export const diamond: Marker.Definition<DiamondMarkerOptions> = (options) => { | ||
const size = options.size || 10 | ||
const width = options.width || size | ||
const height = options.height || size | ||
export const diamond: Marker.Definition<DiamondMarkerOptions> = ({ | ||
size, | ||
width, | ||
height, | ||
offset, | ||
...attrs | ||
}) => { | ||
const s = size || 10 | ||
const w = width || s | ||
const h = height || s | ||
|
||
const path = new Path() | ||
path | ||
.moveTo(0, height / 2) | ||
.lineTo(width / 2, 0) | ||
.lineTo(width, height / 2) | ||
.lineTo(width / 2, height) | ||
.moveTo(0, h / 2) | ||
.lineTo(w / 2, 0) | ||
.lineTo(w, h / 2) | ||
.lineTo(w / 2, h) | ||
.close() | ||
|
||
return { | ||
...attrs, | ||
type: 'path', | ||
d: normalize(path.serialize(), options.offset), | ||
d: normalize(path.serialize(), offset), | ||
} | ||
} |
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 |
---|---|---|
@@ -1,14 +1,20 @@ | ||
import { Attr } from '../../definition' | ||
import { Marker } from './index' | ||
|
||
export interface EllipseMarkerOptions { | ||
export interface EllipseMarkerOptions extends Attr.SimpleAttrs { | ||
rx?: number | ||
ry?: number | ||
} | ||
|
||
export const ellipse: Marker.Definition<EllipseMarkerOptions> = (options) => { | ||
export const ellipse: Marker.Definition<EllipseMarkerOptions> = ({ | ||
rx, | ||
ry, | ||
...attrs | ||
}) => { | ||
return { | ||
...attrs, | ||
type: 'ellipse', | ||
rx: options.rx || 5, | ||
ry: options.ry || 5, | ||
rx: rx || 5, | ||
ry: ry || 5, | ||
} | ||
} |
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 |
---|---|---|
@@ -1,15 +1,22 @@ | ||
import { Attr } from '../../definition' | ||
import { normalize } from './util' | ||
import { Marker } from './index' | ||
|
||
export interface PathMarkerOptions { | ||
export interface PathMarkerOptions extends Attr.SimpleAttrs { | ||
d: string | ||
offsetX?: number | ||
offsetY?: number | ||
} | ||
|
||
export const path: Marker.Definition<PathMarkerOptions> = (options) => { | ||
export const path: Marker.Definition<PathMarkerOptions> = ({ | ||
d, | ||
offsetX, | ||
offsetY, | ||
...attrs | ||
}) => { | ||
return { | ||
...attrs, | ||
type: 'path', | ||
d: normalize(options.d, options.offsetX, options.offsetY), | ||
d: normalize(d, offsetX, offsetY), | ||
} | ||
} |