From ad4d2c8568ad138ec4a41c285d72abb9c54d044b Mon Sep 17 00:00:00 2001 From: dal Date: Fri, 18 Apr 2025 14:45:56 -0600 Subject: [PATCH] =?UTF-8?q?metric=20configs=20=F0=9F=99=8F=F0=9F=8F=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/libs/agents/src/agents/modes/analysis.rs | 1 + .../src/tools/categories/file_tools/common.rs | 103 +++++++++++++++++- api/libs/database/src/types/metric_yml.rs | 22 ++-- 3 files changed, 115 insertions(+), 11 deletions(-) diff --git a/api/libs/agents/src/agents/modes/analysis.rs b/api/libs/agents/src/agents/modes/analysis.rs index 2709faed0..1fdd28484 100644 --- a/api/libs/agents/src/agents/modes/analysis.rs +++ b/api/libs/agents/src/agents/modes/analysis.rs @@ -205,6 +205,7 @@ You can create, update, or modify the following assets, which are automatically - **Review and Update**: After creation, metrics can be reviewed and updated individually or in bulk as needed. - **Use in Dashboards**: Metrics can be saved to dashboards for further use. - **Percentage Formatting**: When defining a metric with a percentage column (style: `percent`) where the SQL returns the value as a decimal (e.g., 0.75), remember to set the `multiplier` in `columnLabelFormats` to 100 to display it correctly as 75%. If the value is already represented as a percentage (e.g., 75), the multiplier should be 1 (or omitted as it defaults to 1). + - **Date Grouping**: For metrics visualizing date columns on the X-axis (e.g., line or combo charts), remember to set the `xAxisTimeInterval` field within the `xAxisConfig` section of `chartConfig` to control how dates are grouped (e.g., `day`, `week`, `month`). This is crucial for meaningful time-series visualizations. - **Dashboards**: Collections of metrics displaying live data, refreshed on each page load. Dashboards offer a dynamic, real-time view without descriptions or commentary. diff --git a/api/libs/agents/src/tools/categories/file_tools/common.rs b/api/libs/agents/src/tools/categories/file_tools/common.rs index a6b110d47..9c26b1db6 100644 --- a/api/libs/agents/src/tools/categories/file_tools/common.rs +++ b/api/libs/agents/src/tools/categories/file_tools/common.rs @@ -244,7 +244,7 @@ required: - chartConfig definitions: - # BASE CHART CONFIG (common parts required by ALL chart types) + # BASE CHART CONFIG (common parts used by ALL chart types) base_chart_config: type: object properties: @@ -275,6 +275,10 @@ definitions: type: boolean gridLines: type: boolean + showLegendHeadline: + oneOf: + - type: boolean + - type: string goalLines: type: array items: @@ -283,10 +287,105 @@ definitions: type: array items: $ref: #/definitions/trendline + disableTooltip: + type: boolean + # Axis Configurations + xAxisConfig: + description: Optional X-axis configuration. Primarily used to set the `xAxisTimeInterval` for date axes (day, week, month, etc.). Other properties control label visibility, title, rotation, and zoom. + $ref: '#/definitions/x_axis_config' + yAxisConfig: + description: Optional Y-axis configuration. Primarily used to set the `yAxisShowAxisLabel` and `yAxisShowAxisTitle` properties. Other properties control label visibility, title, rotation, and zoom. + $ref: '#/definitions/y_axis_config' + y2AxisConfig: + description: Optional secondary Y-axis configuration. Used for combo charts. + $ref: '#/definitions/y2_axis_config' + categoryAxisStyleConfig: + description: Optional style configuration for the category axis (color/grouping). + $ref: '#/definitions/category_axis_style_config' required: - selectedChartType - columnLabelFormats + # AXIS CONFIGURATIONS + x_axis_config: + type: object + properties: + xAxisTimeInterval: + type: string + enum: [day, week, month, quarter, year, 'null'] + description: Time interval for X-axis (combo/line charts). Default: null. + xAxisShowAxisLabel: + type: boolean + description: Show X-axis labels. Default: true. + xAxisShowAxisTitle: + type: boolean + description: Show X-axis title. Default: true. + xAxisAxisTitle: + type: [string, 'null'] + description: X-axis title. Default: null (auto-generates from column names). + xAxisLabelRotation: + type: string # Representing numbers or 'auto' + enum: ["0", "45", "90", auto] + description: Label rotation. Default: auto. + xAxisDataZoom: + type: boolean + description: Enable data zoom on X-axis. Default: false (User only). + additionalProperties: false + required: + - xAxisTimeInterval + + y_axis_config: + type: object + properties: + yAxisShowAxisLabel: + type: boolean + description: Show Y-axis labels. Default: true. + yAxisShowAxisTitle: + type: boolean + description: Show Y-axis title. Default: true. + yAxisAxisTitle: + type: [string, 'null'] + description: Y-axis title. Default: null (uses first plotted column name). + yAxisStartAxisAtZero: + type: [boolean, 'null'] + description: Start Y-axis at zero. Default: true. + yAxisScaleType: + type: string + enum: [log, linear] + description: Scale type for Y-axis. Default: linear. + additionalProperties: false + + y2_axis_config: + type: object + description: Secondary Y-axis configuration (for combo charts). + properties: + y2AxisShowAxisLabel: + type: boolean + description: Show Y2-axis labels. Default: true. + y2AxisShowAxisTitle: + type: boolean + description: Show Y2-axis title. Default: true. + y2AxisAxisTitle: + type: [string, 'null'] + description: Y2-axis title. Default: null (uses first plotted column name). + y2AxisStartAxisAtZero: + type: [boolean, 'null'] + description: Start Y2-axis at zero. Default: true. + y2AxisScaleType: + type: string + enum: [log, linear] + description: Scale type for Y2-axis. Default: linear. + additionalProperties: false + + category_axis_style_config: + type: object + description: Style configuration for the category axis (color/grouping). + properties: + categoryAxisTitle: + type: [string, 'null'] + description: Title for the category axis. + additionalProperties: false + # COLUMN FORMATTING columnLabelFormat: type: object @@ -305,7 +404,7 @@ definitions: # - If the value comes directly from a database column, use multiplier: 1 # - If the value is calculated in your SQL query and not already multiplied by 100, use multiplier: 100 - number - - date + - date # Note: For date columns, consider setting xAxisTimeInterval in xAxisConfig to control date grouping (day, week, month, quarter, year) - string multiplier: type: number diff --git a/api/libs/database/src/types/metric_yml.rs b/api/libs/database/src/types/metric_yml.rs index 6cb82968e..d3110d3df 100644 --- a/api/libs/database/src/types/metric_yml.rs +++ b/api/libs/database/src/types/metric_yml.rs @@ -205,15 +205,19 @@ pub struct BaseChartConfig { #[serde(skip_serializing_if = "Option::is_none")] #[serde(alias = "disable_tooltip")] pub disable_tooltip: Option, - // Updated Axis Configs using defined structs - #[serde(flatten, default)] // Flatten includes fields directly, default handles Option - pub y_axis_config: YAxisConfig, - #[serde(flatten, default)] - pub x_axis_config: XAxisConfig, - #[serde(flatten, default)] - pub category_axis_style_config: CategoryAxisStyleConfig, - #[serde(flatten, default)] - pub y2_axis_config: Y2AxisConfig, + // Updated Axis Configs using defined structs (now optional) + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(alias = "y_axis_config")] + pub y_axis_config: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(alias = "x_axis_config")] + pub x_axis_config: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(alias = "category_axis_style_config")] + pub category_axis_style_config: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(alias = "y2_axis_config")] + pub y2_axis_config: Option, } #[derive(Debug, Serialize, Deserialize, Clone)]