Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix metadata parsing in FigureExtractor. Closes #1764. #1765

Merged
merged 5 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 33 additions & 20 deletions src/common/viz/FigureExtractor.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/*globals define, _*/
/* globals define */
define(['./Utils'], function (Utils) {
const FigureExtractor = function (client) {
this._client = client;
this._metaNodesMap = this._initializeMetaNodesMap();
};
const BASE_METADATA_TYPE = 'Metadata';
const EXTRACTORS = {
GRAPH: 'Graph',
SUBGRAPH: 'SubGraph',
Expand All @@ -14,29 +11,30 @@ define(['./Utils'], function (Utils) {
SCATTER_POINTS: 'ScatterPoints'
};

FigureExtractor.prototype._initializeMetaNodesMap = function () {
const metaNodes = this._client.getAllMetaNodes();
const idsAndTypes = metaNodes.map(node => [node.getId(), node.getAttribute('name')]);
return _.object(idsAndTypes);
const ensureCanExtract = function(metaType) {
if(!Object.values(EXTRACTORS).includes(metaType)) {
throw new Error(`Node of type ${metaType} is not supported yet.`);
}
};

const FigureExtractor = function (client) {
this._client = client;
};

FigureExtractor.prototype.constructor = FigureExtractor;

FigureExtractor.prototype.extract = function(node) {
const extractorFn = this.getMetaType(node);
if (!Object.values(EXTRACTORS).includes(extractorFn)){
throw new Error(`Node of type ${extractorFn} is not supported yet.`);
} else {
return this[extractorFn](node);
}
ensureCanExtract(extractorFn);
return this[extractorFn](node);
};

FigureExtractor.prototype.extractChildrenOfType = function(node, metaType) {
const children = node.getChildrenIds().map(id => this._client.getNode(id));
const children = this.getMetadataChildrenIds(node).map(id => this._client.getNode(id));
return children.filter(node => this.getMetaType(node) === metaType)
.map(child => this.extract(child));
};

FigureExtractor.prototype.constructor = FigureExtractor;

FigureExtractor.prototype[EXTRACTORS.GRAPH] = function(node) {
const id = node.getId(),
execId = this.getExecutionId(node);
Expand All @@ -50,18 +48,19 @@ define(['./Utils'], function (Utils) {
title: node.getAttribute('title'),
};

let childrenIds = node.getChildrenIds();
let childrenIds = this.getMetadataChildrenIds(node);

let childNode, childNodeFn;
desc.subGraphs = childrenIds.map((childId) => {
childNode = this._client.getNode(childId);
childNodeFn = this.getMetaType(childNode);
ensureCanExtract(childNodeFn);
return this[childNodeFn](childNode);
});
desc.subGraphs.sort(this.compareSubgraphIDs);
return desc;
};


FigureExtractor.prototype[EXTRACTORS.SUBGRAPH] = function(node){
const id = node.getId(),
graphId = node.getParentId(),
Expand Down Expand Up @@ -180,6 +179,20 @@ define(['./Utils'], function (Utils) {
}
};

FigureExtractor.prototype.getMetadataChildrenIds = function (node) {
const allMetaNodes = this._client.getAllMetaNodes();
const metadataBaseNode = allMetaNodes
.find(node => node.getAttribute('name') === BASE_METADATA_TYPE);

if(metadataBaseNode) {
return node.getChildrenIds().filter(id => {
return this._client.isTypeOf(id, metadataBaseNode.getId());
});
} else {
return [];
}
};

FigureExtractor.prototype.getGraphNode = function(node) {
return this._getContainmentParentNodeAt(node, 'Graph');
};
Expand All @@ -197,7 +210,7 @@ define(['./Utils'], function (Utils) {

FigureExtractor.prototype.getMetaType = function (node) {
const metaTypeId = node.getMetaTypeId();
return this._metaNodesMap[metaTypeId];
return this._client.getNode(metaTypeId).getAttribute('name');
};

const extractPointsArray = function (pair) {
Expand Down
Binary file modified src/seeds/devProject/devProject.webgmex
Binary file not shown.
Binary file modified src/seeds/pipeline/pipeline.webgmex
Binary file not shown.
2 changes: 2 additions & 0 deletions src/seeds/pipeline/releases.jsonl
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
{"version":"0.20.0","changelog":"Add provenance info to Data nodes"}
{"version":"0.21.0","changelog":"Add provenance to metadata (via WithProvenance mixin)"}
{"version":"0.21.1","changelog":"Update Inheritance of Subgraph, Line, Images, ScatterPoints etc.. nodes"}