Skip to content

Commit

Permalink
Fix link between table event and XY chart
Browse files Browse the repository at this point in the history
Opening an Events Table and a XY chart like "CPU Usage" and clicking on
a row in the table was supposed to show a vertical line in the XY chart,
but this was not happening.

Selecting several rows in the table also was supposed to show a blue
selection area in the chart, which was not working either.

The selection would only work if, apart from opening an Events Table and
a XY chart, a status chart was opened, like the "Resources Chart".

Now all selections work.

Fixes #448.

Signed-off-by: Rodrigo Pinto <rodrigo.pinto@calian.ca>
  • Loading branch information
Rodrigoplp-work committed Jan 7, 2022
1 parent 1d33931 commit 4606227
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/react-components/src/components/xy-output-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { EntryTree } from './utils/filtrer-tree/entry-tree';
import { getAllExpandedNodeIds } from './utils/filtrer-tree/utils';
import { TreeNode } from './utils/filtrer-tree/tree-node';
import ColumnHeader from './utils/filtrer-tree/column-header';
import { signalManager, Signals } from 'traceviewer-base/lib/signals/signal-manager';
import { BIMath } from 'timeline-chart/lib/bigint-utils';
import { ChangeEvent } from 'react';
import { scaleLinear } from 'd3-scale';
import { axisLeft } from 'd3-axis';
import { select } from 'd3-selection';
Expand Down Expand Up @@ -72,6 +72,8 @@ export class XYOutputComponent extends AbstractTreeOutputComponent<AbstractOutpu

private preventDefaultHandler: ((event: WheelEvent) => void) | undefined;

private onSelectionChanged = (payload: { [key: string]: string; }) => this.doHandleSelectionChangedSignal(payload);

constructor(props: AbstractOutputProps) {
super(props);
this.state = {
Expand All @@ -89,6 +91,22 @@ export class XYOutputComponent extends AbstractTreeOutputComponent<AbstractOutpu
this.chartRef = React.createRef();
this.yAxisRef = React.createRef();
this.divRef = React.createRef();

signalManager().on(Signals.SELECTION_CHANGED, this.onSelectionChanged);
}

private doHandleSelectionChangedSignal(payload: { [key: string]: string }) {
const offset = this.props.viewRange.getOffset() || BigInt(0);
const startTimestamp = payload['startTimestamp'];
const endTimestamp = payload['endTimestamp'];
if (startTimestamp !== undefined && endTimestamp !== undefined) {
const selectionRangeStart = BigInt(startTimestamp) - offset;
const selectionRangeEnd = BigInt(endTimestamp) - offset;
this.props.unitController.selectionRange = {
start: selectionRangeStart,
end: selectionRangeEnd
};
}
}

componentDidMount(): void {
Expand Down Expand Up @@ -147,6 +165,11 @@ export class XYOutputComponent extends AbstractTreeOutputComponent<AbstractOutpu
}
}

componentWillUnmount(): void {
super.componentWillUnmount();
signalManager().off(Signals.SELECTION_CHANGED, this.onSelectionChanged);
}

renderTree(): React.ReactNode | undefined {
this.onToggleCheck = this.onToggleCheck.bind(this);
this.onToggleCollapse = this.onToggleCollapse.bind(this);
Expand Down

0 comments on commit 4606227

Please sign in to comment.