Prettified all files.

This commit is contained in:
2019-07-18 12:26:39 +02:00
parent 7744b92771
commit 2d400a18ec
125 changed files with 11184 additions and 8154 deletions
+92 -67
View File
@@ -2,7 +2,7 @@ import Theme from './theme.js'
/**
* Class that represents a PixiJS Progress.
*
*
* @example
* // Create the progress
* const progress = new Progress({
@@ -18,10 +18,9 @@ import Theme from './theme.js'
* @see {@link https://www.iwm-tuebingen.de/iwmbrowser/lib/pixi/progress.html|DocTest}
*/
export default class Progress extends PIXI.Container {
/**
* Creates an instance of a Progress.
*
*
* @constructor
* @param {object} [opts] - An options object to specify to style and behaviour of the progress.
* @param {number} [opts.id=auto generated] - The id of the progress.
@@ -53,36 +52,39 @@ export default class Progress extends PIXI.Container {
* @param {boolean} [opts.visible=true] - Is the progress initially visible (property visible)?
*/
constructor(opts = {}) {
super()
const theme = Theme.fromString(opts.theme)
this.theme = theme
this.opts = Object.assign({}, {
id: PIXI.utils.uid(),
app: window.app,
width: null,
height: 2,
margin: 100,
padding: 0,
fill: theme.fill,
fillAlpha: theme.fillAlpha,
fillActive: theme.primaryColor,
fillActiveAlpha: theme.fillActiveAlpha,
stroke: theme.stroke,
strokeWidth: 0,
strokeAlpha: theme.strokeAlpha,
strokeActive: theme.strokeActive,
strokeActiveWidth: 0,
strokeActiveAlpha: theme.strokeActiveAlpha,
background: false,
backgroundFill: theme.background,
backgroundFillAlpha: 1,
radius: theme.radius,
destroyOnComplete: true,
visible: true
}, opts)
this.opts = Object.assign(
{},
{
id: PIXI.utils.uid(),
app: window.app,
width: null,
height: 2,
margin: 100,
padding: 0,
fill: theme.fill,
fillAlpha: theme.fillAlpha,
fillActive: theme.primaryColor,
fillActiveAlpha: theme.fillActiveAlpha,
stroke: theme.stroke,
strokeWidth: 0,
strokeAlpha: theme.strokeAlpha,
strokeActive: theme.strokeActive,
strokeActiveWidth: 0,
strokeActiveAlpha: theme.strokeActiveAlpha,
background: false,
backgroundFill: theme.background,
backgroundFillAlpha: 1,
radius: theme.radius,
destroyOnComplete: true,
visible: true
},
opts
)
this.id = this.opts.id
@@ -91,7 +93,7 @@ export default class Progress extends PIXI.Container {
this.barActive = null
this.alpha = 0
this.visible = this.opts.visible
this._progress = 0
@@ -104,15 +106,14 @@ export default class Progress extends PIXI.Container {
//-----------------
this.layout()
}
/**
* Creates children and instantiates everything.
*
*
* @private
* @return {Progress} A reference to the progress for chaining.
*/
setup() {
// interaction
//-----------------
this.on('added', e => {
@@ -139,14 +140,13 @@ export default class Progress extends PIXI.Container {
return this
}
/**
* Should be called to refresh the layout of the progress. Can be used after resizing.
*
*
* @return {Progress} A reference to the progress for chaining.
*/
layout() {
const width = this.opts.app.size.width
const height = this.opts.app.size.height
@@ -154,7 +154,10 @@ export default class Progress extends PIXI.Container {
//-----------------
if (this.opts.background) {
this.background.clear()
this.background.beginFill(this.opts.backgroundFill, this.opts.backgroundFillAlpha)
this.background.beginFill(
this.opts.backgroundFill,
this.opts.backgroundFillAlpha
)
this.background.drawRect(0, 0, width, height)
this.background.endFill()
}
@@ -163,15 +166,14 @@ export default class Progress extends PIXI.Container {
return this
}
/**
* Draws the canvas.
*
*
* @private
* @return {Progress} A reference to the progress for chaining.
*/
draw() {
this.bar.clear()
this.barActive.clear()
@@ -180,59 +182,80 @@ export default class Progress extends PIXI.Container {
return this
}
/**
* Draws the bar.
*
*
* @private
* @return {Progress} A reference to the progress for chaining.
*/
drawBar() {
const width = this.opts.app.size.width
const height = this.opts.app.size.height
this.radius = this.opts.radius
if ((this.radius * 2) > this.opts.height) {
if (this.radius * 2 > this.opts.height) {
this.radius = this.opts.height / 2
}
const wantedWidth = this.opts.width || (width - (2 * this.opts.margin))
const wantedWidth = this.opts.width || width - 2 * this.opts.margin
const wantedHeight = this.opts.height
this.bar.lineStyle(this.opts.strokeWidth, this.opts.stroke, this.opts.strokeAlpha)
this.bar.lineStyle(
this.opts.strokeWidth,
this.opts.stroke,
this.opts.strokeAlpha
)
this.bar.beginFill(this.opts.fill, this.opts.fillAlpha)
if (this.radius > 1) {
this.bar.drawRoundedRect(0, 0, wantedWidth, wantedHeight, this.radius)
this.bar.drawRoundedRect(
0,
0,
wantedWidth,
wantedHeight,
this.radius
)
} else {
this.bar.drawRect(0, 0, wantedWidth, wantedHeight)
}
this.bar.endFill()
this.bar.x = width / 2 - this.bar.width / 2
this.bar.y = height / 2 - this.bar.height / 2
return this
}
/**
* Draws the active bar.
*
*
* @private
* @return {Progress} A reference to the progress for chaining.
*/
drawBarActive() {
const wantedWidth = this.bar.width - 2 * this.opts.padding
const wantedHeight = this.bar.height - 2 * this.opts.padding
const wantedWidth = this.bar.width - (2 * this.opts.padding)
const wantedHeight = this.bar.height - (2 * this.opts.padding)
const barActiveWidth = wantedWidth * this._progress / 100
const barActiveWidth = (wantedWidth * this._progress) / 100
this.barActive.lineStyle(this.opts.strokeActiveWidth, this.opts.strokeActive, this.opts.strokeActiveAlpha)
this.barActive.beginFill(this.opts.fillActive, this.opts.fillActiveAlpha)
this.barActive.lineStyle(
this.opts.strokeActiveWidth,
this.opts.strokeActive,
this.opts.strokeActiveAlpha
)
this.barActive.beginFill(
this.opts.fillActive,
this.opts.fillActiveAlpha
)
if (barActiveWidth > 0) {
if (this.radius > 1) {
this.barActive.drawRoundedRect(0, 0, barActiveWidth, wantedHeight, this.radius)
this.barActive.drawRoundedRect(
0,
0,
barActiveWidth,
wantedHeight,
this.radius
)
} else {
this.barActive.drawRect(0, 0, barActiveWidth, wantedHeight)
}
@@ -244,39 +267,41 @@ export default class Progress extends PIXI.Container {
return this
}
/**
* Shows the progress (sets his alpha values to 1).
*
*
* @return {Progress} A reference to the progress for chaining.
*/
show() {
TweenLite.to(this, this.theme.fast, {alpha: 1})
TweenLite.to(this, this.theme.fast, { alpha: 1 })
return this
}
/**
* Hides the progress (sets his alpha values to 1).
*
*
* @return {Progress} A reference to the progress for chaining.
*/
hide() {
TweenLite.to(this, this.theme.fast, {alpha: 0, onComplete: () => this.visible = false})
TweenLite.to(this, this.theme.fast, {
alpha: 0,
onComplete: () => (this.visible = false)
})
return this
}
/**
* Gets or sets the progress. Has to be a number between 0 and 100.
*
*
* @member {number}
*/
get progress() {
return this._progress
}
set progress(value) {
value = Math.round(value)
if (value < 0) {
@@ -294,7 +319,7 @@ export default class Progress extends PIXI.Container {
if (value === 100 && this.opts.destroyOnComplete) {
TweenLite.to(this, this.theme.fast, {
alpha: 0,
onComplete: () => this.destroy({children: true})
onComplete: () => this.destroy({ children: true })
})
}
}