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

new demo site with integrated capture and graph/download, plus Cypress tests #175

Merged
merged 37 commits into from
Nov 15, 2020

Conversation

TonyIversonLin
Copy link
Contributor

Make sure these boxes are checked before your pull request is ready to be reviewed and merged. Thanks!

  • tests pass -- see README.md for how to run them
  • code is in uniquely-named feature branch, and has been rebased on top of latest master (especially if you've been asked to make additional changes)
  • pull request are descriptively named
  • if possible, multiple commits squashed if they're smaller changes
  • reviewed/confirmed/tested by another contributor or maintainer

Please be sure you've reviewed our contribution guidelines at https://publiclab.org/wiki/contributing-to-public-lab-software

Please alert developers on plots-dev@googlegroups.com when your request is ready or if you need assistance.

Thanks!

@welcome
Copy link

welcome bot commented Sep 5, 2020

Thanks for opening this pull request! Dangerbot will test out your code and reply in a bit with some pointers and requests.
There may be some errors, but don't worry! We're here to help! 👍🎉😄

@gitpod-io
Copy link

gitpod-io bot commented Sep 5, 2020

@@ -0,0 +1,363 @@
<!DOCTYPE html>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering how this is distinct from index.html? Thank you!

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fantastic! A couple small notes and requests:

  1. I noticed a .DS_Store file was added, probably inadvertently - can you just remove that? Thanks!
  2. The copy of the new-capture JS files seems like it could diverge development of those files, which may be changing quickly. Was it intentional to make 2 copies of each, and are they exact copies?
  3. The new-capture index.html is still pointed at dist/capture.dist.js, and that file is compiled from the examples/capture/*.js files, not the new new-capture copies, so i believe the new copies are not being used in this demo, is that correct? Below is the Gruntfile code which compiles the files:

capture: {
src: [
'examples/capture/detect_sample_row.js',
'examples/capture/toggleRotation.js',
'examples/capture/getRow.js',
'examples/capture/getUserMedia.js'
],
dest: 'dist/capture.dist.js'
}

Thanks, just need a little clarity on these but overall this is looking really fantastic. I love your final report as well, would you be able to share that in this PR somehow for other contributors to read?

Great work, we're almost there!! Many thanks!



<script src="capture.js" type="text/javascript"></script>
<script src="../../dist/capture.dist.js" type="text/javascript"></script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pointed at the compiled file, see review note about Grunt compilation! Thanks!

@jywarren
Copy link
Member

I'm also seeing an odd error in our Travis build:

27.02s$ npm ci 
> cypress@5.1.0 postinstall /home/travis/build/publiclab/spectral-workbench.js/node_modules/cypress
> node index.js --exec install
> cypress@5.1.0 postinstall /home/travis/build/publiclab/spectral-workbench.js/node_modules/cypress
> node index.js --exec install
/home/travis/build/publiclab/spectral-workbench.js/node_modules/cypress/node_modules/fs-extra/lib/mkdirs/make-dir.js:85
      } catch {
              ^
SyntaxError: Unexpected token {
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:617:28)
    at Object.Module._extensions..js (module.js:664:10)

https://travis-ci.com/github/publiclab/spectral-workbench.js/builds/182860297#L399-L407

This seems related to the npm ci command and/or the postinstall stage of cypress. Does this happen to you on local?

@jywarren
Copy link
Member

And, just confirming that the new capture demo works! Presumably using the compiled (and previous) capture code:

Screen Shot 2020-09-17 at 12 49 06 PM
Screen Shot 2020-09-17 at 12 49 14 PM

A couple icons aren't showing, but it's a minor issue!

@jywarren
Copy link
Member

Ah, i am getting an error and no graph on the final "save graph" step:

Screen Shot 2020-09-17 at 12 51 13 PM

It looks like d3 is not getting loaded?

Uncaught ReferenceError: d3 is not defined
    at Class.init (spectral-workbench.js:5178)
    at new Class (spectral-workbench.js:62)

[2020-09-17T16:48:25.081Z] "GET /bower_components/d3/d3.js" Error (404): "Not found"

Perhaps it has to be included via NPM instead of bower -- the correct route should be /node_modules/d3/d3.js, no?

bower.json Outdated
"moment": "~2.10.6",
"nvd3": "~1.7.1",
"d3": "~3.3.13",
"jquery.steps": "^1.1.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I think we should move this to the package.json file, as we are trying to stop using Bower. I believe all existing dependencies have already been moved, too!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"d3": "~3.5.17",

<script src="../../node_modules/flot/jquery.flot.crosshair.js"></script>
<script src="../../node_modules/flot/jquery.flot.threshold.js"></script>
<script src="../../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="../../bower_components/jquery.steps/build/jquery.steps.min.js"></script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - here, and below, all instances of bower_components should be changed to node_modules and all dependencies but jquery.steps have been transferred there already. That should resolve the last error on the final "plotting" page of the new demo!

@jywarren jywarren changed the title Demo site new demo site with integrated capture and graph/download Sep 17, 2020
@jywarren jywarren changed the title new demo site with integrated capture and graph/download new demo site with integrated capture and graph/download, plus Cypress tests Sep 17, 2020
@TonyIversonLin
Copy link
Contributor Author

TonyIversonLin commented Sep 17, 2020 via email

@jywarren
Copy link
Member

jywarren commented Sep 24, 2020

Something's wrong with d3... but in jasmine!

   - can export SVG...X can export SVG
     TypeError: undefined is not an object (evaluating 'd3.select('svg').data()[0][index].id') in file:///home/travis/build/publiclab/spectral-workbench.js/dist/spectral-workbench.js (line 5374) (1)

'bower_components/nvd3/build/nv.d3.js',
'bower_components/bootstrap-css/js/bootstrap.min.js',
'bower_components/moment/moment.js',
'node_modules/d3/d3.js',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could something be wrong with this line, for jasmine?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes! I think d3 would be in a dist folder... checking...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. <script src="../../node_modules/d3/d3.js" type="text/javascript"></script> indicates not...

@jywarren
Copy link
Member

Oh hmm, a bunch of Jasmine is broken:


     TypeError: undefined is not an object (evaluating 'd3.select('svg').data()[0][index].id') in file:///home/travis/build/publiclab/spectral-workbench.js/dist/spectral-workbench.js (line 5374) (1)
   - can copy calibrations with copyCalibration()...X can copy calibrations with copyCalibration()
     TypeError: undefined is not an object (evaluating 'graph.datum') in file:///home/travis/build/publiclab/spectral-workbench.js/spec/javascripts/api_spec.js (line 128) (1)
   - generates copyCalibration callback...X generates copyCalibration callback
     Expected spy success to have been called. (1)
   - can transform graph data...X can transform graph data
     TypeError: undefined is not an object (evaluating 'graph.datum') in file:///home/travis/build/publiclab/spectral-workbench.js/spec/javascripts/api_spec.js (line 156) (1)
   - can limit graphed data to wavelength range...X can limit graphed data to wavelength range
     TypeError: undefined is not an object (evaluating 'graph.datum') in file:///home/travis/build/publiclab/spectral-workbench.js/spec/javascripts/api_spec.js (line 168) (1)
   - can blend graphed spectrum data with that of another spectrum...X can blend graphed spectrum data with that of another spectrum

@jywarren
Copy link
Member

OK, this is odd. But regarding:

 TypeError: undefined is not an object (evaluating 'graph.datum') in file:///home/travis/build/publiclab/spectral-workbench.js/spec/javascripts/api_spec.js (line 128) (1)

That graph object is defined in the previous test:

graph = new SpectralWorkbench.Graph({

Is there an order of execution issue happening? No, i think perhaps the SVG test failure is causing the graph object not to be initialized. Let's focus on the SVG test.

@jywarren
Copy link
Member

OK, reproduced it by going to the graph example at /examples/index.html, copying /spec/javascript/fixtures/spectrum-9.json to /spectrums/9.json (so the aync fetch of the data works), then running:

graph2 = new SpectralWorkbench.Graph({
      spectrum_id: 9,
      calibrated: true,
      onImageComplete: function() { done(); }
    });

Here's the full trace:

Uncaught TypeError: Cannot read property 'id' of undefined
    at SVGGElement.<anonymous> (spectral-workbench.js:5374)
    at SVGGElement.o (d3.min.js:1)
    at d3.min.js:3
    at Y (d3.min.js:1)
    at Array.Co.each (d3.min.js:3)
    at Array.Co.attr (d3.min.js:3)
    at _graph.load (spectral-workbench.js:5373)
    at Object.success (spectral-workbench.js:127)
    at c (jquery.min.js:2)
    at Object.fireWith [as resolveWith] (jquery.min.js:2)

@jywarren
Copy link
Member

jywarren commented Sep 29, 2020

OK - this is a known error: #165 re: d3 v3.5 vs. 3.4.

Don't know why it's just suddenly showing up on Travis. Let's downgrade again and see.

@jywarren
Copy link
Member

Trying to bump d3 to v3.5.4 because of #180 (comment)

graph demo works:

image

new capture demo works:

image

I think we could do this... but will nvd3 work?

@jywarren
Copy link
Member

Aha ok, so: noting "GET /node_modules/jquery.steps/build/jquery.steps.min.js" Error (404): "Not found"

and, back to the original error:


     TypeError: undefined is not an object (evaluating 'd3.select('svg').data()[0][index].id') in file:///home/travis/build/publiclab/spectral-workbench.js/dist/spectral-workbench.js (line 5374) (1)
   - can copy calibrations with copyCalibration()...X can copy calibrations with copyCalibration()
     TypeError: undefined is not an object (evaluating 'graph.datum') in file:///home/travis/build/publiclab/spectral-workbench.js/spec/javascripts/api_spec.js (line 128) (1)

@jywarren
Copy link
Member

jywarren commented Oct 6, 2020

OK so we have trouble with d3 v3.5 - the known error in our codebase: #165

But v3.4 had caused us trouble with contextify -- specifically we bumped to v3.5.4 to resolve contextify issues in
02c1adc

So we are left with:

  1. solve the known error with TypeError: undefined is not an object (evaluating 'd3.select('svg').data()[0][index].id') in file:///home/travis/build/publiclab/spectral-workbench.js/dist/spectral-workbench.js (line 5374) (1)
  2. find a post-v3.5.4 version that does not have that error - that uses the correct contextify ...?

@jywarren
Copy link
Member

jywarren commented Nov 14, 2020

So, noting that this error would occur a LOT in this file:

var id = d3.select('svg').data()[0][index].id; // this is the real d3 DOM-stored data

because this segment causing it is repeatedly called in that file:

var id = d3.select('svg').data()[0][index].id; // this is the real d3 DOM-stored data

The error cited above was for the first instance. So, we can dig into exactly what is not an object but probably there's something wrong with either the DOM or how we're accessing it.

Actually given Cannot read property 'id' of undefined i guess it's d3.select('svg').data()[0][index] that is not an object. Let's see what it is or if the returned format has changed?

@jywarren
Copy link
Member

jywarren commented Nov 14, 2020

Noting the error occurs in client side of the graph demo!

image

whoa! OK, here are the values:

d3.select('svg').data()[0]
> (4) [{}, {}, {}, {}]
0: {values: Array(21), key: "undefined (average)", color: "#444", id: undefined}
1: {values: Array(21), key: "undefined (R)", color: "rgba(255,0,0,0.2)"}
2: {values: Array(21), key: "undefined (G)", color: "rgba(0,255,0,0.2)"}
3: {values: Array(21), key: "undefined (B)", color: "rgba(0,0,255,0.2)"}
length: 4__proto__: Array(0)

d3.select('svg').data()[0][0].id
> undefined

Something must be going wrong here while inserting this data:

_graph.data = d3.select(_graph.selector + ' svg') //Select the <svg> element you want to render the chart in.
.datum(datum.d3) //Populate the <svg> element with chart data
.call(_graph.chart) //Finally, render the chart!

OK, yes, it's when we call graph.datum.d3():

graph.datum.d3()
> (4) [{}, {}, {}, {}]
0: {values: Array(21), key: "undefined (average)", color: "#444", id: undefined}
1: {values: Array(21), key: "undefined (R)", color: "rgba(255,0,0,0.2)"}
2: {values: Array(21), key: "undefined (G)", color: "rgba(0,255,0,0.2)"}
3: {values: Array(21), key: "undefined (B)", color: "rgba(0,0,255,0.2)"}

@jywarren
Copy link
Member

Hmm, maybe the two errors are different, Cannot read property 'id' of undefined vs TypeError: undefined is not an object (evaluating 'd3.select('svg').data()[0][index].id') -- but they seem to affect almost the same segment of code.

@jywarren
Copy link
Member

Solved TypeError: undefined is not an object (evaluating 'd3.select('svg').data()[0][index].id') in file:///home/travis/build/publiclab/spectral-workbench.js/dist/spectral-workbench.js (line 5374) (1) !!

Now we have one more error -- all these are returning incorrectly... could be related:

   X should initialize line styling and table rows properly
     Expected 1 to be 2. (1)
     Expected 1 to be 2. (2)
     Expected 1 to be 2. (3)
     Expected 1 to be 2. (4)

it("should initialize line styling and table rows properly", function() {
expect(graph).toBeDefined();
expect(graph.datum).toBeDefined();
// you can't do jquery hasClass() to SVGs, but d3 can do classed();
expect(d3.selectAll('g#spectrum-line-1')[0].length).toBe(2); // in main graph and in zoom graph
expect(d3.selectAll('g#spectrum-line-2')[0].length).toBe(2); // in main graph and in zoom graph
expect(d3.selectAll('g#spectrum-line-4')[0].length).toBe(2); // in main graph and in zoom graph
expect(d3.selectAll('g#spectrum-line-6')[0].length).toBe(2); // in main graph and in zoom graph

@jywarren
Copy link
Member

No more test failures!

Just:

101 specs in 14.061s.
>> 0 failures
Fatal error: Callback must be a function�
The command "grunt jasmine" exited with 3.

@jywarren
Copy link
Member

Related to node 10, switched to 12! gruntjs/grunt-contrib-jasmine#266

@jywarren
Copy link
Member

YES!!!! All done! Merging! Thank you!!!!

@jywarren jywarren merged commit ac970d6 into publiclab:main Nov 15, 2020
@welcome
Copy link

welcome bot commented Nov 15, 2020

Congrats on merging your first pull request! 🙌🎉⚡️
Your code will likely be published to https://spectralworkbench.org in the next few days.
In the meantime, can you tell us your Twitter handle so we can thank you properly?
Now that you've completed this, you can help someone else take their first step!
See: Public Lab's coding community!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants