|
|
|
@ -337,6 +337,9 @@ export abstract class PowerButtonShape { |
|
|
|
protected onPowerSymbolLine: Path; |
|
|
|
|
|
|
|
private onIcon$: Observable<Element>; |
|
|
|
private offIcon$: Observable<Element>; |
|
|
|
protected onIconOffsetX: number = 0; |
|
|
|
protected onIconOffsetY: number = 0; |
|
|
|
|
|
|
|
protected constructor(protected widgetContext: WidgetContext, |
|
|
|
protected svgShape: Svg, |
|
|
|
@ -362,10 +365,14 @@ export abstract class PowerButtonShape { |
|
|
|
take(1), |
|
|
|
map((svgElement) => { |
|
|
|
const element = new Element(svgElement.firstChild); |
|
|
|
const iconGroup = this.svgShape.group(); |
|
|
|
element.addTo(iconGroup); |
|
|
|
const box = element.bbox(); |
|
|
|
const scale = size / box.height; |
|
|
|
element.scale(scale); |
|
|
|
return element; |
|
|
|
const scaledBox = iconGroup.bbox(); |
|
|
|
iconGroup.translate(-scaledBox.cx, -scaledBox.cy); |
|
|
|
return iconGroup; |
|
|
|
}), |
|
|
|
catchError(() => of(null) |
|
|
|
)); |
|
|
|
@ -416,8 +423,15 @@ export abstract class PowerButtonShape { |
|
|
|
|
|
|
|
public drawOffShape(centerGroup: G, label: boolean, labelWeight?: string, circleStroke?: boolean) { |
|
|
|
if (this.icons.offButtonIcon.showIcon) { |
|
|
|
this.createIconElement(this.icons.offButtonIcon.icon, this.icons.offButtonIcon.iconSize).subscribe(icon => |
|
|
|
this.offPowerSymbolIcon = icon.center(cx, cy).addTo(centerGroup)); |
|
|
|
this.offIcon$ = this.createIconElement(this.icons.offButtonIcon.icon, this.icons.offButtonIcon.iconSize) |
|
|
|
.pipe(shareReplay(1)); |
|
|
|
|
|
|
|
this.offIcon$.pipe(take(1)).subscribe(icon => { |
|
|
|
this.offPowerSymbolIcon = icon; |
|
|
|
icon.translate(cx, cy); |
|
|
|
centerGroup.add(icon); |
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
if (label) { |
|
|
|
this.offLabelShape = this.createOffLabel(labelWeight).addTo(centerGroup); |
|
|
|
@ -434,9 +448,12 @@ export abstract class PowerButtonShape { |
|
|
|
.pipe(shareReplay(1)); |
|
|
|
|
|
|
|
this.onIcon$.subscribe(icon => { |
|
|
|
this.onPowerSymbolIcon = icon.center(cx, cy); |
|
|
|
const iconBox = icon.bbox(); |
|
|
|
this.onIconOffsetX = iconBox.cx; |
|
|
|
this.onIconOffsetY = iconBox.cy; |
|
|
|
this.onPowerSymbolIcon = icon.translate(cx, cy); |
|
|
|
if (isDefinedAndNotNull(onCenterGroup)) { |
|
|
|
this.onPowerSymbolIcon.addTo(onCenterGroup); |
|
|
|
onCenterGroup.add(this.onPowerSymbolIcon); |
|
|
|
} |
|
|
|
if (isDefinedAndNotNull(mask)) { |
|
|
|
this.createMask(mask, [this.onPowerSymbolIcon]); |
|
|
|
@ -468,7 +485,7 @@ export abstract class PowerButtonShape { |
|
|
|
public onCenterTimeLine(timeline: Timeline, label: boolean) { |
|
|
|
if (this.icons.onButtonIcon.showIcon) { |
|
|
|
if (this.onIcon$) { |
|
|
|
this.onIcon$.subscribe(icon => icon.timeline(timeline)) |
|
|
|
this.onIcon$.subscribe(icon => icon.timeline(timeline)); |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (label) { |
|
|
|
@ -482,7 +499,7 @@ export abstract class PowerButtonShape { |
|
|
|
|
|
|
|
public offCenterColor(mainColor: PowerButtonColor, label: boolean) { |
|
|
|
if (this.icons.offButtonIcon.showIcon) { |
|
|
|
this.offPowerSymbolIcon.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|
|
|
this.offIcon$.subscribe(icon => icon.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity})) |
|
|
|
} else { |
|
|
|
if (label) { |
|
|
|
this.offLabelShape.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|
|
|
@ -495,7 +512,7 @@ export abstract class PowerButtonShape { |
|
|
|
|
|
|
|
public onCenterColor(mainColor: PowerButtonColor, label: boolean) { |
|
|
|
if (this.icons.onButtonIcon.showIcon) { |
|
|
|
this.onPowerSymbolIcon.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|
|
|
this.onIcon$.subscribe((icon)=> icon.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity})) |
|
|
|
} else { |
|
|
|
if (label) { |
|
|
|
this.onLabelShape.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|
|
|
@ -508,7 +525,12 @@ export abstract class PowerButtonShape { |
|
|
|
|
|
|
|
public buttonAnimation(scale: number, label: boolean) { |
|
|
|
if (this.icons.onButtonIcon.showIcon) { |
|
|
|
powerButtonAnimation(this.onPowerSymbolIcon).transform({scale}); |
|
|
|
const translateX = cx - this.onIconOffsetX; |
|
|
|
const translateY = cy - this.onIconOffsetY; |
|
|
|
powerButtonAnimation(this.onPowerSymbolIcon).transform({ |
|
|
|
scale: scale, |
|
|
|
translate: [translateX, translateY] |
|
|
|
}); |
|
|
|
} else { |
|
|
|
if (label) { |
|
|
|
powerButtonAnimation(this.onLabelShape).transform({scale, origin: {x: cx, y: cy}}); |
|
|
|
|