Skip to content

Commit

Permalink
feat: let Pixi Application options be configurable (#470)
Browse files Browse the repository at this point in the history
This lets the users of this library configure Pixi.js Application for pixi layers if default setting don't cover their use case.
  • Loading branch information
ooystein authored Apr 8, 2022
1 parent 64fc8b1 commit 13bec33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ZoomTransform } from 'd3-zoom';
import { Graphics } from 'pixi.js';
import { Application, Graphics } from 'pixi.js';
import { Layer } from './layers/base/Layer';
import { IntersectionReferenceSystem } from './control/IntersectionReferenceSystem';
import Vector2 from '@equinor/videx-vector2';
Expand Down Expand Up @@ -65,7 +65,7 @@ export interface WellborepathLayerOptions extends LayerOptions {

export interface GeomodelLayerOptions extends LayerOptions {}

export interface CompletionLayerOptions extends LayerOptions {}
export interface CompletionLayerOptions extends PixiLayerOptions {}

export interface GeomodelLayerLabelsOptions extends LayerOptions {
margins?: number;
Expand All @@ -91,7 +91,11 @@ export interface CementLayerOptions extends WellComponentBaseOptions {
secondColor?: string;
}

export interface WellComponentBaseOptions extends LayerOptions {
export interface PixiLayerOptions extends LayerOptions {
pixiApplicationOptions?: PixiApplicationOptions;
}

export interface WellComponentBaseOptions extends PixiLayerOptions {
exaggerationFactor?: number;
}

Expand Down Expand Up @@ -202,3 +206,6 @@ export interface CalloutOptions extends LayerOptions {
offsetMax?: number;
offsetFactor?: number;
}

type PixiApplicationConstructorParameters = ConstructorParameters<typeof Application>;
type PixiApplicationOptions = PixiApplicationConstructorParameters[0];
8 changes: 7 additions & 1 deletion src/layers/base/PixiLayer.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { Application, RENDERER_TYPE } from 'pixi.js';
import { Layer } from './Layer';
import { OnMountEvent, OnRescaleEvent, OnResizeEvent, OnUnmountEvent } from '../../interfaces';
import { OnMountEvent, OnRescaleEvent, OnResizeEvent, OnUnmountEvent, PixiLayerOptions } from '../../interfaces';
import { DEFAULT_LAYER_HEIGHT, DEFAULT_LAYER_WIDTH } from '../../constants';

export abstract class PixiLayer extends Layer {
elm: HTMLElement;

ctx: Application;

constructor(id?: string, options?: PixiLayerOptions) {
super(id, options);
}

onMount(event: OnMountEvent): void {
super.onMount(event);

Expand All @@ -19,6 +23,7 @@ export abstract class PixiLayer extends Layer {
this.updateStyle();

const { elm, height, width } = event;
const { pixiApplicationOptions } = this.options as PixiLayerOptions;

const pixiOptions = {
width: width || parseInt(this.elm.getAttribute('width'), 10) || DEFAULT_LAYER_WIDTH,
Expand All @@ -28,6 +33,7 @@ export abstract class PixiLayer extends Layer {
clearBeforeRender: true,
autoResize: true,
preserveDrawingBuffer: true,
...pixiApplicationOptions,
};

this.ctx = new Application(pixiOptions);
Expand Down

0 comments on commit 13bec33

Please sign in to comment.