Revert "add formatter"

This reverts commit ce30989adc.
This commit is contained in:
Hare Sudhan 2024-02-25 16:23:48 -05:00
parent de3ef202d5
commit c5a1b69c30
693 changed files with 26685 additions and 51240 deletions

View file

@ -14,17 +14,13 @@ import Utils from "../Utils.mjs";
*/
export const RECORD_DELIMITER_OPTIONS = ["Line feed", "CRLF"];
/**
* @constant
* @default
*/
export const FIELD_DELIMITER_OPTIONS = [
"Space",
"Comma",
"Semi-colon",
"Colon",
"Tab",
];
export const FIELD_DELIMITER_OPTIONS = ["Space", "Comma", "Semi-colon", "Colon", "Tab"];
/**
* Default from colour
@ -34,9 +30,10 @@ export const FIELD_DELIMITER_OPTIONS = [
*/
export const COLOURS = {
min: "white",
max: "black",
max: "black"
};
/**
* Gets values from input for a plot.
*
@ -47,30 +44,26 @@ export const COLOURS = {
* @param {number} length
* @returns {Object[]}
*/
export function getValues(
input,
recordDelimiter,
fieldDelimiter,
columnHeadingsAreIncluded,
length,
) {
export function getValues(input, recordDelimiter, fieldDelimiter, columnHeadingsAreIncluded, length) {
let headings;
const values = [];
input.split(recordDelimiter).forEach((row, rowIndex) => {
const split = row.split(fieldDelimiter);
if (split.length !== length)
throw new OperationError(`Each row must have length ${length}.`);
input
.split(recordDelimiter)
.forEach((row, rowIndex) => {
const split = row.split(fieldDelimiter);
if (split.length !== length) throw new OperationError(`Each row must have length ${length}.`);
if (columnHeadingsAreIncluded && rowIndex === 0) {
headings = split;
} else {
values.push(split);
}
});
if (columnHeadingsAreIncluded && rowIndex === 0) {
headings = split;
} else {
values.push(split);
}
});
return { headings, values };
}
/**
* Gets values from input for a scatter plot.
*
@ -80,32 +73,25 @@ export function getValues(
* @param {boolean} columnHeadingsAreIncluded - whether we should skip the first record
* @returns {Object[]}
*/
export function getScatterValues(
input,
recordDelimiter,
fieldDelimiter,
columnHeadingsAreIncluded,
) {
export function getScatterValues(input, recordDelimiter, fieldDelimiter, columnHeadingsAreIncluded) {
let { headings, values } = getValues(
input,
recordDelimiter,
fieldDelimiter,
columnHeadingsAreIncluded,
2,
2
);
if (headings) {
headings = { x: headings[0], y: headings[1] };
headings = {x: headings[0], y: headings[1]};
}
values = values.map((row) => {
values = values.map(row => {
const x = parseFloat(row[0]),
y = parseFloat(row[1]);
if (Number.isNaN(x))
throw new OperationError("Values must be numbers in base 10.");
if (Number.isNaN(y))
throw new OperationError("Values must be numbers in base 10.");
if (Number.isNaN(x)) throw new OperationError("Values must be numbers in base 10.");
if (Number.isNaN(y)) throw new OperationError("Values must be numbers in base 10.");
return [x, y];
});
@ -113,6 +99,7 @@ export function getScatterValues(
return { headings, values };
}
/**
* Gets values from input for a scatter plot with colour from the third column.
*
@ -122,33 +109,25 @@ export function getScatterValues(
* @param {boolean} columnHeadingsAreIncluded - whether we should skip the first record
* @returns {Object[]}
*/
export function getScatterValuesWithColour(
input,
recordDelimiter,
fieldDelimiter,
columnHeadingsAreIncluded,
) {
export function getScatterValuesWithColour(input, recordDelimiter, fieldDelimiter, columnHeadingsAreIncluded) {
let { headings, values } = getValues(
input,
recordDelimiter,
fieldDelimiter,
recordDelimiter, fieldDelimiter,
columnHeadingsAreIncluded,
3,
3
);
if (headings) {
headings = { x: headings[0], y: headings[1] };
headings = {x: headings[0], y: headings[1]};
}
values = values.map((row) => {
values = values.map(row => {
const x = parseFloat(row[0]),
y = parseFloat(row[1]),
colour = row[2];
if (Number.isNaN(x))
throw new OperationError("Values must be numbers in base 10.");
if (Number.isNaN(y))
throw new OperationError("Values must be numbers in base 10.");
if (Number.isNaN(x)) throw new OperationError("Values must be numbers in base 10.");
if (Number.isNaN(y)) throw new OperationError("Values must be numbers in base 10.");
return [x, y, Utils.escapeHtml(colour)];
});
@ -165,30 +144,23 @@ export function getScatterValuesWithColour(
* @param {boolean} columnHeadingsAreIncluded - whether we should skip the first record
* @returns {Object[]}
*/
export function getSeriesValues(
input,
recordDelimiter,
fieldDelimiter,
columnHeadingsAreIncluded,
) {
export function getSeriesValues(input, recordDelimiter, fieldDelimiter, columnHeadingsAreIncluded) {
const { values } = getValues(
input,
recordDelimiter,
fieldDelimiter,
recordDelimiter, fieldDelimiter,
false,
3,
3
);
let xValues = new Set();
const series = {};
values.forEach((row) => {
values.forEach(row => {
const serie = row[0],
xVal = row[1],
val = parseFloat(row[2]);
if (Number.isNaN(val))
throw new OperationError("Values must be numbers in base 10.");
if (Number.isNaN(val)) throw new OperationError("Values must be numbers in base 10.");
xValues.add(xVal);
if (typeof series[serie] === "undefined") series[serie] = {};
@ -200,7 +172,7 @@ export function getSeriesValues(
const seriesList = [];
for (const seriesName in series) {
const serie = series[seriesName];
seriesList.push({ name: seriesName, data: serie });
seriesList.push({name: seriesName, data: serie});
}
return { xValues, series: seriesList };