Skip to content

Commit

Permalink
[tests] fixed webGL context init when testing
Browse files Browse the repository at this point in the history
  • Loading branch information
geekplux committed Jun 22, 2017
1 parent 0d04f69 commit 552cceb
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/netjsongraph.three.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ const defaults = {
scaleExtent: [0.25, 5],

scene: new THREE.Scene(),
camera: new THREE.OrthographicCamera(0, defaultWidth, defaultHeight, 0, 1, 1000),
renderer: new THREE.WebGLRenderer({

This comment has been minimized.

Copy link
@geekplux

geekplux Jun 22, 2017

Contributor

I want to set renderer in defaults option in order to make it as a property of Netjsongraph instance. but it will fail the test. @nemesisdesign because test environment does not support WebGL..

 FAIL  tests/api.spec.js
  ● Test suite failed to run

    TypeError: Cannot read property 'getExtension' of null

      at Object.get (node_modules/three/build/three.js:19663:21)
      at new WebGLRenderer (node_modules/three/build/three.js:20096:14)
      at Object.<anonymous> (src/netjsongraph.three.js:36:13)
      at Object.<anonymous> (tests/api.spec.js:1:128)
          at <anonymous>

    .....

  console.log node_modules/three/build/three.js:19874
    THREE.WebGLRenderer 85

  console.error node_modules/three/build/three.js:20090
    THREE.WebGLRenderer: Error creating WebGL context.
alpha: true,
antialias: true // perform antialiasing
})
camera: new THREE.OrthographicCamera(0, defaultWidth, defaultHeight, 0, 1, 1000)
};

class Netjsongraph {
Expand Down Expand Up @@ -164,25 +160,21 @@ class Netjsongraph {
.scaleExtent(_this.scaleExtent)
.on('zoom', function () {
const transform = d3.zoomTransform(this);
console.log(transform.k);
_this.camera.zoom = transform.k;
_this.camera.left += transform.k * 10000;
// _this.camera.z += transform.k * 100;
render();
_this.camera.updateProjectionMatrix();
});
d3.select(_this.el).call(zoom);

function render () {
requestAnimationFrame(render);
renderer.render(scene, camera);
};
}

/**
* Render force layout
*/
render () {
const { width, height, data, scene, camera, renderer } = this;
const { width, height, data, scene, camera } = this;
const renderer = new THREE.WebGLRenderer({
alpha: true,
antialias: true // perform antialiasing
});
renderer.setSize(width, height);
this.el.appendChild(renderer.domElement);
camera.position.z = 5;
Expand Down

0 comments on commit 552cceb

Please sign in to comment.