|
|
|
@ -1,18 +1,11 @@
|
|
|
|
|
import m from 'mithril'; |
|
|
|
|
import { Widget } from 'components/widgets/widget'; |
|
|
|
|
import { NumericValue } from 'components/widgets/numeric-value'; |
|
|
|
|
import { Pipe } from 'utilities/pipe'; |
|
|
|
|
|
|
|
|
|
require('./gauge.css'); |
|
|
|
|
|
|
|
|
|
export class Gauge extends Widget { |
|
|
|
|
private gaugeValue: Pipe<number>; |
|
|
|
|
private gaugeMaxValue: number; |
|
|
|
|
private unit: string; |
|
|
|
|
private decimals: number; |
|
|
|
|
|
|
|
|
|
export class Gauge extends NumericValue { |
|
|
|
|
protected bars: SVGGeometryElement[] = []; |
|
|
|
|
private integralValueElement: HTMLElement; |
|
|
|
|
private decimalValueElement: HTMLElement; |
|
|
|
|
|
|
|
|
|
private displayedValue = 0.0; |
|
|
|
|
private targetValue = 0.0; |
|
|
|
@ -27,13 +20,6 @@ export class Gauge extends Widget {
|
|
|
|
|
|
|
|
|
|
constructor(vnode: any) { |
|
|
|
|
super(vnode); |
|
|
|
|
|
|
|
|
|
this.gaugeValue = vnode.attrs.gaugeValue || new Pipe(0.0); |
|
|
|
|
this.gaugeMaxValue = vnode.attrs.gaugeMaxValue || 1.0; |
|
|
|
|
this.unit = vnode.attrs.unit || ''; |
|
|
|
|
this.decimals = vnode.attrs.decimals || 0; |
|
|
|
|
|
|
|
|
|
this.gaugeValue.onChange(() => this.updateGauge()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onbeforeremove(vnode: m.Vnode<{}, {}>) { |
|
|
|
@ -41,26 +27,15 @@ export class Gauge extends Widget {
|
|
|
|
|
super.onbeforeremove(vnode); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
view(vnode: m.Vnode<{}, {}>): m.Children { |
|
|
|
|
return <div class="widget gauge" style={'flex: ' + this.widgetWidth}> |
|
|
|
|
<p><span class="integral-value"></span><span class="decimal-value"></span><span class="unit">{this.unit}</span></p> |
|
|
|
|
<svg> |
|
|
|
|
</svg> |
|
|
|
|
</div>; |
|
|
|
|
|
|
|
|
|
protected graphicalRepresentation(vnode: m.Vnode<{}, {}>): m.Children { |
|
|
|
|
return <svg></svg>; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
updateGauge() { |
|
|
|
|
protected onValueChange(value: number) { |
|
|
|
|
let now = Date.now() / 1000.0; |
|
|
|
|
|
|
|
|
|
let value = Math.max(0.0, Math.min(this.gaugeMaxValue, this.gaugeValue.get())); |
|
|
|
|
|
|
|
|
|
let valueStr = value.toFixed(this.decimals); |
|
|
|
|
let parts = valueStr.split('.'); |
|
|
|
|
|
|
|
|
|
this.integralValueElement.innerText = parts[0]; |
|
|
|
|
this.decimalValueElement.innerText = this.decimals > 0 ? '.' + parts[1] : ''; |
|
|
|
|
|
|
|
|
|
let ratio = value / this.gaugeMaxValue; |
|
|
|
|
let ratio = value / (this.maxValue || 1.0); |
|
|
|
|
let numBars = this.bars.length; |
|
|
|
|
let threshold = 0.33 / numBars; |
|
|
|
|
|
|
|
|
@ -124,11 +99,4 @@ export class Gauge extends Widget {
|
|
|
|
|
bar.classList.toggle('lit', isLit); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
oncreate(vnode: any) { |
|
|
|
|
this.integralValueElement = vnode.dom.querySelector('span.integral-value'); |
|
|
|
|
this.decimalValueElement = vnode.dom.querySelector('span.decimal-value'); |
|
|
|
|
|
|
|
|
|
this.updateGauge(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|