run prettier(2.0.5) (#1438)

This commit is contained in:
Severiano Badajoz
2020-05-04 10:26:42 -07:00
committed by GitHub
parent b255e32548
commit 6cccc41c0f
118 changed files with 1979 additions and 1584 deletions
+3 -3
View File
@@ -20,7 +20,7 @@ class Camera {
this.prevEvent = {
clientX: 0,
clientY: 0,
type: 0
type: 0,
};
this.canvas = canvas;
this.viewMatrix = mat3.create();
@@ -43,11 +43,11 @@ class Camera {
const m = this.viewMatrix;
const dyRange = [
-panBound - (m[7] + 1) / m[4],
panBound - (m[7] - 1) / m[4]
panBound - (m[7] - 1) / m[4],
];
const dxRange = [
-panBound - (m[6] + 1) / m[0],
panBound - (m[6] - 1) / m[0]
panBound - (m[6] - 1) / m[0],
];
const dxClamped = clamp(dx, dxRange);
+1 -1
View File
@@ -24,7 +24,7 @@ const catLabelSort = (isUserAnno, values) => {
const ints = [];
const unassignedOrNaN = [];
values.forEach(v => {
values.forEach((v) => {
if (isUserAnno && v === globals.unassignedCategoryLabel) {
unassignedOrNaN.push(v);
} else if (String(v).toLowerCase() === "nan") {
+1 -1
View File
@@ -70,7 +70,7 @@ const getCoordinatesByLabel = (
hasFinite: false,
xCoordinates: new Float32Array(numInLabel),
yCoordinates: new Float32Array(numInLabel),
length: 0
length: 0,
};
coordsByCategoryLabel.set(label, coords);
}
+11 -11
View File
@@ -11,15 +11,15 @@ If `setTo` is not undefined, values outside the [lower, upper] range will be set
*/
export default function clip(arr, lower, upper, setTo) {
const lowerSet = setTo === undefined ? lower : setTo;
const upperSet = setTo === undefined ? upper : setTo;
for (let i = 0, l = arr.length; i < l; i += 1) {
const v = arr[i];
if (v < lower) {
arr[i] = lowerSet;
} else if (v > upper) {
arr[i] = upperSet;
}
}
return arr;
const lowerSet = setTo === undefined ? lower : setTo;
const upperSet = setTo === undefined ? upper : setTo;
for (let i = 0, l = arr.length; i < l; i += 1) {
const v = arr[i];
if (v < lower) {
arr[i] = lowerSet;
} else if (v > upper) {
arr[i] = upperSet;
}
}
return arr;
}
+12 -12
View File
@@ -5,17 +5,17 @@ import {
isTypedArray,
isArrayOrTypedArray,
callOnceLazy,
memoize
memoize,
} from "./util";
import {
summarizeContinuous,
summarizeCategorical as _summarizeCategorical
summarizeCategorical as _summarizeCategorical,
} from "./summarize";
import {
histogramCategorical as _histogramCategorical,
hashCategorical,
histogramContinuous,
hashContinuous
hashContinuous,
} from "./histogram";
/*
@@ -140,7 +140,7 @@ class Dataframe {
if (!Array.isArray(columnarData)) {
throw new TypeError("Dataframe constructor requires array of columns");
}
if (!columnarData.every(c => isArrayOrTypedArray(c))) {
if (!columnarData.every((c) => isArrayOrTypedArray(c))) {
throw new TypeError("Dataframe columns must all be Array or TypedArray");
}
if (!isLabelIndex(rowIndex)) {
@@ -153,7 +153,7 @@ class Dataframe {
/* check for expected dimensionality / size */
if (
nCols !== columnarData.length ||
!columnarData.every(c => c.length === nRows)
!columnarData.every((c) => c.length === nRows)
) {
throw new RangeError(
"Dataframe dimension does not match provided data shape"
@@ -261,7 +261,7 @@ class Dataframe {
Create histogram bins for this column. Memoized.
*/
const _memoHistoCat = memoize(_histogramCategorical, hashCategorical);
const histogramCategorical = by => _memoHistoCat(get, by);
const histogramCategorical = (by) => _memoHistoCat(get, by);
let histogram = null;
if (isTypedArray(column)) {
const mFn = memoize(histogramContinuous, hashContinuous);
@@ -293,7 +293,7 @@ class Dataframe {
*/
const {
getOffset: getRowByOffset,
getLabel: getRowByLabel
getLabel: getRowByLabel,
} = this.rowIndex;
this.__columnsAccessor = this.__columns.map((column, idx) => {
if (accessors[idx]) {
@@ -423,7 +423,7 @@ class Dataframe {
// otherwise, bulid a new dataframe combining columns from both
const srcOffsets = srcLabels.map(l => dataframe.colIndex.getOffset(l));
const srcOffsets = srcLabels.map((l) => dataframe.colIndex.getOffset(l));
// check for label collisions
if (dstLabels.some(this.hasCol, this)) {
@@ -435,12 +435,12 @@ class Dataframe {
const { rowIndex } = this;
const columns = [
...this.__columns,
...srcOffsets.map(i => dataframe.__columns[i])
...srcOffsets.map((i) => dataframe.__columns[i]),
];
const colIndex = this.colIndex.withLabels(dstLabels);
const columnsAccessor = [
...this.__columnsAccessor,
...srcOffsets.map(i => dataframe.__columnsAccessor[i])
...srcOffsets.map((i) => dataframe.__columnsAccessor[i]),
];
return new this.constructor(
@@ -604,7 +604,7 @@ class Dataframe {
/* subset rows */
if (rowOffsets) {
columns = columns.map(col => {
columns = columns.map((col) => {
const newCol = new col.constructor(rowOffsets.length);
for (let i = 0, l = rowOffsets.length; i < l; i += 1) {
newCol[i] = col[rowOffsets[i]];
@@ -630,7 +630,7 @@ class Dataframe {
if (!labels) {
return null;
}
return labels.map(label => {
return labels.map((label) => {
const off = index.getOffset(label);
if (off === undefined) {
throw new RangeError(`unknown label: ${label}`);
+2 -2
View File
@@ -59,7 +59,7 @@ export function summarizeContinuous(col) {
nan,
pinf,
ninf,
percentiles
percentiles,
};
}
@@ -77,6 +77,6 @@ export function summarizeCategorical(col) {
categorical: true,
categories: [...categoryCounts.keys()],
categoryCounts,
numCategories: categoryCounts.size
numCategories: categoryCounts.size,
};
}
+6 -6
View File
@@ -1,13 +1,13 @@
export default function fromEntries(arr) {
/*
/*
Similar to Object.fromEntries, but only handles array.
This could be replaced with the standard fucnction once it
is widely available. As of 3/20/2019, it has not yet
been released in the Chrome stable channel.
*/
const obj = {};
for (let i = 0, l = arr.length; i < l; i += 1) {
obj[arr[i][0]] = arr[i][1];
}
return obj;
const obj = {};
for (let i = 0, l = arr.length; i < l; i += 1) {
obj[arr[i][0]] = arr[i][1];
}
return obj;
}
+4 -4
View File
@@ -12,11 +12,11 @@ codebase.
const makeDimensionName = (namespace, key) => `${namespace}_${key}`;
export const layoutDimensionName = key => makeDimensionName("layout", key);
export const obsAnnoDimensionName = key => makeDimensionName("obsAnno", key);
export const diffexpDimensionName = key =>
export const layoutDimensionName = (key) => makeDimensionName("layout", key);
export const obsAnnoDimensionName = (key) => makeDimensionName("obsAnno", key);
export const diffexpDimensionName = (key) =>
makeDimensionName("varData_diffexp", key);
export const userDefinedDimensionName = key =>
export const userDefinedDimensionName = (key) =>
makeDimensionName("varData_userDefined", key);
/*
+2 -2
View File
@@ -16,11 +16,11 @@ function parseColorName(c) {
return [
scaleRGB(parseInt(parsedHex[1], 16)),
scaleRGB(parseInt(parsedHex[2], 16)),
scaleRGB(parseInt(parsedHex[3], 16))
scaleRGB(parseInt(parsedHex[3], 16)),
];
}
export default c => {
export default (c) => {
let cv = colorCache[c];
if (!cv) {
cv = parseColorName(c);
+29 -29
View File
@@ -14,37 +14,37 @@ return Promise.all([
])
*/
export class PromiseLimit {
constructor(maxConcurrency) {
this.queue = new Set();
this.maxConcurrency = maxConcurrency;
this.pending = 0;
}
constructor(maxConcurrency) {
this.queue = new Set();
this.maxConcurrency = maxConcurrency;
this.pending = 0;
}
add(fn, ...args) {
// fn - must return a promise
// args - will be passed to fn
return new Promise((resolve, reject) => {
this.queue.add({ fn, args, resolve, reject });
this._resolveNext(false);
});
}
add(fn, ...args) {
// fn - must return a promise
// args - will be passed to fn
return new Promise((resolve, reject) => {
this.queue.add({ fn, args, resolve, reject });
this._resolveNext(false);
});
}
_resolveNext = (completed = true) => {
if (completed) this.pending -= 1;
_resolveNext = (completed = true) => {
if (completed) this.pending -= 1;
while (this.queue.size > 0 && this.pending < this.maxConcurrency) {
const task = this.queue.values().next().value; // order of insertion
this.pending += 1;
this.queue.delete(task);
const { resolve, reject, fn, args } = task;
while (this.queue.size > 0 && this.pending < this.maxConcurrency) {
const task = this.queue.values().next().value; // order of insertion
this.pending += 1;
this.queue.delete(task);
const { resolve, reject, fn, args } = task;
try {
const result = fn(...args);
result.then(this._resolveNext, this._resolveNext);
result.then(resolve, reject);
} catch (err) {
reject(err);
}
}
};
try {
const result = fn(...args);
result.then(this._resolveNext, this._resolveNext);
result.then(resolve, reject);
} catch (err) {
reject(err);
}
}
};
}
+9 -9
View File
@@ -15,15 +15,15 @@ Arguments:
import { sortArray } from "./typedCrossfilter/sort";
export default function quantile(quantArr, tarr, sorted = false) {
/*
/*
start with the naive (sort) implementation. Later, use a faster partition
*/
const arr = sorted ? tarr : sortArray(new tarr.constructor(tarr)); // copy
const len = arr.length;
return quantArr.map(q => {
if (q === 1) {
return arr[len - 1];
}
return arr[Math.floor(q * len)];
});
const arr = sorted ? tarr : sortArray(new tarr.constructor(tarr)); // copy
const len = arr.length;
return quantArr.map((q) => {
if (q === 1) {
return arr[len - 1];
}
return arr[Math.floor(q * len)];
});
}
+16 -16
View File
@@ -23,28 +23,28 @@ rangeFill(array, start, step) -> array
*/
function _doFill(arr, start, step, count) {
for (let idx = 0, val = start; idx < count; idx += 1, val += step) {
arr[idx] = val;
}
return arr;
for (let idx = 0, val = start; idx < count; idx += 1, val += step) {
arr[idx] = val;
}
return arr;
}
export function rangeFill(arr, start = 0, step = 1) {
return _doFill(arr, start, step, arr.length);
return _doFill(arr, start, step, arr.length);
}
export function range(start, stop, step) {
if (start === undefined) return [];
if (stop === undefined) {
stop = start;
start = 0;
}
step = step || 1; // catch undefind and zero
const len = Math.max(Math.ceil((stop - start) / step), 0);
return _doFill(new Array(len), start, step, len);
if (start === undefined) return [];
if (stop === undefined) {
stop = start;
start = 0;
}
step = step || 1; // catch undefind and zero
const len = Math.max(Math.ceil((stop - start) / step), 0);
return _doFill(new Array(len), start, step, len);
}
export function linspace(start, stop, nsteps) {
const delta = (stop - start) / (nsteps - 1).toFixed();
return range(0, nsteps, 1).map(i => start + i * delta);
}
const delta = (stop - start) / (nsteps - 1).toFixed();
return range(0, nsteps, 1).map((i) => start + i * delta);
}
+8 -8
View File
@@ -9,14 +9,14 @@
// this is is equivalent to d3.scaleLinear().domain([0,1]).range([-1,1])
export default (domain, range) => {
const domainStart = domain[0];
const scale = (range[1] - range[0]) / (domain[1] - domain[0]);
const invScale = 1 / scale;
const rangeStart = range[0];
const f = value => (value - domainStart) * scale + rangeStart;
const domainStart = domain[0];
const scale = (range[1] - range[0]) / (domain[1] - domain[0]);
const invScale = 1 / scale;
const rangeStart = range[0];
const f = (value) => (value - domainStart) * scale + rangeStart;
// inverter
f.invert = value => (value - rangeStart) * invScale + domainStart;
// inverter
f.invert = (value) => (value - rangeStart) * invScale + domainStart;
return f;
return f;
};
+1 -1
View File
@@ -1,5 +1,5 @@
// jshint esversion: 6
export default input => {
export default (input) => {
const outputMax = 1;
const outputMin = 0;
+115 -115
View File
@@ -21,171 +21,171 @@ categorical annotations to be writable.
*/
export function isCategoricalAnnotation(schema, name) {
/* we treat any string, categorical or boolean as a categorical */
const { type } = schema.annotations.obsByName[name];
return type === "string" || type === "boolean" || type === "categorical";
/* we treat any string, categorical or boolean as a categorical */
const { type } = schema.annotations.obsByName[name];
return type === "string" || type === "boolean" || type === "categorical";
}
export function isContinuousAnnotation(schema, name) {
return !isCategoricalAnnotation(schema, name);
return !isCategoricalAnnotation(schema, name);
}
function _isUserAnnotation(schema, name) {
return schema.annotations.obsByName[name]?.writable;
return schema.annotations.obsByName[name]?.writable;
}
export function isUserAnnotation(worldOrUniverse, name) {
return _isUserAnnotation(worldOrUniverse.schema, name);
return _isUserAnnotation(worldOrUniverse.schema, name);
}
export function removeObsAnnoSchema(schema, name) {
/*
/*
remove named annotation from obs annotation schema
*/
/* only remove if it exists and is a user annotation */
if (!_isUserAnnotation(schema, name))
throw new Error("removing non-user-defined schema");
return SchemaHelpers.removeObsAnnoColumn(schema, name);
/* only remove if it exists and is a user annotation */
if (!_isUserAnnotation(schema, name))
throw new Error("removing non-user-defined schema");
return SchemaHelpers.removeObsAnnoColumn(schema, name);
}
export function addObsAnnoSchema(schema, name, colSchema) {
/*
/*
add a categorical type to the obs annotation schema
*/
/* collision detection */
if (schema.annotations.obs.columns.some(v => v.name === name))
throw Error("annotations may not contain duplicate category names");
if (name !== colSchema.name) throw Error("column schema does not match");
return SchemaHelpers.addObsAnnoColumn(schema, name, colSchema);
/* collision detection */
if (schema.annotations.obs.columns.some((v) => v.name === name))
throw Error("annotations may not contain duplicate category names");
if (name !== colSchema.name) throw Error("column schema does not match");
return SchemaHelpers.addObsAnnoColumn(schema, name, colSchema);
}
export function dupObsAnnoSchema(schema, sourceName, dupName, defaultSchema) {
/*
/*
duplicate the obs annotation `sourceName` schema, but with the name `dupName`
*/
const colSchema = {
...schema.annotations.obsByName[sourceName],
...defaultSchema,
name: dupName
};
/* existance check */
if (!colSchema) throw Error("source annotation does not exist");
/* collision detection */
if (schema.annotations.obs.columns.some(v => v.name === dupName))
throw Error("annotations may not contain duplicate category names");
return SchemaHelpers.addObsAnnoColumn(schema, dupName, colSchema);
const colSchema = {
...schema.annotations.obsByName[sourceName],
...defaultSchema,
name: dupName,
};
/* existance check */
if (!colSchema) throw Error("source annotation does not exist");
/* collision detection */
if (schema.annotations.obs.columns.some((v) => v.name === dupName))
throw Error("annotations may not contain duplicate category names");
return SchemaHelpers.addObsAnnoColumn(schema, dupName, colSchema);
}
export function removeObsAnnoCategory(schema, name, category) {
/* don't allow deletion of unassigned category on writable annotations */
/* don't allow deletion of unassigned category on writable annotations */
if (!_isUserAnnotation(schema, name))
throw new Error("unable to modify read-only schema");
if (category === unassignedCategoryLabel)
throw new Error("may not remove unassigned category label");
if (!_isUserAnnotation(schema, name))
throw new Error("unable to modify read-only schema");
if (category === unassignedCategoryLabel)
throw new Error("may not remove unassigned category label");
return SchemaHelpers.removeObsAnnoCategory(schema, name, category);
return SchemaHelpers.removeObsAnnoCategory(schema, name, category);
}
export function addObsAnnoCategory(schema, name, category) {
if (!_isUserAnnotation(schema, name))
throw new Error("unable to modify read-only schema");
if (!_isUserAnnotation(schema, name))
throw new Error("unable to modify read-only schema");
return SchemaHelpers.addObsAnnoCategory(schema, name, category);
return SchemaHelpers.addObsAnnoCategory(schema, name, category);
}
export function setLabelByValue(df, colName, fromLabel, toLabel) {
/*
/*
in the dataframe column `colName`, set any value of `fromLabel` to `toLabel`
*/
const keys = df.colIndex.keys();
const ndf = df.mapColumns((col, colIdx) => {
if (colName !== keys[colIdx]) return col;
const keys = df.colIndex.keys();
const ndf = df.mapColumns((col, colIdx) => {
if (colName !== keys[colIdx]) return col;
/* clone data and return it. */
const newCol = col.slice();
for (let i = 0, l = newCol.length; i < l; i += 1) {
if (newCol[i] === fromLabel) newCol[i] = toLabel;
}
return newCol;
});
return ndf;
/* clone data and return it. */
const newCol = col.slice();
for (let i = 0, l = newCol.length; i < l; i += 1) {
if (newCol[i] === fromLabel) newCol[i] = toLabel;
}
return newCol;
});
return ndf;
}
export function setLabelByMask(df, colName, mask, label) {
/*
/*
in the dataframe column `colName`, set the masked rows to 'label'
*/
const keys = df.colIndex.keys();
const ndf = df.mapColumns((col, colIdx) => {
if (colName !== keys[colIdx]) return col;
const keys = df.colIndex.keys();
const ndf = df.mapColumns((col, colIdx) => {
if (colName !== keys[colIdx]) return col;
/* clone data and return it. */
const newCol = col.slice();
for (let i = 0, l = newCol.length; i < l; i += 1) {
if (mask[i]) newCol[i] = label;
}
return newCol;
});
return ndf;
/* clone data and return it. */
const newCol = col.slice();
for (let i = 0, l = newCol.length; i < l; i += 1) {
if (mask[i]) newCol[i] = label;
}
return newCol;
});
return ndf;
}
export function allHaveLabelByMask(df, colName, label, mask) {
// return true if all rows as indicated by mask have the colname set to label.
// False if not.
const col = df.col(colName);
if (!col) return false;
if (df.length !== mask.length)
throw new RangeError("mismatch on mask length");
// return true if all rows as indicated by mask have the colname set to label.
// False if not.
const col = df.col(colName);
if (!col) return false;
if (df.length !== mask.length)
throw new RangeError("mismatch on mask length");
for (let i = 0; i < df.length; i += 1) {
if (mask[i]) {
if (col.iget(i) !== label) return false;
}
}
return true;
for (let i = 0; i < df.length; i += 1) {
if (mask[i]) {
if (col.iget(i) !== label) return false;
}
}
return true;
}
export function worldToUniverseMask(worldMask, worldObsAnnotations, nObs) {
/*
/*
given world seleciton mask, return a selection mask for entire universe
that has same selection state.
*/
const mask = new Uint8Array(nObs);
const { rowIndex } = worldObsAnnotations;
const mask = new Uint8Array(nObs);
const { rowIndex } = worldObsAnnotations;
for (let i = 0, l = worldMask.length; i < l; i += 1) {
if (worldMask[i]) {
const label = rowIndex.getLabel(i);
mask[label] = 1;
}
}
return mask;
for (let i = 0, l = worldMask.length; i < l; i += 1) {
if (worldMask[i]) {
const label = rowIndex.getLabel(i);
mask[label] = 1;
}
}
return mask;
}
export function createWritableAnnotationDimensions(world, crossfilter) {
const { obsAnnotations, schema } = world;
const writableAnnotations = schema.annotations.obs.columns
.filter(s => s.writable)
.map(s => s.name);
const { obsAnnotations, schema } = world;
const writableAnnotations = schema.annotations.obs.columns
.filter((s) => s.writable)
.map((s) => s.name);
crossfilter = writableAnnotations.reduce((xflt, anno) => {
const dimName = obsAnnoDimensionName(anno);
if (xflt.hasDimension(dimName)) xflt = xflt.delDimension(dimName);
return xflt.addDimension(
dimName,
"enum",
obsAnnotations.col(anno).asArray()
);
}, crossfilter);
return crossfilter;
crossfilter = writableAnnotations.reduce((xflt, anno) => {
const dimName = obsAnnoDimensionName(anno);
if (xflt.hasDimension(dimName)) xflt = xflt.delDimension(dimName);
return xflt.addDimension(
dimName,
"enum",
obsAnnotations.col(anno).asArray()
);
}, crossfilter);
return crossfilter;
}
const legalCharacters = /^(\w|[ .()-])+$/;
export function annotationNameIsErroneous(name) {
/*
/*
Validate the name - return:
* false - a valid name
* string - a named error, indicating why it was invalid.
@@ -196,21 +196,21 @@ export function annotationNameIsErroneous(name) {
2. only accept alpha, numeric, underscore, period, parens, hyphen and space
3. no runs of multiple spaces
*/
if (name === "") {
return "empty-string";
}
if (name[0] === " " || name[name.length - 1] === " ") {
return "trim-spaces";
}
if (!legalCharacters.test(name)) {
return "illegal-characters";
}
for (let i = 1, l = name.length; i < l; i += 1) {
if (name[i] === " " && name[i - 1] === " ") {
return "multi-space-run";
}
}
if (name === "") {
return "empty-string";
}
if (name[0] === " " || name[name.length - 1] === " ") {
return "trim-spaces";
}
if (!legalCharacters.test(name)) {
return "illegal-characters";
}
for (let i = 1, l = name.length; i < l; i += 1) {
if (name[i] === " " && name[i - 1] === " ") {
return "multi-space-run";
}
}
/* all is well! Indicte not erroneous with a false */
return false;
/* all is well! Indicte not erroneous with a false */
return false;
}
+21 -13
View File
@@ -15,7 +15,12 @@ create new colors state object. Paramters:
"color by categorical metadata"}
- colorAccessor - the obs annotations used for color-by
*/
export function createColors(world, colorMode = null, colorAccessor = null, userColors = null) {
export function createColors(
world,
colorMode = null,
colorAccessor = null,
userColors = null
) {
switch (colorMode) {
case "color by categorical metadata": {
if (userColors && colorAccessor in userColors) {
@@ -33,7 +38,7 @@ export function createColors(world, colorMode = null, colorAccessor = null, user
const defaultCellColor = parseRGB(globals.defaultCellColor);
return {
rgb: new Array(world.nObs).fill(defaultCellColor),
scale: undefined
scale: undefined,
};
}
}
@@ -41,14 +46,17 @@ export function createColors(world, colorMode = null, colorAccessor = null, user
export function loadUserColorConfig(userColors) {
const convertedUserColors = {};
Object.keys(userColors).forEach(category => {
const [colors, scaleMap] = Object.keys(userColors[category]).reduce((acc, label, i) => {
const color = parseRGB(userColors[category][label]);
acc[0][label] = color;
acc[1][i] = d3.rgb(255 * color[0], 255 * color[1], 255 * color[2]);
return acc;
}, [{}, {}]);
const scale = i => scaleMap[i];
Object.keys(userColors).forEach((category) => {
const [colors, scaleMap] = Object.keys(userColors[category]).reduce(
(acc, label, i) => {
const color = parseRGB(userColors[category][label]);
acc[0][label] = color;
acc[1][i] = d3.rgb(255 * color[0], 255 * color[1], 255 * color[2]);
return acc;
},
[{}, {}]
);
const scale = (i) => scaleMap[i];
convertedUserColors[category] = { colors, scale };
});
return convertedUserColors;
@@ -147,13 +155,13 @@ function createColorsByExpression(world, accessor) {
return { rgb, scale };
}
export const resetColors = world => {
export const resetColors = (world) => {
const { rgb, scale } = createColors(world);
return {
colorMode: null,
colorAccessor: null,
rgb,
scale
scale,
};
};
@@ -165,7 +173,7 @@ export const checkIfColorByDiffexpAndResetColors = (
if (prevControls.diffexpGenes.includes(state.colorAccessor)) {
return {
...state,
...resetColors(prevWorld)
...resetColors(prevWorld),
};
}
return null;
@@ -8,7 +8,7 @@ import * as globals from "../../globals";
import { rangeFill as fillRange } from "../range";
import {
userDefinedDimensionName,
diffexpDimensionName
diffexpDimensionName,
} from "../nameCreators";
export function maxCategoryItems(config) {
@@ -47,7 +47,7 @@ Remember that option values can be ANY js type, except undefined/null.
function topNCategories(colSchema, summary, N) {
/* return top N by occurrences in the data, preserving original category order */
const { categories } = colSchema;
const counts = categories.map(cat => summary.categoryCounts.get(cat) ?? 0);
const counts = categories.map((cat) => summary.categoryCounts.get(cat) ?? 0);
if (categories.length <= N) {
return [categories, counts];
@@ -80,14 +80,14 @@ export function selectableCategoryNames(schema, maxCatItems, names) {
const { index, columns } = schema.annotations.obs;
return columns
.filter(colSchema => !names || names.indexOf(colSchema.name) !== -1)
.filter(colSchema => {
.filter((colSchema) => !names || names.indexOf(colSchema.name) !== -1)
.filter((colSchema) => {
const { type, name } = colSchema;
const isSelectableType =
type === "string" || type === "boolean" || type === "categorical";
return isSelectableType && name !== index;
})
.map(v => v.name);
.map((v) => v.name);
}
export function createCategoricalSelection(world, names) {
@@ -122,7 +122,7 @@ export function createCategoricalSelection(world, names) {
isTruncated, // bool: true if list was truncated
categoryValueCounts, // array: cardinality of each category,
categorySelected: true, // bool - default state for entire category
isUserAnno // bool
isUserAnno, // bool
};
return acc;
}, {});
+3 -3
View File
@@ -70,7 +70,7 @@ export function decodeMatrixFBS(arrayBuffer, inplace = false) {
nCols,
columns,
colIdx,
rowIdx: null
rowIdx: null,
};
}
@@ -102,9 +102,9 @@ export function encodeMatrixFBS(df) {
let encColumns;
if (shape[0] > 0 && shape[1] > 0) {
const columns = df.columns().map(col => col.asArray());
const columns = df.columns().map((col) => col.asArray());
const cols = columns.map(carr => {
const cols = columns.map((carr) => {
let uType;
let tarr;
if (isTypedArray(carr)) {
+199 -115
View File
@@ -10,18 +10,24 @@ var NetEncoding = NetEncoding || {};
* @enum
*/
NetEncoding.TypedArray = {
NONE: 0, 0: 'NONE',
Float32Array: 1, 1: 'Float32Array',
Int32Array: 2, 2: 'Int32Array',
Uint32Array: 3, 3: 'Uint32Array',
Float64Array: 4, 4: 'Float64Array',
JSONEncodedArray: 5, 5: 'JSONEncodedArray'
NONE: 0,
0: "NONE",
Float32Array: 1,
1: "Float32Array",
Int32Array: 2,
2: "Int32Array",
Uint32Array: 3,
3: "Uint32Array",
Float64Array: 4,
4: "Float64Array",
JSONEncodedArray: 5,
5: "JSONEncodedArray",
};
/**
* @constructor
*/
NetEncoding.Float32Array = function() {
NetEncoding.Float32Array = function () {
/**
* @type {flatbuffers.ByteBuffer}
*/
@@ -38,7 +44,7 @@ NetEncoding.Float32Array = function() {
* @param {flatbuffers.ByteBuffer} bb
* @returns {NetEncoding.Float32Array}
*/
NetEncoding.Float32Array.prototype.__init = function(i, bb) {
NetEncoding.Float32Array.prototype.__init = function (i, bb) {
this.bb_pos = i;
this.bb = bb;
return this;
@@ -49,23 +55,28 @@ NetEncoding.Float32Array.prototype.__init = function(i, bb) {
* @param {NetEncoding.Float32Array=} obj
* @returns {NetEncoding.Float32Array}
*/
NetEncoding.Float32Array.getRootAsFloat32Array = function(bb, obj) {
return (obj || new NetEncoding.Float32Array).__init(bb.readInt32(bb.position()) + bb.position(), bb);
NetEncoding.Float32Array.getRootAsFloat32Array = function (bb, obj) {
return (obj || new NetEncoding.Float32Array()).__init(
bb.readInt32(bb.position()) + bb.position(),
bb
);
};
/**
* @param {number} index
* @returns {number}
*/
NetEncoding.Float32Array.prototype.data = function(index) {
NetEncoding.Float32Array.prototype.data = function (index) {
var offset = this.bb.__offset(this.bb_pos, 4);
return offset ? this.bb.readFloat32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0;
return offset
? this.bb.readFloat32(this.bb.__vector(this.bb_pos + offset) + index * 4)
: 0;
};
/**
* @returns {number}
*/
NetEncoding.Float32Array.prototype.dataLength = function() {
NetEncoding.Float32Array.prototype.dataLength = function () {
var offset = this.bb.__offset(this.bb_pos, 4);
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
};
@@ -73,15 +84,21 @@ NetEncoding.Float32Array.prototype.dataLength = function() {
/**
* @returns {Float32Array}
*/
NetEncoding.Float32Array.prototype.dataArray = function() {
NetEncoding.Float32Array.prototype.dataArray = function () {
var offset = this.bb.__offset(this.bb_pos, 4);
return offset ? new Float32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
return offset
? new Float32Array(
this.bb.bytes().buffer,
this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset),
this.bb.__vector_len(this.bb_pos + offset)
)
: null;
};
/**
* @param {flatbuffers.Builder} builder
*/
NetEncoding.Float32Array.startFloat32Array = function(builder) {
NetEncoding.Float32Array.startFloat32Array = function (builder) {
builder.startObject(1);
};
@@ -89,7 +106,7 @@ NetEncoding.Float32Array.startFloat32Array = function(builder) {
* @param {flatbuffers.Builder} builder
* @param {flatbuffers.Offset} dataOffset
*/
NetEncoding.Float32Array.addData = function(builder, dataOffset) {
NetEncoding.Float32Array.addData = function (builder, dataOffset) {
builder.addFieldOffset(0, dataOffset, 0);
};
@@ -98,7 +115,7 @@ NetEncoding.Float32Array.addData = function(builder, dataOffset) {
* @param {Array.<number>} data
* @returns {flatbuffers.Offset}
*/
NetEncoding.Float32Array.createDataVector = function(builder, data) {
NetEncoding.Float32Array.createDataVector = function (builder, data) {
builder.startVector(4, data.length, 4);
for (var i = data.length - 1; i >= 0; i--) {
builder.addFloat32(data[i]);
@@ -110,7 +127,7 @@ NetEncoding.Float32Array.createDataVector = function(builder, data) {
* @param {flatbuffers.Builder} builder
* @param {number} numElems
*/
NetEncoding.Float32Array.startDataVector = function(builder, numElems) {
NetEncoding.Float32Array.startDataVector = function (builder, numElems) {
builder.startVector(4, numElems, 4);
};
@@ -118,7 +135,7 @@ NetEncoding.Float32Array.startDataVector = function(builder, numElems) {
* @param {flatbuffers.Builder} builder
* @returns {flatbuffers.Offset}
*/
NetEncoding.Float32Array.endFloat32Array = function(builder) {
NetEncoding.Float32Array.endFloat32Array = function (builder) {
var offset = builder.endObject();
return offset;
};
@@ -126,7 +143,7 @@ NetEncoding.Float32Array.endFloat32Array = function(builder) {
/**
* @constructor
*/
NetEncoding.Uint32Array = function() {
NetEncoding.Uint32Array = function () {
/**
* @type {flatbuffers.ByteBuffer}
*/
@@ -143,7 +160,7 @@ NetEncoding.Uint32Array = function() {
* @param {flatbuffers.ByteBuffer} bb
* @returns {NetEncoding.Uint32Array}
*/
NetEncoding.Uint32Array.prototype.__init = function(i, bb) {
NetEncoding.Uint32Array.prototype.__init = function (i, bb) {
this.bb_pos = i;
this.bb = bb;
return this;
@@ -154,23 +171,28 @@ NetEncoding.Uint32Array.prototype.__init = function(i, bb) {
* @param {NetEncoding.Uint32Array=} obj
* @returns {NetEncoding.Uint32Array}
*/
NetEncoding.Uint32Array.getRootAsUint32Array = function(bb, obj) {
return (obj || new NetEncoding.Uint32Array).__init(bb.readInt32(bb.position()) + bb.position(), bb);
NetEncoding.Uint32Array.getRootAsUint32Array = function (bb, obj) {
return (obj || new NetEncoding.Uint32Array()).__init(
bb.readInt32(bb.position()) + bb.position(),
bb
);
};
/**
* @param {number} index
* @returns {number}
*/
NetEncoding.Uint32Array.prototype.data = function(index) {
NetEncoding.Uint32Array.prototype.data = function (index) {
var offset = this.bb.__offset(this.bb_pos, 4);
return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0;
return offset
? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4)
: 0;
};
/**
* @returns {number}
*/
NetEncoding.Uint32Array.prototype.dataLength = function() {
NetEncoding.Uint32Array.prototype.dataLength = function () {
var offset = this.bb.__offset(this.bb_pos, 4);
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
};
@@ -178,15 +200,21 @@ NetEncoding.Uint32Array.prototype.dataLength = function() {
/**
* @returns {Uint32Array}
*/
NetEncoding.Uint32Array.prototype.dataArray = function() {
NetEncoding.Uint32Array.prototype.dataArray = function () {
var offset = this.bb.__offset(this.bb_pos, 4);
return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
return offset
? new Uint32Array(
this.bb.bytes().buffer,
this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset),
this.bb.__vector_len(this.bb_pos + offset)
)
: null;
};
/**
* @param {flatbuffers.Builder} builder
*/
NetEncoding.Uint32Array.startUint32Array = function(builder) {
NetEncoding.Uint32Array.startUint32Array = function (builder) {
builder.startObject(1);
};
@@ -194,7 +222,7 @@ NetEncoding.Uint32Array.startUint32Array = function(builder) {
* @param {flatbuffers.Builder} builder
* @param {flatbuffers.Offset} dataOffset
*/
NetEncoding.Uint32Array.addData = function(builder, dataOffset) {
NetEncoding.Uint32Array.addData = function (builder, dataOffset) {
builder.addFieldOffset(0, dataOffset, 0);
};
@@ -203,7 +231,7 @@ NetEncoding.Uint32Array.addData = function(builder, dataOffset) {
* @param {Array.<number>} data
* @returns {flatbuffers.Offset}
*/
NetEncoding.Uint32Array.createDataVector = function(builder, data) {
NetEncoding.Uint32Array.createDataVector = function (builder, data) {
builder.startVector(4, data.length, 4);
for (var i = data.length - 1; i >= 0; i--) {
builder.addInt32(data[i]);
@@ -215,7 +243,7 @@ NetEncoding.Uint32Array.createDataVector = function(builder, data) {
* @param {flatbuffers.Builder} builder
* @param {number} numElems
*/
NetEncoding.Uint32Array.startDataVector = function(builder, numElems) {
NetEncoding.Uint32Array.startDataVector = function (builder, numElems) {
builder.startVector(4, numElems, 4);
};
@@ -223,7 +251,7 @@ NetEncoding.Uint32Array.startDataVector = function(builder, numElems) {
* @param {flatbuffers.Builder} builder
* @returns {flatbuffers.Offset}
*/
NetEncoding.Uint32Array.endUint32Array = function(builder) {
NetEncoding.Uint32Array.endUint32Array = function (builder) {
var offset = builder.endObject();
return offset;
};
@@ -231,7 +259,7 @@ NetEncoding.Uint32Array.endUint32Array = function(builder) {
/**
* @constructor
*/
NetEncoding.Int32Array = function() {
NetEncoding.Int32Array = function () {
/**
* @type {flatbuffers.ByteBuffer}
*/
@@ -248,7 +276,7 @@ NetEncoding.Int32Array = function() {
* @param {flatbuffers.ByteBuffer} bb
* @returns {NetEncoding.Int32Array}
*/
NetEncoding.Int32Array.prototype.__init = function(i, bb) {
NetEncoding.Int32Array.prototype.__init = function (i, bb) {
this.bb_pos = i;
this.bb = bb;
return this;
@@ -259,23 +287,28 @@ NetEncoding.Int32Array.prototype.__init = function(i, bb) {
* @param {NetEncoding.Int32Array=} obj
* @returns {NetEncoding.Int32Array}
*/
NetEncoding.Int32Array.getRootAsInt32Array = function(bb, obj) {
return (obj || new NetEncoding.Int32Array).__init(bb.readInt32(bb.position()) + bb.position(), bb);
NetEncoding.Int32Array.getRootAsInt32Array = function (bb, obj) {
return (obj || new NetEncoding.Int32Array()).__init(
bb.readInt32(bb.position()) + bb.position(),
bb
);
};
/**
* @param {number} index
* @returns {number}
*/
NetEncoding.Int32Array.prototype.data = function(index) {
NetEncoding.Int32Array.prototype.data = function (index) {
var offset = this.bb.__offset(this.bb_pos, 4);
return offset ? this.bb.readInt32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0;
return offset
? this.bb.readInt32(this.bb.__vector(this.bb_pos + offset) + index * 4)
: 0;
};
/**
* @returns {number}
*/
NetEncoding.Int32Array.prototype.dataLength = function() {
NetEncoding.Int32Array.prototype.dataLength = function () {
var offset = this.bb.__offset(this.bb_pos, 4);
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
};
@@ -283,15 +316,21 @@ NetEncoding.Int32Array.prototype.dataLength = function() {
/**
* @returns {Int32Array}
*/
NetEncoding.Int32Array.prototype.dataArray = function() {
NetEncoding.Int32Array.prototype.dataArray = function () {
var offset = this.bb.__offset(this.bb_pos, 4);
return offset ? new Int32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
return offset
? new Int32Array(
this.bb.bytes().buffer,
this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset),
this.bb.__vector_len(this.bb_pos + offset)
)
: null;
};
/**
* @param {flatbuffers.Builder} builder
*/
NetEncoding.Int32Array.startInt32Array = function(builder) {
NetEncoding.Int32Array.startInt32Array = function (builder) {
builder.startObject(1);
};
@@ -299,7 +338,7 @@ NetEncoding.Int32Array.startInt32Array = function(builder) {
* @param {flatbuffers.Builder} builder
* @param {flatbuffers.Offset} dataOffset
*/
NetEncoding.Int32Array.addData = function(builder, dataOffset) {
NetEncoding.Int32Array.addData = function (builder, dataOffset) {
builder.addFieldOffset(0, dataOffset, 0);
};
@@ -308,7 +347,7 @@ NetEncoding.Int32Array.addData = function(builder, dataOffset) {
* @param {Array.<number>} data
* @returns {flatbuffers.Offset}
*/
NetEncoding.Int32Array.createDataVector = function(builder, data) {
NetEncoding.Int32Array.createDataVector = function (builder, data) {
builder.startVector(4, data.length, 4);
for (var i = data.length - 1; i >= 0; i--) {
builder.addInt32(data[i]);
@@ -320,7 +359,7 @@ NetEncoding.Int32Array.createDataVector = function(builder, data) {
* @param {flatbuffers.Builder} builder
* @param {number} numElems
*/
NetEncoding.Int32Array.startDataVector = function(builder, numElems) {
NetEncoding.Int32Array.startDataVector = function (builder, numElems) {
builder.startVector(4, numElems, 4);
};
@@ -328,7 +367,7 @@ NetEncoding.Int32Array.startDataVector = function(builder, numElems) {
* @param {flatbuffers.Builder} builder
* @returns {flatbuffers.Offset}
*/
NetEncoding.Int32Array.endInt32Array = function(builder) {
NetEncoding.Int32Array.endInt32Array = function (builder) {
var offset = builder.endObject();
return offset;
};
@@ -336,7 +375,7 @@ NetEncoding.Int32Array.endInt32Array = function(builder) {
/**
* @constructor
*/
NetEncoding.Float64Array = function() {
NetEncoding.Float64Array = function () {
/**
* @type {flatbuffers.ByteBuffer}
*/
@@ -353,7 +392,7 @@ NetEncoding.Float64Array = function() {
* @param {flatbuffers.ByteBuffer} bb
* @returns {NetEncoding.Float64Array}
*/
NetEncoding.Float64Array.prototype.__init = function(i, bb) {
NetEncoding.Float64Array.prototype.__init = function (i, bb) {
this.bb_pos = i;
this.bb = bb;
return this;
@@ -364,23 +403,28 @@ NetEncoding.Float64Array.prototype.__init = function(i, bb) {
* @param {NetEncoding.Float64Array=} obj
* @returns {NetEncoding.Float64Array}
*/
NetEncoding.Float64Array.getRootAsFloat64Array = function(bb, obj) {
return (obj || new NetEncoding.Float64Array).__init(bb.readInt32(bb.position()) + bb.position(), bb);
NetEncoding.Float64Array.getRootAsFloat64Array = function (bb, obj) {
return (obj || new NetEncoding.Float64Array()).__init(
bb.readInt32(bb.position()) + bb.position(),
bb
);
};
/**
* @param {number} index
* @returns {number}
*/
NetEncoding.Float64Array.prototype.data = function(index) {
NetEncoding.Float64Array.prototype.data = function (index) {
var offset = this.bb.__offset(this.bb_pos, 4);
return offset ? this.bb.readFloat64(this.bb.__vector(this.bb_pos + offset) + index * 8) : 0;
return offset
? this.bb.readFloat64(this.bb.__vector(this.bb_pos + offset) + index * 8)
: 0;
};
/**
* @returns {number}
*/
NetEncoding.Float64Array.prototype.dataLength = function() {
NetEncoding.Float64Array.prototype.dataLength = function () {
var offset = this.bb.__offset(this.bb_pos, 4);
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
};
@@ -388,15 +432,21 @@ NetEncoding.Float64Array.prototype.dataLength = function() {
/**
* @returns {Float64Array}
*/
NetEncoding.Float64Array.prototype.dataArray = function() {
NetEncoding.Float64Array.prototype.dataArray = function () {
var offset = this.bb.__offset(this.bb_pos, 4);
return offset ? new Float64Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
return offset
? new Float64Array(
this.bb.bytes().buffer,
this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset),
this.bb.__vector_len(this.bb_pos + offset)
)
: null;
};
/**
* @param {flatbuffers.Builder} builder
*/
NetEncoding.Float64Array.startFloat64Array = function(builder) {
NetEncoding.Float64Array.startFloat64Array = function (builder) {
builder.startObject(1);
};
@@ -404,7 +454,7 @@ NetEncoding.Float64Array.startFloat64Array = function(builder) {
* @param {flatbuffers.Builder} builder
* @param {flatbuffers.Offset} dataOffset
*/
NetEncoding.Float64Array.addData = function(builder, dataOffset) {
NetEncoding.Float64Array.addData = function (builder, dataOffset) {
builder.addFieldOffset(0, dataOffset, 0);
};
@@ -413,7 +463,7 @@ NetEncoding.Float64Array.addData = function(builder, dataOffset) {
* @param {Array.<number>} data
* @returns {flatbuffers.Offset}
*/
NetEncoding.Float64Array.createDataVector = function(builder, data) {
NetEncoding.Float64Array.createDataVector = function (builder, data) {
builder.startVector(8, data.length, 8);
for (var i = data.length - 1; i >= 0; i--) {
builder.addFloat64(data[i]);
@@ -425,7 +475,7 @@ NetEncoding.Float64Array.createDataVector = function(builder, data) {
* @param {flatbuffers.Builder} builder
* @param {number} numElems
*/
NetEncoding.Float64Array.startDataVector = function(builder, numElems) {
NetEncoding.Float64Array.startDataVector = function (builder, numElems) {
builder.startVector(8, numElems, 8);
};
@@ -433,7 +483,7 @@ NetEncoding.Float64Array.startDataVector = function(builder, numElems) {
* @param {flatbuffers.Builder} builder
* @returns {flatbuffers.Offset}
*/
NetEncoding.Float64Array.endFloat64Array = function(builder) {
NetEncoding.Float64Array.endFloat64Array = function (builder) {
var offset = builder.endObject();
return offset;
};
@@ -441,7 +491,7 @@ NetEncoding.Float64Array.endFloat64Array = function(builder) {
/**
* @constructor
*/
NetEncoding.JSONEncodedArray = function() {
NetEncoding.JSONEncodedArray = function () {
/**
* @type {flatbuffers.ByteBuffer}
*/
@@ -458,7 +508,7 @@ NetEncoding.JSONEncodedArray = function() {
* @param {flatbuffers.ByteBuffer} bb
* @returns {NetEncoding.JSONEncodedArray}
*/
NetEncoding.JSONEncodedArray.prototype.__init = function(i, bb) {
NetEncoding.JSONEncodedArray.prototype.__init = function (i, bb) {
this.bb_pos = i;
this.bb = bb;
return this;
@@ -469,23 +519,28 @@ NetEncoding.JSONEncodedArray.prototype.__init = function(i, bb) {
* @param {NetEncoding.JSONEncodedArray=} obj
* @returns {NetEncoding.JSONEncodedArray}
*/
NetEncoding.JSONEncodedArray.getRootAsJSONEncodedArray = function(bb, obj) {
return (obj || new NetEncoding.JSONEncodedArray).__init(bb.readInt32(bb.position()) + bb.position(), bb);
NetEncoding.JSONEncodedArray.getRootAsJSONEncodedArray = function (bb, obj) {
return (obj || new NetEncoding.JSONEncodedArray()).__init(
bb.readInt32(bb.position()) + bb.position(),
bb
);
};
/**
* @param {number} index
* @returns {number}
*/
NetEncoding.JSONEncodedArray.prototype.data = function(index) {
NetEncoding.JSONEncodedArray.prototype.data = function (index) {
var offset = this.bb.__offset(this.bb_pos, 4);
return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0;
return offset
? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index)
: 0;
};
/**
* @returns {number}
*/
NetEncoding.JSONEncodedArray.prototype.dataLength = function() {
NetEncoding.JSONEncodedArray.prototype.dataLength = function () {
var offset = this.bb.__offset(this.bb_pos, 4);
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
};
@@ -493,15 +548,21 @@ NetEncoding.JSONEncodedArray.prototype.dataLength = function() {
/**
* @returns {Uint8Array}
*/
NetEncoding.JSONEncodedArray.prototype.dataArray = function() {
NetEncoding.JSONEncodedArray.prototype.dataArray = function () {
var offset = this.bb.__offset(this.bb_pos, 4);
return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
return offset
? new Uint8Array(
this.bb.bytes().buffer,
this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset),
this.bb.__vector_len(this.bb_pos + offset)
)
: null;
};
/**
* @param {flatbuffers.Builder} builder
*/
NetEncoding.JSONEncodedArray.startJSONEncodedArray = function(builder) {
NetEncoding.JSONEncodedArray.startJSONEncodedArray = function (builder) {
builder.startObject(1);
};
@@ -509,7 +570,7 @@ NetEncoding.JSONEncodedArray.startJSONEncodedArray = function(builder) {
* @param {flatbuffers.Builder} builder
* @param {flatbuffers.Offset} dataOffset
*/
NetEncoding.JSONEncodedArray.addData = function(builder, dataOffset) {
NetEncoding.JSONEncodedArray.addData = function (builder, dataOffset) {
builder.addFieldOffset(0, dataOffset, 0);
};
@@ -518,7 +579,7 @@ NetEncoding.JSONEncodedArray.addData = function(builder, dataOffset) {
* @param {Array.<number>} data
* @returns {flatbuffers.Offset}
*/
NetEncoding.JSONEncodedArray.createDataVector = function(builder, data) {
NetEncoding.JSONEncodedArray.createDataVector = function (builder, data) {
builder.startVector(1, data.length, 1);
for (var i = data.length - 1; i >= 0; i--) {
builder.addInt8(data[i]);
@@ -530,7 +591,7 @@ NetEncoding.JSONEncodedArray.createDataVector = function(builder, data) {
* @param {flatbuffers.Builder} builder
* @param {number} numElems
*/
NetEncoding.JSONEncodedArray.startDataVector = function(builder, numElems) {
NetEncoding.JSONEncodedArray.startDataVector = function (builder, numElems) {
builder.startVector(1, numElems, 1);
};
@@ -538,7 +599,7 @@ NetEncoding.JSONEncodedArray.startDataVector = function(builder, numElems) {
* @param {flatbuffers.Builder} builder
* @returns {flatbuffers.Offset}
*/
NetEncoding.JSONEncodedArray.endJSONEncodedArray = function(builder) {
NetEncoding.JSONEncodedArray.endJSONEncodedArray = function (builder) {
var offset = builder.endObject();
return offset;
};
@@ -546,7 +607,7 @@ NetEncoding.JSONEncodedArray.endJSONEncodedArray = function(builder) {
/**
* @constructor
*/
NetEncoding.Column = function() {
NetEncoding.Column = function () {
/**
* @type {flatbuffers.ByteBuffer}
*/
@@ -563,7 +624,7 @@ NetEncoding.Column = function() {
* @param {flatbuffers.ByteBuffer} bb
* @returns {NetEncoding.Column}
*/
NetEncoding.Column.prototype.__init = function(i, bb) {
NetEncoding.Column.prototype.__init = function (i, bb) {
this.bb_pos = i;
this.bb = bb;
return this;
@@ -574,23 +635,30 @@ NetEncoding.Column.prototype.__init = function(i, bb) {
* @param {NetEncoding.Column=} obj
* @returns {NetEncoding.Column}
*/
NetEncoding.Column.getRootAsColumn = function(bb, obj) {
return (obj || new NetEncoding.Column).__init(bb.readInt32(bb.position()) + bb.position(), bb);
NetEncoding.Column.getRootAsColumn = function (bb, obj) {
return (obj || new NetEncoding.Column()).__init(
bb.readInt32(bb.position()) + bb.position(),
bb
);
};
/**
* @returns {NetEncoding.TypedArray}
*/
NetEncoding.Column.prototype.uType = function() {
NetEncoding.Column.prototype.uType = function () {
var offset = this.bb.__offset(this.bb_pos, 4);
return offset ? /** @type {NetEncoding.TypedArray} */ (this.bb.readUint8(this.bb_pos + offset)) : NetEncoding.TypedArray.NONE;
return offset
? /** @type {NetEncoding.TypedArray} */ (this.bb.readUint8(
this.bb_pos + offset
))
: NetEncoding.TypedArray.NONE;
};
/**
* @param {flatbuffers.Table} obj
* @returns {?flatbuffers.Table}
*/
NetEncoding.Column.prototype.u = function(obj) {
NetEncoding.Column.prototype.u = function (obj) {
var offset = this.bb.__offset(this.bb_pos, 6);
return offset ? this.bb.__union(obj, this.bb_pos + offset) : null;
};
@@ -598,7 +666,7 @@ NetEncoding.Column.prototype.u = function(obj) {
/**
* @param {flatbuffers.Builder} builder
*/
NetEncoding.Column.startColumn = function(builder) {
NetEncoding.Column.startColumn = function (builder) {
builder.startObject(2);
};
@@ -606,7 +674,7 @@ NetEncoding.Column.startColumn = function(builder) {
* @param {flatbuffers.Builder} builder
* @param {NetEncoding.TypedArray} uType
*/
NetEncoding.Column.addUType = function(builder, uType) {
NetEncoding.Column.addUType = function (builder, uType) {
builder.addFieldInt8(0, uType, NetEncoding.TypedArray.NONE);
};
@@ -614,7 +682,7 @@ NetEncoding.Column.addUType = function(builder, uType) {
* @param {flatbuffers.Builder} builder
* @param {flatbuffers.Offset} uOffset
*/
NetEncoding.Column.addU = function(builder, uOffset) {
NetEncoding.Column.addU = function (builder, uOffset) {
builder.addFieldOffset(1, uOffset, 0);
};
@@ -622,7 +690,7 @@ NetEncoding.Column.addU = function(builder, uOffset) {
* @param {flatbuffers.Builder} builder
* @returns {flatbuffers.Offset}
*/
NetEncoding.Column.endColumn = function(builder) {
NetEncoding.Column.endColumn = function (builder) {
var offset = builder.endObject();
return offset;
};
@@ -630,7 +698,7 @@ NetEncoding.Column.endColumn = function(builder) {
/**
* @constructor
*/
NetEncoding.Matrix = function() {
NetEncoding.Matrix = function () {
/**
* @type {flatbuffers.ByteBuffer}
*/
@@ -647,7 +715,7 @@ NetEncoding.Matrix = function() {
* @param {flatbuffers.ByteBuffer} bb
* @returns {NetEncoding.Matrix}
*/
NetEncoding.Matrix.prototype.__init = function(i, bb) {
NetEncoding.Matrix.prototype.__init = function (i, bb) {
this.bb_pos = i;
this.bb = bb;
return this;
@@ -658,14 +726,17 @@ NetEncoding.Matrix.prototype.__init = function(i, bb) {
* @param {NetEncoding.Matrix=} obj
* @returns {NetEncoding.Matrix}
*/
NetEncoding.Matrix.getRootAsMatrix = function(bb, obj) {
return (obj || new NetEncoding.Matrix).__init(bb.readInt32(bb.position()) + bb.position(), bb);
NetEncoding.Matrix.getRootAsMatrix = function (bb, obj) {
return (obj || new NetEncoding.Matrix()).__init(
bb.readInt32(bb.position()) + bb.position(),
bb
);
};
/**
* @returns {number}
*/
NetEncoding.Matrix.prototype.nRows = function() {
NetEncoding.Matrix.prototype.nRows = function () {
var offset = this.bb.__offset(this.bb_pos, 4);
return offset ? this.bb.readUint32(this.bb_pos + offset) : 0;
};
@@ -673,7 +744,7 @@ NetEncoding.Matrix.prototype.nRows = function() {
/**
* @returns {number}
*/
NetEncoding.Matrix.prototype.nCols = function() {
NetEncoding.Matrix.prototype.nCols = function () {
var offset = this.bb.__offset(this.bb_pos, 6);
return offset ? this.bb.readUint32(this.bb_pos + offset) : 0;
};
@@ -683,15 +754,20 @@ NetEncoding.Matrix.prototype.nCols = function() {
* @param {NetEncoding.Column=} obj
* @returns {NetEncoding.Column}
*/
NetEncoding.Matrix.prototype.columns = function(index, obj) {
NetEncoding.Matrix.prototype.columns = function (index, obj) {
var offset = this.bb.__offset(this.bb_pos, 8);
return offset ? (obj || new NetEncoding.Column).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
return offset
? (obj || new NetEncoding.Column()).__init(
this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4),
this.bb
)
: null;
};
/**
* @returns {number}
*/
NetEncoding.Matrix.prototype.columnsLength = function() {
NetEncoding.Matrix.prototype.columnsLength = function () {
var offset = this.bb.__offset(this.bb_pos, 8);
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
};
@@ -699,16 +775,20 @@ NetEncoding.Matrix.prototype.columnsLength = function() {
/**
* @returns {NetEncoding.TypedArray}
*/
NetEncoding.Matrix.prototype.colIndexType = function() {
NetEncoding.Matrix.prototype.colIndexType = function () {
var offset = this.bb.__offset(this.bb_pos, 10);
return offset ? /** @type {NetEncoding.TypedArray} */ (this.bb.readUint8(this.bb_pos + offset)) : NetEncoding.TypedArray.NONE;
return offset
? /** @type {NetEncoding.TypedArray} */ (this.bb.readUint8(
this.bb_pos + offset
))
: NetEncoding.TypedArray.NONE;
};
/**
* @param {flatbuffers.Table} obj
* @returns {?flatbuffers.Table}
*/
NetEncoding.Matrix.prototype.colIndex = function(obj) {
NetEncoding.Matrix.prototype.colIndex = function (obj) {
var offset = this.bb.__offset(this.bb_pos, 12);
return offset ? this.bb.__union(obj, this.bb_pos + offset) : null;
};
@@ -716,16 +796,20 @@ NetEncoding.Matrix.prototype.colIndex = function(obj) {
/**
* @returns {NetEncoding.TypedArray}
*/
NetEncoding.Matrix.prototype.rowIndexType = function() {
NetEncoding.Matrix.prototype.rowIndexType = function () {
var offset = this.bb.__offset(this.bb_pos, 14);
return offset ? /** @type {NetEncoding.TypedArray} */ (this.bb.readUint8(this.bb_pos + offset)) : NetEncoding.TypedArray.NONE;
return offset
? /** @type {NetEncoding.TypedArray} */ (this.bb.readUint8(
this.bb_pos + offset
))
: NetEncoding.TypedArray.NONE;
};
/**
* @param {flatbuffers.Table} obj
* @returns {?flatbuffers.Table}
*/
NetEncoding.Matrix.prototype.rowIndex = function(obj) {
NetEncoding.Matrix.prototype.rowIndex = function (obj) {
var offset = this.bb.__offset(this.bb_pos, 16);
return offset ? this.bb.__union(obj, this.bb_pos + offset) : null;
};
@@ -733,7 +817,7 @@ NetEncoding.Matrix.prototype.rowIndex = function(obj) {
/**
* @param {flatbuffers.Builder} builder
*/
NetEncoding.Matrix.startMatrix = function(builder) {
NetEncoding.Matrix.startMatrix = function (builder) {
builder.startObject(7);
};
@@ -741,7 +825,7 @@ NetEncoding.Matrix.startMatrix = function(builder) {
* @param {flatbuffers.Builder} builder
* @param {number} nRows
*/
NetEncoding.Matrix.addNRows = function(builder, nRows) {
NetEncoding.Matrix.addNRows = function (builder, nRows) {
builder.addFieldInt32(0, nRows, 0);
};
@@ -749,7 +833,7 @@ NetEncoding.Matrix.addNRows = function(builder, nRows) {
* @param {flatbuffers.Builder} builder
* @param {number} nCols
*/
NetEncoding.Matrix.addNCols = function(builder, nCols) {
NetEncoding.Matrix.addNCols = function (builder, nCols) {
builder.addFieldInt32(1, nCols, 0);
};
@@ -757,7 +841,7 @@ NetEncoding.Matrix.addNCols = function(builder, nCols) {
* @param {flatbuffers.Builder} builder
* @param {flatbuffers.Offset} columnsOffset
*/
NetEncoding.Matrix.addColumns = function(builder, columnsOffset) {
NetEncoding.Matrix.addColumns = function (builder, columnsOffset) {
builder.addFieldOffset(2, columnsOffset, 0);
};
@@ -766,7 +850,7 @@ NetEncoding.Matrix.addColumns = function(builder, columnsOffset) {
* @param {Array.<flatbuffers.Offset>} data
* @returns {flatbuffers.Offset}
*/
NetEncoding.Matrix.createColumnsVector = function(builder, data) {
NetEncoding.Matrix.createColumnsVector = function (builder, data) {
builder.startVector(4, data.length, 4);
for (var i = data.length - 1; i >= 0; i--) {
builder.addOffset(data[i]);
@@ -778,7 +862,7 @@ NetEncoding.Matrix.createColumnsVector = function(builder, data) {
* @param {flatbuffers.Builder} builder
* @param {number} numElems
*/
NetEncoding.Matrix.startColumnsVector = function(builder, numElems) {
NetEncoding.Matrix.startColumnsVector = function (builder, numElems) {
builder.startVector(4, numElems, 4);
};
@@ -786,7 +870,7 @@ NetEncoding.Matrix.startColumnsVector = function(builder, numElems) {
* @param {flatbuffers.Builder} builder
* @param {NetEncoding.TypedArray} colIndexType
*/
NetEncoding.Matrix.addColIndexType = function(builder, colIndexType) {
NetEncoding.Matrix.addColIndexType = function (builder, colIndexType) {
builder.addFieldInt8(3, colIndexType, NetEncoding.TypedArray.NONE);
};
@@ -794,7 +878,7 @@ NetEncoding.Matrix.addColIndexType = function(builder, colIndexType) {
* @param {flatbuffers.Builder} builder
* @param {flatbuffers.Offset} colIndexOffset
*/
NetEncoding.Matrix.addColIndex = function(builder, colIndexOffset) {
NetEncoding.Matrix.addColIndex = function (builder, colIndexOffset) {
builder.addFieldOffset(4, colIndexOffset, 0);
};
@@ -802,7 +886,7 @@ NetEncoding.Matrix.addColIndex = function(builder, colIndexOffset) {
* @param {flatbuffers.Builder} builder
* @param {NetEncoding.TypedArray} rowIndexType
*/
NetEncoding.Matrix.addRowIndexType = function(builder, rowIndexType) {
NetEncoding.Matrix.addRowIndexType = function (builder, rowIndexType) {
builder.addFieldInt8(5, rowIndexType, NetEncoding.TypedArray.NONE);
};
@@ -810,7 +894,7 @@ NetEncoding.Matrix.addRowIndexType = function(builder, rowIndexType) {
* @param {flatbuffers.Builder} builder
* @param {flatbuffers.Offset} rowIndexOffset
*/
NetEncoding.Matrix.addRowIndex = function(builder, rowIndexOffset) {
NetEncoding.Matrix.addRowIndex = function (builder, rowIndexOffset) {
builder.addFieldOffset(6, rowIndexOffset, 0);
};
@@ -818,7 +902,7 @@ NetEncoding.Matrix.addRowIndex = function(builder, rowIndexOffset) {
* @param {flatbuffers.Builder} builder
* @returns {flatbuffers.Offset}
*/
NetEncoding.Matrix.endMatrix = function(builder) {
NetEncoding.Matrix.endMatrix = function (builder) {
var offset = builder.endObject();
return offset;
};
@@ -827,9 +911,9 @@ NetEncoding.Matrix.endMatrix = function(builder) {
* @param {flatbuffers.Builder} builder
* @param {flatbuffers.Offset} offset
*/
NetEncoding.Matrix.finishMatrixBuffer = function(builder, offset) {
NetEncoding.Matrix.finishMatrixBuffer = function (builder, offset) {
builder.finish(offset);
};
// Exports for ECMAScript6 Modules
export {NetEncoding};
export { NetEncoding };
+13 -13
View File
@@ -19,16 +19,16 @@ System wide schema assumptions:
export function indexEntireSchema(schema) {
/* Index schema for ease of use */
schema.annotations.obsByName = fromEntries(
schema.annotations.obs.columns.map(v => [v.name, v])
schema.annotations.obs.columns.map((v) => [v.name, v])
);
schema.annotations.varByName = fromEntries(
schema.annotations.var.columns.map(v => [v.name, v])
schema.annotations.var.columns.map((v) => [v.name, v])
);
schema.layout.obsByName = fromEntries(
schema.layout.obs.map(v => [v.name, v])
schema.layout.obs.map((v) => [v.name, v])
);
schema.layout.varByName = fromEntries(
schema.layout.var.map(v => [v.name, v])
schema.layout.var.map((v) => [v.name, v])
);
return schema;
@@ -40,8 +40,8 @@ function _copyObsAnno(schema) {
...schema,
annotations: {
...schema.annotations,
obs: _.cloneDeep(schema.annotations.obs)
}
obs: _.cloneDeep(schema.annotations.obs),
},
};
}
@@ -50,22 +50,22 @@ function _copyObsLayout(schema) {
...schema,
layout: {
...schema.layout,
obs: _.cloneDeep(schema.layout.obs)
}
obs: _.cloneDeep(schema.layout.obs),
},
};
}
function _reindexObsAnno(schema) {
/* reindex obs annotations ONLY */
schema.annotations.obsByName = fromEntries(
schema.annotations.obs.columns.map(v => [v.name, v])
schema.annotations.obs.columns.map((v) => [v.name, v])
);
return schema;
}
function _reindexObsLayout(schema) {
schema.layout.obsByName = fromEntries(
schema.layout.obs.map(v => [v.name, v])
schema.layout.obs.map((v) => [v.name, v])
);
return schema;
}
@@ -73,7 +73,7 @@ function _reindexObsLayout(schema) {
export function removeObsAnnoColumn(schema, name) {
const newSchema = _copyObsAnno(schema);
newSchema.annotations.obs.columns = schema.annotations.obs.columns.filter(
v => v.name !== name
(v) => v.name !== name
);
return _reindexObsAnno(newSchema);
}
@@ -115,7 +115,7 @@ export function addObsAnnoCategory(schema, name, category) {
const catAnno = newSchema.annotations.obsByName[name];
catAnno.categories = catLabelSort(catAnno.writable, [
...catAnno.categories,
category
category,
]);
return newSchema;
}
@@ -130,6 +130,6 @@ export function addObsLayout(schema, layout) {
export function removeObsLayout(schema, name) {
/* remove a layout */
const newSchema = _copyObsLayout(schema);
newSchema.layout.obs = schema.layout.obs.filter(v => v.name !== name);
newSchema.layout.obs = schema.layout.obs.filter((v) => v.name !== name);
return _reindexObsLayout(newSchema);
}
+11 -11
View File
@@ -28,7 +28,7 @@ function templateUniverse() {
/*
Var data columns - subset of all
*/
varData: Dataframe.Dataframe.empty(null, new Dataframe.KeyIndex())
varData: Dataframe.Dataframe.empty(null, new Dataframe.KeyIndex()),
};
}
@@ -91,22 +91,22 @@ export function matrixFBSToDataframe(arrayBuffers) {
return Dataframe.Dataframe.empty();
}
const fbs = arrayBuffers.map(ab => decodeMatrixFBS(ab, true)); // leave in place
const fbs = arrayBuffers.map((ab) => decodeMatrixFBS(ab, true)); // leave in place
/* check that all FBS have same row dimensionality */
const { nRows } = fbs[0];
fbs.forEach(b => {
fbs.forEach((b) => {
if (b.nRows !== nRows)
throw new Error("FBS with inconsistent dimensionality");
});
const columns = fbs
.map(fb =>
fb.columns.map(c => {
.map((fb) =>
fb.columns.map((c) => {
if (isFpTypedArray(c) || Array.isArray(c)) return c;
return promoteTypedArray(c);
})
)
.flat();
const colIdx = fbs.map(b => b.colIdx).flat();
const colIdx = fbs.map((b) => b.colIdx).flat();
const nCols = columns.length;
const df = new Dataframe.Dataframe(
@@ -145,8 +145,8 @@ function normalizeSchemaCategory(colSchema, col = undefined) {
let categories = [
...new Set([
...(colSchema.categories ?? []),
...(col?.summarize?.().categories ?? [])
])
...(col?.summarize?.().categories ?? []),
]),
];
if (writable && categories.indexOf(unassignedCategoryLabel) === -1) {
categories = categories.concat(unassignedCategoryLabel);
@@ -165,7 +165,7 @@ function normalizeSchemaCategory(colSchema, col = undefined) {
function normalizeEntireSchema(schema) {
// currently only needed for obsAnnotations
schema.annotations.obs.columns.forEach(colSchema =>
schema.annotations.obs.columns.forEach((colSchema) =>
normalizeSchemaCategory(colSchema)
);
}
@@ -178,9 +178,9 @@ export function addObsAnnotations(universe, df) {
// for all of the new data, reconcile with schema and sort categories.
const dfs = Array.isArray(df) ? df : [df];
const keys = dfs.map(d => d.colIndex.keys()).flat();
const keys = dfs.map((d) => d.colIndex.keys()).flat();
const { schema } = universe;
keys.forEach(k => {
keys.forEach((k) => {
const colSchema = schema.annotations.obsByName[k];
const col = obsAnnotations.col(k);
normalizeSchemaCategory(colSchema, col);
+5 -5
View File
@@ -69,8 +69,8 @@ function templateWorld() {
/* unclipped dataframes - subset, but not value clipped */
unclipped: {
obsAnnotations,
varData
}
varData,
},
};
}
@@ -134,7 +134,7 @@ export function createWorldFromEntireUniverse(universe) {
/* save unclipped copies of potentially clipped dataframes */
world.unclipped = {
obsAnnotations: world.obsAnnotations.clone(),
varData: world.varData.clone()
varData: world.varData.clone(),
};
return world;
@@ -219,7 +219,7 @@ export function createWorldWithNewClip(
newWorld.obsLayout = world.obsLayout.clone();
newWorld.unclipped = {
obsAnnotations: world.unclipped.obsAnnotations.clone(),
varData: world.unclipped.varData.clone()
varData: world.unclipped.varData.clone(),
};
/* and now clip */
@@ -295,7 +295,7 @@ export function createObsDimensions(crossfilter, world, XYdimNames) {
const { schema, obsLayout } = world;
const indexName = schema.annotations.obs.index;
const annoList = schema.annotations.obs.columns.filter(
anno => anno.name !== indexName
(anno) => anno.name !== indexName
);
crossfilter = annoList.reduce((xfltr, anno) => {
return addObsDimension(xfltr, world, anno);
+1 -1
View File
@@ -57,7 +57,7 @@ export default class StateMachine {
);
// all transition names (aka events)
this.events = new Set(transitions.map(tsn => tsn.event));
this.events = new Set(transitions.map((tsn) => tsn.event));
// the transition graph.
// graph[event][from] -> transition
+11 -11
View File
@@ -6,24 +6,24 @@ Various type and schema related helper functions.
Utility function to test for a typed array
*/
export function isTypedArray(x) {
return (
ArrayBuffer.isView(x) &&
Object.prototype.toString.call(x) !== "[object DataView]"
);
return (
ArrayBuffer.isView(x) &&
Object.prototype.toString.call(x) !== "[object DataView]"
);
}
/*
Test for float typed array, ie, Float32TypedArray or Float64TypedArray
*/
export function isFpTypedArray(x) {
let constructor;
const isFloatArray =
x &&
({ constructor } = x) &&
(constructor === Float32Array || constructor === Float64Array);
return isFloatArray;
let constructor;
const isFloatArray =
x &&
({ constructor } = x) &&
(constructor === Float32Array || constructor === Float64Array);
return isFloatArray;
}
export function isArrayOrTypedArray(x) {
return Array.isArray(x) || isTypedArray(x);
return Array.isArray(x) || isTypedArray(x);
}