Comparing version 0.1.0-beta.21 to 0.1.0-beta.22
@@ -1,10 +0,11 @@ | ||
import { AnnotationLineOption } from '../types/index.js'; | ||
import { AnnotationLineOption, AnnotationOption } from '../types/index.js'; | ||
import { BaseComponent } from './base.js'; | ||
export declare class Annotation extends BaseComponent { | ||
export declare class Annotation extends BaseComponent<AnnotationOption> { | ||
get name(): string; | ||
annotationFn: Array<(u: uPlot) => void>; | ||
annotationXFn: Array<(u: uPlot) => void>; | ||
annotationYFn: Array<(u: uPlot) => void>; | ||
render(): void; | ||
update(): void; | ||
lineX(options: AnnotationLineOption): this; | ||
updateLineX(options?: AnnotationLineOption): void; | ||
private updateLineX; | ||
lineY(options: AnnotationLineOption): void; | ||
@@ -11,0 +12,0 @@ getTextPosition(position: 'left' | 'right' | string, start: number, textWidth: number, width: number): number; |
import { StyleSheet, css } from 'aphrodite/no-important.js'; | ||
import { get, merge } from 'lodash'; | ||
import { get, merge, set } from 'lodash'; | ||
import { BaseComponent } from './base.js'; | ||
@@ -22,3 +22,4 @@ const TEXT_SPACE = 4; | ||
super(...arguments); | ||
this.annotationFn = []; | ||
this.annotationXFn = []; | ||
this.annotationYFn = []; | ||
} | ||
@@ -32,2 +33,10 @@ get name() { | ||
this.option = get(opt, this.name, {}); | ||
const x = get(this.option, 'lineX'); | ||
const y = get(this.option, 'lineY'); | ||
if (x) { | ||
this.lineX(x); | ||
} | ||
if (y) { | ||
this.lineY(y); | ||
} | ||
} | ||
@@ -38,2 +47,6 @@ update() { | ||
lineX(options) { | ||
if (this.annotationXFn.length) { | ||
this.updateLineX(options); | ||
return this; | ||
} | ||
this.ctrl.setOption([this.name, 'lineX'], options); | ||
@@ -45,3 +58,3 @@ const fn = (u) => { | ||
stroke: this.ctrl.getTheme().colorVar['n-6'], | ||
}, } = options || get(this.option, 'lineX'); | ||
}, } = get(this.option, 'lineX'); | ||
let ctx = u.ctx; | ||
@@ -58,3 +71,3 @@ ctx.save(); | ||
ctx.stroke(); | ||
if (text?.content) { | ||
if (x0 && text?.content) { | ||
const markE = u.over.querySelector('.u-mark-x'); | ||
@@ -74,3 +87,3 @@ const markLabelE = u.over.querySelector('.u-mark-x-label'); | ||
} | ||
labelEl.textContent = text.content; | ||
labelEl.textContent = String(text.content); | ||
Object.assign(labelEl.style, text.style || {}); | ||
@@ -84,7 +97,9 @@ const labelStyle = getComputedStyle(labelEl); | ||
}; | ||
this.annotationFn.push(fn); | ||
this.annotationXFn.push(fn); | ||
return this; | ||
} | ||
updateLineX(options) { | ||
this.ctrl.setOption([this.name, 'lineX'], merge(get(this.option, 'lineX'), options)); | ||
const opt = merge(get(this.option, 'lineX'), options); | ||
set(this.option, 'lineX', opt); | ||
this.ctrl.setOption([this.name, 'lineX'], opt); | ||
this.ctrl.redraw(); | ||
@@ -112,9 +127,9 @@ } | ||
if (text?.content) { | ||
const { width, actualBoundingBoxDescent } = ctx.measureText(text.content); | ||
const { width, actualBoundingBoxDescent } = ctx.measureText(String(text.content)); | ||
ctx.fillStyle = 'red'; | ||
ctx.fillText(text.content, this.getTextPosition(text.position, x0, width, u.bbox.width), y1 - (actualBoundingBoxDescent + TEXT_SPACE)); | ||
ctx.fillText(String(text.content), this.getTextPosition(text.position, x0, width, u.bbox.width), y1 - (actualBoundingBoxDescent + TEXT_SPACE)); | ||
} | ||
ctx.restore(); | ||
}; | ||
this.annotationFn.push(fn); | ||
this.annotationYFn.push(fn); | ||
} | ||
@@ -136,3 +151,3 @@ getTextPosition(position = 'left', start, textWidth, width) { | ||
(u) => { | ||
this.annotationFn.forEach(fn => fn(u)); | ||
[...this.annotationXFn, ...this.annotationYFn].forEach(fn => fn(u)); | ||
}, | ||
@@ -139,0 +154,0 @@ ], |
@@ -51,3 +51,4 @@ import { get, isNumber } from 'lodash'; | ||
: Math.min(dataMin, min || 0); | ||
return [minV, Math.max(dataMax, max || 0)]; | ||
const maxV = Math.max(dataMax, max || 1); | ||
return [minV, maxV]; | ||
}, | ||
@@ -54,0 +55,0 @@ }; |
@@ -0,1 +1,2 @@ | ||
/// <reference types="web" /> | ||
import { View } from '../../chart/view.js'; | ||
@@ -2,0 +3,0 @@ import { ShapeOptions } from '../../types/index.js'; |
@@ -130,3 +130,3 @@ /// <reference types="react" resolution-mode="require"/> | ||
position?: 'left' | 'right' | string; | ||
content: string; | ||
content: unknown; | ||
style?: object; | ||
@@ -133,0 +133,0 @@ border?: { |
{ | ||
"name": "zz-chart", | ||
"version": "0.1.0-beta.21", | ||
"version": "0.1.0-beta.22", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "author": "Alauda", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
490423
12872