Prettified all files.
This commit is contained in:
+45
-23
@@ -1,13 +1,30 @@
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
export default class Popover extends PIXI.Graphics {
|
||||
|
||||
constructor({title = null, text = null, x = 0, y = 0, placement = 'top', width = 250, titleStyle = {}, textStyle = {fontSize: '1.6em'}} = {}) {
|
||||
constructor({
|
||||
title = null,
|
||||
text = null,
|
||||
x = 0,
|
||||
y = 0,
|
||||
placement = 'top',
|
||||
width = 250,
|
||||
titleStyle = {},
|
||||
textStyle = { fontSize: '1.6em' }
|
||||
} = {}) {
|
||||
super()
|
||||
|
||||
this.opts = {title, text, x, y, placement, width, titleStyle, textStyle}
|
||||
|
||||
this.opts = {
|
||||
title,
|
||||
text,
|
||||
x,
|
||||
y,
|
||||
placement,
|
||||
width,
|
||||
titleStyle,
|
||||
textStyle
|
||||
}
|
||||
|
||||
this.padding = 12
|
||||
|
||||
let style = {
|
||||
@@ -16,12 +33,16 @@ export default class Popover extends PIXI.Graphics {
|
||||
stroke: '#f6f6f6',
|
||||
strokeThickness: 3,
|
||||
wordWrap: true,
|
||||
wordWrapWidth: width - (this.padding * 2)
|
||||
wordWrapWidth: width - this.padding * 2
|
||||
}
|
||||
|
||||
this.titleTextStyle = new PIXI.TextStyle(Object.assign({}, style, titleStyle))
|
||||
this.textTextStyle = new PIXI.TextStyle(Object.assign({}, style, textStyle))
|
||||
|
||||
this.titleTextStyle = new PIXI.TextStyle(
|
||||
Object.assign({}, style, titleStyle)
|
||||
)
|
||||
this.textTextStyle = new PIXI.TextStyle(
|
||||
Object.assign({}, style, textStyle)
|
||||
)
|
||||
|
||||
if (title || text) {
|
||||
this.setup()
|
||||
this.draw()
|
||||
@@ -43,7 +64,10 @@ export default class Popover extends PIXI.Graphics {
|
||||
|
||||
if (this.opts.text) {
|
||||
this.textText = new PIXI.Text(this.opts.text, this.textTextStyle)
|
||||
this.textText.position.set(this.padding, this.titleY + this.titleHeight + this.padding)
|
||||
this.textText.position.set(
|
||||
this.padding,
|
||||
this.titleY + this.titleHeight + this.padding
|
||||
)
|
||||
this.addChild(this.textText)
|
||||
}
|
||||
|
||||
@@ -58,7 +82,7 @@ export default class Popover extends PIXI.Graphics {
|
||||
draw() {
|
||||
this.clear()
|
||||
this.beginFill(0xffffff, 1)
|
||||
this.lineStyle(1, 0x282828, .5)
|
||||
this.lineStyle(1, 0x282828, 0.5)
|
||||
|
||||
// Draw rounded rectangle
|
||||
const height = this.height + this.padding
|
||||
@@ -72,7 +96,7 @@ export default class Popover extends PIXI.Graphics {
|
||||
this.lineStyle(0)
|
||||
this.beginFill(0xf7f7f7, 1)
|
||||
let x = 1
|
||||
let y = this.titleText.x + this.titleText.height + (this.padding / 2)
|
||||
let y = this.titleText.x + this.titleText.height + this.padding / 2
|
||||
this.moveTo(x, y)
|
||||
y = 9
|
||||
this.lineTo(x, y)
|
||||
@@ -82,7 +106,7 @@ export default class Popover extends PIXI.Graphics {
|
||||
this.lineTo(x, y)
|
||||
this.quadraticCurveTo(x + 5, y, x + 5, y + 8)
|
||||
x += 5
|
||||
y += this.titleText.x + this.titleText.height + (this.padding / 2)
|
||||
y += this.titleText.x + this.titleText.height + this.padding / 2
|
||||
this.lineTo(x, y)
|
||||
if (this.opts.text) {
|
||||
x = 1
|
||||
@@ -100,7 +124,6 @@ export default class Popover extends PIXI.Graphics {
|
||||
}
|
||||
|
||||
drawAnchor(placement) {
|
||||
|
||||
let x = 0
|
||||
let y = 0
|
||||
|
||||
@@ -109,7 +132,7 @@ export default class Popover extends PIXI.Graphics {
|
||||
if (this.opts.title) {
|
||||
this.beginFill(0xf7f7f7, 1)
|
||||
}
|
||||
x = (this.width / 2) - 10
|
||||
x = this.width / 2 - 10
|
||||
y = 1
|
||||
this.moveTo(x, y)
|
||||
x += 10
|
||||
@@ -121,7 +144,7 @@ export default class Popover extends PIXI.Graphics {
|
||||
break
|
||||
case 'right':
|
||||
x = 1
|
||||
y = (this.height / 2) - 10
|
||||
y = this.height / 2 - 10
|
||||
if (this.titleY + this.titleHeight > y) {
|
||||
this.beginFill(0xf7f7f7, 1)
|
||||
}
|
||||
@@ -135,7 +158,7 @@ export default class Popover extends PIXI.Graphics {
|
||||
break
|
||||
case 'left':
|
||||
x = this.width - 2
|
||||
y = (this.height / 2) - 10
|
||||
y = this.height / 2 - 10
|
||||
if (this.titleY + this.titleHeight > y) {
|
||||
this.beginFill(0xf7f7f7, 1)
|
||||
}
|
||||
@@ -148,7 +171,7 @@ export default class Popover extends PIXI.Graphics {
|
||||
this.lineTo(x, y)
|
||||
break
|
||||
default:
|
||||
x = (this.width / 2) - 10
|
||||
x = this.width / 2 - 10
|
||||
y = this.height - 2
|
||||
this.moveTo(x, y)
|
||||
x += 10
|
||||
@@ -162,22 +185,21 @@ export default class Popover extends PIXI.Graphics {
|
||||
}
|
||||
|
||||
positioning() {
|
||||
|
||||
const x = this.opts.x
|
||||
const y = this.opts.y
|
||||
|
||||
switch (this.opts.placement) {
|
||||
case 'bottom':
|
||||
this.position.set(x - (this.width / 2), y + 10)
|
||||
this.position.set(x - this.width / 2, y + 10)
|
||||
break
|
||||
case 'right':
|
||||
this.position.set(x, y - (this.height / 2))
|
||||
this.position.set(x, y - this.height / 2)
|
||||
break
|
||||
case 'left':
|
||||
this.position.set(x - this.width, y - (this.height / 2))
|
||||
this.position.set(x - this.width, y - this.height / 2)
|
||||
break
|
||||
default:
|
||||
this.position.set(x - (this.width / 2), y - this.height)
|
||||
this.position.set(x - this.width / 2, y - this.height)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user