Skip to content

Commit

Permalink
feat(event-display): support to hide widgets through URL
Browse files Browse the repository at this point in the history
  • Loading branch information
9inpachi committed Feb 11, 2021
1 parent fe0b2e6 commit cb2ec40
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
9 changes: 6 additions & 3 deletions packages/phoenix-event-display/src/event-display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@ export class EventDisplay {
};
this.graphicsLibrary.setAnimationLoop(uiLoop);

// Process and apply URL options
if (configuration.allowUrlOptions !== false) {
const urlOptionsManager = new URLOptionsManager(this, configuration);
urlOptionsManager.applyOptions();
}

// Allow adding elements through console
this.enableEventDisplayConsole();
// Allow keyboard controls
this.enableKeyboardControls();
// Process and apply URL options
const urlOptionsManager = new URLOptionsManager(this, configuration);
urlOptionsManager.applyOptions();
}

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/phoenix-event-display/src/extras/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PhoenixMenuNode } from '../ui/phoenix-menu/phoenix-menu-node';
* Configuration of the event display.
*/
export interface Configuration {
/** Default view [x,y,z] */
/** Default view [x,y,z]. */
defaultView?: number[];
/** Preset views for switching event display camera. */
presetViews?: PresetView[];
Expand All @@ -20,4 +20,6 @@ export interface Configuration {
elementId?: string;
/** Default event to load when none given in URL. */
defaultEventFile?: { eventFile: string, eventType: string };
/** Whether to allow URL options or not (true by default). */
allowUrlOptions?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class PhoenixLoader implements EventDataLoader {

/**
* Takes an object that represents ONE event and takes care of adding
* the different objects to the graphic library and the UI controls.
* the different objects to the graphics library and the UI controls.
* @param eventData Object representing the event.
* @param graphicsLibrary Service containing functionality to draw the 3D objects.
* @param ui Service for showing menus and controls to manipulate the geometries.
Expand Down
30 changes: 23 additions & 7 deletions packages/phoenix-event-display/src/managers/url-options-manager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { JiveXMLLoader, PhoenixLoader } from "src";
import { Configuration } from "src/extras/configuration";
import { EventDisplay } from "../event-display";
import { StateManager } from "./state-manager";
import { JiveXMLLoader } from '../loaders/jivexml-loader';
import { PhoenixLoader } from '../loaders/phoenix-loader';
import { Configuration } from '../extras/configuration';
import { EventDisplay } from '../event-display';
import { StateManager } from './state-manager';

/**
* A manager for managing options given through URL.
Expand All @@ -21,14 +22,15 @@ export class URLOptionsManager {
}

/**
* Initialize and process all URL options on page load.
* Initialize and apply all URL options on page load.
*/
public applyOptions() {
// Initialize event with data from URL if there is any
this.initEventFromURL(
this.applyEventOptions(
this.configuration.defaultEventFile?.eventFile,
this.configuration.defaultEventFile?.eventType
);
this.applyHideWidgetsOption();
}

/**
Expand All @@ -37,7 +39,7 @@ export class URLOptionsManager {
* @param defaultEventPath Default event path to fallback to if none in URL.
* @param defaultEventType Default event type to fallback to if none in URL.
*/
public initEventFromURL(defaultEventPath?: string, defaultEventType?: string) {
public applyEventOptions(defaultEventPath?: string, defaultEventType?: string) {
if (!('fetch' in window)) {
return;
}
Expand Down Expand Up @@ -96,4 +98,18 @@ export class URLOptionsManager {
loadConfig();
}
}

/**
* Hide all overlay widgets if "hideWidgets" option from the URL is true.
*/
public applyHideWidgetsOption() {
if (Boolean(this.urlOptions.get('hideWidgets')) === true) {
// Hide overlay widgets
document.getElementById('overlayWidgets').style.display = 'none';
// Hide stats
(document.getElementsByClassName('ui-element')[0] as HTMLElement).style.display = 'none';
// Hide dat.GUI menu
document.getElementById('gui').style.display = 'none';
}
}
}

0 comments on commit cb2ec40

Please sign in to comment.