Skip to content

Commit

Permalink
broken
Browse files Browse the repository at this point in the history
  • Loading branch information
tuner committed Dec 7, 2020
1 parent 8d15399 commit bd0b880
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/genome-spy/src/data/flowTransforms/regexFold.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class RegexFoldTransform extends FlowNode {
* @param {any} datum
*/
this.handle = datum => {
// Conserve memory by skipping the columns being gathered
// Save memory by skipping the columns being gathered
/** @type {Record<string, any>} */
const strippedRow = {};
for (const prop in datum) {
Expand Down
25 changes: 25 additions & 0 deletions packages/genome-spy/src/data/flowTransforms/transformFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import FilterTransform from "./filter";
import FlattenCompressedExonsTransform from "./flattenCompressedExons";
import FormulaTransform from "./formula";
import RegexFoldTransform from "./regexFold";

/**
* TODO: Typecasting
* @type {Record<string, function(object):import("../flowNode").default>}
*/
const transforms = {
filter: p => new FilterTransform(p),
flattenCompressedExons: p => new FlattenCompressedExonsTransform(p),
formula: p => new FormulaTransform(p),
regexFold: p => new RegexFoldTransform(p)
};

/** @param {import("../../spec/transform").TransformConfigBase} params */
export default function createTransform(params) {
const f = transforms[params.type];
if (f) {
return f(params);
} else {
throw new Error("Unknown transform: " + params.type);
}
}
21 changes: 21 additions & 0 deletions packages/genome-spy/src/data/sources/dataSourceFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import InlineSource, { isInlineData } from "./inlineSource";
import UrlSource, { isUrlData } from "./urlSource";
import SequenceSource, { isSequenceGenerator } from "./sequenceSource";

/**
* @param {Partial<import("../../spec/data").Data>} params
* @param {string} [baseUrl]
*/
export default function createDataSource(params, baseUrl) {
if (isInlineData(params)) {
return new InlineSource(params);
} else if (isUrlData(params)) {
return new UrlSource(params, baseUrl);
} else if (isSequenceGenerator(params)) {
return new SequenceSource(params);
}

throw new Error(
"Cannot figure out the data source type: " + JSON.stringify(params)
);
}
3 changes: 0 additions & 3 deletions packages/genome-spy/src/data/transforms/transforms.js

This file was deleted.

11 changes: 3 additions & 8 deletions packages/genome-spy/src/spec/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,25 +224,20 @@ export interface CoverageConfig extends TransformConfigBase {
asEnd?: string;
}

export interface SortConfig extends TransformConfigBase {
type: "sort";
export interface CollectConfig extends TransformConfigBase {
type: "collect";

/**
* The sort order.
*/
sort: CompareConfig;
}

export interface UngroupConfig extends TransformConfigBase {
type: "ungroup";
}

export type TransformConfig =
| UngroupConfig
| FlattenDelimitedConfig
| FormulaConfig
| FilterConfig
| GatherConfig
| RegexExtractConfig
| SimpleFilterConfig
| StackConfig
| PileupConfig;
7 changes: 4 additions & 3 deletions packages/genome-spy/src/view/containerView.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ export default class ContainerView extends View {
}

/**
* Visits child views in depth-first order. Terminates the search and returns
* the value if the visitor returns a defined value.
* Visits child views in depth-first pre-order. Terminates the search and returns
* the value if the visitor returns a defined value. The `afterChildren` callback
* allows for post-order traversal
*
* @param {(function(View):("VISIT_SKIP"|"VISIT_STOP"|void)) & { afterChildren?: function}} visitor
* @param {(function(View):("VISIT_SKIP"|"VISIT_STOP"|void)) & { afterChildren?: function(View):void}} visitor
* @returns {any}
*/
visit(visitor) {
Expand Down
69 changes: 69 additions & 0 deletions packages/genome-spy/src/view/flowBuilder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import Collector from "../data/collector";
import createTransform from "../data/flowTransforms/transformFactory";
import createDataSource from "../data/sources/dataSourceFactory";
import { peek } from "../utils/arrayUtils";
import UnitView from "./unitView";

/**
* @typedef {import("../data/flowNode").default} FlowNode
* @typedef {import("./view").default} View
* @param {View} root
*/
export function buildDataFlow(root) {
/** @type {View[]} */
const viewStack = [];

/** @type {FlowNode[]} */
const nodeStack = [];

/** @type {FlowNode[]} */
const dataSources = [];

// TODO: FlowStack

/** @param {View} view */
const processView = view => {
viewStack.push(view);

if (view.spec.data) {
const dataSource = createDataSource(view.spec.data);
nodeStack.push(dataSource);
dataSources.push(dataSource);
}

if (view.spec.transform) {
for (const params of view.spec.transform) {
const transform = createTransform(params);
const previousNode = peek(nodeStack);
if (!previousNode) {
throw new Error(
"Cannot create a transform because no inherited data are available: " +
JSON.stringify(params)
);
}
previousNode.addChild(transform);
}
}

if (view instanceof UnitView) {
const collector = new Collector();
const previousNode = peek(nodeStack);
if (!previousNode) {
throw new Error(
"A unit view has no (inherited) data source: " +
view.getPathString()
);
}
previousNode.addChild(collector);
}
};

/** @param {View} view */
processView.afterChildren = view => {
viewStack.pop();
};

root.visit(processView);

return dataSources;
}
37 changes: 37 additions & 0 deletions packages/genome-spy/src/view/flowBuilder.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Collector from "../data/collector";
import FlowNode from "../data/flowNode";
import InlineSource from "../data/sources/inlineSource";
import { buildDataFlow } from "./flowBuilder";
import { create } from "./testUtils";

/**
*
* @param {FlowNode} node
* @param {number[]} path
*/
function getNodeByPath(node, path) {
for (const elem of path) {
node = node.children[elem];
}
return node;
}

test("Trivial flow", () => {
const root = create({
data: { values: [3.141] },
transform: [
{
type: "formula",
expr: "datum.data * 2",
as: "x"
}
],
mark: "rect"
});

const dataSource = buildDataFlow(root)[0];

expect(dataSource).toBeInstanceOf(InlineSource);
expect(dataSource.children[0]).toBeInstanceOf(InlineSource);
expect(dataSource.children[0].children[0]).toBeInstanceOf(Collector);
});
3 changes: 0 additions & 3 deletions packages/genome-spy/src/view/testUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

import { createView, resolveScalesAndAxes, initializeData } from "./viewUtils";
import DataSource from "../data/dataSource";
import AccessorFactory from "../encoder/accessor";

/**
Expand All @@ -15,8 +14,6 @@ import AccessorFactory from "../encoder/accessor";
export function create(spec, context) {
const c = {
...(context || {}),
/** @param {object} config */
getDataSource: config => new DataSource(config, "."),
accessorFactory: new AccessorFactory()
};

Expand Down
2 changes: 1 addition & 1 deletion packages/genome-spy/src/view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export default class View {
* Visits child views in depth-first order. Visitor's return value
* controls the traversal.
*
* @param {(function(View):(VISIT_SKIP|VISIT_STOP|void)) & { afterChildren?: function}} visitor
* @param {(function(View):(VISIT_SKIP|VISIT_STOP|void)) & { afterChildren?: function(View):void}} visitor
* @returns {any}
*
* @typedef {"VISIT_SKIP"} VISIT_SKIP Don't visit children of the current node
Expand Down
6 changes: 5 additions & 1 deletion packages/genome-spy/src/view/viewUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { VISIT_SKIP } from "./view";
/**
* @typedef {Object} ViewContext
* @prop {import("../genomeSpy").default} genomeSpy TODO: Break genomeSpy dependency
* @prop {function(import("../spec/data").Data, string):import("../data/dataSource").default} getDataSource
* @prop {import("../encoder/accessor").default} accessorFactory
* @prop {import("../coordinateSystem").default} coordinateSystem
* @prop {import("../gl/webGLHelper").default} glHelper
Expand Down Expand Up @@ -127,6 +126,8 @@ export function isFacetMapping(spec) {
* @returns {spec is ViewSpec}
*/
export function isViewSpec(spec) {
return true;
/*
const matches = viewTypes
.map(v => (v.guard(spec) ? v.prop : undefined))
.filter(prop => isString(prop));
Expand All @@ -139,6 +140,7 @@ export function isViewSpec(spec) {
}
return matches.length == 1;
*/
}

/**
Expand Down Expand Up @@ -192,6 +194,7 @@ export function isImportSpec(spec) {
* @returns {typeof View}
*/
export function getViewClass(spec) {
console.log(viewTypes);
for (const viewType of viewTypes) {
if (viewType.guard(spec)) {
return viewType.viewClass;
Expand All @@ -209,6 +212,7 @@ export function getViewClass(spec) {
*/
export function createView(spec, context) {
const ViewClass = getViewClass(spec);
console.log(ViewClass);
return /** @type {View} */ (new ViewClass(
spec,
context,
Expand Down

0 comments on commit bd0b880

Please sign in to comment.