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
42 changes: 35 additions & 7 deletions src/components/marker-chart/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class MarkerChartCanvasImpl extends React.PureComponent<Props> {
this.highlightRow(ctx, newRow);
this.drawMarkers(ctx, hoveredMarker, newRow, newRow + 1);
if (hoveredLabel === null) {
this.drawSeparatorsAndLabels(ctx, newRow, newRow + 1);
this.drawSeparatorsAndLabels(ctx, newRow, newRow + 1, true);
}
}
if (oldRow !== undefined && oldRow !== newRow) {
Expand Down Expand Up @@ -542,10 +542,32 @@ class MarkerChartCanvasImpl extends React.PureComponent<Props> {
return this._textMeasurement;
}

countMarkersInBucketStartingAtRow(rowIndex: number): number {
const { markerTimingAndBuckets } = this.props;
const markerTiming = markerTimingAndBuckets[rowIndex];
if (typeof markerTiming === 'string') {
return 0;
}

const { name } = markerTiming;
let count = markerTiming.length;
for (let row = rowIndex + 1; row < markerTimingAndBuckets.length; ++row) {
if (
typeof markerTimingAndBuckets[row] === 'string' ||
markerTimingAndBuckets[row].name !== name
) {
break;
}
count += markerTimingAndBuckets[row].length;
}
return count;
}

drawSeparatorsAndLabels(
ctx: CanvasRenderingContext2D,
startRow: number,
endRow: number
endRow: number,
drawMarkerCount: boolean = false
) {
const {
markerTimingAndBuckets,
Expand Down Expand Up @@ -587,11 +609,17 @@ class MarkerChartCanvasImpl extends React.PureComponent<Props> {
}

const y = rowIndex * rowHeight - viewportTop;
// Even though it's on active tab view, have a hard cap on the text length.
const fittedText = textMeasurement.getFittedText(
name,
TIMELINE_MARGIN_LEFT
);

const countString = drawMarkerCount
? ` (${this.countMarkersInBucketStartingAtRow(rowIndex)})`
: '';
// Even when it's on active tab view, have a hard cap on the text length.
const fittedText =
textMeasurement.getFittedText(
name,
TIMELINE_MARGIN_LEFT -
(countString ? textMeasurement.getTextWidth(countString) : 0)
) + countString;

if (timelineTrackOrganization.type === 'active-tab') {
// Draw the text backgound for active tab.
Expand Down
18 changes: 15 additions & 3 deletions src/test/components/__snapshots__/MarkerChart.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,13 @@ Array [
"set fillStyle",
"#000000",
],
Array [
"measureText",
" (1)",
],
Array [
"fillText",
"UserTiming",
"UserTiming (1)",
5,
139,
],
Expand Down Expand Up @@ -1262,15 +1266,23 @@ Array [
"set fillStyle",
"#000000",
],
Array [
"measureText",
" (1)",
],
Array [
"set fillStyle",
"#ffffffbf",
],
Array [
"measureText",
"Marker DomEvent (1)",
],
Array [
"fillRect",
0,
16,
85,
105,
16,
],
Array [
Expand All @@ -1279,7 +1291,7 @@ Array [
],
Array [
"fillText",
"Marker DomEvent",
"Marker DomEvent (1)",
5,
27,
],
Expand Down