src/core.js
/**
  * Create a visualization.
  *
  * @param object Vis config
  * @param object Font preloads
  * @return none
  */
Create a visualization.
@param object Vis config
@param object Font preloads
@return none
Create a visualization . @param object Vis config @param object Font preloads @return none
graph(cfg, fonts) {
    let prekit = ["element", "data", "frames", "accessors"];
    let toolkit = ["logLevel", ...prekit, "draw"];
    if (arguments[1] && Array.isArray(arguments[1])) { 
      arguments[1].forEach((f, i) => {
        let font = new FontFace(...f);
        this.fontPromises.push(font.load());
      });
    }
    this.v = {...(this.v||{}), ...cfg};
    if (!this.v.name)
      this.v.name = this.uuidv4();
    this.v = this.resolveCfg(this.v);
    let handlers = {
      mergeDeep:Hive.Object.mergeDeep,
      log:(function (a){this.log(...arguments)}).bind(this),
      warn:(function (a){this.warn(...arguments)}).bind(this),
      error:(function (a){this.error(...arguments)}).bind(this),
      getGraphID:this.getGraphID.bind(this),
      getSize: (function() {return this.tk.element.renderer.getTargetSize()}).bind(this), 
      frames: (function() {this.tk.frames.entry(this.v.frames)}).bind(this),
      draw: (function() {this.tk.draw.draw(this.v.draw)}).bind(this),
      getData:(function (a){return this.tk.data.getData(...arguments)}).bind(this),
      getFrame:this.getFrame.bind(this),
      resolveFrame:d=>this.tk.frames.resolveNode.bind(this.tk.frames)(d),
      getScaledAccessors:(function (a){return (this.tk.accessors.getScaledAccessors).bind(this.tk.accessors)(...arguments)}).bind(this),
      generateAccessor:(function (a){return this.tk.accessors.generateAccessor(...arguments)}).bind(this),
      drawPush:(function (a){return this.tk.draw.push(...arguments)}).bind(this),
      render:d=>this.tk.element.render.bind(this.tk.element)(d),
      getTextWidth:d=>this.tk.element.getTextWidth(d),
      eventRegister:(function (a){this.tk.element.eventRegister(...arguments)}).bind(this),
      sendStateChange:this.sendStateChange.bind(this),
      getTemplates:d=>this.templates,
    }
    prekit.forEach((item, i) => {
        this.tk[item] = new Hive[item[0].toUpperCase()+item.slice(1)](handlers, this.v[item]);
        this.v[item] = this.tk[item].resolveCfg(this.v[item]);
      });
    let modPaths = [];  
    if (this.v.element.popup.enabled && !(Hive.popup)) modPaths.push('./popup.js');
    if (this.v.element.renderer.name == 'svg' && !(Hive.Renderer.svg)) modPaths.push('./renderers/svg.js');
    if (this.v.element.renderer.name == 'paperjs' && !(Hive.Renderer.paperjs)) modPaths.push('./renderers/paperjs.js');
    if (this.v.element.renderer.name == 'three' && !(Hive.Renderer.three)) modPaths.push('./renderers/three.js');
    let modPlugin = this.v.draw.map(d => {if (!Hive.Plugins[d.name]) return `./plugins/${d.name}.js`}).filter(d=>d);
    let guidePlugins = ['line', 'area', 'label'].map(d => {if (!Hive.Plugins[d]) return `./plugins/${d}.js`}).filter(d=>d);
    let pluginPaths = [...new Set([...modPlugin, ...guidePlugins])];
    if (!Hive.Plugins)
      Hive.Plugins = {}; 
    let promises = [...modPaths, ...pluginPaths].map(d => import(d));
		this.bootstrap(toolkit, promises, handlers);
	}
graph ( cfg , fonts ) { let prekit = [ "element" , "data" , "frames" , "accessors" ] ; let toolkit = [ "logLevel" , ... prekit , "draw" ] ; if ( arguments [ 1 ] && Array . isArray ( arguments [ 1 ] ) ) { arguments [ 1 ] . forEach ( ( f , i ) => { let font = new FontFace ( ... f ) ; this . fontPromises . push ( font . load ( ) ) ; } ) ; } this . v = { ... ( this . v || { } ) , ... cfg } ; if ( ! this . v . name ) this . v . name = this . uuidv4 ( ) ; this . v = this . resolveCfg ( this . v ) ; let handlers = { mergeDeep : Hive . Object . mergeDeep , log : ( function ( a ) { this . log ( ... arguments ) } ) . bind ( this ) , warn : ( function ( a ) { this . warn ( ... arguments ) } ) . bind ( this ) , error : ( function ( a ) { this . error ( ... arguments ) } ) . bind ( this ) , getGraphID : this . getGraphID . bind ( this ) , getSize : ( function ( ) { return this . tk . element . renderer . getTargetSize ( ) } ) . bind ( this ) , frames : ( function ( ) { this . tk . frames . entry ( this . v . frames ) } ) . bind ( this ) , draw : ( function ( ) { this . tk . draw . draw ( this . v . draw ) } ) . bind ( this ) , getData : ( function ( a ) { return this . tk . data . getData ( ... arguments ) } ) . bind ( this ) , getFrame : this . getFrame . bind ( this ) , resolveFrame : d => this . tk . frames . resolveNode . bind ( this . tk . frames ) ( d ) , getScaledAccessors : ( function ( a ) { return ( this . tk . accessors . getScaledAccessors ) . bind ( this . tk . accessors ) ( ... arguments ) } ) . bind ( this ) , generateAccessor : ( function ( a ) { return this . tk . accessors . generateAccessor ( ... arguments ) } ) . bind ( this ) , drawPush : ( function ( a ) { return this . tk . draw . push ( ... arguments ) } ) . bind ( this ) , render : d => this . tk . element . render . bind ( this . tk . element ) ( d ) , getTextWidth : d => this . tk . element . getTextWidth ( d ) , eventRegister : ( function ( a ) { this . tk . element . eventRegister ( ... arguments ) } ) . bind ( this ) , sendStateChange : this . sendStateChange . bind ( this ) , getTemplates : d => this . templates , } prekit . forEach ( ( item , i ) => { this . tk [ item ] = new Hive [ item [ 0 ] . toUpperCase ( ) + item . slice ( 1 ) ] ( handlers , this . v [ item ] ) ; this . v [ item ] = this . tk [ item ] . resolveCfg ( this . v [ item ] ) ; } ) ; let modPaths = [ ] ; if ( this . v . element . popup . enabled && ! ( Hive . popup ) ) modPaths . push ( './popup.js' ) ; if ( this . v . element . renderer . name == 'svg' && ! ( Hive . Renderer . svg ) ) modPaths . push ( './renderers/svg.js' ) ; if ( this . v . element . renderer . name == 'paperjs' && ! ( Hive . Renderer . paperjs ) ) modPaths . push ( './renderers/paperjs.js' ) ; if ( this . v . element . renderer . name == 'three' && ! ( Hive . Renderer . three ) ) modPaths . push ( './renderers/three.js' ) ; let modPlugin = this . v . draw . map ( d => { if ( ! Hive . Plugins [ d . name ] ) return ` ${ d . name } ` } ) . filter ( d => d ) ; let guidePlugins = [ 'line' , 'area' , 'label' ] . map ( d => { if ( ! Hive . Plugins [ d ] ) return ` ${ d } ` } ) . filter ( d => d ) ; let pluginPaths = [ ... new Set ( [ ... modPlugin , ... guidePlugins ] ) ] ; if ( ! Hive . Plugins ) Hive . Plugins = { } ; let promises = [ ... modPaths , ... pluginPaths ] . map ( d => import ( d ) ) ; this . bootstrap ( toolkit , promises , handlers ) ; }
Create a visualization.
Create a visualization .
// wait on fonts // this.v.name = "g" + this.utf8ToHex(JSON.stringify({graphid:this.uuidv4()})) // set root defaults // class services // get size of svg // getScale:(function (a){return this.tk.accessors.getScale(...arguments)}).bind(this) // getFixups:d=>this.templates.getFixups(), // setFixups:d=>this.templates.setFixups(d), // dyn load code // force area and text for guides // load plugins.  run bootstrap.