Skip to content

Commit b58689e

Browse files
Move setting container style to its own function
1 parent accbc87 commit b58689e

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed
13 Bytes
Loading

src/graphics3d.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,26 @@ import primitiveFunctions from './primitives/index.js';
1515
import { getBasicMaterial } from './shader.js';
1616
import { getUniformsBuffer } from './uniforms.js';
1717

18+
function setDefaultContainerStyle(container) {
19+
const style = getComputedStyle(container);
20+
21+
if (!style.display) container.style.display = 'block';
22+
if (!style.width) container.style.width = '65vw';
23+
if (!style.maxWidth) container.style.maxWidth = '400px';
24+
if (!style.height) container.style.height = '65vw';
25+
if (!style.maxHeight) container.style.maxHeight = '400px';
26+
// Avoid overflow when a tick numbers is out of the parent element.
27+
if (!style.paddingTop) container.style.paddingTop = '5px';
28+
if (!style.paddingBottom) container.style.paddingBottom = '5px';
29+
// Currently the axes labels are drawn using HTML elements with
30+
// `position: absolute` so the graphics container must have
31+
// `position: relative` to draw the axes labels.
32+
// We don't overwrite it because the user may want to make the container
33+
// have an absolute position.
34+
if (!style.position) container.style.position = 'relative';
35+
if (!style.cursor) container.style.cursor = 'pointer';
36+
}
37+
1838
export default function (
1939
container,
2040
{
@@ -43,21 +63,8 @@ export default function (
4363

4464
const onMouseDownPosition = new Int16Array(2);
4565

46-
container.style.display ||= 'block';
47-
container.style.width ||= '65vw';
48-
container.style.maxWidth ||= '400px';
49-
container.style.height ||= '65vw';
50-
container.style.maxHeight ||= '400px';
51-
// Avoid overflow when a tick numbers is out of the parent element.
52-
container.style.paddingTop ||= '5px';
53-
container.style.paddingBottom ||= '5px';
54-
// Currently the axes labels are drawn using HTML elements with
55-
// `position: absolute` so the graphics container must have
56-
// `position: relative` to draw the axes labels.
57-
// We don't overwrite it because the user may want to make the container
58-
// have an absolute position.
59-
container.style.position ||= 'relative';
60-
container.style.cursor ||= 'pointer';
66+
setDefaultContainerStyle(container);
67+
6168
const defaultCursor = container.style.cursor;
6269

6370
// where the camera is looking (initialized on center of the scene)

0 commit comments

Comments
 (0)