|
|
@ -45,17 +45,10 @@ const DEFAULT_GAUGE_OPTIONS: GaugeOptions = { |
|
|
|
stat: Stat.CURRENT, |
|
|
|
stat: Stat.CURRENT, |
|
|
|
innerRadius: DEFAULT_INNER_RADIUS, |
|
|
|
innerRadius: DEFAULT_INNER_RADIUS, |
|
|
|
outerRadius: DEFAULT_OUTER_RADIUS, |
|
|
|
outerRadius: DEFAULT_OUTER_RADIUS, |
|
|
|
valueTextFormat: { |
|
|
|
valueFormatter: val => val.toString()
|
|
|
|
decimals: DEFAULT_VALUE_TEXT_Decimals |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export class ChartwerkGaugePod extends ChartwerkPod<GaugeTimeSerie, GaugeOptions> { |
|
|
|
export class ChartwerkGaugePod extends ChartwerkPod<GaugeTimeSerie, GaugeOptions> { |
|
|
|
// TODO: better name
|
|
|
|
|
|
|
|
private _gaugeTransform = ''; |
|
|
|
|
|
|
|
private _gaugeCenter = ''; |
|
|
|
|
|
|
|
private _minWH = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor(el: HTMLElement, _series: GaugeTimeSerie[] = [], _options: GaugeOptions = {}) { |
|
|
|
constructor(el: HTMLElement, _series: GaugeTimeSerie[] = [], _options: GaugeOptions = {}) { |
|
|
|
super( |
|
|
|
super( |
|
|
|
d3, el, _series, |
|
|
|
d3, el, _series, |
|
|
@ -69,18 +62,21 @@ export class ChartwerkGaugePod extends ChartwerkPod<GaugeTimeSerie, GaugeOptions |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this._setBoundingBox(); |
|
|
|
|
|
|
|
this._renderValueArc(); |
|
|
|
this._renderValueArc(); |
|
|
|
this._renderThresholdArc(); |
|
|
|
this._renderThresholdArc(); |
|
|
|
this._renderValue(); |
|
|
|
this._renderValue(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private _setBoundingBox(): void { |
|
|
|
get _gaugeTransform(): string { |
|
|
|
// TODO: refactor
|
|
|
|
return `translate(${this.width / 2},${0.8 * this.height})`; |
|
|
|
this._gaugeTransform = `translate(${this.width / 2},${0.8 * this.height})`; |
|
|
|
} |
|
|
|
this._gaugeCenter = `translate(${this.width / 2 + this.margin.left},${0.8 * this.height})`; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this._minWH = _.min([0.6 * this.width, this.height]); |
|
|
|
get _gaugeCenter(): string { |
|
|
|
|
|
|
|
return `translate(${this.width / 2 + this.margin.left},${0.8 * this.height})`; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get _minWH(): number { |
|
|
|
|
|
|
|
return _.min([0.6 * this.width, this.height]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private _renderValue(): void { |
|
|
|
private _renderValue(): void { |
|
|
@ -210,8 +206,11 @@ export class ChartwerkGaugePod extends ChartwerkPod<GaugeTimeSerie, GaugeOptions |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private get _valueText(): string { |
|
|
|
private get _valueText(): string { |
|
|
|
const decimalsCount = this._valueTextDecimals; |
|
|
|
if(this.options.valueFormatter) { |
|
|
|
return this.aggregatedValue.toFixed(decimalsCount); |
|
|
|
console.log('valueFormatter function is not specified, rendering raw value'); |
|
|
|
|
|
|
|
return this.aggregatedValue.toString(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return this.options.valueFormatter(this.aggregatedValue); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private get _valueTextFontSize(): number { |
|
|
|
private get _valueTextFontSize(): number { |
|
|
@ -268,13 +267,6 @@ export class ChartwerkGaugePod extends ChartwerkPod<GaugeTimeSerie, GaugeOptions |
|
|
|
return scale; |
|
|
|
return scale; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private get _valueTextDecimals(): number { |
|
|
|
|
|
|
|
if(this.options.valueTextFormat === undefined) { |
|
|
|
|
|
|
|
throw new Error(`Options has no valueTextFormat`);
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return this.options.valueTextFormat.decimals; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private get aggregatedValue(): number { |
|
|
|
private get aggregatedValue(): number { |
|
|
|
switch(this._stat) { |
|
|
|
switch(this._stat) { |
|
|
|
case Stat.CURRENT: |
|
|
|
case Stat.CURRENT: |
|
|
|