Skip to content

Commit

Permalink
added clearAllData method, added some misc documentation (#255)
Browse files Browse the repository at this point in the history
* added clearAllData method, added some misc documentation

* capitalized comments

Co-authored-by: Brynjulf <[email protected]>
  • Loading branch information
Brynjulf and Brynjulf authored May 18, 2020
1 parent ba03d8b commit a561eb8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 21 deletions.
26 changes: 23 additions & 3 deletions src/control/LayerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class LayerManager {
private _svgContainer: Selection<HTMLElement, unknown, null, undefined>;

/**
* Class for handling layers
* Handles layers and axis also holds a zoom and pan handler object
* @param container root container
* @param scaleOptions
* @param axisOptions
Expand Down Expand Up @@ -56,17 +56,32 @@ export class LayerManager {
this.rescale = this.rescale.bind(this);
}

/**
* Adds and mounts an array of layers
* @param layers array of layers
*/
addLayers(layers: Layer[]): LayerManager {
layers.forEach((layer) => this.addLayer(layer));
return this;
}

/**
* Gets all layers currently mounted
*/
getLayers(): Layer[] {
return this.layers;
}

/**
* adds the layer to the manager, and mounts it
* Clears data from all mounted layers
*/
clearAllData(): LayerManager {
this.layers.forEach((l) => l.clearData());
return this;
}

/**
* Adds the layer to the manager, and mounts it
* @param layer Layer
* @param params extra params to pass to the onUpdate method
*/
Expand All @@ -78,7 +93,7 @@ export class LayerManager {
}

/**
* remove layer from manager, and unmounts it
* Remove layer from manager, and unmounts it
* @param layerId name of layer
*/
removeLayer(layerId: string): LayerManager {
Expand Down Expand Up @@ -124,6 +139,11 @@ export class LayerManager {
return this;
}

/**
* Adjust layers, axis, and zoom according to inputted dimensions
* @param width (required)
* @param height (required)
*/
adjustToSize(width: number, height: number): void {
const layersWidth = Math.max(this._axis ? width - HORIZONTAL_AXIS_MARGIN : width, 0);
const layersHeight = Math.max(this._axis ? height - VERTICAL_AXIS_MARGIN : height, 0);
Expand Down
45 changes: 27 additions & 18 deletions src/control/MainController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ export class Controller {
}

/**
* adds layer to list, and initializes it
* Clears data from all mounted layers
*/
clearAllData(): Controller {
this.layerManager.clearAllData();
return this;
}

/**
* Adds layer to list, and initializes it
* @param layer layer object
* @param params (optional) adds additional parameters to the onUpdateEvent
*/
Expand All @@ -77,7 +85,7 @@ export class Controller {
}

/**
* remove layer from list
* Remove layer from list
* @param layerId string id
*/
removeLayer(layerId: string): Controller {
Expand All @@ -86,15 +94,15 @@ export class Controller {
}

/**
* find first layer with given id, returns undefined if none are found
* Find first layer with given id, returns undefined if none are found
* @param layerId string id
*/
getLayer(layerId: string): Layer {
return this.layerManager.getLayer(layerId);
}

/**
* sets visibility to true and rescales the layer
* Sets visibility to true and rescales the layer
* @param layerId string id
*/
showLayer(layerId: string): Controller {
Expand All @@ -103,7 +111,7 @@ export class Controller {
}

/**
* sets visibility to false
* Sets visibility to false
* @param layerId string id
*/
hideLayer(layerId: string): Controller {
Expand All @@ -112,8 +120,9 @@ export class Controller {
}

/**
* Adjust zoom due to changes in size of target
* @param force - force update even if size did not change, defaults to false
* Adjust layers, axis, overlay, and zoom according to inputted dimensions
* @param width (required)
* @param height (required)
*/
adjustToSize(width: number, height: number): Controller {
this.layerManager.adjustToSize(width, height);
Expand All @@ -137,7 +146,7 @@ export class Controller {
}

/**
* sets bounds for zoom and pan handler
* Sets bounds for zoom and pan handler
* @param xBounds - domain in x-direction
* @param yBounds - domain in y-direction
*/
Expand All @@ -147,39 +156,39 @@ export class Controller {
}

/**
* display both axes
* Display both axes
*/
showAxis(): Controller {
this.layerManager.showAxis();
return this;
}

/**
* hide both axes
* Hide both axes
*/
hideAxis(): Controller {
this.layerManager.hideAxis();
return this;
}

/**
* shows labels in x and y
* Shows labels in x and y
*/
showAxisLabels(): Controller {
this.layerManager.showAxisLabels();
return this;
}

/**
* hide labels in x and y
* Hide labels in x and y
*/
hideAxisLabels(): Controller {
this.layerManager.hideAxisLabels();
return this;
}

/**
* sets domain offset, offset is subtracted from domain
* Sets domain offset, offset is subtracted from domain
* @param x
* @param y
*/
Expand All @@ -189,7 +198,7 @@ export class Controller {
}

/**
* sets domain offset in x-direction, offset is subtracted from domain
* Sets domain offset in x-direction, offset is subtracted from domain
* @param x
*/
setXAxisOffset(x: number): Controller {
Expand All @@ -198,7 +207,7 @@ export class Controller {
}

/**
* sets domain offset in y-direction, offset is subtracted from domain
* Sets domain offset in y-direction, offset is subtracted from domain
* @param y
*/
setYAxisOffset(y: number): Controller {
Expand All @@ -207,7 +216,7 @@ export class Controller {
}

/**
* defines min and max of how much one can zoom
* Defines min and max of how much one can zoom
* @param zoomlevels
*/
setZoomLevelBoundary(zoomlevels: [number, number]): Controller {
Expand All @@ -216,7 +225,7 @@ export class Controller {
}

/**
* defines how far in one can zoom
* Defines how far in one can zoom
* @param zoomlevel
*/
setMaxZoomLevel(zoomlevel: number): Controller {
Expand All @@ -225,7 +234,7 @@ export class Controller {
}

/**
* defines how far out one can zoom
* Defines how far out one can zoom
* @param zoomlevel
*/
setMinZoomLevel(zoomlevel: number): Controller {
Expand Down

0 comments on commit a561eb8

Please sign in to comment.