Youen Toupin
3 years ago
6 changed files with 123 additions and 21 deletions
@ -0,0 +1,13 @@
|
||||
div.widget span.integral-value { |
||||
font-size: 2.3rem; |
||||
font-family: monospace; |
||||
} |
||||
|
||||
div.widget span.decimal-value { |
||||
font-size: 1.6rem; |
||||
font-family: monospace; |
||||
} |
||||
|
||||
div.widget span.unit { |
||||
font-size: 1.6rem; |
||||
} |
@ -0,0 +1,47 @@
|
||||
import m from 'mithril'; |
||||
import { Widget } from 'components/widgets/widget'; |
||||
import { Pipe } from 'utilities/pipe'; |
||||
|
||||
require('./numeric-value.css'); |
||||
|
||||
export class NumericValue extends Widget { |
||||
private value: Pipe<number>; |
||||
private unit: string; |
||||
private decimals: number; |
||||
|
||||
private integralValueElement: HTMLElement; |
||||
private decimalValueElement: HTMLElement; |
||||
|
||||
constructor(vnode: any) { |
||||
super(vnode); |
||||
|
||||
this.value = vnode.attrs.value || new Pipe(0.0); |
||||
this.unit = vnode.attrs.unit || ''; |
||||
this.decimals = vnode.attrs.decimals || 0; |
||||
|
||||
this.value.onChange(() => this.onValueChange()); |
||||
} |
||||
|
||||
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> |
||||
</div>; |
||||
} |
||||
|
||||
onValueChange() { |
||||
let value = this.value.get(); |
||||
|
||||
let valueStr = value.toFixed(this.decimals); |
||||
let parts = valueStr.split('.'); |
||||
|
||||
this.integralValueElement.innerText = parts[0]; |
||||
this.decimalValueElement.innerText = this.decimals > 0 ? '.' + parts[1] : ''; |
||||
} |
||||
|
||||
oncreate(vnode: any) { |
||||
this.integralValueElement = vnode.dom.querySelector('span.integral-value'); |
||||
this.decimalValueElement = vnode.dom.querySelector('span.decimal-value'); |
||||
|
||||
this.onValueChange(); |
||||
} |
||||
} |
Loading…
Reference in new issue