Skip to content

Commit

Permalink
Version 1.5.3: Remove plot method.
Browse files Browse the repository at this point in the history
  • Loading branch information
derpylz committed Apr 1, 2022
1 parent ecc0ff2 commit 9557b67
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 22 deletions.
1 change: 1 addition & 0 deletions build/babyplots.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,6 @@ export declare class Plots {
resize(width?: number, height?: number): Plots;
thumbnail(size: number, saveCallback: (data: string) => void): void;
dispose(): void;
removePlot(index: number): Plots;
addLabels(labelList: [[number, number, number, string, string?, number?]]): void;
}
12 changes: 11 additions & 1 deletion 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.

1 change: 1 addition & 0 deletions build/utils/Label.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export declare class AnnotationManager {
addLabels(labelList: [number, number, number, string, string?, number?][]): number[];
private _editLabelText;
private _removeLabelByUI;
removeLabelsByPlot(plot: Plot): void;
removeLabel(index: number): void;
exportLabels(): [number, number, number, string, string, number][];
fixLabels(): void;
Expand Down
12 changes: 12 additions & 0 deletions build/utils/Label.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/utils/Label.js.map

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions build/utils/Plot.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/utils/Plot.js.map

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

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.5.2",
"version": "1.5.3",
"description": "Easy interactive 3d plots.",
"main": "build/babyplots.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/babyplots.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,6 @@ export declare class Plots {
resize(width?: number, height?: number): Plots;
thumbnail(size: number, saveCallback: (data: string) => void): void;
dispose(): void;
removePlot(index: number): Plots;
addLabels(labelList: [[number, number, number, string, string?, number?]]): void;
}
25 changes: 11 additions & 14 deletions src/babyplots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ export class Plots {
plots: []
};

this.scene.onPointerDown = (function (_evt: any, pickResult: PickingInfo) {
this.scene.onPointerPick = (function (_evt: any, pickResult: PickingInfo) {
// (this as Plots)._annotationManager.clearInfo();
for (let i = 0; i < (this as Plots).plots.length; i++) {
let plot = (this as Plots).plots[i];
Expand Down Expand Up @@ -991,19 +991,6 @@ export class Plots {
// update labels
this._annotationManager.update();

// for (let pltIdx = 0; pltIdx < this.plots.length; pltIdx++) {
// const plot = this.plots[pltIdx];
// plot.update();
// }
// if (this._mouseOverCheck) {
// const pickResult = this._scene.pick(this._scene.pointerX, this._scene.pointerY);
// const faceId = pickResult.faceId;
// if (faceId == -1) {
// return;
// }
// const idx = this._SPS.pickedParticles[faceId].idx;
// this._mouseOverCallback(idx);
// }
}


Expand Down Expand Up @@ -2324,6 +2311,16 @@ export class Plots {
lblCntrl.remove();
}

removePlot(index: number): Plots {
let plot = this.plots[index];
if (plot === undefined) return;
this._annotationManager.removeLabelsByPlot(plot);
plot.dispose();
this.plots.splice(index);
this._downloadObj["plots"].splice(index);
return this;
}

/**
* Add labels from a list of labels.
*
Expand Down
1 change: 1 addition & 0 deletions src/utils/Label.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export declare class AnnotationManager {
addLabels(labelList: [number, number, number, string, string?, number?][]): number[];
private _editLabelText;
private _removeLabelByUI;
removeLabelsByPlot(plot: Plot): void;
removeLabel(index: number): void;
exportLabels(): [number, number, number, string, string, number][];
fixLabels(): void;
Expand Down
11 changes: 11 additions & 0 deletions src/utils/Label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ export class AnnotationManager {
if (this._showLabels) {
for (let i = 0; i < this.labels.length; i++) {
const label = this.labels[i];
if (label === undefined) continue;
label.update(this._camera, this._scene);
}
}
Expand Down Expand Up @@ -463,6 +464,16 @@ export class AnnotationManager {
this.removeLabel(labelNum);
}

removeLabelsByPlot(plot: Plot): void {
for (let i = 0; i < this.labels.length; i++) {
const l = this.labels[i];
if (l === undefined) continue;
if(l.plotCreated === plot) {
this.removeLabel(i);
}
}
}

removeLabel(index: number): void {
// remove label
if(this.labels[index] === undefined) return;
Expand Down
8 changes: 7 additions & 1 deletion src/utils/Plot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ export abstract class Plot {
setLooping(looping: boolean): void { }
dispose(): void {
if (this.mesh !== undefined) {

this.mesh.dispose()
}
if (this.meshes !== undefined) {
for (let i = 0; i < this.meshes.length; i++) {
const m = this.meshes[i];
m.dispose();
}
}
}
}
Expand Down

0 comments on commit 9557b67

Please sign in to comment.