diff --git a/src/components/marker-chart/Canvas.js b/src/components/marker-chart/Canvas.js index 74c62871c5..3fae84d869 100644 --- a/src/components/marker-chart/Canvas.js +++ b/src/components/marker-chart/Canvas.js @@ -207,7 +207,7 @@ class MarkerChartCanvasImpl extends React.PureComponent { 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) { @@ -542,10 +542,32 @@ class MarkerChartCanvasImpl extends React.PureComponent { 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, @@ -587,11 +609,17 @@ class MarkerChartCanvasImpl extends React.PureComponent { } 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. diff --git a/src/test/components/__snapshots__/MarkerChart.test.js.snap b/src/test/components/__snapshots__/MarkerChart.test.js.snap index 33bfed573f..f12b9498fc 100644 --- a/src/test/components/__snapshots__/MarkerChart.test.js.snap +++ b/src/test/components/__snapshots__/MarkerChart.test.js.snap @@ -261,9 +261,13 @@ Array [ "set fillStyle", "#000000", ], + Array [ + "measureText", + " (1)", + ], Array [ "fillText", - "UserTiming", + "UserTiming (1)", 5, 139, ], @@ -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 [ @@ -1279,7 +1291,7 @@ Array [ ], Array [ "fillText", - "Marker DomEvent", + "Marker DomEvent (1)", 5, 27, ],