Widget actions: Add aggregation type parameter for analyzer action (#3195)

Closes #3088.

Signed-off-by: Florian Hotze <dev@florianhotze.com>
pull/3199/head
Florian Hotze 2025-05-21 14:00:50 +02:00 committed by GitHub
parent 3742650a9e
commit 68df4be547
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 35 additions and 22 deletions

View File

@ -1,5 +1,6 @@
// parameter group & parameters definitions for actions
import { po, pt, pi, pb } from './helpers.js'
import { aggregationTypeOptions } from './chart/options.js'
export const actionGroup = (label, description, groupPrefix) => {
groupPrefix = (groupPrefix) ? groupPrefix += '_' : ''
@ -131,6 +132,10 @@ export const actionParams = (groupName, paramPrefix) => {
]).v((value, configuration, configDescription, parameters) => {
return ['analyzer'].indexOf(configuration[paramPrefix + 'action']) >= 0
}),
po(paramPrefix + 'actionAnalyzerAggregation', 'Initial Aggregation', 'The initial aggregation of the analyzer - ', aggregationTypeOptions)
.v((value, configuration, configDescription, parameters) => {
return ['analyzer'].indexOf(configuration[paramPrefix + 'action']) >= 0 && configuration[paramPrefix + 'actionAnalyzerCoordSystem'] === 'aggregate'
}),
pt(paramPrefix + 'actionConfirmation', 'Action Confirmation', 'Shows a dialog or sheet to ask for confirmation before the action is executed. Can either be a text to show in the dialog or a JSON object <code>{ type: "dialog", title: "Confirm", text: "Are you sure?" }</code> or <code>{ type: "sheet", text: "Confirm", color: "green" }</code>').a(),
pt(paramPrefix + 'actionFeedback', 'Action Feedback', 'Shows a toast popup when the action has been executed. Can either be a text to show or a JSON object including some of the <a class="external text-color-blue" target="_blank" href="https://framework7.io/docs/toast.html#toast-parameters">supported parameters</a>').a()
.v((value, configuration, configDescription, parameters) => {

View File

@ -3,6 +3,7 @@
import { actionGroup, actionParams } from '../actions.js'
import { pg, pb, pt, pn, pi } from '../helpers.js'
import { aggregationTypeOptions, dimensionTypeOptions } from './options.js'
const positionGroup = pg('position', 'Position', 'Each parameter accepts pixel values or percentages. Additionally, top accepts "top", "middle" and "bottom" to align the component vertically, and left accepts "left", "center" and "right" to align the component horizontally')
@ -123,25 +124,7 @@ const seriesTypeParameter = (...types) => {
}
const aggregationFunctionParameter = pt('aggregationFunction', 'Aggregation Function', 'How to reduce the data points in a same aggregation cluster to a single value. If not specified, the average function will be used.')
.o([
{ value: 'average', label: 'Average' },
{ value: 'sum', label: 'Sum' },
{ value: 'min', label: 'Minimum' },
{ value: 'max', label: 'Maximum' },
{ value: 'first', label: 'First (earliest)' },
{ value: 'last', label: 'Last (latest)' },
{ value: 'diff_first', label: 'Difference of firsts' },
{ value: 'diff_last', label: 'Difference of lasts' }
], true)
const dimensionTypesOptions = [
{ value: 'minute', label: 'Minute of Hour' },
{ value: 'hour', label: 'Hour of Day' },
{ value: 'isoWeekday', label: 'Day of Week (starting on Monday)' },
{ value: 'weekday', label: 'Day of Week (starting on Sunday)' },
{ value: 'date', label: 'Day of Month' },
{ value: 'month', label: 'Month of Year' }
]
.o(aggregationTypeOptions, true)
export default {
'oh-chart-grid': {
@ -357,7 +340,7 @@ export default {
type: 'TEXT',
description: 'The largest data point cluster size.<br />It should be consistent with the chart type, and match the type of a category axis where this series will appear.',
limitToOptions: true,
options: dimensionTypesOptions
options: dimensionTypeOptions
},
{
name: 'dimension2',
@ -365,7 +348,7 @@ export default {
type: 'TEXT',
description: 'The smallest data point cluster size.<br />Set only when you have 2 category axes (for instance day of the week and hour of the day), and make sure to match the type of the 2nd axis.',
limitToOptions: true,
options: dimensionTypesOptions
options: dimensionTypeOptions
},
{
name: 'transpose',

View File

@ -0,0 +1,19 @@
export const dimensionTypeOptions = [
{ value: 'minute', label: 'Minute of Hour' },
{ value: 'hour', label: 'Hour of Day' },
{ value: 'isoWeekday', label: 'Day of Week (starting on Monday)' },
{ value: 'weekday', label: 'Day of Week (starting on Sunday)' },
{ value: 'date', label: 'Day of Month' },
{ value: 'month', label: 'Month of Year' }
]
export const aggregationTypeOptions = [
{ value: 'average', label: 'Average' },
{ value: 'sum', label: 'Sum' },
{ value: 'min', label: 'Minimum' },
{ value: 'max', label: 'Maximum' },
{ value: 'first', label: 'First (earliest)' },
{ value: 'last', label: 'Last (latest)' },
{ value: 'diff_first', label: 'Difference of firsts' },
{ value: 'diff_last', label: 'Difference of lasts' }
]

View File

@ -285,10 +285,11 @@ export const actionsMixin = {
let actionAnalyzerItems = actionConfig[prefix + 'actionAnalyzerItems']
const actionAnalyzerChartType = actionConfig[prefix + 'actionAnalyzerChartType']
const actionAnalyzerCoordSystem = actionConfig[prefix + 'actionAnalyzerCoordSystem']
const actionAnalyzerAggregation = actionConfig[prefix + 'actionAnalyzerAggregation']
if (Array.isArray(actionAnalyzerItems)) {
actionAnalyzerItems = actionAnalyzerItems.join(',')
}
this.$f7.views.main.router.navigate(`/analyzer/?items=${actionAnalyzerItems || ''}&chartType=${actionAnalyzerChartType || ''}&coordSystem=${actionAnalyzerCoordSystem || ''}`)
this.$f7.views.main.router.navigate(`/analyzer/?items=${actionAnalyzerItems || ''}&chartType=${actionAnalyzerChartType || ''}&coordSystem=${actionAnalyzerCoordSystem || ''}&aggregation=${actionAnalyzerAggregation || ''}`)
console.log('Opening the analyzer')
break
case 'url':

View File

@ -330,6 +330,11 @@ export default {
this.updateItems(this.$f7route.query.items.split(',')).then(() => {
if (this.$f7route.query.chartType) this.changeChartType(this.$f7route.query.chartType)
if (this.$f7route.query.coordSystem) this.changeCoordSystem(this.$f7route.query.coordSystem)
if (this.$f7route.query.aggregation) {
for (const options in this.seriesOptions) {
this.$set(this.seriesOptions[options], 'aggregation', this.$f7route.query.aggregation)
}
}
})
},
updateItems (itemNames) {