1
0
Fork 0

feat(core): Added support for custom sample styles

This commit is contained in:
Joost De Cock 2020-07-11 15:15:02 +02:00
parent e415816f66
commit 7d3815939b
7 changed files with 66 additions and 110 deletions

View file

@ -182,7 +182,18 @@ 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, this.settings.sample.styles))
.attr(
'style',
extraClass === 'sample-focus'
? this.settings.sample
? this.settings.sample.focusStyle || sampleStyle(run, runs)
: sampleStyle(run, runs)
: sampleStyle(
run,
runs,
this.settings.sample ? this.settings.sample.styles || false : false
)
)
.attr('data-sample-run', run)
.attr('data-sample-runs', runs)
if (this.parts[i].points.anchor)
@ -216,11 +227,6 @@ Pattern.prototype.sampleOption = function (optionName) {
step = (option.max / factor - val) / 9
for (let run = 1; run < 11; run++) {
this.settings.options[optionName] = val
this.debug({
type: 'info',
label: '🏃🏿‍♀️ Sample run',
msg: `Sampling option ${optionName} with value ${round(val)}`
})
this.sampleRun(parts, anchors, run, 10)
val += step
}
@ -238,11 +244,6 @@ Pattern.prototype.sampleListOption = function (optionName) {
let runs = option.list.length
for (let val of option.list) {
this.settings.options[optionName] = val
this.debug({
type: 'info',
label: '🏃🏿‍♀️ Sample run',
msg: `Sampling option ${optionName} with value ${round(val)}`
})
this.sampleRun(parts, anchors, run, runs)
run++
}
@ -266,11 +267,6 @@ Pattern.prototype.sampleMeasurement = function (measurementName) {
val = val * 0.9
for (let run = 1; run < 11; run++) {
this.settings.measurements[measurementName] = val
this.debug({
type: 'info',
label: '🏃🏿‍♀️ Sample run',
msg: `Sampling option ${measurementName} with value ${round(val)}`
})
this.sampleRun(parts, anchors, run, 10)
val += step
}
@ -288,18 +284,18 @@ Pattern.prototype.sampleModels = function (models, focus = false) {
this.runHooks('preSample')
let anchors = {}
let parts = this.sampleParts()
let run = 0
// If there's a focus, do it first so it's at the bottom of the SVG
if (focus) {
this.settings.measurements = models[focus]
this.sampleRun(parts, anchors, -1, -1, 'sample-focus')
delete models[focus]
}
let run = -1
let runs = Object.keys(models).length
for (let l in models) {
run++
this.settings.measurements = models[l]
this.debug({
type: 'info',
label: '🏃🏿‍♀️ Sample run',
msg: `Sampling model ${l}`
})
let className = l === focus ? 'sample-focus' : ''
this.sampleRun(parts, anchors, run, runs, className)
this.sampleRun(parts, anchors, run, runs)
}
this.parts = parts
this.runHooks('postSample')
@ -307,11 +303,6 @@ Pattern.prototype.sampleModels = function (models, focus = false) {
return this
}
/** Debug method, exposes debug hook */
Pattern.prototype.debug = function (data) {
this.runHooks('debug', data)
}
Pattern.prototype.render = function () {
this.svg = new Svg(this)
this.svg.hooks = this.hooks
@ -324,11 +315,6 @@ Pattern.prototype.on = function (hook, method, data) {
}
Pattern.prototype.use = function (plugin, data) {
this.debug({
type: 'success',
label: '🔌 Plugin loaded',
msg: `${plugin.name} v${plugin.version}`
})
if (plugin.hooks) this.loadPluginHooks(plugin, data)
if (plugin.macros) this.loadPluginMacros(plugin)