@data-vision/interactive-chart 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +144 -0
- package/build/bar.cjs +1 -0
- package/build/bar.d.ts +10 -0
- package/build/bar.js +44 -0
- package/build/base/chart.d.ts +137 -0
- package/build/base/color.d.ts +18 -0
- package/build/base/dragable.d.ts +29 -0
- package/build/base/field.d.ts +18 -0
- package/build/base/index.d.ts +5 -0
- package/build/base/point.d.ts +15 -0
- package/build/brush/brush.d.ts +49 -0
- package/build/brush/crop.d.ts +12 -0
- package/build/brush/index.d.ts +2 -0
- package/build/brush/range.d.ts +6 -0
- package/build/brush/thumb.d.ts +6 -0
- package/build/chart-Cj4Fiwnb.js +965 -0
- package/build/chart-Dr9ZOezr.cjs +1 -0
- package/build/dataset-Bv37sY1L.js +18 -0
- package/build/dataset-D4KLCpTU.cjs +1 -0
- package/build/heatmap-BlMqliH5.cjs +1 -0
- package/build/heatmap-Br4YjrBg.js +859 -0
- package/build/heatmap.cjs +1 -0
- package/build/heatmap.d.ts +91 -0
- package/build/heatmap.js +5 -0
- package/build/index.cjs +1 -0
- package/build/index.d.ts +7 -0
- package/build/index.js +20 -0
- package/build/legend/index.d.ts +1 -0
- package/build/legend/legend.d.ts +20 -0
- package/build/line.cjs +1 -0
- package/build/line.d.ts +11 -0
- package/build/line.js +23 -0
- package/build/otdr.cjs +1 -0
- package/build/otdr.d.ts +186 -0
- package/build/otdr.js +417 -0
- package/build/tooltip/crosshair.d.ts +20 -0
- package/build/tooltip/index.d.ts +2 -0
- package/build/tooltip/tooltip.d.ts +12 -0
- package/build/type.d.ts +78 -0
- package/build/util/dataset.d.ts +6 -0
- package/build/util/date.d.ts +1 -0
- package/build/util/env.d.ts +15 -0
- package/build/util/event.d.ts +6 -0
- package/build/util/index.d.ts +6 -0
- package/build/util/numeric.d.ts +26 -0
- package/build/util/style.d.ts +3 -0
- package/package.json +53 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./heatmap-BlMqliH5.cjs");require("./chart-Dr9ZOezr.cjs");module.exports=e.HeatMap;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Dragable, Point } from './base';
|
|
2
|
+
import type { Edge, RangeValue, InteractEvent, DragUpdateContext, CSSProperties } from './type';
|
|
3
|
+
interface Config {
|
|
4
|
+
xUnit: string;
|
|
5
|
+
gridColor: string;
|
|
6
|
+
textColor: string;
|
|
7
|
+
accentColor: string;
|
|
8
|
+
fontSize: number;
|
|
9
|
+
cropStyle: CSSProperties;
|
|
10
|
+
tooltipStyle: CSSProperties;
|
|
11
|
+
maxCacheSize: number;
|
|
12
|
+
legend: boolean;
|
|
13
|
+
grid: Edge;
|
|
14
|
+
}
|
|
15
|
+
declare class HeatMap extends Dragable<RangeValue> {
|
|
16
|
+
private root;
|
|
17
|
+
private resizeObserver;
|
|
18
|
+
private dpr;
|
|
19
|
+
private canvasContainer;
|
|
20
|
+
private canvas;
|
|
21
|
+
static version: string;
|
|
22
|
+
static config: Config;
|
|
23
|
+
private width;
|
|
24
|
+
private height;
|
|
25
|
+
private context;
|
|
26
|
+
private dataCache;
|
|
27
|
+
private dataLength;
|
|
28
|
+
private precision;
|
|
29
|
+
private cropMode;
|
|
30
|
+
private cropOrigin;
|
|
31
|
+
private cropOffset;
|
|
32
|
+
private gradient;
|
|
33
|
+
private brush;
|
|
34
|
+
private legend;
|
|
35
|
+
private tooltip;
|
|
36
|
+
private crop;
|
|
37
|
+
private crosshair;
|
|
38
|
+
private grid;
|
|
39
|
+
private static defaultRange;
|
|
40
|
+
private static defaultDataRange;
|
|
41
|
+
static xMinScale: number;
|
|
42
|
+
static xMaxScale: number;
|
|
43
|
+
static axisXScaleOffset: Point;
|
|
44
|
+
static axisYScaleOffset: Point;
|
|
45
|
+
private static brushHeight;
|
|
46
|
+
private range;
|
|
47
|
+
private dataRange;
|
|
48
|
+
private raf;
|
|
49
|
+
constructor(root: HTMLElement);
|
|
50
|
+
get $root(): HTMLElement;
|
|
51
|
+
get $canvas(): HTMLCanvasElement;
|
|
52
|
+
private updateGrid;
|
|
53
|
+
private get maxCacheSize();
|
|
54
|
+
private get drawRatio();
|
|
55
|
+
private brushLabelFrom;
|
|
56
|
+
private brushLabelTo;
|
|
57
|
+
reset(): void;
|
|
58
|
+
private setCursor;
|
|
59
|
+
protected getOffset(event: InteractEvent): Point;
|
|
60
|
+
onStart(event: InteractEvent): void;
|
|
61
|
+
onUpdate({ value, delta }: DragUpdateContext<RangeValue>): RangeValue;
|
|
62
|
+
private get scale();
|
|
63
|
+
private get cropRange();
|
|
64
|
+
private updateCrop;
|
|
65
|
+
onEnd(): void;
|
|
66
|
+
protected get rect(): Point;
|
|
67
|
+
protected get drawWidth(): number;
|
|
68
|
+
protected get drawHeight(): number;
|
|
69
|
+
private get pointRange();
|
|
70
|
+
private onBrushValueChange;
|
|
71
|
+
private onLegendValueChange;
|
|
72
|
+
setDataLength(value: number): void;
|
|
73
|
+
setPrecision(value: number): void;
|
|
74
|
+
setData(data: Uint8ClampedArray): void;
|
|
75
|
+
setDataFilter([min, max]: RangeValue): void;
|
|
76
|
+
private updateDraw;
|
|
77
|
+
private drawAxisX;
|
|
78
|
+
private drawScaleX;
|
|
79
|
+
private drawAxisY;
|
|
80
|
+
private drawScaleY;
|
|
81
|
+
private onMouseMove;
|
|
82
|
+
private onMouseLeave;
|
|
83
|
+
private onDblClick;
|
|
84
|
+
private onDprChange;
|
|
85
|
+
private initCanvas;
|
|
86
|
+
private updateCanvas;
|
|
87
|
+
private onResize;
|
|
88
|
+
resize(): void;
|
|
89
|
+
dispose(): void;
|
|
90
|
+
}
|
|
91
|
+
export default HeatMap;
|
package/build/heatmap.js
ADDED
package/build/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./heatmap-BlMqliH5.cjs"),a=require("./line.cjs"),o=require("./bar.cjs"),t=require("./otdr.cjs"),e=require("./chart-Dr9ZOezr.cjs");exports.Gradient=r.Gradient;exports.HeatMap=r.HeatMap;exports.RgbColor=r.RgbColor;exports.Line=a.default;exports.Bar=o.default;Object.defineProperty(exports,"MeasureMode",{enumerable:!0,get:()=>t.MeasureMode});exports.Otdr=t.default;exports.Chart=e.Chart;exports.ControlType=e.ControlType;exports.Dragable=e.Dragable;exports.DragableThumb=e.DragableThumb;exports.Field=e.Field;exports.Point=e.Point;
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as HeatMap } from './heatmap';
|
|
2
|
+
export type * from './heatmap';
|
|
3
|
+
export { default as Line } from './line';
|
|
4
|
+
export { default as Bar } from './bar';
|
|
5
|
+
export { default as Otdr, MeasureMode, type OtdrEvent, type OtdrDataSet, type OnMeasureChange, type MeasureChangeData } from './otdr';
|
|
6
|
+
export * from './base';
|
|
7
|
+
export * from './type';
|
package/build/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { G as e, H as o, R as t } from "./heatmap-Br4YjrBg.js";
|
|
2
|
+
import { default as f } from "./line.js";
|
|
3
|
+
import { default as d } from "./bar.js";
|
|
4
|
+
import { MeasureMode as m, default as b } from "./otdr.js";
|
|
5
|
+
import { C as x, a as i, D as n, b as C, F as g, P as D } from "./chart-Cj4Fiwnb.js";
|
|
6
|
+
export {
|
|
7
|
+
d as Bar,
|
|
8
|
+
x as Chart,
|
|
9
|
+
i as ControlType,
|
|
10
|
+
n as Dragable,
|
|
11
|
+
C as DragableThumb,
|
|
12
|
+
g as Field,
|
|
13
|
+
e as Gradient,
|
|
14
|
+
o as HeatMap,
|
|
15
|
+
f as Line,
|
|
16
|
+
m as MeasureMode,
|
|
17
|
+
b as Otdr,
|
|
18
|
+
D as Point,
|
|
19
|
+
t as RgbColor
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './legend';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Brush } from '../brush';
|
|
2
|
+
import type { CSSProperties, DragableContext, DragUpdateContext, RangeValue } from '../type';
|
|
3
|
+
export declare class Legend extends Brush {
|
|
4
|
+
private _root;
|
|
5
|
+
private _container;
|
|
6
|
+
private colors;
|
|
7
|
+
protected thumbSize: number;
|
|
8
|
+
constructor(root: HTMLElement, { initValue, colors, style }: {
|
|
9
|
+
initValue?: RangeValue;
|
|
10
|
+
colors: string[];
|
|
11
|
+
style?: CSSProperties;
|
|
12
|
+
});
|
|
13
|
+
protected get trackHeight(): number;
|
|
14
|
+
private setContainer;
|
|
15
|
+
private createScale;
|
|
16
|
+
protected onUpdate({ delta }: DragUpdateContext<number>): number;
|
|
17
|
+
protected getStyle({ value }: DragableContext<number>): string;
|
|
18
|
+
protected getRangeStyle({ value }: DragableContext<RangeValue>): string;
|
|
19
|
+
dispose(): void;
|
|
20
|
+
}
|
package/build/line.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const q=require("./dataset-D4KLCpTU.cjs"),c=require("./chart-Dr9ZOezr.cjs");class s extends c.Chart{draw(e){const{data:o,xMin:r,xMax:f,yMin:u,scale:a,grid:h,rect:y,sample:p}=this;if(o)for(const i of o){const{color:M,data:g,lineWidth:m=1,precision:l=1}=i;e.lineWidth=m,e.strokeStyle=M,e.beginPath();const{start:T,end:v,loop:S}=q.fitDataset(g,l,[r,f]);S(a.x,(t,b)=>{const C=i.data.slice(t,Math.min(t+b,v+1)),k=p(C,s.config.dataSampleMethod),n=h.left+(l*t-r)/a.x,d=y.y-(k-u)/a.y;t===T?e.moveTo(n,d):e.lineTo(n,d)}),e.stroke()}}}exports.ControlType=c.ControlType;exports.default=s;
|
package/build/line.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Chart } from './base';
|
|
2
|
+
import type { Dataset } from './type';
|
|
3
|
+
export { ControlType, type Dataset } from './type';
|
|
4
|
+
export interface LineDataSet extends Dataset {
|
|
5
|
+
color: string;
|
|
6
|
+
lineWidth?: number;
|
|
7
|
+
}
|
|
8
|
+
declare class Line extends Chart<LineDataSet[]> {
|
|
9
|
+
protected draw(context: CanvasRenderingContext2D): void;
|
|
10
|
+
}
|
|
11
|
+
export default Line;
|
package/build/line.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { f as W } from "./dataset-Bv37sY1L.js";
|
|
2
|
+
import { C as b } from "./chart-Cj4Fiwnb.js";
|
|
3
|
+
import { a as j } from "./chart-Cj4Fiwnb.js";
|
|
4
|
+
class d extends b {
|
|
5
|
+
// @override
|
|
6
|
+
draw(a) {
|
|
7
|
+
const { data: s, xMin: e, xMax: f, yMin: c, scale: o, grid: m, rect: p, sample: h } = this;
|
|
8
|
+
if (s)
|
|
9
|
+
for (const r of s) {
|
|
10
|
+
const { color: y, data: M, lineWidth: g = 1, precision: i = 1 } = r;
|
|
11
|
+
a.lineWidth = g, a.strokeStyle = y, a.beginPath();
|
|
12
|
+
const { start: x, end: C, loop: T } = W(M, i, [e, f]);
|
|
13
|
+
T(o.x, (t, k) => {
|
|
14
|
+
const v = r.data.slice(t, Math.min(t + k, C + 1)), S = h(v, d.config.dataSampleMethod), n = m.left + (i * t - e) / o.x, l = p.y - (S - c) / o.y;
|
|
15
|
+
t === x ? a.moveTo(n, l) : a.lineTo(n, l);
|
|
16
|
+
}), a.stroke();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
j as ControlType,
|
|
22
|
+
d as default
|
|
23
|
+
};
|
package/build/otdr.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const M=require("./chart-Dr9ZOezr.cjs"),C=require("./dataset-D4KLCpTU.cjs");exports.LineStyle=void 0;(function(u){u[u.solid=0]="solid",u[u.dashed=1]="dashed"})(exports.LineStyle||(exports.LineStyle={}));exports.MeasureMode=void 0;(function(u){u[u.two_points=0]="two_points",u[u.four_points=1]="four_points",u[u.none=2]="none"})(exports.MeasureMode||(exports.MeasureMode={}));var c;(function(u){u.line_A="A",u.line_B="B",u.line_a="a",u.line_b="b"})(c||(c={}));class y{constructor(e,t,i){Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"color",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"style",{enumerable:!0,configurable:!0,writable:!0,value:exports.LineStyle.solid}),Object.defineProperty(this,"location",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"order",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=e,this.color=t,i&&(this.style=i),this.location=0,this.order=y.orderMap.get(e)??0}copy(){return new y(this.name,this.color).copyWith({location:this.location,style:this.style})}copyWith({name:e,color:t,style:i,location:s,order:n}){return this.name=e??this.name,this.color=t??this.color,this.style=i??this.style,this.location=s??this.location,this.order=n??this.order,this}}Object.defineProperty(y,"orderMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map});class b extends M.Chart{static initConfig(){const e=M.Chart.config;e.measureLine={a:{location:"10%",order:0,color:"#f00",style:exports.LineStyle.dashed},A:{location:"25%",order:1,color:"#f00",style:exports.LineStyle.solid},B:{location:"75%",order:2,color:"cyan",style:exports.LineStyle.solid},b:{location:"90%",order:3,color:"cyan",style:exports.LineStyle.dashed}},e.grid.top=15,b.config=e}constructor(e){super(e),Object.defineProperty(this,"activeEvent",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"measureMode",{enumerable:!0,configurable:!0,writable:!0,value:exports.MeasureMode.none}),Object.defineProperty(this,"measureLine_a",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"measureLine_A",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"measureLine_B",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"measureLine_b",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"activeMeasureLine",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"draggedMeasureLine",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"onMeasureChange",{enumerable:!0,configurable:!0,writable:!0,value:null}),this.measureLine_a=this.createMeasureLine(c.line_a),this.measureLine_A=this.createMeasureLine(c.line_A),this.measureLine_B=this.createMeasureLine(c.line_B),this.measureLine_b=this.createMeasureLine(c.line_b)}createMeasureLine(e){const{color:t,style:i,order:s}=b.config.measureLine[e];return y.orderMap.set(e,s),new y(e,t,i)}mergeDataset(e){const{lineWidth:t=1,precision:i=1,events:s=[],...n}=e;return{lineWidth:t,precision:i,events:s,...n}}loopDatasets(e,t){if(e)for(const i of e){const s=this.mergeDataset(i);t(s)}}draw(e){const{width:t,height:i,data:s,scale:n,sample:r}=this;this.loopDatasets(s,({color:o,data:a,lineWidth:d,precision:f})=>{e.lineWidth=d,e.strokeStyle=o,e.beginPath();const{start:h,end:v,loop:m}=C.fitDataset(a,f,this.xRange);m(n.x,(l,p)=>{const w=a.slice(l,Math.min(l+p,v+1)),x=r(w,b.config.dataSampleMethod),{x:L,y:g}=this.getDataOffset({x:l,y:x},f);l===h?e.moveTo(L,g):e.lineTo(L,g)}),e.stroke(),this.snapshot=e.getImageData(0,0,t,i)})}get measureEnabled(){return this.measureMode!==exports.MeasureMode.none}drawAnnotations(e){this.measureEnabled&&this.drawMeasureLines()}getDataOffset({x:e,y:t},i=1){const{scaleGrid:s,rect:n,xMin:r,yMin:o,scale:a}=this;return{x:s.left+(i*e-r)/a.x,y:n.y-(t-o)/a.y}}getEventOffset({offset:e,size:t}){const{x:i,y:s}=this.getDataOffset(e),{width:n,height:r}=t;return{x:i-n/2,y:s-r*2}}drawSnapshot(e){this.loopDatasets(this.data,t=>{this.drawEvents(t)})}drawEvents(e){const{context:t,activeEvent:i,dpr:s,xMin:n,xMax:r,yMin:o,yMax:a,xUnit:d,yUnit:f}=this,{events:h,color:v}=e;for(const m of h){const{x:l,y:p}=this.getEventOffset(m),{key:w,value:x,offset:L,size:g,image:j,renderLabel:_,renderValue:O}=m;if(t.drawImage(j,l,p,g.width,g.height),i?.key===w){t.strokeStyle=v,t.lineWidth=1,t.strokeRect(l,p,g.width,g.height);const[P,D]=[l+g.width/2,p+g.height];t.beginPath(),t.moveTo(P,D),t.lineTo(P,D+32),t.stroke();const E=16*s.value;t.save(),t.fillStyle=v;const S={xMin:n,xMax:r,yMin:o,yMax:a,xUnit:d,yUnit:f,event:m,dataset:e};t.fillText(`${O?O(x,S):x}`,l,p-E*2),t.fillText(`${_?_(L.x,S):L.x}`,l,p-E),t.restore()}}}setActiveEvent(e){if(this.data){let t=null;if(e!==null)for(const i of this.data){let s=!1;const{events:n}=this.mergeDataset(i);for(const r of n)if(r.key===e){t=r,s=!0;break}if(s)break}if(t?.key!==this.activeEvent?.key){if(t){const{x:i,y:s}=t.offset;this.setCenter(i,s)}return this.activeEvent=t,this.shouldUpdate=!0,!0}}return!1}get measureLines(){const{measureMode:e,measureLine_A:t,measureLine_B:i,measureLine_a:s,measureLine_b:n}=this;let r=[];return e===exports.MeasureMode.two_points?r=[t,i]:e===exports.MeasureMode.four_points&&(r=[t,s,n,i]),r}onMouseMove(e){super.onMouseMove(e);const{data:t,context:i,dpr:s,dragging:n}=this,r=this.getOffset(e).multiply(s.value);let o=null;if(this.loopDatasets(t,({events:a})=>{for(const d of a){const{x:f,y:h}=this.getEventOffset(d),{width:v,height:m}=d.size,l=new Path2D;l.moveTo(f-v/2,h-m/2),l.rect(f,h,v,m),i.isPointInPath(l,r.x,r.y)&&(o=d)}}),this.activeEvent!==o&&(this.activeEvent=o,this.useSnapshot=this.shouldUpdate=!0),!n){const a=this.findNearMeasureLine(r);a!==this.activeMeasureLine&&(this.setCursor(a?"ew-resize":void 0),this.activeMeasureLine=a,this.useSnapshot=this.shouldUpdate=!0)}}get $measureLines(){const{measureLines:e,draggedMeasureLine:t}=this;return t!==null?[...e.filter(({name:i})=>i!==t.name),t]:e}drawMeasureLines(){for(const e of this.$measureLines)this.drawMeasureLine(e)}getLineOffset(e){const{x:t}=this.getDataOffset({x:e.location,y:0});return t}get xRange(){return this.bounds.x}drawMeasureLine(e){const{context:t,rect:i,scaleGrid:s,activeMeasureLine:n}=this,r=M.clampInRange(e.location,this.xRange);r!==e.location&&(e.location=r,this.emitMeasureChangeEvent(n));const{name:o,color:a,style:d}=e,{width:f}=M.measureText(t,o),h=this.getLineOffset(e);t.save(),t.fillStyle=a,t.fillText(o,h-f/2,7),t.beginPath(),t.moveTo(h,s.top),t.lineTo(h,i.y),t.strokeStyle=a,d===exports.LineStyle.dashed&&t.setLineDash([2,2]),t.lineWidth=n?.name===o?2:1,t.stroke(),t.restore()}getMeasureLineDefaultAttrs(e){const{location:t,...i}=b.config.measureLine[e];let s=0;return typeof t=="number"?s=t:s=this.getRatioOffset(+t.replace(/%$/,"")/100).x,{name:e,location:s,...i}}get measureLinesMoved(){return this.measureLines.some(e=>{const{location:t}=this.getMeasureLineDefaultAttrs(e.name);return e.location!==t})}initMeasureLine(e,t){const i=this.getMeasureLineDefaultAttrs(t);e.copyWith(i)}initMeasureLines(e){const t=e??this.measureMode;switch(t){case exports.MeasureMode.two_points:case exports.MeasureMode.four_points:this.initMeasureLine(this.measureLine_A,c.line_A),this.initMeasureLine(this.measureLine_B,c.line_B),t===exports.MeasureMode.four_points&&(this.initMeasureLine(this.measureLine_a,c.line_a),this.initMeasureLine(this.measureLine_b,c.line_b));break;case exports.MeasureMode.none:}}get measureValue(){return this.measureLines.map(({name:e,location:t})=>({name:e,location:t}))}setMeasureMode(e){this.measureMode!==e&&(this.initMeasureLines(e),this.measureMode=e,this.shouldUpdate=!0)}fitDatasets(e=!0){if(this.data){let t=0,i=0,s=0;for(const n of this.data){const{data:r,precision:o}=this.mergeDataset(n);t=Math.max(t,r.length*o),s=M.getMin([s,...r]),i=M.getMax([i,...r])}t>0&&(this.xMin=0,this.xMax=t,this.yMin=s,this.yMax=i,this.shouldUpdate=e)}}reset(){super.reset(()=>{this.fitDatasets(!1),this.measureEnabled&&this.measureLinesMoved&&(this.initMeasureLines(),this.emitMeasureChangeEvent(null))})}findNearMeasureLine(e){for(let t=this.$measureLines.length-1;t>=0;t--){const i=this.$measureLines[t],s=this.getLineOffset(i);if(e.x<s+5&&e.x>s-5)return i}return null}onStart(e){e.stopPropagation,this.activeMeasureLine!==null?this.dragging=!0:super.onStart(e)}emitMeasureChangeEvent(e){const{measureLines:t}=this,i=t.map(({name:s,location:n})=>({name:s,location:e?.name===s?e.location:n}));this.onMeasureChange?.({current:e,context:i})}updateMeasureLines(){const{activeMeasureLine:e,measureLines:t}=this;if(e!==null){const{name:i,location:s,order:n}=e;for(const r of t)r.name!==i&&(n>r.order&&s<r.location||n<r.order&&s>r.location)&&(r.location=e.location)}}onUpdate(e){const{activeMeasureLine:t,scale:i,dpr:s}=this;if(t!==null){const{x:n}=e.delta.multiply(i).multiply(s.value),{name:r,location:o}=t,a=M.clampInRange(o+n,this.xRange);return a!==o&&(t.location=a,this.updateMeasureLines(),this.emitMeasureChangeEvent({name:r,location:a}),this.useSnapshot=this.shouldUpdate=!0),this.draggedMeasureLine=t,e.value}return super.onUpdate(e)}}Object.defineProperty(b,"version",{enumerable:!0,configurable:!0,writable:!0,value:"0.2.0"});b.initConfig();exports.ControlType=M.ControlType;exports.default=b;
|
package/build/otdr.d.ts
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { Chart, type Config } from './base';
|
|
2
|
+
import type { Dataset, DragUpdateContext, Offset, Size, PartialRequired, InteractEvent } from './type';
|
|
3
|
+
export { ControlType } from './type';
|
|
4
|
+
/**
|
|
5
|
+
* 线条样式
|
|
6
|
+
*/
|
|
7
|
+
export declare enum LineStyle {
|
|
8
|
+
/**
|
|
9
|
+
* 实线
|
|
10
|
+
*/
|
|
11
|
+
solid = 0,
|
|
12
|
+
/**
|
|
13
|
+
* 虚线
|
|
14
|
+
*/
|
|
15
|
+
dashed = 1
|
|
16
|
+
}
|
|
17
|
+
type MergedOtdrDataset = PartialRequired<OtdrDataSet, 'lineWidth' | 'precision' | 'events'>;
|
|
18
|
+
interface EventRenderContext {
|
|
19
|
+
xUnit: string;
|
|
20
|
+
yUnit: string;
|
|
21
|
+
event: OtdrEvent;
|
|
22
|
+
dataset: MergedOtdrDataset;
|
|
23
|
+
xMin: number;
|
|
24
|
+
xMax: number;
|
|
25
|
+
yMin: number;
|
|
26
|
+
yMax: number;
|
|
27
|
+
}
|
|
28
|
+
interface OtdrEventRender {
|
|
29
|
+
(value: number, context: EventRenderContext): number | string;
|
|
30
|
+
}
|
|
31
|
+
export interface OtdrEvent {
|
|
32
|
+
/**
|
|
33
|
+
* 用于标识唯一性
|
|
34
|
+
*/
|
|
35
|
+
key: string | number;
|
|
36
|
+
/**
|
|
37
|
+
* 事件的值
|
|
38
|
+
*/
|
|
39
|
+
value: number;
|
|
40
|
+
/**
|
|
41
|
+
* 标题渲染函数
|
|
42
|
+
*/
|
|
43
|
+
renderLabel?: OtdrEventRender;
|
|
44
|
+
/**
|
|
45
|
+
* 事件值渲染函数
|
|
46
|
+
*/
|
|
47
|
+
renderValue?: OtdrEventRender;
|
|
48
|
+
/**
|
|
49
|
+
* 原始坐标
|
|
50
|
+
*/
|
|
51
|
+
offset: Offset;
|
|
52
|
+
/**
|
|
53
|
+
* 绘制尺寸
|
|
54
|
+
*/
|
|
55
|
+
size: Size;
|
|
56
|
+
/**
|
|
57
|
+
* 图片源
|
|
58
|
+
*/
|
|
59
|
+
image: CanvasImageSource;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 测量模式/方法
|
|
63
|
+
*/
|
|
64
|
+
export declare enum MeasureMode {
|
|
65
|
+
/**
|
|
66
|
+
* 两点法 A_B
|
|
67
|
+
*/
|
|
68
|
+
two_points = 0,
|
|
69
|
+
/**
|
|
70
|
+
* 四点法 A_a_b_B
|
|
71
|
+
*/
|
|
72
|
+
four_points = 1,
|
|
73
|
+
/**
|
|
74
|
+
* 不适用
|
|
75
|
+
*/
|
|
76
|
+
none = 2
|
|
77
|
+
}
|
|
78
|
+
declare enum MeasureLineName {
|
|
79
|
+
line_A = "A",
|
|
80
|
+
line_B = "B",
|
|
81
|
+
line_a = "a",
|
|
82
|
+
line_b = "b"
|
|
83
|
+
}
|
|
84
|
+
export interface MeasureValue {
|
|
85
|
+
name: MeasureLineName;
|
|
86
|
+
location: number;
|
|
87
|
+
}
|
|
88
|
+
interface MeasureLineMeta {
|
|
89
|
+
color: string;
|
|
90
|
+
style: LineStyle;
|
|
91
|
+
order: number;
|
|
92
|
+
}
|
|
93
|
+
interface MeasureLineAttrs extends MeasureValue, MeasureLineMeta {
|
|
94
|
+
}
|
|
95
|
+
declare class MeasureLine implements MeasureLineAttrs {
|
|
96
|
+
/**
|
|
97
|
+
* 测量线的标题, 绘制在测量线的某一侧
|
|
98
|
+
*/
|
|
99
|
+
name: MeasureLineName;
|
|
100
|
+
/**
|
|
101
|
+
* 测量线的颜色
|
|
102
|
+
*/
|
|
103
|
+
color: string;
|
|
104
|
+
/**
|
|
105
|
+
* 线条样式
|
|
106
|
+
*/
|
|
107
|
+
style: LineStyle;
|
|
108
|
+
/**
|
|
109
|
+
* 测量线与纵坐标平行, 位置即为横坐标的偏移量
|
|
110
|
+
*/
|
|
111
|
+
location: number;
|
|
112
|
+
/**
|
|
113
|
+
* 测量线的排序, 越小越靠前
|
|
114
|
+
*/
|
|
115
|
+
order: number;
|
|
116
|
+
static orderMap: Map<MeasureLineName, number>;
|
|
117
|
+
constructor(name: MeasureLineName, color: string, style?: LineStyle);
|
|
118
|
+
copy(): MeasureLine;
|
|
119
|
+
copyWith({ name, color, style, location, order }: Partial<MeasureLineAttrs>): this;
|
|
120
|
+
}
|
|
121
|
+
type LocationValue = number | `${number}%`;
|
|
122
|
+
interface MeasureLineConfig extends MeasureLineMeta {
|
|
123
|
+
location: LocationValue;
|
|
124
|
+
}
|
|
125
|
+
export interface MeasureChangeData {
|
|
126
|
+
current: MeasureValue | null;
|
|
127
|
+
context: MeasureValue[];
|
|
128
|
+
}
|
|
129
|
+
export interface OnMeasureChange {
|
|
130
|
+
(data: MeasureChangeData): void;
|
|
131
|
+
}
|
|
132
|
+
interface OtdrConfig extends Config {
|
|
133
|
+
measureLine: Record<MeasureLineName, MeasureLineConfig>;
|
|
134
|
+
}
|
|
135
|
+
export interface OtdrDataSet extends Dataset {
|
|
136
|
+
color: string;
|
|
137
|
+
lineWidth?: number;
|
|
138
|
+
events?: OtdrEvent[];
|
|
139
|
+
}
|
|
140
|
+
declare class Otdr extends Chart<OtdrDataSet[]> {
|
|
141
|
+
protected activeEvent: OtdrEvent | null;
|
|
142
|
+
protected measureMode: MeasureMode;
|
|
143
|
+
private measureLine_a;
|
|
144
|
+
private measureLine_A;
|
|
145
|
+
private measureLine_B;
|
|
146
|
+
private measureLine_b;
|
|
147
|
+
private activeMeasureLine;
|
|
148
|
+
private draggedMeasureLine;
|
|
149
|
+
onMeasureChange: OnMeasureChange | null;
|
|
150
|
+
static version: string;
|
|
151
|
+
static config: OtdrConfig;
|
|
152
|
+
static initConfig(): void;
|
|
153
|
+
constructor(root: HTMLElement);
|
|
154
|
+
private createMeasureLine;
|
|
155
|
+
protected mergeDataset(dataset: OtdrDataSet): MergedOtdrDataset;
|
|
156
|
+
protected loopDatasets(data: OtdrDataSet[] | null, iterator: (dataset: MergedOtdrDataset) => void): void;
|
|
157
|
+
protected draw(context: CanvasRenderingContext2D): void;
|
|
158
|
+
protected get measureEnabled(): boolean;
|
|
159
|
+
protected drawAnnotations(_context: CanvasRenderingContext2D): void;
|
|
160
|
+
protected getDataOffset({ x, y }: Offset, precision?: number): Offset;
|
|
161
|
+
private getEventOffset;
|
|
162
|
+
protected drawSnapshot(_context: CanvasRenderingContext2D): void;
|
|
163
|
+
private drawEvents;
|
|
164
|
+
setActiveEvent(key: OtdrEvent['key'] | null): boolean;
|
|
165
|
+
protected get measureLines(): MeasureLine[];
|
|
166
|
+
protected onMouseMove(event: MouseEvent): void;
|
|
167
|
+
protected get $measureLines(): MeasureLine[];
|
|
168
|
+
protected drawMeasureLines(): void;
|
|
169
|
+
private getLineOffset;
|
|
170
|
+
private get xRange();
|
|
171
|
+
private drawMeasureLine;
|
|
172
|
+
protected getMeasureLineDefaultAttrs(name: MeasureLineName): MeasureLineAttrs;
|
|
173
|
+
protected get measureLinesMoved(): boolean;
|
|
174
|
+
private initMeasureLine;
|
|
175
|
+
private initMeasureLines;
|
|
176
|
+
get measureValue(): MeasureValue[];
|
|
177
|
+
setMeasureMode(mode: MeasureMode): void;
|
|
178
|
+
fitDatasets(update?: boolean): void;
|
|
179
|
+
reset(): void;
|
|
180
|
+
private findNearMeasureLine;
|
|
181
|
+
protected onStart(event: InteractEvent): void;
|
|
182
|
+
private emitMeasureChangeEvent;
|
|
183
|
+
private updateMeasureLines;
|
|
184
|
+
protected onUpdate(event: DragUpdateContext<number>): number;
|
|
185
|
+
}
|
|
186
|
+
export default Otdr;
|