js/figure.js
/**
 * Finds visualisation divs by id and sets up a chart in each, as defined by chartDescriptions.
 * All charts created by this function call will share the given dataset and palette.
 **/
Finds visualisation divs by id and sets up a chart in each, as defined by chartDescriptions.
All charts created by this function call will share the given dataset and palette.
Finds visualisation divs by id and sets up a chart in each as defined by chartDescriptions . All charts created by this function call will share the given dataset and palette .
function insertCharts(chartDescriptions, dataset, palette) {
	let charts = [];
	for(let i = 0; i < chartDescriptions.length; i++) {
		let d = chartDescriptions[i];
		let holder = document.getElementById(d.id);
		if(typeof holder == 'undefined' || holder == null) {
			console.log("Error: no DOM element with id "+d.id+" for a chart.");
			continue;
		}
		if(d.type == 'scatter') {
			let chart = new ScatterPlot(holder, dataset, d.width, d.height);
			chart.setPalette(palette);
			let logX = false;
			let logY = false;
			if(d.hasOwnProperty('logX')) {
				logX = d.logX;
				chart.setFilter(function(v) {return v[d.x] > 0;});
			}
			if(d.hasOwnProperty('xRange')) {
				let range = d['xRange'];
				if(d.hasOwnProperty('logX') && d.logX) range = [Math.max(0,range[0]),Math.max(0,range[1])];
				chart.setFilter(function(v) {return v[d.x] > range[0] && v[d.x] < range[1];});
			}
			if(d.hasOwnProperty('logY')) logY = d.logY;
			if(d.hasOwnProperty('size')) chart.setSizeAttribute(d.size);
			chart.prepareAxes(d.x,d.y,logX,logY);
			charts.push(chart);
		}
		if(d.type == 'distribution') {
			let chart = new Distribution(holder, dataset, d.width, d.height);
			chart.setPalette(palette);
			if(d.hasOwnProperty('xRange')) {
				let range = d['xRange'];
				chart.setFilter(function(v) {return v[d.x] > range[0] && v[d.x] < range[1];});
			}
			chart.prepareAxes(d.x);
			charts.push(chart);
		}
		if(d.type == 'histogram') {
			d.y = "count"; 
			let chart = new Histogram(holder, dataset, d.width, d.height);
			chart.setPalette(palette);
			if(d.hasOwnProperty('xRange')) {
				let range = d['xRange'];
				chart.setFilter(function(v) {return v[d.x] > range[0] && v[d.x] < range[1];});
			}
			chart.prepareAxes();
			charts.push(chart);
		}
		if(d.hasOwnProperty('yLabel') && d.yLabel)
			createYLabel(holder,dataset.withUnits(d.y));
		if(d.hasOwnProperty('xLabel') && d.xLabel)
			createXLabel(holder,dataset.withUnits(d.x));
	}
	return charts;
}
function insertCharts ( chartDescriptions , dataset , palette ) { let charts = [ ] ; for ( let i = 0 ; i < chartDescriptions . length ; i ++ ) { let d = chartDescriptions [ i ] ; let holder = document . getElementById ( d . id ) ; if ( typeof holder == 'undefined' || holder == null ) { console . log ( "Error: no DOM element with id " + d . id + " for a chart." ) ; continue ; } if ( d . type == 'scatter' ) { let chart = new ScatterPlot ( holder , dataset , d . width , d . height ) ; chart . setPalette ( palette ) ; let logX = false ; let logY = false ; if ( d . hasOwnProperty ( 'logX' ) ) { logX = d . logX ; chart . setFilter ( function ( v ) { return v [ d . x ] > 0 ; } ) ; } if ( d . hasOwnProperty ( 'xRange' ) ) { let range = d [ 'xRange' ] ; if ( d . hasOwnProperty ( 'logX' ) && d . logX ) range = [ Math . max ( 0 , range [ 0 ] ) , Math . max ( 0 , range [ 1 ] ) ] ; chart . setFilter ( function ( v ) { return v [ d . x ] > range [ 0 ] && v [ d . x ] < range [ 1 ] ; } ) ; } if ( d . hasOwnProperty ( 'logY' ) ) logY = d . logY ; if ( d . hasOwnProperty ( 'size' ) ) chart . setSizeAttribute ( d . size ) ; chart . prepareAxes ( d . x , d . y , logX , logY ) ; charts . push ( chart ) ; } if ( d . type == 'distribution' ) { let chart = new Distribution ( holder , dataset , d . width , d . height ) ; chart . setPalette ( palette ) ; if ( d . hasOwnProperty ( 'xRange' ) ) { let range = d [ 'xRange' ] ; chart . setFilter ( function ( v ) { return v [ d . x ] > range [ 0 ] && v [ d . x ] < range [ 1 ] ; } ) ; } chart . prepareAxes ( d . x ) ; charts . push ( chart ) ; } if ( d . type == 'histogram' ) { d . y = "count" ; let chart = new Histogram ( holder , dataset , d . width , d . height ) ; chart . setPalette ( palette ) ; if ( d . hasOwnProperty ( 'xRange' ) ) { let range = d [ 'xRange' ] ; chart . setFilter ( function ( v ) { return v [ d . x ] > range [ 0 ] && v [ d . x ] < range [ 1 ] ; } ) ; } chart . prepareAxes ( ) ; charts . push ( chart ) ; } if ( d . hasOwnProperty ( 'yLabel' ) && d . yLabel ) createYLabel ( holder , dataset . withUnits ( d . y ) ) ; if ( d . hasOwnProperty ( 'xLabel' ) && d . xLabel ) createXLabel ( holder , dataset . withUnits ( d . x ) ) ; } return charts ; }
Finds visualisation divs by id and sets up a chart in each, as defined by chartDescriptions.
Finds visualisation divs by id and sets up a chart in each as defined by chartDescriptions .
// fixed for histograms