move to iife rather than es, add support for Wx and streamlit
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import { Drawing } from "../drawing/drawing";
|
||||
import { DrawingOptions } from "../drawing/options";
|
||||
import { GlobalParams } from "../general/global-params";
|
||||
|
||||
declare const window: GlobalParams;
|
||||
@ -23,7 +24,7 @@ export class ColorPicker {
|
||||
private rgba: number[] | undefined;
|
||||
|
||||
constructor(saveDrawings: Function,
|
||||
private colorOption: string,
|
||||
private colorOption: keyof DrawingOptions,
|
||||
) {
|
||||
this.saveDrawings = saveDrawings
|
||||
|
||||
@ -121,7 +122,9 @@ export class ColorPicker {
|
||||
}
|
||||
openMenu(rect: DOMRect) {
|
||||
if (!Drawing.lastHoveredObject) return;
|
||||
this.rgba = ColorPicker.extractRGBA(Drawing.lastHoveredObject._options[this.colorOption])
|
||||
this.rgba = ColorPicker.extractRGBA(
|
||||
Drawing.lastHoveredObject._options[this.colorOption] as string
|
||||
)
|
||||
this.opacity = this.rgba[3];
|
||||
this._updateOpacitySlider();
|
||||
this._div.style.top = (rect.top-30)+'px'
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { Drawing } from "../drawing/drawing";
|
||||
import { DrawingTool } from "../drawing/drawing-tool";
|
||||
import { DrawingOptions } from "../drawing/options";
|
||||
import { GlobalParams } from "../general/global-params";
|
||||
import { ColorPicker } from "./color-picker";
|
||||
import { StylePicker } from "./style-picker";
|
||||
@ -64,7 +65,7 @@ export class ContextMenu {
|
||||
for (const optionName of Object.keys(Drawing.hoveredObject._options)) {
|
||||
let subMenu;
|
||||
if (optionName.toLowerCase().includes('color')) {
|
||||
subMenu = new ColorPicker(this.saveDrawings, optionName);
|
||||
subMenu = new ColorPicker(this.saveDrawings, optionName as keyof DrawingOptions);
|
||||
} else if (optionName === 'lineStyle') {
|
||||
subMenu = new StylePicker(this.saveDrawings)
|
||||
} else continue;
|
||||
|
||||
@ -1,10 +1,3 @@
|
||||
import { Box } from "../box/box";
|
||||
import { HorizontalLine } from "../horizontal-line/horizontal-line";
|
||||
import { RayLine } from "../horizontal-line/ray-line";
|
||||
import { TrendLine } from "../trend-line/trend-line";
|
||||
import { VerticalLine } from "../vertical-line/vertical-line";
|
||||
import { Table } from "./table";
|
||||
|
||||
export interface GlobalParams extends Window {
|
||||
pane: paneStyle; // TODO shouldnt need this cause of css variables
|
||||
handlerInFocus: string;
|
||||
@ -12,15 +5,6 @@ export interface GlobalParams extends Window {
|
||||
containerDiv: HTMLElement;
|
||||
setCursor: Function;
|
||||
cursor: string;
|
||||
Handler: any;
|
||||
Table: typeof Table;
|
||||
|
||||
HorizontalLine: typeof HorizontalLine;
|
||||
TrendLine: typeof TrendLine;
|
||||
Box: typeof Box;
|
||||
RayLine: typeof RayLine;
|
||||
VerticalLine: typeof VerticalLine;
|
||||
|
||||
}
|
||||
|
||||
interface paneStyle {
|
||||
@ -57,13 +41,11 @@ export function globalParamInit() {
|
||||
document.body.style.cursor = window.cursor;
|
||||
}
|
||||
window.cursor = 'default';
|
||||
window.Table = Table;
|
||||
}
|
||||
|
||||
window.HorizontalLine = HorizontalLine;
|
||||
window.TrendLine = TrendLine;
|
||||
window.Box = Box;
|
||||
window.RayLine = RayLine;
|
||||
window.VerticalLine = VerticalLine;
|
||||
export const setCursor = (type: string | undefined) => {
|
||||
if (type) window.cursor = type;
|
||||
document.body.style.cursor = window.cursor;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -308,13 +308,9 @@ export class Handler {
|
||||
chart.div.appendChild(searchWindow);
|
||||
|
||||
chart.commandFunctions.push((event: KeyboardEvent) => {
|
||||
console.log('1')
|
||||
if (window.handlerInFocus !== chart.id) return false
|
||||
console.log(searchWindow.style)
|
||||
if (searchWindow.style.display === 'none') {
|
||||
console.log('3')
|
||||
if (/^[a-zA-Z0-9]$/.test(event.key)) {
|
||||
console.log('4')
|
||||
searchWindow.style.display = 'flex';
|
||||
sBox.focus();
|
||||
return true
|
||||
@ -370,5 +366,3 @@ export class Handler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.Handler = Handler;
|
||||
8
src/general/index.ts
Normal file
8
src/general/index.ts
Normal file
@ -0,0 +1,8 @@
|
||||
// TODO this won't be necessary with ws
|
||||
|
||||
export * from './handler';
|
||||
export * from './global-params';
|
||||
export * from './legend';
|
||||
export * from './table';
|
||||
export * from './toolbox';
|
||||
export * from './topbar';
|
||||
@ -23,7 +23,7 @@ export class ToolBox {
|
||||
private static readonly HORZ_SVG: string = '<rect x="4" y="14" width="9" height="1"/><rect x="16" y="14" width="9" height="1"/><path d="M11.67,14.5l2.83,2.83l2.83-2.83l-2.83-2.83L11.67,14.5z M15.91,14.5l-1.41,1.41l-1.41-1.41l1.41-1.41L15.91,14.5z"/>';
|
||||
private static readonly RAY_SVG: string = '<rect x="8" y="14" width="17" height="1"/><path d="M3.67,14.5l2.83,2.83l2.83-2.83L6.5,11.67L3.67,14.5z M7.91,14.5L6.5,15.91L5.09,14.5l1.41-1.41L7.91,14.5z"/>';
|
||||
private static readonly BOX_SVG: string = '<rect x="8" y="6" width="12" height="1"/><rect x="9" y="22" width="11" height="1"/><path d="M3.67,6.5L6.5,9.33L9.33,6.5L6.5,3.67L3.67,6.5z M7.91,6.5L6.5,7.91L5.09,6.5L6.5,5.09L7.91,6.5z"/><path d="M19.67,6.5l2.83,2.83l2.83-2.83L22.5,3.67L19.67,6.5z M23.91,6.5L22.5,7.91L21.09,6.5l1.41-1.41L23.91,6.5z"/><path d="M19.67,22.5l2.83,2.83l2.83-2.83l-2.83-2.83L19.67,22.5z M23.91,22.5l-1.41,1.41l-1.41-1.41l1.41-1.41L23.91,22.5z"/><path d="M3.67,22.5l2.83,2.83l2.83-2.83L6.5,19.67L3.67,22.5z M7.91,22.5L6.5,23.91L5.09,22.5l1.41-1.41L7.91,22.5z"/><rect x="22" y="9" width="1" height="11"/><rect x="6" y="9" width="1" height="11"/>';
|
||||
// private static readonly VERT_SVG: string = '';
|
||||
private static readonly VERT_SVG: string = ToolBox.RAY_SVG;
|
||||
|
||||
div: HTMLDivElement;
|
||||
private activeIcon: Icon | null = null;
|
||||
@ -65,14 +65,14 @@ export class ToolBox {
|
||||
this.buttons.push(this._makeToolBoxElement(HorizontalLine, 'KeyH', ToolBox.HORZ_SVG));
|
||||
this.buttons.push(this._makeToolBoxElement(RayLine, 'KeyR', ToolBox.RAY_SVG));
|
||||
this.buttons.push(this._makeToolBoxElement(Box, 'KeyB', ToolBox.BOX_SVG));
|
||||
this.buttons.push(this._makeToolBoxElement(VerticalLine, 'KeyV', ToolBox.RAY_SVG));
|
||||
this.buttons.push(this._makeToolBoxElement(VerticalLine, 'KeyV', ToolBox.VERT_SVG, true));
|
||||
for (const button of this.buttons) {
|
||||
div.appendChild(button);
|
||||
}
|
||||
return div
|
||||
}
|
||||
|
||||
private _makeToolBoxElement(DrawingType: new (...args: any[]) => Drawing, keyCmd: string, paths: string) {
|
||||
private _makeToolBoxElement(DrawingType: new (...args: any[]) => Drawing, keyCmd: string, paths: string, rotate=false) {
|
||||
const elem = document.createElement('div')
|
||||
elem.classList.add("toolbox-button");
|
||||
|
||||
@ -101,6 +101,13 @@ export class ToolBox {
|
||||
}
|
||||
return false;
|
||||
})
|
||||
|
||||
if (rotate == true) {
|
||||
svg.style.transform = 'rotate(90deg)';
|
||||
svg.style.transformBox = 'fill-box';
|
||||
svg.style.transformOrigin = 'center';
|
||||
}
|
||||
|
||||
return elem
|
||||
}
|
||||
|
||||
|
||||
@ -82,7 +82,6 @@ export class HorizontalLine extends Drawing {
|
||||
protected _childHandleMouseUpInteraction = () => {
|
||||
this._handleMouseUpInteraction();
|
||||
if (!this._callbackName) return;
|
||||
console.log(window.callbackFunction);
|
||||
window.callbackFunction(`${this._callbackName}_~_${this._point.price.toFixed(8)}`);
|
||||
}
|
||||
}
|
||||
6
src/index.ts
Normal file
6
src/index.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export * from './general';
|
||||
export * from './horizontal-line/horizontal-line';
|
||||
export * from './vertical-line/vertical-line';
|
||||
export * from './box/box';
|
||||
export * from './trend-line/trend-line';
|
||||
export * from './vertical-line/vertical-line';
|
||||
@ -87,7 +87,6 @@ export class VerticalLine extends Drawing {
|
||||
protected _childHandleMouseUpInteraction = () => {
|
||||
this._handleMouseUpInteraction();
|
||||
if (!this._callbackName) return;
|
||||
console.log(window.callbackFunction);
|
||||
window.callbackFunction(`${this._callbackName}_~_${this._point.price.toFixed(8)}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user