Skip to content

Commit dbe5489

Browse files
committed
Add colors to latex plots
1 parent 34aa5a8 commit dbe5489

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

demo/hist_build3d.htm

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@
5757
renderer.render( scene, camera );
5858
}
5959

60-
async function create3d(obj, opt, x = 0, lbl = '') {
60+
async function create3d(obj, opt, x = 0, lbl = '', scale = 1) {
6161
return build3d(obj, opt).then(obj3d => {
6262
obj3d.position.x = x;
63+
if (scale !== 1)
64+
obj3d.scale.set(scale, scale, scale);
6365

6466
scene.add(obj3d);
6567

@@ -70,13 +72,13 @@
7072
latex.fTextSize = 10; // absolute size
7173

7274
return build3d(latex);
73-
}).then(obj3d => {
74-
// latex created in X/Y coordinates
75-
obj3d.geometry.rotateX(Math.PI / 2);
75+
}).then(text3d => {
76+
// latex created in X/Y coordinates,
77+
text3d.traverse(obj3d => obj3d.geometry?.rotateX(Math.PI / 2));
7678

77-
obj3d.position.x = x;
78-
obj3d.position.z = -100;
79-
scene.add(obj3d);
79+
text3d.position.x = x;
80+
text3d.position.z = -100;
81+
scene.add(text3d);
8082
});
8183
}
8284

@@ -108,22 +110,30 @@
108110

109111
window.addEventListener( 'resize', onWindowResize, false );
110112

111-
let filename = 'https://root.cern/js/files/hsimple.root';
113+
let filename = 'https://root.cern/js/files/hsimple.root',
114+
filename2 = 'https://jsroot.gsi.de/files/graph2d.root';
112115

113116
let file = await openFile(filename);
114117
let hist2 = await file.readObject('hpxpy');
115118

116-
await create3d(hist2, 'lego2', 0, 'TH2 lego plot');
119+
await create3d(hist2, 'lego2', 150, '#color[2]{TH2} #color[4]{lego} plot');
117120

118121
let tuple = await file.readObject('ntuple');
119122
let hist3 = await treeDraw(tuple, 'px:py:pz;hbins:15');
120123

121-
await create3d(hist3, 'box3', -400, 'TH3 box plot');
124+
await create3d(hist3, 'box3', -150, '#color[2]{TH3} #color[4]{box} plot');
122125

123126
let hist1 = await file.readObject('hpx');
124127

125-
await create3d(hist1, 'lego2', 400, 'TH1 lego plot');
128+
await create3d(hist1, 'lego2', 400, '#color[2]{TH1} #color[4]{lego} plot');
129+
130+
let geom = await httpRequest('https://root.cern/js/files/geom/simple_alice.json.gz', 'object');
131+
await create3d(geom, '', -400, '#color[2]{Geometry} build', 0.2);
132+
133+
let file2 = await openFile(filename2);
134+
let gr2 = await file2.readObject('Graph2D');
126135

136+
await create3d(gr2, 'p', 650, '#color[2]{TGraph2D} drawing with #color[4]{p}');
127137

128138
camera.updateProjectionMatrix();
129139

0 commit comments

Comments
 (0)