-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
export createPrimitive functions instead of primitive class
- Loading branch information
Showing
54 changed files
with
495 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { IPaneApi } from '../api/ipane-api'; | ||
import { IPanePrimitive } from '../api/ipane-primitive-api'; | ||
|
||
import { DeepPartial } from '../helpers/strict-type-checks'; | ||
|
||
import { IPrimitiveWrapper } from './primitive-wrapper-base'; | ||
|
||
/** | ||
* Interface for a primitive with options. | ||
*/ | ||
export interface IPanePrimitiveWithOptions<T, K> extends IPanePrimitive<T> { | ||
/** | ||
* @param options - Options to apply. The options are deeply merged with the current options. | ||
*/ | ||
applyOptions?: (options: DeepPartial<K>) => void; | ||
} | ||
|
||
export class PanePrimitiveWrapper<T, Options = unknown, TPrimitive extends IPanePrimitiveWithOptions<T, Options> = IPanePrimitive<T>> implements IPrimitiveWrapper<T, Options> { | ||
protected _primitive: TPrimitive; | ||
protected _pane: IPaneApi<T>; | ||
|
||
public constructor(pane: IPaneApi<T>, primitive: TPrimitive) { | ||
this._pane = pane; | ||
this._primitive = primitive; | ||
this._attach(); | ||
} | ||
|
||
public detach(): void { | ||
this._pane.detachPrimitive(this._primitive); | ||
} | ||
|
||
public getPane(): IPaneApi<T> { | ||
return this._pane; | ||
} | ||
|
||
public applyOptions(options: DeepPartial<Options>): void { | ||
this._primitive.applyOptions?.(options); | ||
} | ||
|
||
private _attach(): void { | ||
this._pane.attachPrimitive(this._primitive); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { DeepPartial } from '../helpers/strict-type-checks'; | ||
|
||
/** | ||
* Interface for a primitive wrapper. It must be implemented to add some plugin to the chart. | ||
*/ | ||
export interface IPrimitiveWrapper<T, Options = unknown> { | ||
/** | ||
* @param options - Options to apply. The options are deeply merged with the current options. | ||
*/ | ||
applyOptions(options: DeepPartial<Options>): void; | ||
/** | ||
* Detaches the plugin from the pane/series. | ||
*/ | ||
detach(): void; | ||
} | ||
|
||
/** | ||
* Interface for a plugin that adds primitive with options. | ||
*/ | ||
export interface IPrimitiveWithOptions<Options = unknown> { | ||
/** | ||
* @param options - Options to apply. The options are deeply merged with the current options. | ||
*/ | ||
applyOptions(options: DeepPartial<Options>): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { IPanePrimitive, PaneAttachedParameter } from '../api/ipane-primitive-api'; | ||
|
||
import { DeepPartial } from '../helpers/strict-type-checks'; | ||
|
||
export abstract class PrimitiveWrapper<T, Options = unknown> { | ||
protected _primitive: IPanePrimitive<T>; | ||
protected _options: Options; | ||
|
||
public constructor(primitive: IPanePrimitive<T>, options: Options) { | ||
this._primitive = primitive; | ||
this._options = options; | ||
} | ||
|
||
public detach(): void { | ||
this._primitive.detached?.(); | ||
} | ||
|
||
public abstract applyOptions(options: DeepPartial<Options>): void; | ||
|
||
protected _attachToPrimitive(params: PaneAttachedParameter<T>): void { | ||
this._primitive.attached?.(params); | ||
} | ||
|
||
protected _requestUpdate(): void { | ||
this._primitive.updateAllViews?.(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.