-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '3032-harmonize-data-explorer-and-live-dashboard' of git…
…hub.com:apache/streampipes into 3032-harmonize-data-explorer-and-live-dashboard
- Loading branch information
Showing
8 changed files
with
304 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
ui/src/app/data-explorer/components/widgets/gauge/config/gauge-widget-config.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<!-- | ||
~ Licensed to the Apache Software Foundation (ASF) under one or more | ||
~ contributor license agreements. See the NOTICE file distributed with | ||
~ this work for additional information regarding copyright ownership. | ||
~ The ASF licenses this file to You 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. | ||
~ | ||
--> | ||
|
||
<sp-visualization-config-outer | ||
[configurationValid]=" | ||
currentlyConfiguredWidget.visualizationConfig.configurationValid | ||
" | ||
> | ||
<sp-configuration-box title="Field"> | ||
<sp-select-property | ||
[availableProperties]="fieldProvider.numericFields" | ||
[selectedProperty]=" | ||
currentlyConfiguredWidget.visualizationConfig.selectedProperty | ||
" | ||
(changeSelectedProperty)="setSelectedProperty($event)" | ||
> | ||
</sp-select-property> | ||
</sp-configuration-box> | ||
<sp-configuration-box | ||
title="Settings" | ||
*ngIf=" | ||
currentlyConfiguredWidget.visualizationConfig.selectedProperty | ||
?.fieldCharacteristics.numeric | ||
" | ||
> | ||
<div fxLayout="column"> | ||
<div fxFlex fxLayoutAlign="start center" class="ml-10 mb-10"> | ||
<small>Min</small> | ||
<span fxFlex></span> | ||
<mat-form-field appearance="outline" color="accent" fxFlex="30"> | ||
<input | ||
matInput | ||
type="number" | ||
[(ngModel)]=" | ||
currentlyConfiguredWidget.visualizationConfig.min | ||
" | ||
(ngModelChange)="triggerViewRefresh()" | ||
/> | ||
</mat-form-field> | ||
</div> | ||
<div fxFlex fxLayoutAlign="start center" class="ml-10 mb-10"> | ||
<small>Max</small> | ||
<span fxFlex></span> | ||
<mat-form-field appearance="outline" color="accent" fxFlex="30"> | ||
<input | ||
matInput | ||
type="number" | ||
[(ngModel)]=" | ||
currentlyConfiguredWidget.visualizationConfig.max | ||
" | ||
(ngModelChange)="triggerViewRefresh()" | ||
/> | ||
</mat-form-field> | ||
</div> | ||
</div> | ||
</sp-configuration-box> | ||
</sp-visualization-config-outer> |
60 changes: 60 additions & 0 deletions
60
ui/src/app/data-explorer/components/widgets/gauge/config/gauge-widget-config.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 } from '@angular/core'; | ||
import { BaseWidgetConfig } from '../../base/base-widget-config'; | ||
import { WidgetConfigurationService } from '../../../../services/widget-configuration.service'; | ||
import { DataExplorerFieldProviderService } from '../../../../services/data-explorer-field-provider-service'; | ||
import { GaugeVisConfig, GaugeWidgetModel } from '../model/gauge-widget.model'; | ||
import { DataExplorerField } from '@streampipes/platform-services'; | ||
|
||
@Component({ | ||
selector: 'sp-data-explorer-gauge-widget-config', | ||
templateUrl: './gauge-widget-config.component.html', | ||
}) | ||
export class GaugeWidgetConfigComponent extends BaseWidgetConfig< | ||
GaugeWidgetModel, | ||
GaugeVisConfig | ||
> { | ||
constructor( | ||
widgetConfigurationService: WidgetConfigurationService, | ||
fieldService: DataExplorerFieldProviderService, | ||
) { | ||
super(widgetConfigurationService, fieldService); | ||
} | ||
|
||
setSelectedProperty(field: DataExplorerField) { | ||
this.currentlyConfiguredWidget.visualizationConfig.selectedProperty = | ||
field; | ||
this.triggerViewRefresh(); | ||
} | ||
|
||
protected applyWidgetConfig(config: GaugeVisConfig): void { | ||
config.selectedProperty = this.fieldService.getSelectedField( | ||
config.selectedProperty, | ||
this.fieldProvider.numericFields, | ||
() => this.fieldProvider.numericFields[0], | ||
); | ||
config.min ??= 0; | ||
config.max ??= 100; | ||
} | ||
|
||
protected requiredFieldsForChartPresent(): boolean { | ||
return this.fieldProvider.numericFields.length > 0; | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
ui/src/app/data-explorer/components/widgets/gauge/gauge-renderer.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 { inject, Injectable } from '@angular/core'; | ||
import { GaugeWidgetModel } from './model/gauge-widget.model'; | ||
import { EChartsOption, GaugeSeriesOption } from 'echarts'; | ||
import { FieldUpdateInfo } from '../../../models/field-update.model'; | ||
import { | ||
DataExplorerField, | ||
SpQueryResult, | ||
} from '@streampipes/platform-services'; | ||
import { | ||
SpEchartsRenderer, | ||
WidgetEchartsAppearanceConfig, | ||
} from '../../../models/dataview-dashboard.model'; | ||
import { WidgetSize } from '../../../models/dataset.model'; | ||
import { EchartsBasicOptionsGeneratorService } from '../../../echarts-renderer/echarts-basic-options-generator.service'; | ||
import { SpFieldUpdateService } from '../../../services/field-update.service'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class SpGaugeRendererService | ||
implements SpEchartsRenderer<GaugeWidgetModel> | ||
{ | ||
protected fieldUpdateService = inject(SpFieldUpdateService); | ||
protected echartsBaseOptionsGenerator = inject( | ||
EchartsBasicOptionsGeneratorService, | ||
); | ||
|
||
makeSeriesItem( | ||
seriesName: string, | ||
fieldName: string, | ||
value: number, | ||
widgetConfig: GaugeWidgetModel, | ||
): GaugeSeriesOption { | ||
const visConfig = widgetConfig.visualizationConfig; | ||
return { | ||
name: seriesName, | ||
type: 'gauge', | ||
progress: { | ||
show: true, | ||
}, | ||
detail: { | ||
show: true, | ||
valueAnimation: false, | ||
formatter: '{value}', | ||
}, | ||
min: visConfig.min, | ||
max: visConfig.max, | ||
data: [ | ||
{ | ||
value: value, | ||
name: fieldName, | ||
}, | ||
], | ||
}; | ||
} | ||
|
||
getSelectedField(widgetConfig: GaugeWidgetModel): DataExplorerField { | ||
return widgetConfig.visualizationConfig.selectedProperty; | ||
} | ||
|
||
handleUpdatedFields( | ||
fieldUpdateInfo: FieldUpdateInfo, | ||
widgetConfig: GaugeWidgetModel, | ||
): void { | ||
this.fieldUpdateService.updateAnyField( | ||
this.getSelectedField(widgetConfig), | ||
fieldUpdateInfo, | ||
); | ||
} | ||
|
||
render( | ||
queryResult: SpQueryResult[], | ||
widgetConfig: GaugeWidgetModel, | ||
_widgetSize: WidgetSize, | ||
): EChartsOption { | ||
const option = this.echartsBaseOptionsGenerator.makeBaseConfig( | ||
widgetConfig.baseAppearanceConfig as WidgetEchartsAppearanceConfig, | ||
{}, | ||
); | ||
const selectedField = this.getSelectedField(widgetConfig); | ||
const sourceIndex = selectedField.sourceIndex; | ||
const dataSeries = queryResult[sourceIndex].allDataSeries[0]; | ||
const columnIndex = dataSeries.headers.indexOf( | ||
selectedField.fullDbName, | ||
); | ||
const data = parseFloat(dataSeries.rows[0][columnIndex].toFixed(2)); | ||
Object.assign(option, { | ||
grid: { | ||
width: '100%', | ||
height: '100%', | ||
}, | ||
series: this.makeSeriesItem( | ||
'', | ||
selectedField.fullDbName, | ||
data, | ||
widgetConfig, | ||
), | ||
}); | ||
|
||
return option; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
ui/src/app/data-explorer/components/widgets/gauge/model/gauge-widget.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 { | ||
DataExplorerDataConfig, | ||
DataExplorerField, | ||
DataExplorerWidgetModel, | ||
} from '@streampipes/platform-services'; | ||
import { | ||
AxisConfig, | ||
DataExplorerVisConfig, | ||
} from '../../../../models/dataview-dashboard.model'; | ||
|
||
export interface GaugeVisConfig extends DataExplorerVisConfig { | ||
selectedProperty: DataExplorerField; | ||
min: number; | ||
max: number; | ||
} | ||
|
||
export interface GaugeWidgetModel extends DataExplorerWidgetModel { | ||
dataConfig: DataExplorerDataConfig; | ||
visualizationConfig: GaugeVisConfig; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters