Skip to content
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
14 changes: 10 additions & 4 deletions src/components/shared/thread/SampleGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getSampleIndexClosestToCenteredTime,
} from 'firefox-profiler/profile-logic/profile-data';
import { bisectionRight } from 'firefox-profiler/utils/bisect';
import { withSize } from 'firefox-profiler/components/shared/WithSize';
import { BLUE_70, BLUE_40 } from 'photon-colors';

import './SampleGraph.css';
Expand All @@ -25,6 +26,7 @@ import type {
CallNodeInfo,
IndexIntoCallNodeTable,
} from 'firefox-profiler/types';
import type { SizeProps } from 'firefox-profiler/components/shared/WithSize';

type Props = {|
+className: string,
Expand All @@ -41,9 +43,10 @@ type Props = {|
sampleIndex: IndexIntoSamplesTable
) => void,
+trackName: string,
...SizeProps,
|};

export class ThreadSampleGraph extends PureComponent<Props> {
export class ThreadSampleGraphImpl extends PureComponent<Props> {
_canvas: null | HTMLCanvasElement = null;
_resizeListener: () => void;
_takeCanvasRef = (canvas: HTMLCanvasElement | null) =>
Expand Down Expand Up @@ -78,14 +81,15 @@ export class ThreadSampleGraph extends PureComponent<Props> {
callNodeInfo,
selectedCallNodeIndex,
categories,
width,
height,
} = this.props;

const devicePixelRatio = canvas.ownerDocument
? canvas.ownerDocument.defaultView.devicePixelRatio
: 1;
const rect = canvas.getBoundingClientRect();
canvas.width = Math.round(rect.width * devicePixelRatio);
canvas.height = Math.round(rect.height * devicePixelRatio);
canvas.width = Math.round(width * devicePixelRatio);
canvas.height = Math.round(height * devicePixelRatio);
const ctx = canvas.getContext('2d');
let maxDepth = 0;
const { callNodeTable, stackIndexToCallNodeIndex } = callNodeInfo;
Expand Down Expand Up @@ -239,3 +243,5 @@ export class ThreadSampleGraph extends PureComponent<Props> {
);
}
}

export const ThreadSampleGraph = withSize<Props>(ThreadSampleGraphImpl);
11 changes: 11 additions & 0 deletions src/test/components/__snapshots__/SampleGraph.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

exports[`SampleGraph matches the 2d canvas draw snapshot 1`] = `
Array [
Array [
"set fillStyle",
"#003eaa",
],
Array [
"fillRect",
-0.4,
0,
0.8,
0,
],
Array [
"set fillStyle",
"#003eaa",
Expand Down
Loading