scripts/experiment-properties/graphing/custom_graphing_controller.js
import {create_distractor_scatter_plot} from "/scripts/experiment-properties/graphing/d3-custom-plots/distractor_scatter_plot.js";
import {create_estimation_plot,
create_estimation_interference_plot,
create_estimation_multi_interference_plot,
create_estimation_bisection_plot} from "/scripts/experiment-properties/graphing/d3-custom-plots/estimation_plot.js";
export {is_custom_plot, prepare_custom_plot};
/**
* Checks if the experiment needs a custom plot.
*
* @param {object} experiment
* @return {boolean}
*/
function is_custom_plot(experiment) {
if (experiment.condition_group === "distractor") {
return true;
}
else if (experiment.constructor.name === "Estimation") {
return true;
}
return false;
}
/**
* Routes to the correct plotting code in /d3-custom-plots depending on
* experiment condition.
*
* @param {object} experiment
* @return {boolean}
*/
function prepare_custom_plot(experiment) {
if (experiment.condition_group === "distractor") {
prepare_distractor_scatter_plot(experiment);
}
else if (experiment.constructor.name === "Estimation") {
prepare_estimation_plot(experiment);
}
else {
throw Error("Condition " + experiment.condition_name + " does not have a custom plot function.");
}
}
////////////////////////////////////////////////////////////////////////////////////////
// CUSTOM PREPARE METHODS HERE
////////////////////////////////////////////////////////////////////////////////////////
/**
* Sets up attributes from trial data for distractor scatter plots and creates the plots.
*
* @param {object} experiment
*/
function prepare_distractor_scatter_plot(experiment) {
let datasets = experiment.coordinates;
let distractors = experiment.distractor_coordinates;
console.log("distractor coords: " + JSON.stringify(distractors));
let trial_data = experiment.trial_data;
console.log("trial data: " + JSON.stringify(trial_data));
let attributes = "";
for (let i in datasets) {
attributes = {
target: {
dataset: datasets[i],
graph_attributes: {
axis_color: ("axis_color" in trial_data ? trial_data.axis_color : "BLACK"),
point_color: ("target_color" in trial_data ? trial_data.target_color : "BLACK"),
point_shape: ("target_shape" in trial_data ? trial_data.target_shape : "circle"),
point_size: ("point_size" in trial_data ? trial_data.point_size : 3),
row: ("row" in trial_data? trial_data.row : 0),
col: ("col" in trial_data? trial_data.col : 0),
alternate_scaling: ("alternate_scaling" in trial_data ? trial_data.alternate_scaling : false)
}
},
distractor: {
dataset: distractors[i],
graph_attributes: {
point_color: ("dist_color" in trial_data ? trial_data.dist_color : "RED"),
point_shape: ("dist_shape" in trial_data ? trial_data.dist_shape : "circle"),
point_size: ("point_size" in trial_data ? trial_data.point_size : 3),
alternate_scaling: ("alternate_scaling" in trial_data ? trial_data.alternate_scaling : false)
}
}
};
create_distractor_scatter_plot(attributes);
}
// Set background color
document.body.style.backgroundColor = (trial_data.background_color ? trial_data.background_color : "WHITE");
}
/**
* Retrieves attributes to run all estimation plots + calls correct plot method depending on
* condition.
*
* @param {object} experiment
*/
function prepare_estimation_plot(experiment) {
// Defer to model level for attribute computation
let attributes = experiment.compute_plot_attributes();
let name_array = experiment.condition_name.split("_");
if (name_array.includes("interference")) {
if (name_array.includes("multi")) {
create_estimation_multi_interference_plot(experiment, attributes);
}
else {
create_estimation_interference_plot(experiment, attributes);
}
}
else if (name_array.includes("bisection")) {
create_estimation_bisection_plot(experiment, attributes);
}
else {
create_estimation_plot(experiment, attributes);
}
}