feat(core): Add support for injecting sample styles
This allows you to override the (path) styles when we sample the pattern by setting `settings.sample.styles`. This closes #380
This commit is contained in:
parent
803dd112ed
commit
673743faae
2 changed files with 7 additions and 5 deletions
|
@ -182,7 +182,9 @@ Pattern.prototype.sampleRun = function (parts, anchors, run, runs, extraClass =
|
|||
for (let j in this.parts[i].paths) {
|
||||
parts[i].paths[j + '_' + run] = this.parts[i].paths[j]
|
||||
.clone()
|
||||
.attr('style', sampleStyle(run, runs))
|
||||
.attr('style', sampleStyle(run, runs, this.settings.sample.styles))
|
||||
.attr('data-sample-run', run)
|
||||
.attr('data-sample-runs', runs)
|
||||
if (this.parts[i].points.anchor)
|
||||
parts[i].paths[j + '_' + run] = parts[i].paths[j + '_' + run].translate(dx, dy)
|
||||
if (extraClass !== false) parts[i].paths[j + '_' + run].attributes.add('class', extraClass)
|
||||
|
|
|
@ -319,10 +319,10 @@ export function round(value) {
|
|||
return Math.round(value * 1e2) / 1e2
|
||||
}
|
||||
|
||||
export function sampleStyle(run, runs) {
|
||||
let hue = (run - 1) * (330 / runs)
|
||||
|
||||
return `stroke: hsl(${hue}, 100%, 35%);`
|
||||
export function sampleStyle(run, runs, styles = false) {
|
||||
return styles && Array.isArray(styles) && styles.length > 0
|
||||
? styles[run % styles.length]
|
||||
: `stroke: hsl(${(run - 1) * (330 / runs)}, 100%, 35%);`
|
||||
}
|
||||
|
||||
export function deg2rad(degrees) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue