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

Add "figure mode" button [WIP] #767

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
22 changes: 22 additions & 0 deletions emperor/support_files/js/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,25 @@ define([
});
this.$plotSpace.append(this.$optionsButton);

/**
* @type {Node}
* jQuery object
*/
this.$figureModeButton = $('<button name="dm-button">&nbsp;</button>');
this.$figureModeButton.css({
'position': 'absolute',
'z-index': '3',
'top': '5px',
'right': '40px'
}).attr('title', 'Figure Mode').on('click', function(event) {
scope.controllers.axes.updateVisibleAxes(null, 2);
Copy link
Member

Choose a reason for hiding this comment

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

For updating different attributes of the axes controller, I would suggest using scope.controllers.axes.fromJSON, then you encode these attributes as an object and you should be good to go (see the unit tests for some examples).

scope.controllers.axes._colorChanged("axes-color", "#000000");
scope.controllers.axes._colorChanged("background-color", "#ffffff");
scope.controllers.shape.makeEverythingACircle();
// TODO: fix axis labels
});
this.$plotSpace.append(this.$figureModeButton);

// default decomposition view uses the full window
this.addSceneView();

Expand All @@ -274,6 +293,9 @@ define([
scope.$optionsButton.button({text: false,
icons: {primary: ' ui-icon-gear'}});

scope.$figureModeButton.button({text: false,
icons: {primary: ' ui-icon-lightbulb'}});

scope._buildUI();
// Hide the loading splashscreen
scope.$divId.find('.loading').hide();
Expand Down
24 changes: 24 additions & 0 deletions emperor/support_files/js/shape-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,30 @@ define([
});
};

/**
*
* Analogue of _resetAttribute() above, but makes everything a circle instead
*
* NOTE: In the future, making this pay more close attention to the current
* shapes of each object (like how DecompositionView._buildVegaSpec() works)
* may be preferable. However, that may require adding more 2D shape options
* to Emperor.
*
* @extends EmperorAttributeABC
*
*/
ShapeController.prototype.makeEverythingACircle = function() {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a unit test for this method?

EmperorAttributeABC.prototype._resetAttribute.call(this);
var scope = this;

_.each(this.decompViewDict, function(view) {
scope.setPlottableAttributes(view, 'Circle', view.decomp.plottable);
view.needsUpdate = true;
});
};



/**
* Helper function to set the shape of plottable
*
Expand Down
10 changes: 7 additions & 3 deletions emperor/support_files/js/shapes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// shapes.
define(['jquery', 'three', 'underscore'], function($, THREE, _) {

var SPHERE = 'Sphere', SQUARE = 'Square', CONE = 'Cone',
var SPHERE = 'Sphere', CIRCLE = 'Circle', SQUARE = 'Square', CONE = 'Cone',
ICOSAHEDRON = 'Icosahedron', CYLINDER = 'Cylinder',
OCTAHEDRON = 'Diamond', RING = 'Ring', STAR = 'Star';

var shapes = [SPHERE, OCTAHEDRON, CONE, CYLINDER, RING, SQUARE, ICOSAHEDRON,
STAR];
var shapes = [SPHERE, CIRCLE, OCTAHEDRON, CONE, CYLINDER, RING, SQUARE,
ICOSAHEDRON, STAR];

/**
*
Expand All @@ -35,6 +35,10 @@ define(['jquery', 'three', 'underscore'], function($, THREE, _) {
switch (shapeName) {
case SPHERE:
return new THREE.SphereGeometry(factor, 8, 8);
case CIRCLE:
geom = new THREE.CircleGeometry(factor, 16);
geom.rotateX(0.3);
return geom;
case SQUARE:
geom = new THREE.PlaneGeometry(factor * 2, factor * 2, 2, 2);
geom.rotateX(0.3);
Expand Down
1 change: 1 addition & 0 deletions emperor/support_files/js/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,7 @@ DecompositionView.prototype._buildVegaSpec = function() {
// Maps THREE.js geometries to vega shapes
var getShape = {
Sphere: 'circle',
Circle: 'circle',
Diamond: 'diamond',
Cone: 'triangle-down',
Cylinder: 'square',
Expand Down
5 changes: 3 additions & 2 deletions tests/javascript_tests/test_shape_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ requirejs([
module('Shape Controller', {
setup: function() {
// setup function
this.shapesAvailable = ['Sphere', 'Diamond', 'Cone', 'Cylinder',
'Ring', 'Square', 'Icosahedron', 'Star'];
this.shapesAvailable = ['Sphere', 'Circle', 'Diamond', 'Cone',
'Cylinder', 'Ring', 'Square', 'Icosahedron',
'Star'];
this.sharedDecompositionViewDict = {};

var UIState1 = new UIState();
Expand Down