Skip to content

Commit 136e9e5

Browse files
authored
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 963afb7 commit 136e9e5

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ $_data_table_initial_height: 100px;
9191
}
9292

9393
.chart-container {
94+
display: flex;
95+
flex-direction: column;
9496
flex-grow: 1;
9597
overflow: hidden;
9698
resize: vertical;
@@ -109,8 +111,7 @@ $_data_table_initial_height: 100px;
109111
}
110112

111113
line-chart {
112-
display: block;
113-
height: 100%;
114+
flex-grow: 1;
114115
}
115116
}
116117

tensorboard/webapp/widgets/line_chart_v2/lib/BUILD

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 8 additions & 3 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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)