svelteplot 0.4.6 → 0.4.7-pr-216.0
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/dist/core/Plot.svelte +50 -28
- package/dist/helpers/colors.d.ts +1 -1
- package/dist/helpers/index.d.ts +2 -2
- package/dist/helpers/scales.d.ts +2 -2
- package/dist/helpers/scales.js +21 -10
- package/dist/helpers/typeChecks.d.ts +4 -4
- package/dist/marks/AreaX.svelte.d.ts +2 -1
- package/dist/marks/AreaY.svelte.d.ts +2 -1
- package/dist/marks/AxisX.svelte.d.ts +1 -1
- package/dist/marks/AxisY.svelte.d.ts +1 -1
- package/dist/marks/BarX.svelte.d.ts +1 -1
- package/dist/marks/BollingerX.svelte.d.ts +2 -74
- package/dist/marks/BollingerY.svelte.d.ts +2 -74
- package/dist/marks/ColorLegend.svelte +2 -2
- package/dist/marks/CustomMark.svelte.d.ts +2 -81
- package/dist/marks/DifferenceY.svelte.d.ts +7 -67
- package/dist/marks/Line.svelte.d.ts +2 -2
- package/dist/marks/LineX.svelte.d.ts +2 -1
- package/dist/marks/LineY.svelte.d.ts +2 -1
- package/dist/marks/helpers/CanvasLayer.svelte +1 -1
- package/dist/marks/helpers/RectPath.svelte.d.ts +3 -63
- package/dist/marks/helpers/Regression.svelte +1 -1
- package/dist/regression/exponential.d.ts +17 -0
- package/dist/regression/exponential.js +56 -0
- package/dist/regression/index.d.ts +10 -0
- package/dist/regression/index.js +10 -0
- package/dist/regression/linear.d.ts +17 -0
- package/dist/regression/linear.js +59 -0
- package/dist/regression/loess.d.ts +14 -0
- package/dist/regression/loess.js +122 -0
- package/dist/regression/logarithmic.d.ts +20 -0
- package/dist/regression/logarithmic.js +60 -0
- package/dist/regression/polynomial.d.ts +21 -0
- package/dist/regression/polynomial.js +160 -0
- package/dist/regression/power.d.ts +18 -0
- package/dist/regression/power.js +56 -0
- package/dist/regression/quadratic.d.ts +19 -0
- package/dist/regression/quadratic.js +70 -0
- package/dist/regression/types.d.ts +4 -0
- package/dist/regression/types.js +1 -0
- package/dist/regression/utils/determination.d.ts +6 -0
- package/dist/regression/utils/determination.js +16 -0
- package/dist/regression/utils/geometry.d.ts +9 -0
- package/dist/regression/utils/geometry.js +12 -0
- package/dist/regression/utils/interpose.d.ts +6 -0
- package/dist/regression/utils/interpose.js +37 -0
- package/dist/regression/utils/median.d.ts +4 -0
- package/dist/regression/utils/median.js +8 -0
- package/dist/regression/utils/ols.d.ts +6 -0
- package/dist/regression/utils/ols.js +9 -0
- package/dist/regression/utils/points.d.ts +11 -0
- package/dist/regression/utils/points.js +45 -0
- package/dist/transforms/bollinger.d.ts +1 -67
- package/dist/transforms/group.d.ts +4 -12
- package/dist/transforms/interval.d.ts +2 -124
- package/dist/transforms/recordize.d.ts +1 -4
- package/dist/transforms/select.d.ts +7 -434
- package/dist/transforms/sort.d.ts +3 -246
- package/dist/transforms/stack.d.ts +3 -23
- package/dist/transforms/window.d.ts +2 -130
- package/dist/types/plot.d.ts +14 -7
- package/dist/types/scale.d.ts +6 -0
- package/package.json +128 -128
|
@@ -1,83 +1,23 @@
|
|
|
1
1
|
import type { ChannelAccessor, CurveName, DataRecord } from '../types/index.js';
|
|
2
2
|
import type { CurveFactory } from 'd3-shape';
|
|
3
3
|
declare class __sveltets_Render<Datum extends DataRecord> {
|
|
4
|
-
props(): Omit<
|
|
5
|
-
filter?: import("../types/index.js").ConstantAccessor<boolean, Datum>;
|
|
6
|
-
facet?: "auto" | "include" | "exclude";
|
|
7
|
-
fx: ChannelAccessor<Datum>;
|
|
8
|
-
fy: ChannelAccessor<Datum>;
|
|
9
|
-
dx: import("../types/index.js").ConstantAccessor<number, Datum>;
|
|
10
|
-
dy: import("../types/index.js").ConstantAccessor<number, Datum>;
|
|
11
|
-
fill: ChannelAccessor<Datum>;
|
|
12
|
-
fillOpacity: import("../types/index.js").ConstantAccessor<number, Datum>;
|
|
13
|
-
sort: {
|
|
14
|
-
channel: string;
|
|
15
|
-
order?: "ascending" | "descending";
|
|
16
|
-
} | ((a: import("../types/index.js").RawValue, b: import("../types/index.js").RawValue) => number) | import("../types/index.js").ConstantAccessor<import("../types/index.js").RawValue, Datum>;
|
|
17
|
-
stroke: ChannelAccessor<Datum>;
|
|
18
|
-
strokeWidth: import("../types/index.js").ConstantAccessor<number, Datum>;
|
|
19
|
-
strokeOpacity: import("../types/index.js").ConstantAccessor<number, Datum>;
|
|
20
|
-
strokeLinejoin: import("../types/index.js").ConstantAccessor<import("csstype").Property.StrokeLinejoin, Datum>;
|
|
21
|
-
strokeLinecap: import("../types/index.js").ConstantAccessor<import("csstype").Property.StrokeLinecap, Datum>;
|
|
22
|
-
strokeMiterlimit: import("../types/index.js").ConstantAccessor<number, Datum>;
|
|
23
|
-
opacity: ChannelAccessor<Datum>;
|
|
24
|
-
strokeDasharray: import("../types/index.js").ConstantAccessor<string, Datum>;
|
|
25
|
-
strokeDashoffset: import("../types/index.js").ConstantAccessor<number, Datum>;
|
|
26
|
-
mixBlendMode: import("../types/index.js").ConstantAccessor<import("csstype").Property.MixBlendMode, Datum>;
|
|
27
|
-
clipPath: string;
|
|
28
|
-
imageFilter: import("../types/index.js").ConstantAccessor<string, Datum>;
|
|
29
|
-
shapeRendering: import("../types/index.js").ConstantAccessor<import("csstype").Property.ShapeRendering, Datum>;
|
|
30
|
-
paintOrder: import("../types/index.js").ConstantAccessor<string, Datum>;
|
|
31
|
-
onclick?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
32
|
-
ondblclick?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
33
|
-
onmouseup?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
34
|
-
onmousedown?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
35
|
-
onmouseenter?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
36
|
-
onmousemove?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
37
|
-
onmouseleave?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
38
|
-
onmouseout?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
39
|
-
onmouseover?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
40
|
-
onpointercancel?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
41
|
-
onpointerdown?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
42
|
-
onpointerup?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
43
|
-
onpointerenter?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
44
|
-
onpointerleave?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
45
|
-
onpointermove?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
46
|
-
onpointerover?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
47
|
-
onpointerout?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
48
|
-
ondrag?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
49
|
-
ondrop?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
50
|
-
ondragstart?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
51
|
-
ondragenter?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
52
|
-
ondragleave?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
53
|
-
ondragover?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
54
|
-
ondragend?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
55
|
-
ontouchstart?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
56
|
-
ontouchmove?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
57
|
-
ontouchend?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
58
|
-
ontouchcancel?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
59
|
-
oncontextmenu?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
60
|
-
onwheel?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
61
|
-
class?: string;
|
|
62
|
-
style?: string;
|
|
63
|
-
cursor: import("../types/index.js").ConstantAccessor<import("csstype").Property.Cursor, Datum>;
|
|
64
|
-
}>, "fill" | "fillOpacity"> & {
|
|
4
|
+
props(): Omit<BaseMarkProps<Datum_1>, "fill" | "fillOpacity"> & {
|
|
65
5
|
data: Datum[];
|
|
66
|
-
x1: ChannelAccessor<
|
|
6
|
+
x1: ChannelAccessor<Datum_1>;
|
|
67
7
|
/**
|
|
68
8
|
* the horizontal position of the metric; bound to the x scale
|
|
69
9
|
*/
|
|
70
|
-
x2: ChannelAccessor<
|
|
71
|
-
x: ChannelAccessor<
|
|
10
|
+
x2: ChannelAccessor<Datum_1>;
|
|
11
|
+
x: ChannelAccessor<Datum_1>;
|
|
72
12
|
/**
|
|
73
13
|
* the vertical position of the comparison; bound to the y scale
|
|
74
14
|
*/
|
|
75
|
-
y1: ChannelAccessor<
|
|
15
|
+
y1: ChannelAccessor<Datum_1>;
|
|
76
16
|
/**
|
|
77
17
|
* the vertical position of the metric; bound to the y scale
|
|
78
18
|
*/
|
|
79
|
-
y2: ChannelAccessor<
|
|
80
|
-
y: ChannelAccessor<
|
|
19
|
+
y2: ChannelAccessor<Datum_1>;
|
|
20
|
+
y: ChannelAccessor<Datum_1>;
|
|
81
21
|
fillOpacity?: number;
|
|
82
22
|
/**
|
|
83
23
|
* the stroke color of the "positive" area; defaults to 'blue'
|
|
@@ -14,7 +14,7 @@ declare class __sveltets_Render<Datum extends DataRecord> {
|
|
|
14
14
|
sort: {
|
|
15
15
|
channel: string;
|
|
16
16
|
order?: "ascending" | "descending";
|
|
17
|
-
} | ((a: RawValue, b: RawValue) => number) | ConstantAccessor<RawValue, Datum>;
|
|
17
|
+
} | ((a: import("../types/data.js").RawValue, b: import("../types/data.js").RawValue) => number) | ConstantAccessor<import("../types/data.js").RawValue, Datum>;
|
|
18
18
|
stroke: ChannelAccessor<Datum>;
|
|
19
19
|
strokeWidth: ConstantAccessor<number, Datum>;
|
|
20
20
|
strokeOpacity: ConstantAccessor<number, Datum>;
|
|
@@ -72,7 +72,7 @@ declare class __sveltets_Render<Datum extends DataRecord> {
|
|
|
72
72
|
outlineStrokeOpacity?: number;
|
|
73
73
|
curve?: CurveName | CurveFactory | "auto";
|
|
74
74
|
tension?: number;
|
|
75
|
-
sort?: ConstantAccessor<RawValue,
|
|
75
|
+
sort?: ConstantAccessor<RawValue, Datum_1> | {
|
|
76
76
|
channel: "stroke" | "fill";
|
|
77
77
|
};
|
|
78
78
|
text?: ConstantAccessor<string, Datum>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { recordizeX } from '../index.js';
|
|
1
2
|
import type { DataRow } from '../index.js';
|
|
2
3
|
declare class __sveltets_Render<Datum extends DataRow> {
|
|
3
4
|
props(): Omit<import("../types").MarkerOptions & Partial<{
|
|
@@ -70,7 +71,7 @@ declare class __sveltets_Render<Datum extends DataRow> {
|
|
|
70
71
|
outlineStrokeOpacity?: number;
|
|
71
72
|
curve?: import("../types").CurveName | import("d3-shape").CurveFactory | "auto";
|
|
72
73
|
tension?: number;
|
|
73
|
-
sort?: import("../types").ConstantAccessor<
|
|
74
|
+
sort?: import("../types").ConstantAccessor<recordizeX, Datum_1> | {
|
|
74
75
|
channel: "stroke" | "fill";
|
|
75
76
|
};
|
|
76
77
|
text?: import("../types").ConstantAccessor<string, Record<string | symbol, import("../types").RawValue>>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { recordizeY } from '../index.js';
|
|
1
2
|
import type { DataRow } from '../index.js';
|
|
2
3
|
declare class __sveltets_Render<Datum extends DataRow> {
|
|
3
4
|
props(): Omit<import("../types").MarkerOptions & Partial<{
|
|
@@ -70,7 +71,7 @@ declare class __sveltets_Render<Datum extends DataRow> {
|
|
|
70
71
|
outlineStrokeOpacity?: number;
|
|
71
72
|
curve?: import("../types").CurveName | import("d3-shape").CurveFactory | "auto";
|
|
72
73
|
tension?: number;
|
|
73
|
-
sort?: import("../types").ConstantAccessor<
|
|
74
|
+
sort?: import("../types").ConstantAccessor<recordizeY, Datum_1> | {
|
|
74
75
|
channel: "stroke" | "fill";
|
|
75
76
|
};
|
|
76
77
|
text?: import("../types").ConstantAccessor<string, Record<string | symbol, import("../types").RawValue>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { getContext } from 'svelte';
|
|
3
|
-
import type { PlotContext } from '../../
|
|
3
|
+
import type { PlotContext } from '../../types/plot';
|
|
4
4
|
import { devicePixelRatio } from 'svelte/reactivity/window';
|
|
5
5
|
import { MediaQuery } from 'svelte/reactivity';
|
|
6
6
|
import type { Attachment } from 'svelte/attachments';
|
|
@@ -1,75 +1,15 @@
|
|
|
1
|
-
import type { BaseRectMarkProps } from '../../types/mark.js';
|
|
1
|
+
import type { BaseMarkProps, BaseRectMarkProps } from '../../types/mark.js';
|
|
2
2
|
import type { DataRecord, ScaledDataRecord } from '../../types/data.js';
|
|
3
3
|
import type { UsedScales } from '../../types/index.js';
|
|
4
4
|
declare class __sveltets_Render<Datum extends DataRecord> {
|
|
5
5
|
props(): {
|
|
6
|
-
datum: ScaledDataRecord<
|
|
6
|
+
datum: ScaledDataRecord<Datum_1>;
|
|
7
7
|
class: string | null;
|
|
8
8
|
x: number;
|
|
9
9
|
y: number;
|
|
10
10
|
width: number;
|
|
11
11
|
height: number;
|
|
12
|
-
options: BaseRectMarkProps<
|
|
13
|
-
filter?: import("../../types/index.js").ConstantAccessor<boolean, Datum>;
|
|
14
|
-
facet?: "auto" | "include" | "exclude";
|
|
15
|
-
fx: import("../../types/index.js").ChannelAccessor<Datum>;
|
|
16
|
-
fy: import("../../types/index.js").ChannelAccessor<Datum>;
|
|
17
|
-
dx: import("../../types/index.js").ConstantAccessor<number, Datum>;
|
|
18
|
-
dy: import("../../types/index.js").ConstantAccessor<number, Datum>;
|
|
19
|
-
fill: import("../../types/index.js").ChannelAccessor<Datum>;
|
|
20
|
-
fillOpacity: import("../../types/index.js").ConstantAccessor<number, Datum>;
|
|
21
|
-
sort: {
|
|
22
|
-
channel: string;
|
|
23
|
-
order?: "ascending" | "descending";
|
|
24
|
-
} | ((a: import("../../types/data.js").RawValue, b: import("../../types/data.js").RawValue) => number) | import("../../types/index.js").ConstantAccessor<import("../../types/data.js").RawValue, Datum>;
|
|
25
|
-
stroke: import("../../types/index.js").ChannelAccessor<Datum>;
|
|
26
|
-
strokeWidth: import("../../types/index.js").ConstantAccessor<number, Datum>;
|
|
27
|
-
strokeOpacity: import("../../types/index.js").ConstantAccessor<number, Datum>;
|
|
28
|
-
strokeLinejoin: import("../../types/index.js").ConstantAccessor<import("csstype").Property.StrokeLinejoin, Datum>;
|
|
29
|
-
strokeLinecap: import("../../types/index.js").ConstantAccessor<import("csstype").Property.StrokeLinecap, Datum>;
|
|
30
|
-
strokeMiterlimit: import("../../types/index.js").ConstantAccessor<number, Datum>;
|
|
31
|
-
opacity: import("../../types/index.js").ChannelAccessor<Datum>;
|
|
32
|
-
strokeDasharray: import("../../types/index.js").ConstantAccessor<string, Datum>;
|
|
33
|
-
strokeDashoffset: import("../../types/index.js").ConstantAccessor<number, Datum>;
|
|
34
|
-
mixBlendMode: import("../../types/index.js").ConstantAccessor<import("csstype").Property.MixBlendMode, Datum>;
|
|
35
|
-
clipPath: string;
|
|
36
|
-
imageFilter: import("../../types/index.js").ConstantAccessor<string, Datum>;
|
|
37
|
-
shapeRendering: import("../../types/index.js").ConstantAccessor<import("csstype").Property.ShapeRendering, Datum>;
|
|
38
|
-
paintOrder: import("../../types/index.js").ConstantAccessor<string, Datum>;
|
|
39
|
-
onclick?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
40
|
-
ondblclick?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
41
|
-
onmouseup?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
42
|
-
onmousedown?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
43
|
-
onmouseenter?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
44
|
-
onmousemove?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
45
|
-
onmouseleave?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
46
|
-
onmouseout?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
47
|
-
onmouseover?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
48
|
-
onpointercancel?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
49
|
-
onpointerdown?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
50
|
-
onpointerup?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
51
|
-
onpointerenter?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
52
|
-
onpointerleave?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
53
|
-
onpointermove?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
54
|
-
onpointerover?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
55
|
-
onpointerout?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
56
|
-
ondrag?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
57
|
-
ondrop?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
58
|
-
ondragstart?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
59
|
-
ondragenter?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
60
|
-
ondragleave?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
61
|
-
ondragover?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
62
|
-
ondragend?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
63
|
-
ontouchstart?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
64
|
-
ontouchmove?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
65
|
-
ontouchend?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
66
|
-
ontouchcancel?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
67
|
-
oncontextmenu?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
68
|
-
onwheel?: import("svelte/elements.js").MouseEventHandler<SVGPathElement>;
|
|
69
|
-
class?: string;
|
|
70
|
-
style?: string;
|
|
71
|
-
cursor: import("../../types/index.js").ConstantAccessor<import("csstype").Property.Cursor, Datum>;
|
|
72
|
-
}>;
|
|
12
|
+
options: BaseRectMarkProps<Datum_1> & BaseMarkProps<Datum_1>;
|
|
73
13
|
/**
|
|
74
14
|
* By default, the `inset` property is applied to all four insets. Mark components
|
|
75
15
|
* can tweak this behavior for insetTop and insetBottom by setting the
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
regressionLog,
|
|
44
44
|
regressionPow,
|
|
45
45
|
regressionLoess
|
|
46
|
-
} from '
|
|
46
|
+
} from '../../regression/index.js';
|
|
47
47
|
import { resolveChannel } from '../../helpers/resolve.js';
|
|
48
48
|
import { confidenceInterval } from '../../helpers/math.js';
|
|
49
49
|
import callWithProps from '../../helpers/callWithProps.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PredictFunction, Domain, DataPoint, Accessor } from './types.js';
|
|
2
|
+
export type ExponentialOutput = [DataPoint, DataPoint] & {
|
|
3
|
+
a: number;
|
|
4
|
+
b: number;
|
|
5
|
+
predict: PredictFunction;
|
|
6
|
+
rSquared: number;
|
|
7
|
+
};
|
|
8
|
+
export interface ExponentialRegression<T> {
|
|
9
|
+
(data: T[]): ExponentialOutput;
|
|
10
|
+
domain(): Domain;
|
|
11
|
+
domain(arr: Domain): this;
|
|
12
|
+
x(): Accessor<T>;
|
|
13
|
+
x(fn: Accessor<T>): this;
|
|
14
|
+
y(): Accessor<T>;
|
|
15
|
+
y(fn: Accessor<T>): this;
|
|
16
|
+
}
|
|
17
|
+
export default function exponential<T = DataPoint>(): ExponentialRegression<T>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapted from https://github.com/HarryStevens/d3-regression
|
|
3
|
+
*/
|
|
4
|
+
import { determination } from './utils/determination.js';
|
|
5
|
+
import { interpose } from './utils/interpose.js';
|
|
6
|
+
import { ols } from './utils/ols.js';
|
|
7
|
+
import { visitPoints } from './utils/points.js';
|
|
8
|
+
export default function exponential() {
|
|
9
|
+
let y = (d) => d[1], x = (d) => d[0], domain;
|
|
10
|
+
const exponentialRegression = function (data) {
|
|
11
|
+
let n = 0, Y = 0, YL = 0, XY = 0, XYL = 0, X2Y = 0, xmin = domain ? +domain[0] : Infinity, xmax = domain ? +domain[1] : -Infinity;
|
|
12
|
+
visitPoints(data, x, y, (dx, dy) => {
|
|
13
|
+
const ly = Math.log(dy), xy = dx * dy;
|
|
14
|
+
++n;
|
|
15
|
+
Y += (dy - Y) / n;
|
|
16
|
+
XY += (xy - XY) / n;
|
|
17
|
+
X2Y += (dx * xy - X2Y) / n;
|
|
18
|
+
YL += (dy * ly - YL) / n;
|
|
19
|
+
XYL += (xy * ly - XYL) / n;
|
|
20
|
+
if (!domain) {
|
|
21
|
+
if (dx < xmin)
|
|
22
|
+
xmin = dx;
|
|
23
|
+
if (dx > xmax)
|
|
24
|
+
xmax = dx;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
let [a, b] = ols(XY / Y, YL / Y, XYL / Y, X2Y / Y);
|
|
28
|
+
a = Math.exp(a);
|
|
29
|
+
const fn = (xx) => a * Math.exp(b * xx);
|
|
30
|
+
const out = interpose(xmin, xmax, fn);
|
|
31
|
+
out.a = a;
|
|
32
|
+
out.b = b;
|
|
33
|
+
out.predict = fn;
|
|
34
|
+
out.rSquared = determination(data, x, y, Y, fn);
|
|
35
|
+
return out;
|
|
36
|
+
};
|
|
37
|
+
exponentialRegression.domain = function (arr) {
|
|
38
|
+
if (!arguments.length)
|
|
39
|
+
return domain;
|
|
40
|
+
domain = arr;
|
|
41
|
+
return exponentialRegression;
|
|
42
|
+
};
|
|
43
|
+
exponentialRegression.x = function (fn) {
|
|
44
|
+
if (!arguments.length)
|
|
45
|
+
return x;
|
|
46
|
+
x = fn;
|
|
47
|
+
return exponentialRegression;
|
|
48
|
+
};
|
|
49
|
+
exponentialRegression.y = function (fn) {
|
|
50
|
+
if (!arguments.length)
|
|
51
|
+
return y;
|
|
52
|
+
y = fn;
|
|
53
|
+
return exponentialRegression;
|
|
54
|
+
};
|
|
55
|
+
return exponentialRegression;
|
|
56
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapted from https://github.com/HarryStevens/d3-regression
|
|
3
|
+
*/
|
|
4
|
+
export { default as regressionLinear } from './linear.js';
|
|
5
|
+
export { default as regressionPoly } from './polynomial.js';
|
|
6
|
+
export { default as regressionExp } from './exponential.js';
|
|
7
|
+
export { default as regressionLog } from './logarithmic.js';
|
|
8
|
+
export { default as regressionPow } from './power.js';
|
|
9
|
+
export { default as regressionQuad } from './quadratic.js';
|
|
10
|
+
export { default as regressionLoess } from './loess.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapted from https://github.com/HarryStevens/d3-regression
|
|
3
|
+
*/
|
|
4
|
+
export { default as regressionLinear } from './linear.js';
|
|
5
|
+
export { default as regressionPoly } from './polynomial.js';
|
|
6
|
+
export { default as regressionExp } from './exponential.js';
|
|
7
|
+
export { default as regressionLog } from './logarithmic.js';
|
|
8
|
+
export { default as regressionPow } from './power.js';
|
|
9
|
+
export { default as regressionQuad } from './quadratic.js';
|
|
10
|
+
export { default as regressionLoess } from './loess.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PredictFunction, Accessor, DataPoint, Domain } from './types.js';
|
|
2
|
+
export type LinearOutput = [DataPoint, DataPoint] & {
|
|
3
|
+
a: number;
|
|
4
|
+
b: number;
|
|
5
|
+
predict: PredictFunction;
|
|
6
|
+
rSquared: number;
|
|
7
|
+
};
|
|
8
|
+
export interface LinearRegression<T> {
|
|
9
|
+
(data: T[]): LinearOutput;
|
|
10
|
+
domain(): Domain;
|
|
11
|
+
domain(arr: Domain): this;
|
|
12
|
+
x(): Accessor<T>;
|
|
13
|
+
x(fn: Accessor<T>): this;
|
|
14
|
+
y(): Accessor<T>;
|
|
15
|
+
y(fn: Accessor<T>): this;
|
|
16
|
+
}
|
|
17
|
+
export default function linear<T = DataPoint>(): LinearRegression<T>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapted from https://github.com/HarryStevens/d3-regression
|
|
3
|
+
*/
|
|
4
|
+
import { determination } from './utils/determination.js';
|
|
5
|
+
import { ols } from './utils/ols.js';
|
|
6
|
+
import { visitPoints } from './utils/points.js';
|
|
7
|
+
export default function linear() {
|
|
8
|
+
let x = (d) => d[0], y = (d) => d[1], domain;
|
|
9
|
+
const linearRegression = function (data) {
|
|
10
|
+
let n = 0, X = 0, // sum of x
|
|
11
|
+
Y = 0, // sum of y
|
|
12
|
+
XY = 0, // sum of x*y
|
|
13
|
+
X2 = 0, // sum of x*x
|
|
14
|
+
xmin = domain ? +domain[0] : Infinity, xmax = domain ? +domain[1] : -Infinity;
|
|
15
|
+
visitPoints(data, x, y, (dx, dy) => {
|
|
16
|
+
++n;
|
|
17
|
+
X += (dx - X) / n;
|
|
18
|
+
Y += (dy - Y) / n;
|
|
19
|
+
XY += (dx * dy - XY) / n;
|
|
20
|
+
X2 += (dx * dx - X2) / n;
|
|
21
|
+
if (!domain) {
|
|
22
|
+
if (dx < xmin)
|
|
23
|
+
xmin = dx;
|
|
24
|
+
if (dx > xmax)
|
|
25
|
+
xmax = dx;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const [intercept, slope] = ols(X, Y, XY, X2);
|
|
29
|
+
const fn = (xx) => slope * xx + intercept;
|
|
30
|
+
const out = [
|
|
31
|
+
[xmin, fn(xmin)],
|
|
32
|
+
[xmax, fn(xmax)]
|
|
33
|
+
];
|
|
34
|
+
out.a = slope;
|
|
35
|
+
out.b = intercept;
|
|
36
|
+
out.predict = fn;
|
|
37
|
+
out.rSquared = determination(data, x, y, Y, fn);
|
|
38
|
+
return out;
|
|
39
|
+
};
|
|
40
|
+
linearRegression.domain = function (arr) {
|
|
41
|
+
if (!arguments.length)
|
|
42
|
+
return domain;
|
|
43
|
+
domain = arr;
|
|
44
|
+
return linearRegression;
|
|
45
|
+
};
|
|
46
|
+
linearRegression.x = function (fn) {
|
|
47
|
+
if (!arguments.length)
|
|
48
|
+
return x;
|
|
49
|
+
x = fn;
|
|
50
|
+
return linearRegression;
|
|
51
|
+
};
|
|
52
|
+
linearRegression.y = function (fn) {
|
|
53
|
+
if (!arguments.length)
|
|
54
|
+
return y;
|
|
55
|
+
y = fn;
|
|
56
|
+
return linearRegression;
|
|
57
|
+
};
|
|
58
|
+
return linearRegression;
|
|
59
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapted from https://github.com/HarryStevens/d3-regression
|
|
3
|
+
*/
|
|
4
|
+
import type { Accessor, DataPoint } from './types.js';
|
|
5
|
+
export interface LoessRegression<T> {
|
|
6
|
+
(data: T[]): DataPoint[];
|
|
7
|
+
bandwidth(): number;
|
|
8
|
+
bandwidth(bw: number): this;
|
|
9
|
+
x(): Accessor<T>;
|
|
10
|
+
x(fn: Accessor<T>): this;
|
|
11
|
+
y(): Accessor<T>;
|
|
12
|
+
y(fn: Accessor<T>): this;
|
|
13
|
+
}
|
|
14
|
+
export default function loess<T = DataPoint>(): LoessRegression<T>;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapted from https://github.com/HarryStevens/d3-regression
|
|
3
|
+
*/
|
|
4
|
+
// Adapted from science.js by Jason Davies
|
|
5
|
+
// License: https://github.com/jasondavies/science.js/blob/master/LICENSE
|
|
6
|
+
// Source: https://github.com/jasondavies/science.js/blob/master/src/stats/loess.js
|
|
7
|
+
// Adapted from vega-statistics by Jeffrey Heer
|
|
8
|
+
// License: https://github.com/vega/vega/blob/f058b099decad9db78301405dd0d2e9d8ba3d51a/LICENSE
|
|
9
|
+
// Source: https://github.com/vega/vega/blob/f21cb8792b4e0cbe2b1a3fd44b0f5db370dbaadb/packages/vega-statistics/src/regression/loess.js
|
|
10
|
+
import { median } from './utils/median.js';
|
|
11
|
+
import { ols } from './utils/ols.js';
|
|
12
|
+
import { points } from './utils/points.js';
|
|
13
|
+
const maxiters = 2, epsilon = 1e-12;
|
|
14
|
+
export default function loess() {
|
|
15
|
+
let x = (d) => d[0], y = (d) => d[1], bandwidth = 0.3;
|
|
16
|
+
const loessRegression = function loessRegression(data) {
|
|
17
|
+
const [xv, yv, ux, uy] = points(data, (dd) => x(dd), (dd) => y(dd), true);
|
|
18
|
+
const n = xv.length;
|
|
19
|
+
const bw = Math.max(2, ~~(bandwidth * n)); // # of nearest neighbors
|
|
20
|
+
const yhat = new Float64Array(n);
|
|
21
|
+
const residuals = new Float64Array(n);
|
|
22
|
+
const robustWeights = new Float64Array(n).fill(1);
|
|
23
|
+
for (let iter = -1; ++iter <= maxiters;) {
|
|
24
|
+
const interval = [0, bw - 1];
|
|
25
|
+
for (let i = 0; i < n; ++i) {
|
|
26
|
+
const dx = xv[i];
|
|
27
|
+
const i0 = interval[0];
|
|
28
|
+
const i1 = interval[1];
|
|
29
|
+
const edge = dx - xv[i0] > xv[i1] - dx ? i0 : i1;
|
|
30
|
+
let W = 0, X = 0, Y = 0, XY = 0, X2 = 0;
|
|
31
|
+
const denom = 1 / Math.abs(xv[edge] - dx || 1);
|
|
32
|
+
for (let k = i0; k <= i1; ++k) {
|
|
33
|
+
const xk = xv[k];
|
|
34
|
+
const yk = yv[k];
|
|
35
|
+
const w = tricube(Math.abs(dx - xk) * denom) * robustWeights[k];
|
|
36
|
+
const xkw = xk * w;
|
|
37
|
+
W += w;
|
|
38
|
+
X += xkw;
|
|
39
|
+
Y += yk * w;
|
|
40
|
+
XY += yk * xkw;
|
|
41
|
+
X2 += xk * xkw;
|
|
42
|
+
}
|
|
43
|
+
// Linear regression fit
|
|
44
|
+
const [a, b] = ols(X / W, Y / W, XY / W, X2 / W);
|
|
45
|
+
yhat[i] = a + b * dx;
|
|
46
|
+
residuals[i] = Math.abs(yv[i] - yhat[i]);
|
|
47
|
+
updateInterval(xv, i + 1, interval);
|
|
48
|
+
}
|
|
49
|
+
if (iter === maxiters) {
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
const medianResidual = median(residuals);
|
|
53
|
+
if (Math.abs(medianResidual) < epsilon)
|
|
54
|
+
break;
|
|
55
|
+
for (let i = 0, arg, w; i < n; ++i) {
|
|
56
|
+
arg = residuals[i] / (6 * medianResidual);
|
|
57
|
+
// Default to epsilon (rather than zero) for large deviations
|
|
58
|
+
// Keeping weights tiny but non-zero prevents singularites
|
|
59
|
+
robustWeights[i] = arg >= 1 ? epsilon : (w = 1 - arg * arg) * w;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return output(xv, yhat, ux, uy);
|
|
63
|
+
};
|
|
64
|
+
loessRegression.bandwidth = function (bw) {
|
|
65
|
+
if (!arguments.length)
|
|
66
|
+
return bandwidth;
|
|
67
|
+
bandwidth = bw;
|
|
68
|
+
return loessRegression;
|
|
69
|
+
};
|
|
70
|
+
loessRegression.x = function (fn) {
|
|
71
|
+
if (!arguments.length)
|
|
72
|
+
return x;
|
|
73
|
+
x = fn;
|
|
74
|
+
return loessRegression;
|
|
75
|
+
};
|
|
76
|
+
loessRegression.y = function (fn) {
|
|
77
|
+
if (!arguments.length)
|
|
78
|
+
return y;
|
|
79
|
+
y = fn;
|
|
80
|
+
return loessRegression;
|
|
81
|
+
};
|
|
82
|
+
return loessRegression;
|
|
83
|
+
}
|
|
84
|
+
// Weighting kernel for local regression
|
|
85
|
+
function tricube(x) {
|
|
86
|
+
return (x = 1 - x * x * x) * x * x;
|
|
87
|
+
}
|
|
88
|
+
// Advance sliding window interval of nearest neighbors
|
|
89
|
+
function updateInterval(xv, i, interval) {
|
|
90
|
+
let val = xv[i], left = interval[0], right = interval[1] + 1;
|
|
91
|
+
if (right >= xv.length)
|
|
92
|
+
return;
|
|
93
|
+
// Step right if distance to new right edge is <= distance to old left edge
|
|
94
|
+
// Step when distance is equal to ensure movement over duplicate x values
|
|
95
|
+
while (i > left && xv[right] - val <= val - xv[left]) {
|
|
96
|
+
interval[0] = ++left;
|
|
97
|
+
interval[1] = right;
|
|
98
|
+
++right;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Generate smoothed output points
|
|
102
|
+
// Average points with repeated x values
|
|
103
|
+
function output(xv, yhat, ux, uy) {
|
|
104
|
+
const n = xv.length, out = [];
|
|
105
|
+
let i = 0, cnt = 0, prev = [], v;
|
|
106
|
+
for (; i < n; ++i) {
|
|
107
|
+
v = xv[i] + ux;
|
|
108
|
+
if (prev[0] === v) {
|
|
109
|
+
// Average output values via online update
|
|
110
|
+
prev[1] += (yhat[i] - prev[1]) / ++cnt;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// Add new output point
|
|
114
|
+
cnt = 0;
|
|
115
|
+
prev[1] += uy;
|
|
116
|
+
prev = [v, yhat[i]];
|
|
117
|
+
out.push(prev);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
prev[1] += uy;
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PredictFunction, DataPoint, Accessor, Domain } from './types.js';
|
|
2
|
+
type LogarithmicOutput = [DataPoint, DataPoint] & {
|
|
3
|
+
a: number;
|
|
4
|
+
b: number;
|
|
5
|
+
predict: PredictFunction;
|
|
6
|
+
rSquared: number;
|
|
7
|
+
};
|
|
8
|
+
export interface LogarithmicRegression<T> {
|
|
9
|
+
(data: T[]): LogarithmicOutput;
|
|
10
|
+
domain(): Domain;
|
|
11
|
+
domain(arr: Domain): this;
|
|
12
|
+
x(): Accessor<T>;
|
|
13
|
+
x(fn: Accessor<T>): this;
|
|
14
|
+
y(): Accessor<T>;
|
|
15
|
+
y(fn: Accessor<T>): this;
|
|
16
|
+
base(): number;
|
|
17
|
+
base(b: number): this;
|
|
18
|
+
}
|
|
19
|
+
export default function logarithmic<T = DataPoint>(): LogarithmicRegression<T>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapted from https://github.com/HarryStevens/d3-regression
|
|
3
|
+
*/
|
|
4
|
+
import { determination } from './utils/determination.js';
|
|
5
|
+
import { interpose } from './utils/interpose.js';
|
|
6
|
+
import { ols } from './utils/ols.js';
|
|
7
|
+
import { visitPoints } from './utils/points.js';
|
|
8
|
+
export default function logarithmic() {
|
|
9
|
+
let x = (d) => d[0], y = (d) => d[1], base = Math.E, domain;
|
|
10
|
+
const logarithmicRegression = function (data) {
|
|
11
|
+
let n = 0, X = 0, Y = 0, XY = 0, X2 = 0, xmin = domain ? +domain[0] : Infinity, xmax = domain ? +domain[1] : -Infinity, lb = Math.log(base);
|
|
12
|
+
visitPoints(data, x, y, (dx, dy) => {
|
|
13
|
+
const lx = Math.log(dx) / lb;
|
|
14
|
+
++n;
|
|
15
|
+
X += (lx - X) / n;
|
|
16
|
+
Y += (dy - Y) / n;
|
|
17
|
+
XY += (lx * dy - XY) / n;
|
|
18
|
+
X2 += (lx * lx - X2) / n;
|
|
19
|
+
if (!domain) {
|
|
20
|
+
if (dx < xmin)
|
|
21
|
+
xmin = dx;
|
|
22
|
+
if (dx > xmax)
|
|
23
|
+
xmax = dx;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
const [intercept, slope] = ols(X, Y, XY, X2);
|
|
27
|
+
const fn = (xx) => (slope * Math.log(xx)) / lb + intercept;
|
|
28
|
+
const out = interpose(xmin, xmax, fn);
|
|
29
|
+
out.a = slope;
|
|
30
|
+
out.b = intercept;
|
|
31
|
+
out.predict = fn;
|
|
32
|
+
out.rSquared = determination(data, x, y, Y, fn);
|
|
33
|
+
return out;
|
|
34
|
+
};
|
|
35
|
+
logarithmicRegression.domain = function (arr) {
|
|
36
|
+
if (!arguments.length)
|
|
37
|
+
return domain;
|
|
38
|
+
domain = arr;
|
|
39
|
+
return logarithmicRegression;
|
|
40
|
+
};
|
|
41
|
+
logarithmicRegression.x = function (fn) {
|
|
42
|
+
if (!arguments.length)
|
|
43
|
+
return x;
|
|
44
|
+
x = fn;
|
|
45
|
+
return logarithmicRegression;
|
|
46
|
+
};
|
|
47
|
+
logarithmicRegression.y = function (fn) {
|
|
48
|
+
if (!arguments.length)
|
|
49
|
+
return y;
|
|
50
|
+
y = fn;
|
|
51
|
+
return logarithmicRegression;
|
|
52
|
+
};
|
|
53
|
+
logarithmicRegression.base = function (b) {
|
|
54
|
+
if (!arguments.length)
|
|
55
|
+
return base;
|
|
56
|
+
base = b;
|
|
57
|
+
return logarithmicRegression;
|
|
58
|
+
};
|
|
59
|
+
return logarithmicRegression;
|
|
60
|
+
}
|