48 changed files with 870 additions and 178 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,159 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2024 The Thingsboard Authors |
|||
|
|||
Licensed under the Apache License, Version 2.0 (the "License"); |
|||
you may not use this file except in compliance with the License. |
|||
You may obtain a copy of the License at |
|||
|
|||
http://www.apache.org/licenses/LICENSE-2.0 |
|||
|
|||
Unless required by applicable law or agreed to in writing, software |
|||
distributed under the License is distributed on an "AS IS" BASIS, |
|||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
See the License for the specific language governing permissions and |
|||
limitations under the License. |
|||
|
|||
--> |
|||
<ng-container [formGroup]="timeSeriesChartWidgetSettingsForm"> |
|||
<tb-time-series-chart-thresholds-panel |
|||
formControlName="thresholds" |
|||
[aliasController]="aliasController" |
|||
[dataKeyCallbacks]="dataKeyCallbacks" |
|||
[datasource]="datasource" |
|||
[widgetConfig]="widgetConfig?.config"> |
|||
</tb-time-series-chart-thresholds-panel> |
|||
<div class="tb-form-panel"> |
|||
<div class="tb-form-panel-title" translate>widgets.time-series-chart.chart-style</div> |
|||
<div class="tb-form-row"> |
|||
<mat-slide-toggle class="mat-slide" formControlName="dataZoom"> |
|||
{{ 'widgets.time-series-chart.data-zoom' | translate }} |
|||
</mat-slide-toggle> |
|||
</div> |
|||
<div class="tb-form-row"> |
|||
<mat-slide-toggle class="mat-slide" formControlName="stack"> |
|||
<div tb-hint-tooltip-icon="{{'widgets.time-series-chart.stack-mode-hint' | translate}}"> |
|||
{{ 'widgets.time-series-chart.stack-mode' | translate }} |
|||
</div> |
|||
</mat-slide-toggle> |
|||
</div> |
|||
<div class="tb-form-panel"> |
|||
<div class="tb-form-panel-title" translate>widgets.time-series-chart.axis.axes</div> |
|||
<tb-time-series-chart-axis-settings |
|||
formControlName="yAxis" |
|||
axisType="yAxis"> |
|||
</tb-time-series-chart-axis-settings> |
|||
<tb-time-series-chart-axis-settings |
|||
formControlName="xAxis" |
|||
axisType="xAxis"> |
|||
</tb-time-series-chart-axis-settings> |
|||
</div> |
|||
<div class="tb-form-panel tb-slide-toggle"> |
|||
<mat-expansion-panel class="tb-settings" [expanded]="timeSeriesChartWidgetSettingsForm.get('showLegend').value" |
|||
[disabled]="!timeSeriesChartWidgetSettingsForm.get('showLegend').value"> |
|||
<mat-expansion-panel-header fxLayout="row wrap"> |
|||
<mat-panel-title> |
|||
<mat-slide-toggle class="mat-slide" formControlName="showLegend" (click)="$event.stopPropagation()" |
|||
fxLayoutAlign="center"> |
|||
{{ 'widget-config.legend' | translate }} |
|||
</mat-slide-toggle> |
|||
</mat-panel-title> |
|||
</mat-expansion-panel-header> |
|||
<ng-template matExpansionPanelContent> |
|||
<div class="tb-form-row space-between"> |
|||
<div>{{ 'legend.label' | translate }}</div> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<tb-font-settings formControlName="legendLabelFont" |
|||
previewText="Temperature"> |
|||
</tb-font-settings> |
|||
<tb-color-input asBoxInput |
|||
colorClearButton |
|||
formControlName="legendLabelColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
<tb-legend-config hideDirection |
|||
formControlName="legendConfig"> |
|||
</tb-legend-config> |
|||
</ng-template> |
|||
</mat-expansion-panel> |
|||
</div> |
|||
<div class="tb-form-panel tb-slide-toggle"> |
|||
<mat-expansion-panel class="tb-settings" [expanded]="timeSeriesChartWidgetSettingsForm.get('showTooltip').value" |
|||
[disabled]="!timeSeriesChartWidgetSettingsForm.get('showTooltip').value"> |
|||
<mat-expansion-panel-header fxLayout="row wrap"> |
|||
<mat-panel-title> |
|||
<mat-slide-toggle class="mat-slide" formControlName="showTooltip" (click)="$event.stopPropagation()" |
|||
fxLayoutAlign="center"> |
|||
{{ 'widget-config.tooltip' | translate }} |
|||
</mat-slide-toggle> |
|||
</mat-panel-title> |
|||
</mat-expansion-panel-header> |
|||
<ng-template matExpansionPanelContent> |
|||
<div class="tb-form-row space-between"> |
|||
<div>{{ 'tooltip.trigger' | translate }}</div> |
|||
<mat-chip-listbox class="center-stretch" formControlName="tooltipTrigger"> |
|||
<mat-chip-option [selectable]="timeSeriesChartWidgetSettingsForm.get('tooltipTrigger').value !== EChartsTooltipTrigger.point" |
|||
[value]="EChartsTooltipTrigger.point">{{ 'tooltip.trigger-point' | translate }}</mat-chip-option> |
|||
<mat-chip-option [selectable]="timeSeriesChartWidgetSettingsForm.get('tooltipTrigger').value !== EChartsTooltipTrigger.axis" |
|||
[value]="EChartsTooltipTrigger.axis">{{ 'tooltip.trigger-axis' | translate }}</mat-chip-option> |
|||
</mat-chip-listbox> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<div>{{ 'tooltip.value' | translate }}</div> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<tb-font-settings formControlName="tooltipValueFont" |
|||
[previewText]="tooltipValuePreviewFn"> |
|||
</tb-font-settings> |
|||
<tb-color-input asBoxInput |
|||
colorClearButton |
|||
formControlName="tooltipValueColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row column-xs"> |
|||
<mat-slide-toggle class="mat-slide fixed-title-width" formControlName="tooltipShowDate"> |
|||
{{ 'tooltip.date' | translate }} |
|||
</mat-slide-toggle> |
|||
<div fxFlex.gt-xs fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<tb-date-format-select fxFlex excludeLastUpdateAgo formControlName="tooltipDateFormat"></tb-date-format-select> |
|||
<tb-font-settings formControlName="tooltipDateFont" |
|||
[previewText]="tooltipDatePreviewFn"> |
|||
</tb-font-settings> |
|||
<tb-color-input asBoxInput |
|||
colorClearButton |
|||
formControlName="tooltipDateColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row"> |
|||
<mat-slide-toggle class="mat-slide" formControlName="tooltipDateInterval"> |
|||
<div tb-hint-tooltip-icon="{{'tooltip.show-date-time-interval-hint' | translate}}"> |
|||
{{ 'tooltip.show-date-time-interval' | translate }} |
|||
</div> |
|||
</mat-slide-toggle> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<div>{{ 'tooltip.background-color' | translate }}</div> |
|||
<tb-color-input asBoxInput |
|||
colorClearButton |
|||
formControlName="tooltipBackgroundColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<div>{{ 'tooltip.background-blur' | translate }}</div> |
|||
<mat-form-field appearance="outline" class="number" subscriptSizing="dynamic"> |
|||
<input matInput formControlName="tooltipBackgroundBlur" type="number" min="0" step="1" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
<div matSuffix>px</div> |
|||
</mat-form-field> |
|||
</div> |
|||
</ng-template> |
|||
</mat-expansion-panel> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<div>{{ 'widgets.background.background' | translate }}</div> |
|||
<tb-background-settings formControlName="background"> |
|||
</tb-background-settings> |
|||
</div> |
|||
</div> |
|||
</ng-container> |
|||
@ -0,0 +1,174 @@ |
|||
///
|
|||
/// Copyright © 2016-2024 The Thingsboard Authors
|
|||
///
|
|||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|||
/// you may not use this file except in compliance with the License.
|
|||
/// You may obtain a copy of the License at
|
|||
///
|
|||
/// http://www.apache.org/licenses/LICENSE-2.0
|
|||
///
|
|||
/// Unless required by applicable law or agreed to in writing, software
|
|||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
/// See the License for the specific language governing permissions and
|
|||
/// limitations under the License.
|
|||
///
|
|||
|
|||
import { Component, Injector } from '@angular/core'; |
|||
import { |
|||
Datasource, |
|||
legendPositions, |
|||
legendPositionTranslationMap, |
|||
WidgetSettings, |
|||
WidgetSettingsComponent |
|||
} from '@shared/models/widget.models'; |
|||
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { formatValue, mergeDeep } from '@core/utils'; |
|||
import { DateFormatProcessor, DateFormatSettings } from '@shared/models/widget-settings.models'; |
|||
import { |
|||
barChartWithLabelsDefaultSettings |
|||
} from '@home/components/widget/lib/chart/bar-chart-with-labels-widget.models'; |
|||
import { EChartsTooltipTrigger } from '../../chart/echarts-widget.models'; |
|||
import { |
|||
timeSeriesChartWidgetDefaultSettings, TimeSeriesChartWidgetSettings |
|||
} from '@home/components/widget/lib/chart/time-series-chart-widget.models'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-time-series-chart-widget-settings', |
|||
templateUrl: './time-series-chart-widget-settings.component.html', |
|||
styleUrls: ['./../widget-settings.scss'] |
|||
}) |
|||
export class TimeSeriesChartWidgetSettingsComponent extends WidgetSettingsComponent { |
|||
|
|||
public get datasource(): Datasource { |
|||
const datasources: Datasource[] = this.widgetConfig.config.datasources; |
|||
if (datasources && datasources.length) { |
|||
return datasources[0]; |
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
EChartsTooltipTrigger = EChartsTooltipTrigger; |
|||
|
|||
legendPositions = legendPositions; |
|||
|
|||
legendPositionTranslationMap = legendPositionTranslationMap; |
|||
|
|||
timeSeriesChartWidgetSettingsForm: UntypedFormGroup; |
|||
|
|||
tooltipValuePreviewFn = this._tooltipValuePreviewFn.bind(this); |
|||
|
|||
tooltipDatePreviewFn = this._tooltipDatePreviewFn.bind(this); |
|||
|
|||
constructor(protected store: Store<AppState>, |
|||
private $injector: Injector, |
|||
private fb: UntypedFormBuilder) { |
|||
super(store); |
|||
} |
|||
|
|||
protected settingsForm(): UntypedFormGroup { |
|||
return this.timeSeriesChartWidgetSettingsForm; |
|||
} |
|||
|
|||
protected defaultSettings(): WidgetSettings { |
|||
return mergeDeep({} as TimeSeriesChartWidgetSettings, timeSeriesChartWidgetDefaultSettings); |
|||
} |
|||
|
|||
protected onSettingsSet(settings: WidgetSettings) { |
|||
this.timeSeriesChartWidgetSettingsForm = this.fb.group({ |
|||
|
|||
thresholds: [settings.thresholds, []], |
|||
|
|||
dataZoom: [settings.dataZoom, []], |
|||
stack: [settings.stack, []], |
|||
|
|||
yAxis: [settings.yAxis, []], |
|||
xAxis: [settings.xAxis, []], |
|||
|
|||
showLegend: [settings.showLegend, []], |
|||
legendLabelFont: [settings.legendLabelFont, []], |
|||
legendLabelColor: [settings.legendLabelColor, []], |
|||
legendConfig: [settings.legendConfig, []], |
|||
|
|||
showTooltip: [settings.showTooltip, []], |
|||
tooltipTrigger: [settings.tooltipTrigger, []], |
|||
tooltipValueFont: [settings.tooltipValueFont, []], |
|||
tooltipValueColor: [settings.tooltipValueColor, []], |
|||
tooltipShowDate: [settings.tooltipShowDate, []], |
|||
tooltipDateFormat: [settings.tooltipDateFormat, []], |
|||
tooltipDateFont: [settings.tooltipDateFont, []], |
|||
tooltipDateColor: [settings.tooltipDateColor, []], |
|||
tooltipDateInterval: [settings.tooltipDateInterval, []], |
|||
|
|||
tooltipBackgroundColor: [settings.tooltipBackgroundColor, []], |
|||
tooltipBackgroundBlur: [settings.tooltipBackgroundBlur, []], |
|||
|
|||
background: [settings.background, []] |
|||
}); |
|||
} |
|||
|
|||
protected validatorTriggers(): string[] { |
|||
return ['showLegend', 'showTooltip', 'tooltipShowDate']; |
|||
} |
|||
|
|||
protected updateValidators(emitEvent: boolean) { |
|||
const showLegend: boolean = this.timeSeriesChartWidgetSettingsForm.get('showLegend').value; |
|||
const showTooltip: boolean = this.timeSeriesChartWidgetSettingsForm.get('showTooltip').value; |
|||
const tooltipShowDate: boolean = this.timeSeriesChartWidgetSettingsForm.get('tooltipShowDate').value; |
|||
|
|||
if (showLegend) { |
|||
this.timeSeriesChartWidgetSettingsForm.get('legendLabelFont').enable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('legendLabelColor').enable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('legendConfig').enable(); |
|||
} else { |
|||
this.timeSeriesChartWidgetSettingsForm.get('legendLabelFont').disable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('legendLabelColor').disable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('legendConfig').disable(); |
|||
} |
|||
|
|||
if (showTooltip) { |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipTrigger').enable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipValueFont').enable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipValueColor').enable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipShowDate').enable({emitEvent: false}); |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipBackgroundColor').enable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipBackgroundBlur').enable(); |
|||
if (tooltipShowDate) { |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipDateFormat').enable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipDateFont').enable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipDateColor').enable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipDateInterval').enable(); |
|||
} else { |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipDateFormat').disable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipDateFont').disable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipDateColor').disable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipDateInterval').disable(); |
|||
} |
|||
} else { |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipValueFont').disable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipValueColor').disable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipShowDate').disable({emitEvent: false}); |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipDateFormat').disable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipDateFont').disable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipDateColor').disable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipDateInterval').disable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipBackgroundColor').disable(); |
|||
this.timeSeriesChartWidgetSettingsForm.get('tooltipBackgroundBlur').disable(); |
|||
} |
|||
} |
|||
|
|||
private _tooltipValuePreviewFn(): string { |
|||
return formatValue(22, 0, '°C', false); |
|||
} |
|||
|
|||
private _tooltipDatePreviewFn(): string { |
|||
const dateFormat: DateFormatSettings = this.timeSeriesChartWidgetSettingsForm.get('tooltipDateFormat').value; |
|||
const processor = DateFormatProcessor.fromSettings(this.$injector, dateFormat); |
|||
processor.update(Date.now()); |
|||
return processor.formatted; |
|||
} |
|||
|
|||
} |
|||
Loading…
Reference in new issue