-
Notifications
You must be signed in to change notification settings - Fork 75
Plotly Visualizer Widget For DeepForge. Fixes #1308, #1290 #1329
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
3c22464
WIP-#1290: Update pipeline.webgmex to incorporate color of line2d(patch)
umesh-timalsina f6ef511
WIP- #1290: Update the library seed to incorporate subgraphs, add nod…
umesh-timalsina 1fee673
#1290- Modify exisiting widget to support updated metamodel (Should c…
umesh-timalsina fca7d57
WIP #1308, #1290: Create a new Branch For plotly.js visualizer, plotl…
umesh-timalsina 74c6931
WIP- #1308, #1290: Add single plot support via plotly visualizer(Upda…
umesh-timalsina 21133b7
WIP- #1290, #1308: Add Plotly JSON Helper with changeset to the widget
umesh-timalsina 60c0771
WIP- #1308: Complete ExecutionIndex Graph Creation Logic
umesh-timalsina edd98cb
WIP- #1308: Add Multiple Execution visualization support to subplots …
umesh-timalsina f975e4e
WIP: #1308: Remove changeset, matplotlib maps from requirements, chan…
umesh-timalsina 066830e
#1308: Checkout LineGraph visualizer from master
umesh-timalsina aeac790
#1308:- Refactor ExecutionIndexWidget to consolidate multiple graphs …
umesh-timalsina 50807be
#1308: Fix graph display issue for running executions
umesh-timalsina 9a3705f
Remove invalid codeclimate config
umesh-timalsina 5478bd3
#1308- Codeclimate fix
umesh-timalsina 44f0d98
Merge branch 'master' into 1308-plotly-viz
umesh-timalsina 5fa7cfb
1. Use Map insted of ForEach in PlotlyDescExtractor.js
umesh-timalsina a654551
Remove unused id from plotlyGraphWidget.removeNode
umesh-timalsina 1ac67e7
Refactor setDisplayedExecutions to take after clicked states only, ch…
umesh-timalsina 3a3aa1a
Modify subgraph title display, refactor ExecuteJob.Metadata.js to rem…
umesh-timalsina 1ae02fc
WIP Fixed indentation issues (eslint)
brollb b87c04b
WIP Add plotly.min.js to ignore codeclimate files
brollb 106b5c3
Merge branch 'master' into 1308-plotly-viz
brollb 08be7de
WIP minor style fixes
brollb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,246 @@ | ||
| /*globals define*/ | ||
| define([], function () { | ||
| const PlotlyDescExtractor = function (client) { | ||
| this._client = client; | ||
| }; | ||
|
|
||
| PlotlyDescExtractor.prototype.constructor = PlotlyDescExtractor; | ||
|
|
||
| PlotlyDescExtractor.prototype.getGraphDesc = function (node) { | ||
| const id = node.getId(), | ||
| jobId = node.getParentId(), | ||
| execId = this._client.getNode(jobId).getParentId(); | ||
| let desc = { | ||
| id: id, | ||
| execId: execId, | ||
| type: 'graph', | ||
| name: node.getAttribute('name'), | ||
| graphId: node.getAttribute('id'), | ||
| title: node.getAttribute('title'), | ||
| }; | ||
| let subGraphNodeIds = node.getChildrenIds(); | ||
| desc.subGraphs = subGraphNodeIds.map((subGraphNodeId) => { | ||
| let subGraphNode = this._client.getNode(subGraphNodeId); | ||
| return this.getSubGraphDesc(subGraphNode); | ||
| }); | ||
| desc.subGraphs.sort(this.compareSubgraphIDs); | ||
| return desc; | ||
| }; | ||
|
|
||
| PlotlyDescExtractor.prototype.getSubGraphDesc = function (node) { | ||
| let id = node.getId(), | ||
| graphId = node.getParentId(), | ||
| jobId = this._client.getNode(graphId).getParentId(), | ||
| execId = this._client.getNode(jobId).getParentId(), | ||
| desc; | ||
|
|
||
| desc = { | ||
| id: id, | ||
| execId: execId, | ||
| type: 'subgraph', | ||
| graphId: this._client.getNode(graphId).getAttribute('id'), | ||
| subgraphId: node.getAttribute('id'), | ||
| subgraphName: node.getAttribute('name'), | ||
| title: node.getAttribute('title'), | ||
| xlim: node.getAttribute('xlim'), | ||
| ylim: node.getAttribute('ylim'), | ||
| xlabel: node.getAttribute('xlabel'), | ||
| ylabel: node.getAttribute('ylabel'), | ||
| }; | ||
|
|
||
| const lineIds = node.getChildrenIds(); | ||
| desc.lines = lineIds.map((lineId) => { | ||
| let lineNode = this._client.getNode(lineId); | ||
| return this.getLineDesc(lineNode); | ||
| }); | ||
brollb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return desc; | ||
| }; | ||
|
|
||
| PlotlyDescExtractor.prototype.getLineDesc = function (node) { | ||
| let id = node.getId(), | ||
| subGraphId = node.getParentId(), | ||
| graphId = this._client.getNode(subGraphId).getParentId(), | ||
| jobId = this._client.getNode(graphId).getParentId(), | ||
| execId = this._client.getNode(jobId).getParentId(), | ||
| points, | ||
| desc; | ||
|
|
||
| points = node.getAttribute('points').split(';') | ||
| .filter(data => !!data) // remove any '' | ||
| .map(pair => { | ||
| const [x, y] = pair.split(',').map(num => parseFloat(num)); | ||
| return {x, y}; | ||
| }); | ||
| desc = { | ||
| id: id, | ||
| execId: execId, | ||
| subgraphId: this._client.getNode(node.getParentId()).getAttribute('id'), | ||
| lineName: node.getAttribute('name'), | ||
| label: node.getAttribute('label'), | ||
| name: node.getAttribute('name'), | ||
| type: 'line', | ||
| points: points, | ||
| color: node.getAttribute('color') | ||
| }; | ||
|
|
||
| return desc; | ||
| }; | ||
|
|
||
|
|
||
| PlotlyDescExtractor.prototype.compareSubgraphIDs = function (desc1, desc2) { | ||
| if (desc1.subgraphId >= desc2.subgraphId) return 1; | ||
| else return -1; | ||
| }; | ||
|
|
||
| PlotlyDescExtractor.prototype.descToPlotlyJSON = function (desc) { | ||
| let plotlyJSON = {}; | ||
| if (desc) { | ||
| plotlyJSON.layout = createLayout(desc); | ||
| let dataArr = desc.subGraphs.map((subGraph, index) => { | ||
| return createScatterTraces(subGraph, index); | ||
| }); | ||
| plotlyJSON.data = flatten(dataArr); | ||
| const axesData = addAxesLabels(desc.subGraphs); | ||
| Object.keys(axesData).forEach((axis) => { | ||
| plotlyJSON.layout[axis] = axesData[axis]; | ||
| }); | ||
| plotlyJSON.id = desc.id; | ||
| } | ||
| return plotlyJSON; | ||
| }; | ||
|
|
||
| /*** Helper Methods For Creating The plotly JSON Reference ***/ | ||
| const TraceTypes = { | ||
| SCATTER: 'scatter', | ||
| IMAGE: 'image' | ||
| }; | ||
|
|
||
| const descHasMultipleSubPlots = function (desc) { | ||
| return desc.subGraphs.length > 1; | ||
| }; | ||
|
|
||
| const createLayout = function (desc) { | ||
| let layout = { | ||
| title: desc.title, | ||
| height: 500 | ||
| }; | ||
| // Every plot should be drawn as n * 2 Grid?? | ||
| if (descHasMultipleSubPlots(desc)) { | ||
| const numRows = Math.ceil(desc.subGraphs.length / 2); | ||
| layout.height = 250 * numRows; | ||
| let subPlots = []; | ||
| let currentSubplotAxes; | ||
| for (let i = 0; i < numRows * 2; i += 2) { | ||
| if (i === 0) | ||
| currentSubplotAxes = ['xy', 'x2y2']; | ||
| else | ||
| currentSubplotAxes = [`x${i + 1}y${i + 1}`, `x${i + 2}y${i + 2}`]; | ||
| subPlots.push(currentSubplotAxes); | ||
| } | ||
| layout.grid = { | ||
| subplots: subPlots | ||
| }; | ||
| layout.annotations = addAnnotations(desc.subGraphs); | ||
| } else { | ||
| if (!layout.title) | ||
| layout.title = desc.subGraphs[0].title; | ||
| else | ||
| layout.title = { | ||
| text: `${layout.title}<br>${desc.subGraphs[0].title}` | ||
| }; | ||
| } | ||
| return layout; | ||
| }; | ||
|
|
||
| // https://github.com/plotly/plotly.js/issues/2746#issuecomment-528342877 | ||
umesh-timalsina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // At present the only hacky way to add subplots title | ||
| const addAnnotations = function (subGraphs) { | ||
| const evenLength = subGraphs.length % 2 === 0 ? subGraphs.length : subGraphs.length + 1; | ||
| return subGraphs.map((subGraph, index) => { | ||
| const yPosMarker = (index % 2 === 0) ? index : index - 1; | ||
| return { | ||
| text: `<b>${subGraph.title}</b>`, | ||
| font: { | ||
| family: 'Arial', | ||
| color: 'black', | ||
| size: 14 | ||
| }, | ||
| showarrow: false, | ||
| xref: 'paper', | ||
| yref: 'paper', | ||
| align: 'center', | ||
| x: (index % 2 === 0) ? 0.15 : 0.85, | ||
| y: (1 - yPosMarker / evenLength) * 1.1 - 0.06 | ||
| }; | ||
| }); | ||
| }; | ||
|
|
||
| const createScatterTraces = function (subGraph, index) { | ||
| let traceArr = subGraph.lines.map(line => { | ||
| let points = pointsToCartesianArray(line.points); | ||
| let traceData = { | ||
| x: points[0], | ||
| y: points[1], | ||
| name: line.label, | ||
| type: TraceTypes.SCATTER, | ||
| mode: line.marker ? 'line+marker' : 'line', | ||
| line: { | ||
| width: line.lineWidth ? line.lineWidth : 3, | ||
| color: line.color | ||
| }, | ||
| }; | ||
| if (index !== 0) { | ||
| traceData.xaxis = `x${index + 1}`; | ||
| traceData.yaxis = `y${index + 1}`; | ||
| } | ||
| return traceData; | ||
| }); | ||
| return traceArr; | ||
| }; | ||
|
|
||
| const addAxesLabels = function (subGraphs) { | ||
| let axesData = {}; | ||
| subGraphs.forEach((subGraph, index) => { | ||
| let xAxisName = `xaxis${index + 1}`; | ||
| let yAxisName = `yaxis${index + 1}`; | ||
| if (index === 0) { | ||
| xAxisName = 'xaxis'; | ||
| yAxisName = 'yaxis'; | ||
| } | ||
| axesData[xAxisName] = { | ||
| title: { | ||
| text: subGraph.xlabel, | ||
| color: '#7f7f7f', | ||
| standoff: 0 | ||
| } | ||
| }; | ||
| axesData[yAxisName] = { | ||
| title: { | ||
| text: subGraph.ylabel, | ||
| color: '#7f7f7f', | ||
| standoff: 0 | ||
| } | ||
| }; | ||
| }); | ||
| return axesData; | ||
| }; | ||
|
|
||
| const pointsToCartesianArray = function (points) { | ||
| let x = [], | ||
| y = []; | ||
| points.forEach((point) => { | ||
| x.push(point.x); | ||
| y.push(point.y); | ||
| }); | ||
| return [x, y]; | ||
| }; | ||
|
|
||
| const flatten = function (arr) { | ||
| return arr.reduce(function (flat, toFlatten) { | ||
| return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten); | ||
| }, []); | ||
| }; | ||
|
|
||
|
|
||
| return PlotlyDescExtractor; | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.