Skip to content

Commit

Permalink
Version 1.3.1; zUp replaced by upAxis option.
Browse files Browse the repository at this point in the history
  • Loading branch information
derpylz committed Jan 5, 2022
1 parent b155d68 commit 879da63
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 23 deletions.
2 changes: 1 addition & 1 deletion build/babyplots.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export declare class Plots {
private _uniqID;
private _shapeLegendPosition;
private _fsUIDirty;
private _zUp;
private _upAxis;
canvas: HTMLCanvasElement;
scene: Scene;
camera: ArcRotateCamera;
Expand Down
34 changes: 26 additions & 8 deletions build/babyplots.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/babyplots.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/babyplots.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/babyplots.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babyplots",
"version": "1.3.0",
"version": "1.3.1",
"description": "Easy interactive 3d plots.",
"main": "build/babyplots.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion src/babyplots.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export declare class Plots {
private _uniqID;
private _shapeLegendPosition;
private _fsUIDirty;
private _zUp;
private _upAxis;
canvas: HTMLCanvasElement;
scene: Scene;
camera: ArcRotateCamera;
Expand All @@ -228,6 +228,7 @@ export declare class Plots {
uiLayer: AdvancedDynamicTexture;
animPaused: boolean;
constructor(canvasElement: string, options?: {});
private _updateCameraUpVector;
fromJSON(plotData: {}): void;
createButtons(whichBtns?: string[]): void;
private _prepDownloadObj;
Expand Down
41 changes: 32 additions & 9 deletions src/babyplots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export class Plots {
private _uniqID: string;
private _shapeLegendPosition: string;
private _fsUIDirty: boolean = true;
private _zUp: boolean = false;
private _upAxis: string = "+y";

/** HTML canvas element for this babyplots visualization. */
canvas: HTMLCanvasElement;
Expand Down Expand Up @@ -419,7 +419,7 @@ export class Plots {
turntable: false,
rotationRate: 0.01,
shapeLegendTitle: "",
zUp: false,
upAxis: "+y",
}
Object.assign(opts, options);

Expand All @@ -439,10 +439,8 @@ export class Plots {
this.scene.activeCamera = this.camera;
this.camera.inputs.attached.keyboard.detachControl();
this.camera.wheelPrecision = 50;
this._zUp = opts.zUp;
if (opts.zUp) {
this.camera.upVector = new Vector3(0, 0, 1);
}
this._upAxis = opts.upAxis;
this._updateCameraUpVector();

// background color
this.scene.clearColor = Color4.FromHexString(opts.backgroundColor);
Expand Down Expand Up @@ -536,6 +534,30 @@ export class Plots {
}).bind(this);
}

private _updateCameraUpVector() {
switch (this._upAxis) {
case "+x":
this.camera.upVector = new Vector3(1, 0, 0);
break;
case "-x":
this.camera.upVector = new Vector3(-1, 0, 0);
break;
case "+z":
this.camera.upVector = new Vector3(0, 0, 1);
break;
case "-z":
this.camera.upVector = new Vector3(0, 0, -1);
break;
case "-y":
this.camera.upVector = new Vector3(0, -1, 0);
break;
case "+y":
default:
this.camera.upVector = new Vector3(0, 1, 0);
break;
}
}

/**
* Load a visualization from a saved JSON object. The R, JavaScript and Python implementations of babyplots as well as the NPC allow the export of visualizations as JSON files. Loading of a saved visualization using fromJSON() overwrites previously set properties of the Plots object.
*
Expand Down Expand Up @@ -564,8 +586,9 @@ export class Plots {
if (plotData["shapeLegendTitle"] !== undefined) {
this.shapeLegendTitle = plotData["shapeLegendTitle"];
}
if (plotData["zUp"] !== undefined) {
this._zUp = plotData["zUp"];
if (plotData["upAxis"] !== undefined) {
this._upAxis = plotData["upAxis"];
this._updateCameraUpVector();
}
for (let plotIdx = 0; plotIdx < plotData["plots"].length; plotIdx++) {
const plot = plotData["plots"][plotIdx];
Expand Down Expand Up @@ -759,7 +782,7 @@ export class Plots {
this._downloadObj["cameraAlpha"] = this.camera.alpha;
this._downloadObj["cameraBeta"] = this.camera.beta;
this._downloadObj["cameraRadius"] = this.camera.radius;
this._downloadObj["zUp"] = this._zUp;
this._downloadObj["upAxis"] = this._upAxis;
}

private _downloadJson() {
Expand Down

0 comments on commit 879da63

Please sign in to comment.