Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: supporting aggregation queries in visualization #2506

Merged
merged 4 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Dashboard } from '@hypertrace/hyperdash';
import { recordObservable, runFakeRxjs } from '@hypertrace/test-utils';
import { MockService } from 'ng-mocks';
import { EMPTY, of } from 'rxjs';
import { CartesianSeriesVisualizationType } from '../../shared/components/cartesian/chart';
import { CartesianSeriesVisualizationType, ScaleType } from '../../shared/components/cartesian/chart';
import { ExploreVisualizationRequest } from '../../shared/components/explore-query-editor/explore-visualization-builder';
import { LegendPosition } from '../../shared/components/legend/legend.component';
import { ExplorerVisualizationCartesianDataSourceModel } from '../../shared/dashboard/data/graphql/explorer-visualization/explorer-visualization-cartesian-data-source.model';
Expand Down Expand Up @@ -45,6 +45,11 @@ describe('Explorer dashboard builder', () => {
'selection-handler': {
type: 'cartesian-explorer-selection-handler',
'show-context-menu': false
},
'x-axis': {
type: 'cartesian-axis',
'scale-type': ScaleType.Band,
'show-tick-labels': false
}
},
onReady: expect.any(Function)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,7 @@ export class ExplorerDashboardBuilder {
type: 'cartesian-explorer-selection-handler',
'show-context-menu': false
},
...(!isEmpty(request.groupBy) && isEmpty(request.interval)
? {
'x-axis': {
type: 'cartesian-axis',
'scale-type': ScaleType.Band
}
}
: {})
...this.buildXAxis(request)
},
onReady: dashboard => {
dashboard.createAndSetRootDataFromModelClass(ExplorerVisualizationCartesianDataSourceModel);
Expand Down Expand Up @@ -168,6 +161,29 @@ export class ExplorerDashboardBuilder {
};
}

private buildXAxis(request: ExploreVisualizationRequest): object {
if (isEmpty(request.interval)) {
if (isEmpty(request.groupBy)) {
return {
'x-axis': {
type: 'cartesian-axis',
'scale-type': ScaleType.Band,
'show-tick-labels': false
}
};
} else {
return {
'x-axis': {
type: 'cartesian-axis',
'scale-type': ScaleType.Band
}
};
}
}

return {};
}

private getRendererForType(type: AttributeMetadataType): string {
switch (type) {
case AttributeMetadataType.Long:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import {
</div>
<div class="filters-row">
<ht-explore-query-order-by-editor
*ngIf="!currentVisualization.interval"
*ngIf="!currentVisualization.interval && currentVisualization.groupBy"
class="order-by"
[orderByExpression]="currentVisualization.orderBy"
[context]="currentVisualization.context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export abstract class ExploreCartesianDataSourceModel extends GraphQlDataSourceM
return aggregatableSpecs.map(spec => this.buildGroupedTimeseriesData(spec, groupByExpressions, result)).flat();
}

return [];
return aggregatableSpecs.map(spec => this.buildMetricAggregationSeriesData(spec, result));
}

private buildSeries(request: ExploreRequestState, result: SeriesData, color: string): Observable<ExplorerSeries> {
Expand Down Expand Up @@ -174,6 +174,15 @@ export abstract class ExploreCartesianDataSourceModel extends GraphQlDataSourceM
};
}

public buildMetricAggregationSeriesData(spec: AggregatableSpec, result: ExploreResult): SeriesData {
const metricAggregationData = result.getMetricAggregationSeriesData(spec.name, spec.aggregation);

return {
data: metricAggregationData?.value ? [['', metricAggregationData.value]] : [],
spec: spec
};
}

public buildGroupedTimeseriesData(
spec: AggregatableSpec,
groupByExpressions: AttributeExpression[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export class ExploreResult {
);
}

public getMetricAggregationSeriesData(metricKey: string, aggregation: MetricAggregationType): MetricAggregationData {
return this.extractMetricAggregationForSpec(this.specBuilder.exploreSpecificationForKey(metricKey, aggregation));
}

public getGroupedTimeSeriesData(
groupExpressions: AttributeExpression[],
metricKey: string,
Expand All @@ -64,10 +68,24 @@ export class ExploreResult {
return this.resultsContainingSpec(spec).map(result => this.resultToGroupData(result, groupBySpecs, spec));
}

private extractMetricAggregationForSpec(spec: ExploreSpecification): MetricAggregationData {
return this.resultToMetricAggregationDataData(this.resultsContainingSpec(spec)?.[0], spec);
}

private extractTimeseriesForSpec(spec: ExploreSpecification): MetricTimeseriesInterval[] {
return this.resultsToTimeseriesIntervals(this.resultsContainingSpec(spec), spec);
}

private resultToMetricAggregationDataData(
result: GraphQlExploreResult | undefined,
spec: ExploreSpecification
): MetricAggregationData {
return {
key: spec.name,
value: result?.[spec.resultAlias()].value as number
};
}

private resultToGroupData(
result: GraphQlExploreResult,
groupBySpecs: ExploreSpecification[],
Expand Down Expand Up @@ -143,3 +161,8 @@ interface GroupData {
keys: string[];
value: number;
}

interface MetricAggregationData {
key: string;
value: number | undefined;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,20 @@ export class CartesianAxisModel {
})
public minUpperLimit?: number;

@ModelProperty({
key: 'show-tick-labels',
required: false,
displayName: 'Show Tick Labels',
type: BOOLEAN_PROPERTY.type
})
public showTickLabels?: boolean;

public getAxisOption(): Partial<Axis> {
return {
scale: this.scale,
gridLines: this.showGridLines,
max: this.minUpperLimit
max: this.minUpperLimit,
tickLabels: this.showTickLabels
};
}
}