-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
166 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/genome-spy/src/data/flowTransforms/transformFactory.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters