function set_graphic_option_parameters(
options = {
}
) {
let extent = options.extent;
let { image_width = 500, image_height = 0.625 * image_width } = options;
let xmin, xmax, ymin, ymax;
xmin = extent[0][0];
xmax = extent[0][1];
ymin = extent[1][0];
ymax = extent[1][1];
let internal_padding = 0;
let xrange = xmax - xmin;
xmin = xmin - internal_padding * xrange;
xmax = xmax + internal_padding * xrange;
xrange = xmax - xmin;
let yrange = ymax - ymin;
ymin = ymin - internal_padding * yrange;
ymax = ymax + internal_padding * yrange;
yrange = ymax - ymin;
let xmid = (xmax + xmin) / 2;
let ymid = (ymax + ymin) / 2;
if (xrange * image_height > yrange * image_width) {
let delta = xrange / image_width;
ymin = ymid - (image_height * delta) / 2;
ymax = ymid + (image_height * delta) / 2;
} else if (xrange * image_height <= yrange * image_width) {
let delta = yrange / image_height;
xmin = xmid - (image_width * delta) / 2;
xmax = xmid + (image_width * delta) / 2;
}
let external_padding;
if (options.padding === 0) {
external_padding = 0;
} else if (!options.padding) {
external_padding = 10;
} else {
external_padding = options.padding;
}
let xScale = d3
.scaleLinear()
.domain([xmin, xmax])
.range([external_padding, image_width - external_padding]);
let yScale = d3
.scaleLinear()
.domain([ymin, ymax])
.range([image_height - external_padding, external_padding]);
let rScale = d3
.scaleLinear()
.domain([0, xmax - xmin])
.range([0, image_width - external_padding]);
let fill_colors, colors;
if (options.colors) {
options.fill_colors = options.colors;
colors = [];
for (let i = 0; i < 20; i++) {
colors.push(d3.schemeCategory10[i % 10]);
}
}
if (options.fill_colors && options.fill_colors.constructor === Array) {
fill_colors = options.fill_colors;
} else if (!options.fill_colors) {
fill_colors = ["black"];
} else if (options.fill_colors == "auto") {
fill_colors = [];
for (let i = 0; i < 20; i++) {
fill_colors.push(d3.schemeCategory10[i % 10]);
}
} else if (
options.fill_colors &&
typeof options.fill_colors == "string" &&
options.fill_colors != "none"
) {
fill_colors = [options.fill_colors];
} else if (options.fill_colors == "none") {
fill_colors = "none";
} else if (options.fill_colors) {
fill_colors = [];
for (let i = 0; i < 20; i++) {
fill_colors.push(d3.schemeCategory10[i % 10]);
}
}
let stroke_colors;
if (options.stroke_colors && options.stroke_colors.constructor === Array) {
stroke_colors = options.stroke_colors;
} else if (!options.stroke_colors) {
stroke_colors = ["black"];
} else if (options.stroke_colors == "auto") {
stroke_colors = [];
for (let i = 0; i < 20; i++) {
stroke_colors.push(d3.schemeCategory10[i % 10]);
}
} else if (options.stroke_colors == "match") {
stroke_colors = fill_colors;
} else if (
options.stroke_colors &&
typeof options.stroke_colors == "string" &&
options.stroke_colors != "none"
) {
stroke_colors = [options.stroke_colors];
} else {
stroke_colors = "none";
}
return [
image_width,
image_height,
xScale,
yScale,
rScale,
fill_colors,
stroke_colors
];
}