Skip to content

Commit e99a784

Browse files
committed
Fix safari chart rendering issues. (#6303)
* Motivation for features / changes I found a couple of problems with scalar line chart rendering in Safari while investigating #6280. * Safari 16.4 introduced limited OffscreenCanvas support. Notably it does not include 'webgl2' support. We have to be a bit more strict with our OffscreenCanvas feature detection to check for 'webgl2' support. * Scalar line charts still would not render in either canvas or svg mode until the charts were resized manually. We have to adjust our CSS in order to convince WebKit to render the line chart with the space available to it. We use 'flex' for this. * Testing I tested in both Safari and Chrome that Canvas/Three.js and SVG rendering work (using forceSVG=false and forceSVG=true, respectively). I imported the changes internally and ran internal presubmits. I did not write any more tests because (1) utils.ts is currently not covered by tests and (2) this is a Safari problem which only has best effort support.
1 parent e03778d commit e99a784

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

tensorboard/webapp/metrics/views/card_renderer/scalar_card_component.scss

+3-2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ $_title-to-heading-gap: 12px;
7878
}
7979

8080
.chart-container {
81+
display: flex;
82+
flex-direction: column;
8183
flex-grow: 1;
8284

8385
mat-spinner {
@@ -94,8 +96,7 @@ $_title-to-heading-gap: 12px;
9496
}
9597

9698
line-chart {
97-
display: block;
98-
height: 100%;
99+
flex-grow: 1;
99100
}
100101
}
101102

tensorboard/webapp/widgets/line_chart_v2/lib/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ tf_ts_library(
112112
visibility = ["//tensorboard:internal"],
113113
deps = [
114114
":internal_types",
115+
"@npm//@types/offscreencanvas",
115116
],
116117
)
117118

tensorboard/webapp/widgets/line_chart_v2/lib/renderer/threejs_renderer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export class ThreeRenderer implements ObjectRenderer<CacheValue> {
278278
onContextLost?: EventListener
279279
) {
280280
if (
281-
ChartUtils.isOffscreenCanvasSupported() &&
281+
ChartUtils.isWebGl2OffscreenCanvasSupported() &&
282282
canvas instanceof OffscreenCanvas
283283
) {
284284
// THREE.js require the style object which Offscreen canvas lacks.

tensorboard/webapp/widgets/line_chart_v2/lib/utils.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@ function isWebGl2Supported(): boolean {
4343
return cachedIsWebGl2Supported;
4444
}
4545

46-
function isOffscreenCanvasSupported(): boolean {
47-
return self.hasOwnProperty('OffscreenCanvas');
46+
function isWebGl2OffscreenCanvasSupported(): boolean {
47+
if (!self.hasOwnProperty('OffscreenCanvas')) {
48+
return false;
49+
}
50+
// Safari 16.4 rolled out OffscreenCanvas support but without webgl2 support.
51+
const context = new OffscreenCanvas(0, 0).getContext('webgl2');
52+
return Boolean(context);
4853
}
4954

5055
function arePolylinesEqual(lineA: Polyline, lineB: Polyline) {
@@ -72,7 +77,7 @@ function areExtentsEqual(extentA: Extent, extentB: Extent): boolean {
7277
export const ChartUtils = {
7378
convertRectToExtent,
7479
isWebGl2Supported,
75-
isOffscreenCanvasSupported,
80+
isWebGl2OffscreenCanvasSupported,
7681
arePolylinesEqual,
7782
areExtentsEqual,
7883
};

tensorboard/webapp/widgets/line_chart_v2/line_chart_component.scss

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ limitations under the License.
1616

1717
:host {
1818
contain: strict;
19-
display: inline-block;
19+
display: flex;
20+
flex-direction: column;
2021

2122
::ng-deep .line-chart:has(.horizontal-prospective-area:hover) {
2223
.x-axis {
@@ -37,6 +38,7 @@ limitations under the License.
3738
.container {
3839
background: inherit;
3940
display: grid;
41+
flex-grow: 1;
4042
height: 100%;
4143
overflow: hidden;
4244
width: 100%;

tensorboard/webapp/widgets/line_chart_v2/line_chart_component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ export class LineChartComponent
397397

398398
const useWorker =
399399
rendererType !== RendererType.SVG &&
400-
ChartUtils.isOffscreenCanvasSupported();
400+
ChartUtils.isWebGl2OffscreenCanvasSupported();
401401
const klass = useWorker ? WorkerChart : ChartImpl;
402402
this.lineChart = new klass(params);
403403
}

0 commit comments

Comments
 (0)