diff --git a/lwc-plugin-custom-primitives/.gitignore b/lwc-plugin-custom-primitives/.gitignore
deleted file mode 100644
index a90cc13..0000000
--- a/lwc-plugin-custom-primitives/.gitignore
+++ /dev/null
@@ -1,24 +0,0 @@
-# Logs
-logs
-*.log
-npm-debug.log*
-yarn-debug.log*
-yarn-error.log*
-pnpm-debug.log*
-lerna-debug.log*
-
-node_modules
-dist
-typings
-*.local
-
-# Editor directories and files
-.vscode/*
-!.vscode/extensions.json
-.idea
-.DS_Store
-*.suo
-*.ntvs*
-*.njsproj
-*.sln
-*.sw?
diff --git a/lwc-plugin-custom-primitives/README.md b/lwc-plugin-custom-primitives/README.md
deleted file mode 100644
index 211250c..0000000
--- a/lwc-plugin-custom-primitives/README.md
+++ /dev/null
@@ -1,38 +0,0 @@
-# Custom Primitives - Lightweight Charts™ Plugin
-
-Description of the Plugin.
-
-- Developed for Lightweight Charts version: `v4.1.0`
-
-## Running Locally
-
-```shell
-npm install
-npm run dev
-```
-
-Visit `localhost:5173` in the browser.
-
-## Compiling
-
-```shell
-npm run compile
-```
-
-Check the output in the `dist` folder.
-
-## Publishing To NPM
-
-You can configure the contents of the package's `package.json` within the
-`compile.mjs` script.
-
-Once you have compiled the plugin (see above section) then you can publish the
-package to NPM with these commands:
-
-```shell
-cd dist
-npm publish
-```
-
-Hint: append `--dry-run` to the end of the publish command to see the results of
-the publish command without actually uploading the package to NPM.
diff --git a/lwc-plugin-custom-primitives/compile.mjs b/lwc-plugin-custom-primitives/compile.mjs
deleted file mode 100644
index ffc34b5..0000000
--- a/lwc-plugin-custom-primitives/compile.mjs
+++ /dev/null
@@ -1,116 +0,0 @@
-import { dirname, resolve } from 'node:path';
-import { copyFileSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
-import { build, defineConfig } from 'vite';
-import { fileURLToPath } from 'url';
-import { generateDtsBundle } from 'dts-bundle-generator';
-
-function buildPackageJson(packageName) {
- /*
- Define the contents of the package's package.json here.
- */
- return {
- name: packageName,
- version: '1.0.0',
- keywords: ['lwc-plugin', 'lightweight-charts'],
- type: 'module',
- main: `./${packageName}.umd.cjs`,
- module: `./${packageName}.js`,
- types: `./${packageName}.d.ts`,
- exports: {
- import: {
- types: `./${packageName}.d.ts`,
- default: `./${packageName}.js`,
- },
- require: {
- types: `./${packageName}.d.cts`,
- default: `./${packageName}.umd.cjs`,
- },
- },
- };
-}
-
-const __filename = fileURLToPath(import.meta.url);
-const currentDir = dirname(__filename);
-
-const pluginFileName = 'custom-primitives';
-const pluginFile = resolve(currentDir, 'src', `${pluginFileName}.ts`);
-
-const pluginsToBuild = [
- {
- filepath: pluginFile,
- exportName: 'lwc-plugin-custom-primitives',
- name: 'CustomPrimitives',
- },
-];
-
-const compiledFolder = resolve(currentDir, 'dist');
-if (!existsSync(compiledFolder)) {
- mkdirSync(compiledFolder);
-}
-
-const buildConfig = ({
- filepath,
- name,
- exportName,
- formats = ['es', 'umd'],
-}) => {
- return defineConfig({
- publicDir: false,
- build: {
- outDir: `dist`,
- emptyOutDir: true,
- copyPublicDir: false,
- lib: {
- entry: filepath,
- name,
- formats,
- fileName: exportName,
- },
- rollupOptions: {
- external: ['lightweight-charts', 'fancy-canvas'],
- output: {
- globals: {
- 'lightweight-charts': 'LightweightCharts',
- },
- },
- },
- },
- });
-};
-
-const startTime = Date.now().valueOf();
-console.log('⚡️ Starting');
-console.log('Bundling the plugin...');
-const promises = pluginsToBuild.map(file => {
- return build(buildConfig(file));
-});
-await Promise.all(promises);
-console.log('Generating the package.json file...');
-pluginsToBuild.forEach(file => {
- const packagePath = resolve(compiledFolder, 'package.json');
- const content = JSON.stringify(
- buildPackageJson(file.exportName),
- undefined,
- 4
- );
- writeFileSync(packagePath, content, { encoding: 'utf-8' });
-});
-console.log('Generating the typings files...');
-pluginsToBuild.forEach(file => {
- try {
- const esModuleTyping = generateDtsBundle([
- {
- filePath: `./typings/${pluginFileName}.d.ts`,
- },
- ]);
- const typingFilePath = resolve(compiledFolder, `${file.exportName}.d.ts`);
- writeFileSync(typingFilePath, esModuleTyping.join('\n'), {
- encoding: 'utf-8',
- });
- copyFileSync(typingFilePath, resolve(compiledFolder, `${file.exportName}.d.cts`));
- } catch (e) {
- console.error('Error generating typings for: ', file.exportName);
- }
-});
-const endTime = Date.now().valueOf();
-console.log(`🎉 Done (${endTime - startTime}ms)`);
diff --git a/lwc-plugin-custom-primitives/index.html b/lwc-plugin-custom-primitives/index.html
deleted file mode 100644
index 3f1b3a1..0000000
--- a/lwc-plugin-custom-primitives/index.html
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
diff --git a/lwc-plugin-custom-primitives/package.json b/lwc-plugin-custom-primitives/package.json
deleted file mode 100644
index 6bf8786..0000000
--- a/lwc-plugin-custom-primitives/package.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "name": "lwc-plugin-custom-primitives",
- "type": "module",
- "scripts": {
- "dev": "vite --config src/vite.config.js",
- "compile": "tsc && node compile.mjs"
- },
- "devDependencies": {
- "typescript": "^5.0.4",
- "vite": "^4.3.1"
- },
- "dependencies": {
- "dts-bundle-generator": "^8.0.1",
- "fancy-canvas": "^2.1.0",
- "lightweight-charts": "^4.1.0-rc2"
- }
-}
diff --git a/lwc-plugin-custom-primitives/src/axis-pane-renderer.ts b/lwc-plugin-custom-primitives/src/axis-pane-renderer.ts
deleted file mode 100644
index 49380b2..0000000
--- a/lwc-plugin-custom-primitives/src/axis-pane-renderer.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-import { CanvasRenderingTarget2D } from 'fancy-canvas';
-import { ISeriesPrimitivePaneRenderer } from 'lightweight-charts';
-import { positionsBox } from './helpers/dimensions/positions';
-
-export class CustomPrimitivesAxisPaneRenderer implements ISeriesPrimitivePaneRenderer {
- _p1: number | null;
- _p2: number | null;
- _fillColor: string;
- _vertical: boolean = false;
-
- constructor(
- p1: number | null,
- p2: number | null,
- fillColor: string,
- vertical: boolean
- ) {
- this._p1 = p1;
- this._p2 = p2;
- this._fillColor = fillColor;
- this._vertical = vertical;
- }
-
- draw(target: CanvasRenderingTarget2D) {
- target.useBitmapCoordinateSpace(scope => {
- if (this._p1 === null || this._p2 === null) return;
- const ctx = scope.context;
- ctx.globalAlpha = 0.5;
- const positions = positionsBox(
- this._p1,
- this._p2,
- this._vertical ? scope.verticalPixelRatio : scope.horizontalPixelRatio
- );
- ctx.fillStyle = this._fillColor;
- if (this._vertical) {
- ctx.fillRect(0, positions.position, 15, positions.length);
- } else {
- ctx.fillRect(positions.position, 0, positions.length, 15);
- }
- });
- }
-}
diff --git a/lwc-plugin-custom-primitives/src/axis-pane-view.ts b/lwc-plugin-custom-primitives/src/axis-pane-view.ts
deleted file mode 100644
index a040e98..0000000
--- a/lwc-plugin-custom-primitives/src/axis-pane-view.ts
+++ /dev/null
@@ -1,55 +0,0 @@
-import {
- Coordinate,
- ISeriesPrimitivePaneView,
- SeriesPrimitivePaneViewZOrder,
-} from 'lightweight-charts';
-import { CustomPrimitivesAxisPaneRenderer } from './axis-pane-renderer';
-import { CustomPrimitivesDataSource } from './data-source';
-
-abstract class CustomPrimitivesAxisPaneView implements ISeriesPrimitivePaneView {
- _source: CustomPrimitivesDataSource;
- _p1: number | null = null;
- _p2: number | null = null;
- _vertical: boolean = false;
-
- constructor(source: CustomPrimitivesDataSource, vertical: boolean) {
- this._source = source;
- this._vertical = vertical;
- }
-
- abstract getPoints(): [Coordinate | null, Coordinate | null];
-
- update() {
- [this._p1, this._p2] = this.getPoints();
- }
-
- renderer() {
- return new CustomPrimitivesAxisPaneRenderer(
- this._p1,
- this._p2,
- this._source.options.fillColor,
- this._vertical
- );
- }
- zOrder(): SeriesPrimitivePaneViewZOrder {
- return 'bottom';
- }
-}
-
-export class CustomPrimitivesPriceAxisPaneView extends CustomPrimitivesAxisPaneView {
- getPoints(): [Coordinate | null, Coordinate | null] {
- const series = this._source.series;
- const y1 = series.priceToCoordinate(this._source.p1.price);
- const y2 = series.priceToCoordinate(this._source.p2.price);
- return [y1, y2];
- }
-}
-
-export class CustomPrimitivesTimeAxisPaneView extends CustomPrimitivesAxisPaneView {
- getPoints(): [Coordinate | null, Coordinate | null] {
- const timeScale = this._source.chart.timeScale();
- const x1 = timeScale.timeToCoordinate(this._source.p1.time);
- const x2 = timeScale.timeToCoordinate(this._source.p2.time);
- return [x1, x2];
- }
-}
diff --git a/lwc-plugin-custom-primitives/src/axis-view.ts b/lwc-plugin-custom-primitives/src/axis-view.ts
deleted file mode 100644
index 435f73f..0000000
--- a/lwc-plugin-custom-primitives/src/axis-view.ts
+++ /dev/null
@@ -1,57 +0,0 @@
-import { Coordinate, ISeriesPrimitiveAxisView } from 'lightweight-charts';
-import { Point, CustomPrimitivesDataSource } from './data-source';
-
-abstract class CustomPrimitivesAxisView implements ISeriesPrimitiveAxisView {
- _source: CustomPrimitivesDataSource;
- _p: Point;
- _pos: Coordinate | null = null;
- constructor(source: CustomPrimitivesDataSource, p: Point) {
- this._source = source;
- this._p = p;
- }
- abstract update(): void;
- abstract text(): string;
-
- coordinate() {
- return this._pos ?? -1;
- }
-
- visible(): boolean {
- return this._source.options.showLabels;
- }
-
- tickVisible(): boolean {
- return this._source.options.showLabels;
- }
-
- textColor() {
- return this._source.options.labelTextColor;
- }
- backColor() {
- return this._source.options.labelColor;
- }
- movePoint(p: Point) {
- this._p = p;
- this.update();
- }
-}
-
-export class CustomPrimitivesTimeAxisView extends CustomPrimitivesAxisView {
- update() {
- const timeScale = this._source.chart.timeScale();
- this._pos = timeScale.timeToCoordinate(this._p.time);
- }
- text() {
- return this._source.options.timeLabelFormatter(this._p.time);
- }
-}
-
-export class CustomPrimitivesPriceAxisView extends CustomPrimitivesAxisView {
- update() {
- const series = this._source.series;
- this._pos = series.priceToCoordinate(this._p.price);
- }
- text() {
- return this._source.options.priceLabelFormatter(this._p.price);
- }
-}
diff --git a/lwc-plugin-custom-primitives/src/custom-primitives.ts b/lwc-plugin-custom-primitives/src/custom-primitives.ts
deleted file mode 100644
index 1dc770b..0000000
--- a/lwc-plugin-custom-primitives/src/custom-primitives.ts
+++ /dev/null
@@ -1,139 +0,0 @@
-import { AutoscaleInfo, Logical, Time, DataChangedScope } from 'lightweight-charts';
-import {
- CustomPrimitivesPriceAxisPaneView,
- CustomPrimitivesTimeAxisPaneView,
-} from './axis-pane-view';
-import { CustomPrimitivesPriceAxisView, CustomPrimitivesTimeAxisView } from './axis-view';
-import { Point, CustomPrimitivesDataSource } from './data-source';
-import { CustomPrimitivesOptions, defaultOptions } from './options';
-import { CustomPrimitivesPaneView } from './pane-view';
-import { PluginBase } from './plugin-base';
-
-export class CustomPrimitives
- extends PluginBase
- implements CustomPrimitivesDataSource
-{
- _options: CustomPrimitivesOptions;
- _p1: Point;
- _p2: Point;
- _paneViews: CustomPrimitivesPaneView[];
- _timeAxisViews: CustomPrimitivesTimeAxisView[];
- _priceAxisViews: CustomPrimitivesPriceAxisView[];
- _priceAxisPaneViews: CustomPrimitivesPriceAxisPaneView[];
- _timeAxisPaneViews: CustomPrimitivesTimeAxisPaneView[];
-
- constructor(
- p1: Point,
- p2: Point,
- options: Partial = {}
- ) {
- super();
- this._p1 = p1;
- this._p2 = p2;
- this._options = {
- ...defaultOptions,
- ...options,
- };
- this._paneViews = [new CustomPrimitivesPaneView(this)];
- this._timeAxisViews = [
- new CustomPrimitivesTimeAxisView(this, p1),
- new CustomPrimitivesTimeAxisView(this, p2),
- ];
- this._priceAxisViews = [
- new CustomPrimitivesPriceAxisView(this, p1),
- new CustomPrimitivesPriceAxisView(this, p2),
- ];
- this._priceAxisPaneViews = [new CustomPrimitivesPriceAxisPaneView(this, true)];
- this._timeAxisPaneViews = [new CustomPrimitivesTimeAxisPaneView(this, false)];
- }
-
- updateAllViews() {
- //* Use this method to update any data required by the
- //* views to draw.
- this._paneViews.forEach(pw => pw.update());
- this._timeAxisViews.forEach(pw => pw.update());
- this._priceAxisViews.forEach(pw => pw.update());
- this._priceAxisPaneViews.forEach(pw => pw.update());
- this._timeAxisPaneViews.forEach(pw => pw.update());
- }
-
- priceAxisViews() {
- //* Labels rendered on the price scale
- return this._priceAxisViews;
- }
-
- timeAxisViews() {
- //* labels rendered on the time scale
- return this._timeAxisViews;
- }
-
- paneViews() {
- //* rendering on the main chart pane
- return this._paneViews;
- }
-
- priceAxisPaneViews() {
- //* rendering on the price scale
- return this._priceAxisPaneViews;
- }
-
- timeAxisPaneViews() {
- //* rendering on the time scale
- return this._timeAxisPaneViews;
- }
-
- autoscaleInfo(
- startTimePoint: Logical,
- endTimePoint: Logical
- ): AutoscaleInfo | null {
- //* Use this method to provide autoscale information if your primitive
- //* should have the ability to remain in view automatically.
- if (
- this._timeCurrentlyVisible(this.p1.time, startTimePoint, endTimePoint) ||
- this._timeCurrentlyVisible(this.p2.time, startTimePoint, endTimePoint)
- ) {
- return {
- priceRange: {
- minValue: Math.min(this.p1.price, this.p2.price),
- maxValue: Math.max(this.p1.price, this.p2.price),
- },
- };
- }
- return null;
- }
-
- dataUpdated(scope: DataChangedScope): void {
- //* This method will be called by PluginBase when the data on the
- //* series has changed.
- }
-
- _timeCurrentlyVisible(
- time: Time,
- startTimePoint: Logical,
- endTimePoint: Logical
- ): boolean {
- const ts = this.chart.timeScale();
- const coordinate = ts.timeToCoordinate(time);
- if (coordinate === null) return false;
- const logical = ts.coordinateToLogical(coordinate);
- if (logical === null) return false;
- return logical <= endTimePoint && logical >= startTimePoint;
- }
-
- public get options(): CustomPrimitivesOptions {
- return this._options;
- }
-
- applyOptions(options: Partial) {
- this._options = { ...this._options, ...options };
- this.requestUpdate();
- }
-
- public get p1(): Point {
- return this._p1;
- }
-
- public get p2(): Point {
- return this._p2;
- }
-}
diff --git a/lwc-plugin-custom-primitives/src/data-source.ts b/lwc-plugin-custom-primitives/src/data-source.ts
deleted file mode 100644
index 6c14142..0000000
--- a/lwc-plugin-custom-primitives/src/data-source.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import {
- IChartApi,
- ISeriesApi,
- SeriesOptionsMap,
- Time,
-} from 'lightweight-charts';
-import { CustomPrimitivesOptions } from './options';
-
-export interface Point {
- time: Time;
- price: number;
-}
-
-export interface CustomPrimitivesDataSource {
- chart: IChartApi;
- series: ISeriesApi;
- options: CustomPrimitivesOptions;
- p1: Point;
- p2: Point;
-}
diff --git a/lwc-plugin-custom-primitives/src/example/example.ts b/lwc-plugin-custom-primitives/src/example/example.ts
deleted file mode 100644
index a884dbe..0000000
--- a/lwc-plugin-custom-primitives/src/example/example.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { createChart } from 'lightweight-charts';
-import { generateLineData } from '../sample-data';
-import { CustomPrimitives } from '../custom-primitives';
-
-const chart = ((window as unknown as any).chart = createChart('chart', {
- autoSize: true,
-}));
-
-const lineSeries = chart.addLineSeries({
- color: '#000000',
-});
-const data = generateLineData();
-lineSeries.setData(data);
-
-const time1 = data[data.length - 50].time;
-const time2 = data[data.length - 10].time;
-
-const primitive = new CustomPrimitives(
- { price: 100, time: time1 },
- { price: 500, time: time2 }
-);
-
-lineSeries.attachPrimitive(primitive);
diff --git a/lwc-plugin-custom-primitives/src/example/index.html b/lwc-plugin-custom-primitives/src/example/index.html
deleted file mode 100644
index ed1334b..0000000
--- a/lwc-plugin-custom-primitives/src/example/index.html
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
- Template Drawing Primitive Plugin Example
-
-
-
-
-
-
-
diff --git a/lwc-plugin-custom-primitives/src/helpers/assertions.ts b/lwc-plugin-custom-primitives/src/helpers/assertions.ts
deleted file mode 100644
index e68742f..0000000
--- a/lwc-plugin-custom-primitives/src/helpers/assertions.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * Ensures that value is defined.
- * Throws if the value is undefined, returns the original value otherwise.
- *
- * @param value - The value, or undefined.
- * @returns The passed value, if it is not undefined
- */
-export function ensureDefined(value: undefined): never;
-export function ensureDefined(value: T | undefined): T;
-export function ensureDefined(value: T | undefined): T {
- if (value === undefined) {
- throw new Error('Value is undefined');
- }
-
- return value;
-}
-
-/**
- * Ensures that value is not null.
- * Throws if the value is null, returns the original value otherwise.
- *
- * @param value - The value, or null.
- * @returns The passed value, if it is not null
- */
-export function ensureNotNull(value: null): never;
-export function ensureNotNull(value: T | null): T;
-export function ensureNotNull(value: T | null): T {
- if (value === null) {
- throw new Error('Value is null');
- }
-
- return value;
-}
diff --git a/lwc-plugin-custom-primitives/src/helpers/dimensions/common.ts b/lwc-plugin-custom-primitives/src/helpers/dimensions/common.ts
deleted file mode 100644
index 394c6bb..0000000
--- a/lwc-plugin-custom-primitives/src/helpers/dimensions/common.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-export interface BitmapPositionLength {
- /** coordinate for use with a bitmap rendering scope */
- position: number;
- /** length for use with a bitmap rendering scope */
- length: number;
-}
diff --git a/lwc-plugin-custom-primitives/src/helpers/dimensions/crosshair-width.ts b/lwc-plugin-custom-primitives/src/helpers/dimensions/crosshair-width.ts
deleted file mode 100644
index 9d14991..0000000
--- a/lwc-plugin-custom-primitives/src/helpers/dimensions/crosshair-width.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * Default grid / crosshair line width in Bitmap sizing
- * @param horizontalPixelRatio - horizontal pixel ratio
- * @returns default grid / crosshair line width in Bitmap sizing
- */
-export function gridAndCrosshairBitmapWidth(
- horizontalPixelRatio: number
-): number {
- return Math.max(1, Math.floor(horizontalPixelRatio));
-}
-
-/**
- * Default grid / crosshair line width in Media sizing
- * @param horizontalPixelRatio - horizontal pixel ratio
- * @returns default grid / crosshair line width in Media sizing
- */
-export function gridAndCrosshairMediaWidth(
- horizontalPixelRatio: number
-): number {
- return (
- gridAndCrosshairBitmapWidth(horizontalPixelRatio) / horizontalPixelRatio
- );
-}
diff --git a/lwc-plugin-custom-primitives/src/helpers/dimensions/full-width.ts b/lwc-plugin-custom-primitives/src/helpers/dimensions/full-width.ts
deleted file mode 100644
index 6f4d40d..0000000
--- a/lwc-plugin-custom-primitives/src/helpers/dimensions/full-width.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-import { BitmapPositionLength } from './common';
-
-/**
- * Calculates the position and width which will completely full the space for the bar.
- * Useful if you want to draw something that will not have any gaps between surrounding bars.
- * @param xMedia - x coordinate of the bar defined in media sizing
- * @param halfBarSpacingMedia - half the width of the current barSpacing (un-rounded)
- * @param horizontalPixelRatio - horizontal pixel ratio
- * @returns position and width which will completely full the space for the bar
- */
-export function fullBarWidth(
- xMedia: number,
- halfBarSpacingMedia: number,
- horizontalPixelRatio: number
-): BitmapPositionLength {
- const fullWidthLeftMedia = xMedia - halfBarSpacingMedia;
- const fullWidthRightMedia = xMedia + halfBarSpacingMedia;
- const fullWidthLeftBitmap = Math.round(
- fullWidthLeftMedia * horizontalPixelRatio
- );
- const fullWidthRightBitmap = Math.round(
- fullWidthRightMedia * horizontalPixelRatio
- );
- const fullWidthBitmap = fullWidthRightBitmap - fullWidthLeftBitmap;
- return {
- position: fullWidthLeftBitmap,
- length: fullWidthBitmap,
- };
-}
diff --git a/lwc-plugin-custom-primitives/src/helpers/dimensions/positions.ts b/lwc-plugin-custom-primitives/src/helpers/dimensions/positions.ts
deleted file mode 100644
index a021b07..0000000
--- a/lwc-plugin-custom-primitives/src/helpers/dimensions/positions.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-import { BitmapPositionLength } from './common';
-
-function centreOffset(lineBitmapWidth: number): number {
- return Math.floor(lineBitmapWidth * 0.5);
-}
-
-/**
- * Calculates the bitmap position for an item with a desired length (height or width), and centred according to
- * an position coordinate defined in media sizing.
- * @param positionMedia - position coordinate for the bar (in media coordinates)
- * @param pixelRatio - pixel ratio. Either horizontal for x positions, or vertical for y positions
- * @param desiredWidthMedia - desired width (in media coordinates)
- * @returns Position of of the start point and length dimension.
- */
-export function positionsLine(
- positionMedia: number,
- pixelRatio: number,
- desiredWidthMedia: number = 1,
- widthIsBitmap?: boolean
-): BitmapPositionLength {
- const scaledPosition = Math.round(pixelRatio * positionMedia);
- const lineBitmapWidth = widthIsBitmap
- ? desiredWidthMedia
- : Math.round(desiredWidthMedia * pixelRatio);
- const offset = centreOffset(lineBitmapWidth);
- const position = scaledPosition - offset;
- return { position, length: lineBitmapWidth };
-}
-
-/**
- * Determines the bitmap position and length for a dimension of a shape to be drawn.
- * @param position1Media - media coordinate for the first point
- * @param position2Media - media coordinate for the second point
- * @param pixelRatio - pixel ratio for the corresponding axis (vertical or horizontal)
- * @returns Position of of the start point and length dimension.
- */
-export function positionsBox(
- position1Media: number,
- position2Media: number,
- pixelRatio: number
-): BitmapPositionLength {
- const scaledPosition1 = Math.round(pixelRatio * position1Media);
- const scaledPosition2 = Math.round(pixelRatio * position2Media);
- return {
- position: Math.min(scaledPosition1, scaledPosition2),
- length: Math.abs(scaledPosition2 - scaledPosition1) + 1,
- };
-}
diff --git a/lwc-plugin-custom-primitives/src/helpers/time.ts b/lwc-plugin-custom-primitives/src/helpers/time.ts
deleted file mode 100644
index ed65475..0000000
--- a/lwc-plugin-custom-primitives/src/helpers/time.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { Time, isUTCTimestamp, isBusinessDay } from 'lightweight-charts';
-
-export function convertTime(t: Time): number {
- if (isUTCTimestamp(t)) return t * 1000;
- if (isBusinessDay(t)) return new Date(t.year, t.month, t.day).valueOf();
- const [year, month, day] = t.split('-').map(parseInt);
- return new Date(year, month, day).valueOf();
-}
-
-export function displayTime(time: Time): string {
- if (typeof time == 'string') return time;
- const date = isBusinessDay(time)
- ? new Date(time.year, time.month, time.day)
- : new Date(time * 1000);
- return date.toLocaleDateString();
-}
-
-export function formattedDateAndTime(timestamp: number | undefined): [string, string] {
- if (!timestamp) return ['', ''];
- const dateObj = new Date(timestamp);
-
- // Format date string
- const year = dateObj.getFullYear();
- const month = dateObj.toLocaleString('default', { month: 'short' });
- const date = dateObj.getDate().toString().padStart(2, '0');
- const formattedDate = `${date} ${month} ${year}`;
-
- // Format time string
- const hours = dateObj.getHours().toString().padStart(2, '0');
- const minutes = dateObj.getMinutes().toString().padStart(2, '0');
- const formattedTime = `${hours}:${minutes}`;
-
- return [formattedDate, formattedTime];
-}
diff --git a/lwc-plugin-custom-primitives/src/options.ts b/lwc-plugin-custom-primitives/src/options.ts
deleted file mode 100644
index 04fa40c..0000000
--- a/lwc-plugin-custom-primitives/src/options.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import { Time, isBusinessDay } from 'lightweight-charts';
-
-export interface CustomPrimitivesOptions {
- //* Define the options for the primitive.
- fillColor: string;
- labelColor: string;
- labelTextColor: string;
- showLabels: boolean;
- priceLabelFormatter: (price: number) => string;
- timeLabelFormatter: (time: Time) => string;
-}
-
-export const defaultOptions: CustomPrimitivesOptions = {
- //* Define the default values for all the primitive options.
- fillColor: 'rgba(200, 50, 100, 0.75)',
- labelColor: 'rgba(200, 50, 100, 1)',
- labelTextColor: 'white',
- showLabels: true,
- priceLabelFormatter: (price: number) => price.toFixed(2),
- timeLabelFormatter: (time: Time) => {
- if (typeof time == 'string') return time;
- const date = isBusinessDay(time)
- ? new Date(time.year, time.month, time.day)
- : new Date(time * 1000);
- return date.toLocaleDateString();
- },
-} as const;
diff --git a/lwc-plugin-custom-primitives/src/pane-renderer.ts b/lwc-plugin-custom-primitives/src/pane-renderer.ts
deleted file mode 100644
index a69c6cd..0000000
--- a/lwc-plugin-custom-primitives/src/pane-renderer.ts
+++ /dev/null
@@ -1,46 +0,0 @@
-import { CanvasRenderingTarget2D } from 'fancy-canvas';
-import { ISeriesPrimitivePaneRenderer } from 'lightweight-charts';
-import { ViewPoint } from './pane-view';
-import { positionsBox } from './helpers/dimensions/positions';
-
-export class CustomPrimitivesPaneRenderer implements ISeriesPrimitivePaneRenderer {
- _p1: ViewPoint;
- _p2: ViewPoint;
- _fillColor: string;
-
- constructor(p1: ViewPoint, p2: ViewPoint, fillColor: string) {
- this._p1 = p1;
- this._p2 = p2;
- this._fillColor = fillColor;
- }
-
- draw(target: CanvasRenderingTarget2D) {
- target.useBitmapCoordinateSpace(scope => {
- if (
- this._p1.x === null ||
- this._p1.y === null ||
- this._p2.x === null ||
- this._p2.y === null
- )
- return;
- const ctx = scope.context;
- const horizontalPositions = positionsBox(
- this._p1.x,
- this._p2.x,
- scope.horizontalPixelRatio
- );
- const verticalPositions = positionsBox(
- this._p1.y,
- this._p2.y,
- scope.verticalPixelRatio
- );
- ctx.fillStyle = this._fillColor;
- ctx.fillRect(
- horizontalPositions.position,
- verticalPositions.position,
- horizontalPositions.length,
- verticalPositions.length
- );
- });
- }
-}
diff --git a/lwc-plugin-custom-primitives/src/pane-view.ts b/lwc-plugin-custom-primitives/src/pane-view.ts
deleted file mode 100644
index 810538c..0000000
--- a/lwc-plugin-custom-primitives/src/pane-view.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-import { Coordinate, ISeriesPrimitivePaneView } from 'lightweight-charts';
-import { CustomPrimitivesPaneRenderer } from './pane-renderer';
-import { CustomPrimitivesDataSource } from './data-source';
-
-export interface ViewPoint {
- x: Coordinate | null;
- y: Coordinate | null;
-}
-
-export class CustomPrimitivesPaneView implements ISeriesPrimitivePaneView {
- _source: CustomPrimitivesDataSource;
- _p1: ViewPoint = { x: null, y: null };
- _p2: ViewPoint = { x: null, y: null };
-
- constructor(source: CustomPrimitivesDataSource) {
- this._source = source;
- }
-
- update() {
- const series = this._source.series;
- const y1 = series.priceToCoordinate(this._source.p1.price);
- const y2 = series.priceToCoordinate(this._source.p2.price);
- const timeScale = this._source.chart.timeScale();
- const x1 = timeScale.timeToCoordinate(this._source.p1.time);
- const x2 = timeScale.timeToCoordinate(this._source.p2.time);
- this._p1 = { x: x1, y: y1 };
- this._p2 = { x: x2, y: y2 };
- }
-
- renderer() {
- return new CustomPrimitivesPaneRenderer(
- this._p1,
- this._p2,
- this._source.options.fillColor
- );
- }
-}
diff --git a/lwc-plugin-custom-primitives/src/plugin-base.ts b/lwc-plugin-custom-primitives/src/plugin-base.ts
deleted file mode 100644
index def9684..0000000
--- a/lwc-plugin-custom-primitives/src/plugin-base.ts
+++ /dev/null
@@ -1,56 +0,0 @@
-import {
- DataChangedScope,
- IChartApi,
- ISeriesApi,
- ISeriesPrimitive,
- SeriesAttachedParameter,
- SeriesOptionsMap,
- Time,
-} from 'lightweight-charts';
-import { ensureDefined } from './helpers/assertions';
-
-//* PluginBase is a useful base to build a plugin upon which
-//* already handles creating getters for the chart and series,
-//* and provides a requestUpdate method.
-export abstract class PluginBase implements ISeriesPrimitive