js/units.js
/**
 * Updates all data points and returns new label, scale, and units strings.
 * It is up to the caller to replace all instances of the attribute 
 * with the new label.
 **/
Updates all data points and returns new label, scale, and units strings.
It is up to the caller to replace all instances of the attribute
with the new label.
Updates all data points and returns new label scale and units strings . It is up to the caller to replace all instances of the attribute with the new label .
function rescaleAxis(label, data) {
	let scale = 1.0;
	let name = label;
	let scaleName = ""; 
	let units = "";
	if(hasUnits(label)) {
		let existingScale = findLabelScale(label);
		units = existingScale[1];
		if(units == "%") { 
			existingScale[0] = 1.0;
		}
		else if(units == "s") { 
			let scaleIndex = rescaleFactor(data,label,SCALE_TIME,existingScale[0]);
			if(scaleIndex != -1) {
				scale = SCALE_TIME[scaleIndex][0];
				scaleName = SCALE_TIME[scaleIndex][1];
			}
		}
		else {
			let scaleIndex = rescaleFactor(data,label,SCALE_UNITS,existingScale[0]);
			if(scaleIndex != -1) {
				scale = SCALE_UNITS[scaleIndex][0];
				scaleName = SCALE_UNITS[scaleIndex][1];
			}
		}
		scale /= existingScale[0]; 
		name = name.substring(0,name.indexOf("(")).trim();
	} else {
		let scaleIndex = rescaleFactor(data,label,SCALE_TEXT);
		if(scaleIndex != -1) {
			scale = SCALE_TEXT[scaleIndex][0];
			scaleName = SCALE_TEXT[scaleIndex][1];
		}
	}
	if(scale != 1.0 || name != label) {
		for(let i = 0; i < data.length; i++) {
			let scaled = data[i][label] / scale;
			data[i][name] = scaled;
		}
	}
	return [name,scaleName,units];
}
function rescaleAxis ( label , data ) { let scale = 1.0 ; let name = label ; let scaleName = "" ; let units = "" ; if ( hasUnits ( label ) ) { let existingScale = findLabelScale ( label ) ; units = existingScale [ 1 ] ; if ( units == "%" ) { existingScale [ 0 ] = 1.0 ; } else if ( units == "s" ) { let scaleIndex = rescaleFactor ( data , label , SCALE_TIME , existingScale [ 0 ] ) ; if ( scaleIndex != - 1 ) { scale = SCALE_TIME [ scaleIndex ] [ 0 ] ; scaleName = SCALE_TIME [ scaleIndex ] [ 1 ] ; } } else { let scaleIndex = rescaleFactor ( data , label , SCALE_UNITS , existingScale [ 0 ] ) ; if ( scaleIndex != - 1 ) { scale = SCALE_UNITS [ scaleIndex ] [ 0 ] ; scaleName = SCALE_UNITS [ scaleIndex ] [ 1 ] ; } } scale /= existingScale [ 0 ] ; name = name . substring ( 0 , name . indexOf ( "(" ) ) . trim ( ) ; } else { let scaleIndex = rescaleFactor ( data , label , SCALE_TEXT ) ; if ( scaleIndex != - 1 ) { scale = SCALE_TEXT [ scaleIndex ] [ 0 ] ; scaleName = SCALE_TEXT [ scaleIndex ] [ 1 ] ; } } if ( scale != 1.0 || name != label ) { for ( let i = 0 ; i < data . length ; i ++ ) { let scaled = data [ i ] [ label ] / scale ; data [ i ] [ name ] = scaled ; } } return [ name , scaleName , units ] ; }
Updates all data points and returns new label, scale, and units strings.
Updates all data points and returns new label scale and units strings .
//e.g. m (milli-) or k (kilo-) //ignore these //nothing //time! //amount to adjust values by // work directly with a new text scale //Then: rescale *every* attribute, remove its units string, create a new scale+units string for each. //apply