Namespace: JSROOT

JSROOT

Core methods of JavaScript ROOT

Classes

DrawOptions

Draw options interpreter.

TAttFillHandler

Handle for fill attributes.

TAttLineHandler
Handle for line attributes.
TAttMarkerHandler

Handle for marker attributes.

TAxisPainter

Painter for TAxis/TGaxis objects.

TBasePainter

Basic painter class.

TCanvasPainter

Painter for TCanvas object.

TDrawSelector

Selector class for TTree::Draw function

TF1Painter

Painter for TF1 object.

TFile

Interface to read objects from ROOT files.

TFramePainter

Painter for TFrame object.

TGraphPainter

Painter for TGraph object.

TH1Painter

Painter for TH1 classes

TH2Painter

Painter for TH2 classes

THistPainter

Basic painter for histogram classes

TObjectPainter
Basic painter for objects inside TCanvas/TPad.
TPadPainter

Painter for TPad object.

TSelector

class to read data from TTree

WebWindowHandle
Client communication handle for TWebWindow.

Namespaces

TreeMethods

these are TTree methods, which are automatically assigned to every TTree

Methods

staticJSROOT.addDrawFunc(args)

Register draw function for the class

List of supported draw options could be provided, separated with ';' Several different draw functions for the same class or kind could be specified

Name Type Description
args object

arguments

Name Type Default Description
name string

class name

prereq string optional

prerequicities to load before search for the draw function

func string

name of draw function for the class

direct string false optional

if true, function is just Redraw() method of TObjectPainter

opt string

list of supported draw options (separated with semicolon) like "col;scat;"

icon string optional

icon name shown for the class in hierarchy browser

staticJSROOT.AssertPrerequisites(kind, callback)

Load JSROOT functionality.

As first argument, required components should be specifed:

  • 'io' TFile functionality
  • 'tree' TTree support
  • '2d' basic 2d graphic (TCanvas/TPad/TFrame)
  • '3d' basic 3d graphic (three.js)
  • 'hist' histograms 2d graphic
  • 'hist3d' histograms 3d graphic
  • 'more2d' extra 2d graphic (TGraph, TF1)
  • 'v7' ROOT v7 graphics
  • 'v7hist' ROOT v7 histograms
  • 'v7more' ROOT v7 special classes
  • 'math' some methods from TMath class
  • 'jq' jQuery and jQuery-ui
  • 'hierarchy' hierarchy browser
  • 'jq2d' jQuery-dependent part of hierarchy
  • 'openui5' OpenUI5 and related functionality
  • 'geom' TGeo support
  • 'simple' for basic user interface
  • 'load:<path/script.js>' list of user-specific scripts at the end of kind string

One could combine several compopnents, separating them by semicolon. Depending of available components, either require.js or plain script loading will be used

Name Type Description
kind string

modules to load

callback function

called when all specified modules are loaded

Example
JSROOT.AssertPrerequisites("io;tree", function() {
   var selector = new JSROOT.TSelector;
});

staticJSROOT.cleanup(divid)

Safely remove all JSROOT objects from specified element

Name Type Description
divid string | object

id or DOM element

Example
JSROOT.cleanup("drawing");
JSROOT.cleanup(document.querySelector("#drawing"));

staticJSROOT.CloseCurrentWindow()

Tries to close current browser tab

Many browsers do not allow simple window.close() call, therefore try several workarounds

.

Tries to close current browser tab

Many browsers do not allow simple window.close() call, therefore try several workarounds

staticJSROOT.ConnectWebWindow(arg)

Method used to initialize connection to web window.

Name Type Description
arg object

arguemnts

Name Type Description
prereq string optional

prerequicities, which should be loaded

socket_kind string optional

kind of connection longpoll|websocket, detected automatically from URL

receiver object

instance of receiver for websocket events, allows to initiate connection immediately

first_recv string

required prefix in the first message from TWebWindow, remain part of message will be returned as arg.first_msg

prereq2 string optional

second part of prerequcities, which is loaded parallel to connecting with WebWindow

callback function

function which is called with WebWindowHandle or when establish connection and get first portion of data

staticJSROOT.Create(typename)

Create some ROOT classes

Name Type Description
typename string

ROOT class name

Example
var obj = JSROOT.Create("TNamed");
obj.fName = "name";
obj.fTitle = "title";

staticJSROOT.draw(divid, obj, opt, drawcallback)

Draw object in specified HTML element with given draw options.

A complete list of options can be found depending of the object's ROOT class to draw: https://root.cern/js/latest/examples.htm

Name Type Description
divid string | object

id of div element to draw or directly DOMElement

obj object

object to draw, object type should be registered before in JSROOT

opt string

draw options separated by space, comma or semicolon

drawcallback function

function called when drawing is completed, first argument is object painter instance

Example
var filename = "https://root.cern/js/files/hsimple.root";
JSROOT.OpenFile(filename, function(file) {
   file.ReadObject("hpxpy;1", function(obj) {
      JSROOT.draw("drawing", obj, "colz;logx;gridx;gridy");
   });
});

staticJSROOT.GetMainPainter(divid)

Returns main painter object for specified HTML element

Name Type Description
divid string | object

id or DOM element

staticJSROOT.MakeSVG(args, callback)

Create SVG image for provided object.

Function especially useful in Node.js environment to generate images for supported ROOT classes

Name Type Description
args object

contains different settings

Name Type Default Description
object object

object for the drawing

option string optional

draw options

width number 1200 optional

image width

height number 800 optional

image height

callback function

called with svg code as string argument

staticJSROOT.NewHttpRequest(url, kind, user_call_back){object}

Create asynchronous XMLHttpRequest object.

One should call req.send() to submit request kind of the request can be:

  • "bin" - abstract binary data, result as string (default)
  • "buf" - abstract binary data, result as BufferArray
  • "text" - returns req.responseText
  • "object" - returns JSROOT.parse(req.responseText)
  • "multi" - returns correctly parsed multi.json request
  • "xml" - returns req.responseXML
  • "head" - returns request itself, uses "HEAD" method

Result will be returned to the callback function. Request will be set as this pointer in the callback. If failed, request returns null

Name Type Description
url string

URL for the request

kind string

kind of requested data

user_call_back function

called when request is completed

Returns:
Type Description
object XMLHttpRequest object
Example
JSROOT.NewHttpRequest("https://root.cern/js/files/thstack.json.gz", "object",
                      function(res) {
    if (res) console.log('Retrieve object', res._typename);
        else console.error('Fail to get object');
}).send();

staticJSROOT.OpenFile(filename, filename, callback)

Open ROOT file for reading

depending from file location, different class will be created to provide access to objects from the file

Name Type Description
filename string

name of file to open

filename File

JS object to access local files, see https://developer.mozilla.org/en-US/docs/Web/API/File

callback function

function called with file handle

Example
JSROOT.OpenFile("https://root.cern/js/files/hsimple.root", function(f) {
   console.log("Open file", f.fFileName);
});

staticJSROOT.parse(json){object|null}

Parse JSON code produced with TBufferJSON.

Name Type Description
json string

string to parse

Returns:
Type Description
object | null returns parsed object

staticJSROOT.parse_multi(json){Array|null}

Parse multi.json request results

Method should be used to parse JSON code, produced by multi.json request of THttpServer

Name Type Description
json string

string to parse

Returns:
Type Description
Array | null returns array of parsed elements

staticJSROOT.redraw(divid, obj, opt, callback)

Redraw object in specified HTML element with given draw options.

If drawing was not drawn before, it will be performed with JSROOT.draw. If drawing was already done, that content will be updated

Name Type Description
divid string | object

id of div element to draw or directly DOMElement

obj object

object to draw, object type should be registered before in JSROOT

opt string

draw options

callback function

function called when drawing is completed, first argument will be object painter instance

staticJSROOT.resize(divid, arg)

Check resize of drawn element

As first argument divid one should use same argument as for the drawing As second argument, one could specify "true" value to force redrawing of the element even after minimal resize of the element Or one just supply object with exact sizes like { width:300, height:200, force:true };

Name Type Description
divid string | object

id or DOM element

arg boolean | object

options on how to resize

Example
JSROOT.resize("drawing", { width: 500, height: 200 } );
JSROOT.resize(document.querySelector("#drawing"), true);

staticJSROOT.StoreJSON(divid){string}

Save object, drawn in specified element, as JSON.

Normally it is TCanvas object with list of primitives

Name Type Description
divid string | object

id of top div element or directly DOMElement

Returns:
Type Description
string produced JSON string

staticJSROOT.toJSON()

Method converts JavaScript object into ROOT-like JSON

Produced JSON can be used in JSROOT.parse() again When performed properly, JSON can be used in TBufferJSON to read data back with C++