mirror of
https://github.com/idrawjs/idraw
synced 2026-05-24 10:08:34 +00:00
fix: add idraw default opts
This commit is contained in:
parent
686ed54b54
commit
82f7095ae8
4 changed files with 40 additions and 28 deletions
|
|
@ -1,7 +1,7 @@
|
|||
# @idraw/core
|
||||
|
||||
* [] License text in JS result
|
||||
* [] Options default data
|
||||
* [x] License text in JS result
|
||||
* [x] Options default data
|
||||
* [] Support gradient color
|
||||
* [] Listen keyboard action
|
||||
* [] Keep all num two decimals
|
||||
|
|
|
|||
11
packages/idraw/src/config.ts
Normal file
11
packages/idraw/src/config.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { PrivateOptions } from './types';
|
||||
|
||||
export const defaultOptions: PrivateOptions = {
|
||||
width: 400,
|
||||
height: 300,
|
||||
contextWidth: 400,
|
||||
contextHeight: 300,
|
||||
devicePixelRatio: 1,
|
||||
onlyRender: false,
|
||||
maxRecords: 10,
|
||||
}
|
||||
|
|
@ -1,22 +1,9 @@
|
|||
import Core from '@idraw/core';
|
||||
import {
|
||||
TypeData,
|
||||
TypeCoreOptions,
|
||||
TypeConfig,
|
||||
TypeData, TypeConfig,
|
||||
} from '@idraw/types';
|
||||
|
||||
type Options = {
|
||||
maxRecords?: number;
|
||||
} & TypeCoreOptions;
|
||||
|
||||
type PrivateOptions = {
|
||||
maxRecords: number;
|
||||
} & Options;
|
||||
|
||||
type Record = {
|
||||
data: TypeData;
|
||||
time: number;
|
||||
}
|
||||
import { Options, Record, PrivateOptions } from './types';
|
||||
import { defaultOptions } from './config';
|
||||
|
||||
const _opts = Symbol('_opts');
|
||||
const _doRecords = Symbol('_doRecords');
|
||||
|
|
@ -33,12 +20,12 @@ class IDraw extends Core {
|
|||
|
||||
constructor(mount: HTMLDivElement, opts: Options, config?: TypeConfig) {
|
||||
super(mount, {
|
||||
width: opts.width,
|
||||
height: opts.height,
|
||||
contextWidth: opts.contextWidth,
|
||||
contextHeight: opts.contextHeight,
|
||||
devicePixelRatio: opts.devicePixelRatio,
|
||||
onlyRender: opts.onlyRender
|
||||
width: opts.width || defaultOptions.width,
|
||||
height: opts.height || defaultOptions.height,
|
||||
contextWidth: opts.contextWidth || defaultOptions.contextWidth,
|
||||
contextHeight: opts.contextHeight || defaultOptions.contextHeight,
|
||||
devicePixelRatio: opts.devicePixelRatio || defaultOptions.devicePixelRatio,
|
||||
onlyRender: opts.onlyRender || defaultOptions.onlyRender,
|
||||
}, config || {});
|
||||
this[_opts] = this._createOpts(opts);
|
||||
this[_initEvent]();
|
||||
|
|
@ -109,10 +96,7 @@ class IDraw extends Core {
|
|||
}
|
||||
|
||||
private _createOpts(opts: Options): PrivateOptions {
|
||||
const defaultOpts = {
|
||||
maxRecords: 10,
|
||||
};
|
||||
return { ...defaultOpts, ...opts };
|
||||
return { ...defaultOptions, ...opts };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
17
packages/idraw/src/types.ts
Normal file
17
packages/idraw/src/types.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import {
|
||||
TypeData,
|
||||
TypeCoreOptions,
|
||||
} from '@idraw/types';
|
||||
|
||||
export type Options = {
|
||||
maxRecords?: number;
|
||||
} & TypeCoreOptions;
|
||||
|
||||
export type PrivateOptions = {
|
||||
maxRecords: number;
|
||||
} & Options;
|
||||
|
||||
export type Record = {
|
||||
data: TypeData;
|
||||
time: number;
|
||||
}
|
||||
Loading…
Reference in a new issue