-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
datatrails: synchronize the range of the y axis for all breakdown pan…
…els (#84781) feat: sync the yaxis of breakdown panels
- Loading branch information
1 parent
b6cea0d
commit 810c224
Showing
6 changed files
with
250 additions
and
46 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
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,8 @@ | ||
import { PanelOptionsBuilders } from '@grafana/scenes'; | ||
import { SortOrder } from '@grafana/schema/dist/esm/index'; | ||
import { TooltipDisplayMode } from '@grafana/ui'; | ||
|
||
export const breakdownPanelOptions = PanelOptionsBuilders.timeseries() | ||
.setOption('tooltip', { mode: TooltipDisplayMode.Multi, sort: SortOrder.Descending, maxHeight: 250 }) | ||
.setOption('legend', { showLegend: false }) | ||
.build(); |
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
83 changes: 83 additions & 0 deletions
83
public/app/features/trails/ActionTabs/yAxisSyncBehavior.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,83 @@ | ||
import { BusEventWithPayload } from '@grafana/data'; | ||
import { | ||
FieldConfigBuilders, | ||
SceneCSSGridItem, | ||
SceneDataProvider, | ||
SceneStatelessBehavior, | ||
VizPanel, | ||
sceneGraph, | ||
} from '@grafana/scenes'; | ||
|
||
import { BreakdownScene } from './BreakdownScene'; | ||
import { findSceneObjectsByType } from './utils'; | ||
|
||
export class BreakdownAxisChangeEvent extends BusEventWithPayload<{ min: number; max: number }> { | ||
public static type = 'selected-metric-query-results-event'; | ||
} | ||
|
||
export const yAxisSyncBehavior: SceneStatelessBehavior = (sceneObject: SceneCSSGridItem) => { | ||
const breakdownScene = sceneGraph.getAncestor(sceneObject, BreakdownScene); | ||
|
||
// Handle query runners from vizPanels that haven't been activated yet | ||
findSceneObjectsByType(sceneObject, VizPanel).forEach((vizPanel) => { | ||
if (vizPanel.isActive) { | ||
registerDataProvider(vizPanel.state.$data); | ||
} else { | ||
vizPanel.addActivationHandler(() => { | ||
registerDataProvider(vizPanel.state.$data); | ||
}); | ||
} | ||
}); | ||
|
||
// Register the data providers of all present vizpanels | ||
findSceneObjectsByType(sceneObject, VizPanel).forEach((vizPanel) => registerDataProvider(vizPanel.state.$data)); | ||
|
||
function registerDataProvider(dataProvider?: SceneDataProvider) { | ||
if (!dataProvider) { | ||
return; | ||
} | ||
|
||
if (!dataProvider.isActive) { | ||
dataProvider.addActivationHandler(() => { | ||
// Call this function again when the dataprovider is activated | ||
registerDataProvider(dataProvider); | ||
}); | ||
} | ||
|
||
// Report the panel data if it is already populated | ||
if (dataProvider.state.data) { | ||
breakdownScene.reportBreakdownPanelData(dataProvider.state.data); | ||
} | ||
|
||
// Report the panel data whenever it is updated | ||
dataProvider.subscribeToState(({ data }, _) => { | ||
breakdownScene.reportBreakdownPanelData(data); | ||
}); | ||
} | ||
|
||
const axisChangeSubscription = breakdownScene.subscribeToEvent(BreakdownAxisChangeEvent, (event) => { | ||
if (!sceneObject.isActive) { | ||
axisChangeSubscription.unsubscribe(); | ||
return; | ||
} | ||
|
||
const fieldConfig = FieldConfigBuilders.timeseries() | ||
.setCustomFieldConfig('axisSoftMin', event.payload.min) | ||
.setCustomFieldConfig('axisSoftMax', event.payload.max) | ||
.build(); | ||
|
||
findSceneObjectsByType(sceneObject, VizPanel).forEach((vizPanel) => { | ||
function update() { | ||
vizPanel.onFieldConfigChange(fieldConfig); | ||
} | ||
|
||
if (vizPanel.isActive) { | ||
// Update axis for panels that are already active | ||
update(); | ||
} else { | ||
// Update inactive panels once they become active. | ||
vizPanel.addActivationHandler(update); | ||
} | ||
}); | ||
}); | ||
}; |
Oops, something went wrong.