Skip to content

Commit

Permalink
fix: interface
Browse files Browse the repository at this point in the history
  • Loading branch information
stagas committed Jan 22, 2022
1 parent 365396f commit a640be5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const MAX_ZOOM = 100_000
* for example acquiring it through a `querySelector()`.
*/
export interface HTMLPlotElement {
/** Width of plot */
width: number
/** Height of plot */
height: number
/** The pixel ratio. Defaults to `window.devicePixelRatio` */
pixelRatio: number
/** Array-like number data to plot */
Expand Down Expand Up @@ -68,7 +72,7 @@ export class PlotElement extends HTMLElement {
]
}

state: HTMLPlotElement = {
state: Partial<HTMLPlotElement> = {
pixelRatio: window.devicePixelRatio,
data: [] as number[],
zoom: 1,
Expand All @@ -93,7 +97,7 @@ export class PlotElement extends HTMLElement {
this.addEventListener(
'wheel',
e => {
const zoom = +this.state.zoom - Math.min(50, this.state.zoom ** 1.15) * 0.0006 * e.deltaY
const zoom = +this.state.zoom! - Math.min(50, this.state.zoom! ** 1.15) * 0.0006 * e.deltaY

this.setAttribute('zoom', '' + zoom)
},
Expand All @@ -108,19 +112,19 @@ export class PlotElement extends HTMLElement {
}

draw() {
this.context.fillStyle = this.state.background
this.context.fillStyle = this.state.background!
this.context.fillRect(0, 0, this.canvas.width, this.canvas.height)
drawLine({ context: this.context, ...this.state })
}

attributeChangedCallback(name: string, _: string, value: string | number) {
switch (name) {
case 'width':
this.canvas.width = +value * this.state.pixelRatio
this.canvas.width = +value * this.state.pixelRatio!
this.canvas.style.width = value + 'px'
break
case 'height':
this.canvas.height = +value * this.state.pixelRatio
this.canvas.height = +value * this.state.pixelRatio!
this.canvas.style.height = value + 'px'
break
case 'zoom':
Expand Down

0 comments on commit a640be5

Please sign in to comment.