Skip to content

Commit

Permalink
added the ability to toggle axis (#193)
Browse files Browse the repository at this point in the history
Co-authored-by: Brynjulf <[email protected]>
  • Loading branch information
Brynjulf and Brynjulf committed Apr 22, 2020
1 parent 81d0533 commit 17f6eb5
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .storybook/src/intersection.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,16 @@ export const intersection = () => {
const btnCompletion = createButton(controller, completionLayer, 'Completion');
const btnGeomodelLabels = createButton(controller, geomodelLabelsLayer, 'Geo model labels');
const btnSeismic = createButton(controller, seismicLayer, 'Seismic');
let show = true;
const toggleAxis = createButtonWithCb('Toggle axis', () => {
if (show) {
controller.hideAxis();
show = false;
} else {
controller.showAxis();
show = true;
}
});
const btnLarger = createButtonWithCb('800x600', () => {
const w = 800;
const h = 600;
Expand Down Expand Up @@ -263,6 +273,7 @@ export const intersection = () => {
btnContainer.appendChild(btnSeismic);
btnContainer.appendChild(btnLarger);
btnContainer.appendChild(btnSmaller);
btnContainer.appendChild(toggleAxis);

root.appendChild(container);
root.appendChild(btnContainer);
Expand Down
20 changes: 20 additions & 0 deletions src/components/axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { OnResizeEvent, OnRescaleEvent } from '../interfaces';
type Options = {
offsetX: number;
offsetY: number;
visible: boolean;
};

export class Axis {
Expand All @@ -19,6 +20,7 @@ export class Axis {
unitOfMeasure: string;
private _offsetX: number = 0;
private _offsetY: number = 0;
private visible: boolean = true;

constructor(
mainGroup: Selection<SVGElement, any, null, undefined>,
Expand All @@ -39,6 +41,9 @@ export class Axis {
if (options && options.offsetX) {
this._offsetY = options.offsetY;
}
if (options && options.visible) {
this.visible = options.visible;
}
this._scaleX = scaleLinear().domain([0, 1]).range([0, 1]);
this._scaleY = scaleLinear().domain([0, 1]).range([0, 1]);
}
Expand Down Expand Up @@ -144,7 +149,22 @@ export class Axis {
_scaleX.domain([xBounds[0] - offsetX, xBounds[1] - offsetX]).range(xRange);
_scaleY.domain([yBounds[0] - offsetY, yBounds[1] - offsetY]).range(yRange);

if (this.visible) {
this.render();
}
}

show(): Axis {
this.visible = true;
this.mainGroup.attr('visibility', 'visible');
this.render();
return this;
}

hide(): Axis {
this.visible = false;
this.mainGroup.attr('visibility', 'hidden');
return this;
}

get offsetX(): number {
Expand Down
10 changes: 10 additions & 0 deletions src/control/LayerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ export class LayerManager {
this.layers.forEach((layer) => (layer.referenceSystem = irs));
}

showAxis(): LayerManager {
this.axis.show();
return this;
}

hideAxis(): LayerManager {
this.axis.hide();
return this;
}

setAxisOffset(x: number, y: number): LayerManager {
this.axis.offsetX = x;
this.axis.offsetY = y;
Expand Down
10 changes: 10 additions & 0 deletions src/control/MainController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ export class Controller {
return this;
}

showAxis(): Controller {
this.layerManager.showAxis();
return this;
}

hideAxis(): Controller {
this.layerManager.hideAxis();
return this;
}

setAxisOffset(x: number, y: number): Controller {
this.layerManager.setAxisOffset(x, y);
return this;
Expand Down

0 comments on commit 17f6eb5

Please sign in to comment.