layerchart 0.0.1 → 0.0.2
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/components/Area.svelte +38 -0
- package/components/Area.svelte.d.ts +28 -0
- package/components/AreaStack.svelte +40 -0
- package/components/AreaStack.svelte.d.ts +20 -0
- package/components/AxisX.svelte +52 -0
- package/components/AxisX.svelte.d.ts +23 -0
- package/components/AxisY.svelte +69 -0
- package/components/AxisY.svelte.d.ts +23 -0
- package/components/Bar.svelte +93 -0
- package/components/Bar.svelte.d.ts +32 -0
- package/components/Baseline.svelte +21 -0
- package/components/Baseline.svelte.d.ts +17 -0
- package/components/Chart.svelte +50 -0
- package/components/Chart.svelte.d.ts +24 -0
- package/components/Circle.svelte +15 -0
- package/components/Circle.svelte.d.ts +22 -0
- package/components/ClevelandDotPlot.svelte +44 -0
- package/components/ClevelandDotPlot.svelte.d.ts +21 -0
- package/components/HighlightBar.svelte +27 -0
- package/components/HighlightBar.svelte.d.ts +18 -0
- package/components/HighlightLine.svelte +52 -0
- package/components/HighlightLine.svelte.d.ts +17 -0
- package/components/Label.svelte +96 -0
- package/components/Label.svelte.d.ts +22 -0
- package/components/Line.svelte +18 -0
- package/components/Line.svelte.d.ts +23 -0
- package/components/Path.svelte +36 -0
- package/components/Path.svelte.d.ts +25 -0
- package/components/Rect.svelte +25 -0
- package/components/Rect.svelte.d.ts +25 -0
- package/components/Scatter.svelte +25 -0
- package/components/Scatter.svelte.d.ts +33 -0
- package/components/Text.svelte +129 -0
- package/components/Text.svelte.d.ts +28 -0
- package/components/Threshold.svelte +83 -0
- package/components/Threshold.svelte.d.ts +35 -0
- package/components/Tooltip.svelte +120 -0
- package/components/Tooltip.svelte.d.ts +33 -0
- package/docs/Blockquote.svelte +7 -0
- package/docs/Blockquote.svelte.d.ts +23 -0
- package/docs/Code.svelte +6 -0
- package/docs/Code.svelte.d.ts +23 -0
- package/docs/Layout.svelte +20 -0
- package/docs/Layout.svelte.d.ts +29 -0
- package/docs/Link.svelte +7 -0
- package/docs/Link.svelte.d.ts +27 -0
- package/docs/Preview.svelte +19 -0
- package/docs/Preview.svelte.d.ts +19 -0
- package/package.json +73 -26
- package/stores/motionStore.d.ts +8 -0
- package/stores/motionStore.js +16 -0
- package/utils/event.d.ts +4 -0
- package/utils/event.js +42 -0
- package/utils/genData.d.ts +19 -0
- package/utils/genData.js +35 -0
- package/utils/pivot.d.ts +14 -0
- package/utils/pivot.js +36 -0
- package/utils/scales.d.ts +10 -0
- package/utils/scales.js +21 -0
- package/utils/string.d.ts +4 -0
- package/utils/string.js +27 -0
- package/utils/ticks.d.ts +3 -0
- package/utils/ticks.js +157 -0
- package/.prettierrc +0 -6
- package/src/app.html +0 -12
- package/src/global.d.ts +0 -1
- package/src/routes/index.svelte +0 -2
- package/static/favicon.png +0 -0
- package/svelte.config.js +0 -15
- package/tsconfig.json +0 -31
package/utils/pivot.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { group } from 'd3-array';
|
|
2
|
+
export function getAccessor(key) {
|
|
3
|
+
if (typeof key === 'function') {
|
|
4
|
+
return key;
|
|
5
|
+
}
|
|
6
|
+
else {
|
|
7
|
+
return (d) => d[key];
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Pivot longer (columns to rows)
|
|
12
|
+
* - see: https://observablehq.com/d/3ea8d446f5ba96fe
|
|
13
|
+
* - see also: https://observablehq.com/d/ac2a320cf2b0adc4 as generator
|
|
14
|
+
*/
|
|
15
|
+
export function pivotLonger(data, columns, name, value) {
|
|
16
|
+
const keep = data.columns.filter((c) => !columns.includes(c));
|
|
17
|
+
return data.flatMap((d) => {
|
|
18
|
+
const base = keep.map((k) => [k, d[k]]);
|
|
19
|
+
return columns.map((column) => {
|
|
20
|
+
return Object.fromEntries([...base, [name, column], [value, d[column]]]);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Pivot wider (rows to columns)
|
|
26
|
+
* - see: https://github.com/d3/d3-array/issues/142#issuecomment-761861983
|
|
27
|
+
*/
|
|
28
|
+
export function pivotWider(data, column, name, value) {
|
|
29
|
+
return Array.from(group(data, (d) => d[column]), ([columnVal, items]) => Object.fromEntries([[column, columnVal]].concat(items.map((d) => [d[name], d[value]]))));
|
|
30
|
+
}
|
|
31
|
+
export function first(items) {
|
|
32
|
+
return items[0];
|
|
33
|
+
}
|
|
34
|
+
export function last(items) {
|
|
35
|
+
return items[items.length - 1];
|
|
36
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Implemenation for missing `scaleBand().invert()`
|
|
3
|
+
*
|
|
4
|
+
* See: https://stackoverflow.com/a/50846323/191902
|
|
5
|
+
* https://github.com/d3/d3-scale/pull/64
|
|
6
|
+
* https://github.com/vega/vega-scale/blob/master/src/scaleBand.js#L118
|
|
7
|
+
* https://observablehq.com/@d3/ordinal-brushing
|
|
8
|
+
*/
|
|
9
|
+
export declare function scaleBandInvert(scale: any): (value: any) => any;
|
|
10
|
+
export declare function isScaleBand(scale: any): boolean;
|
package/utils/scales.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Implemenation for missing `scaleBand().invert()`
|
|
3
|
+
*
|
|
4
|
+
* See: https://stackoverflow.com/a/50846323/191902
|
|
5
|
+
* https://github.com/d3/d3-scale/pull/64
|
|
6
|
+
* https://github.com/vega/vega-scale/blob/master/src/scaleBand.js#L118
|
|
7
|
+
* https://observablehq.com/@d3/ordinal-brushing
|
|
8
|
+
*/
|
|
9
|
+
export function scaleBandInvert(scale) {
|
|
10
|
+
const domain = scale.domain();
|
|
11
|
+
const paddingOuter = scale(domain[0]);
|
|
12
|
+
const eachBand = scale.step();
|
|
13
|
+
return function (value) {
|
|
14
|
+
// TODO: Should this use Math.round to better select? https://stackoverflow.com/questions/38633082/d3-getting-invert-value-of-band-scales/50846323#comment104743795_50846323
|
|
15
|
+
const index = Math.floor((value - paddingOuter) / eachBand);
|
|
16
|
+
return domain[Math.max(0, Math.min(index, domain.length - 1))];
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function isScaleBand(scale) {
|
|
20
|
+
return typeof scale.bandwidth === 'function';
|
|
21
|
+
}
|
package/utils/string.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { memoize } from 'lodash-es';
|
|
2
|
+
const MEASUREMENT_ELEMENT_ID = '__text_measurement_id';
|
|
3
|
+
function _getStringWidth(str, style) {
|
|
4
|
+
try {
|
|
5
|
+
// Calculate length of each word to be used to determine number of words per line
|
|
6
|
+
let textEl = document.getElementById(MEASUREMENT_ELEMENT_ID);
|
|
7
|
+
if (!textEl) {
|
|
8
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
9
|
+
svg.style.width = '0';
|
|
10
|
+
svg.style.height = '0';
|
|
11
|
+
svg.style.position = 'absolute';
|
|
12
|
+
svg.style.top = '-100%';
|
|
13
|
+
svg.style.left = '-100%';
|
|
14
|
+
textEl = document.createElementNS('http://www.w3.org/2000/svg', 'text');
|
|
15
|
+
textEl.setAttribute('id', MEASUREMENT_ELEMENT_ID);
|
|
16
|
+
svg.appendChild(textEl);
|
|
17
|
+
document.body.appendChild(svg);
|
|
18
|
+
}
|
|
19
|
+
Object.assign(textEl.style, style);
|
|
20
|
+
textEl.textContent = str;
|
|
21
|
+
return textEl.getComputedTextLength();
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export const getStringWidth = memoize(_getStringWidth, (str, style) => `${str}_${JSON.stringify(style)}`);
|
package/utils/ticks.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function getMajorTicks(start: Date, end: Date): import("d3-time").TimeInterval;
|
|
2
|
+
export declare function formatMajorTick(date: Date, rangeStart: Date, rangeEnd: Date): string;
|
|
3
|
+
export declare function getMinorTicks(start: Date, end: Date): import("d3-time").TimeInterval;
|
package/utils/ticks.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { timeYear, timeMonth, timeWeek, timeDay, timeHour, timeMinute, timeSecond, timeMillisecond } from 'd3-time';
|
|
2
|
+
import { format } from 'date-fns';
|
|
3
|
+
import { formatDate, PeriodType } from 'svelte-ux/utils/date';
|
|
4
|
+
import { getDuration } from 'svelte-ux/utils/duration';
|
|
5
|
+
import { fail } from 'svelte-ux/types';
|
|
6
|
+
// TODO: Use PeriodType along with Duration to format (and possibly select intervals)
|
|
7
|
+
const majorTicks = [
|
|
8
|
+
{
|
|
9
|
+
predicate: (duration) => duration == null,
|
|
10
|
+
interval: timeYear.every(1),
|
|
11
|
+
format: (date) => date.toString()
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
predicate: (duration) => duration.years > 1,
|
|
15
|
+
interval: timeYear.every(1),
|
|
16
|
+
format: (date) => formatDate(date, PeriodType.CalendarYear, 'short')
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
predicate: (duration) => duration.years,
|
|
20
|
+
interval: timeMonth.every(1),
|
|
21
|
+
format: (date) => formatDate(date, PeriodType.Month, 'short')
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
predicate: (duration) => duration.days > 30,
|
|
25
|
+
interval: timeMonth.every(1),
|
|
26
|
+
format: (date) => formatDate(date, PeriodType.Month, 'short')
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
predicate: (duration) => duration.days,
|
|
30
|
+
interval: timeDay.every(1),
|
|
31
|
+
format: (date) => formatDate(date, PeriodType.Day, 'short')
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
predicate: (duration) => duration.hours,
|
|
35
|
+
interval: timeHour.every(1),
|
|
36
|
+
format: (date) => format(date, 'h:mm a')
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
predicate: (duration) => duration.minutes > 10,
|
|
40
|
+
interval: timeMinute.every(10),
|
|
41
|
+
format: (date) => format(date, 'h:mm a')
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
predicate: (duration) => duration.minutes,
|
|
45
|
+
interval: timeMinute.every(1),
|
|
46
|
+
format: (date) => format(date, 'h:mm a')
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
predicate: (duration) => duration.seconds > 10,
|
|
50
|
+
interval: timeSecond.every(10),
|
|
51
|
+
format: (date) => format(date, 'h:mm:ss')
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
predicate: (duration) => duration.seconds,
|
|
55
|
+
interval: timeSecond.every(1),
|
|
56
|
+
format: (date) => format(date, 'h:mm:ss')
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
predicate: (duration) => true,
|
|
60
|
+
interval: timeMillisecond.every(100),
|
|
61
|
+
format: (date) => format(date, 'h:mm:ss.SSS')
|
|
62
|
+
}
|
|
63
|
+
];
|
|
64
|
+
const minorTicks = [
|
|
65
|
+
{
|
|
66
|
+
predicate: (duration) => duration == null,
|
|
67
|
+
interval: timeYear.every(1),
|
|
68
|
+
format: (date) => date.toString()
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
predicate: (duration) => duration.years,
|
|
72
|
+
interval: timeMonth.every(1),
|
|
73
|
+
format: (date) => formatDate(date, PeriodType.Month, 'short')
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
predicate: (duration) => duration.days > 90,
|
|
77
|
+
interval: timeMonth.every(1),
|
|
78
|
+
format: (date) => formatDate(date, PeriodType.Month, 'short')
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
predicate: (duration) => duration.days > 30,
|
|
82
|
+
interval: timeWeek.every(1),
|
|
83
|
+
format: (date) => formatDate(date, PeriodType.WeekSun, 'short')
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
predicate: (duration) => duration.days > 7,
|
|
87
|
+
interval: timeDay.every(1),
|
|
88
|
+
format: (date) => formatDate(date, PeriodType.Day, 'short')
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
predicate: (duration) => duration.days > 3,
|
|
92
|
+
interval: timeHour.every(8),
|
|
93
|
+
format: (date) => format(date, 'h:mm a')
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
predicate: (duration) => duration.days,
|
|
97
|
+
interval: timeHour.every(1),
|
|
98
|
+
format: (date) => format(date, 'h:mm a')
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
predicate: (duration) => duration.hours,
|
|
102
|
+
interval: timeMinute.every(15),
|
|
103
|
+
format: (date) => format(date, 'h:mm a')
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
predicate: (duration) => duration.minutes > 10,
|
|
107
|
+
interval: timeMinute.every(10),
|
|
108
|
+
format: (date) => format(date, 'h:mm a')
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
predicate: (duration) => duration.minutes > 2,
|
|
112
|
+
interval: timeMinute.every(1),
|
|
113
|
+
format: (date) => format(date, 'h:mm a')
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
predicate: (duration) => duration.minutes,
|
|
117
|
+
interval: timeSecond.every(10),
|
|
118
|
+
format: (date) => format(date, 'h:mm:ss')
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
predicate: (duration) => duration.seconds,
|
|
122
|
+
interval: timeSecond.every(1),
|
|
123
|
+
format: (date) => format(date, 'h:mm:ss')
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
predicate: (duration) => true,
|
|
127
|
+
interval: timeMillisecond.every(10),
|
|
128
|
+
format: (date) => format(date, 'h:mm:ss.SSS')
|
|
129
|
+
}
|
|
130
|
+
];
|
|
131
|
+
export function getMajorTicks(start, end) {
|
|
132
|
+
const duration = getDuration(start, end);
|
|
133
|
+
for (var t of majorTicks) {
|
|
134
|
+
if (t.predicate(duration)) {
|
|
135
|
+
return t.interval;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
fail(`Unable to locate major ticks for duration: ${duration}`);
|
|
139
|
+
}
|
|
140
|
+
export function formatMajorTick(date, rangeStart, rangeEnd) {
|
|
141
|
+
const duration = getDuration(rangeStart, rangeEnd);
|
|
142
|
+
for (var t of majorTicks) {
|
|
143
|
+
if (t.predicate(duration)) {
|
|
144
|
+
return t.format(date);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
fail(`Unable to format major ticks for duration: ${duration}`);
|
|
148
|
+
}
|
|
149
|
+
export function getMinorTicks(start, end) {
|
|
150
|
+
const duration = getDuration(start, end);
|
|
151
|
+
for (var t of minorTicks) {
|
|
152
|
+
if (t.predicate(duration)) {
|
|
153
|
+
return t.interval;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
fail(`Unable to locate minor ticks for duration: ${duration}`);
|
|
157
|
+
}
|
package/.prettierrc
DELETED
package/src/app.html
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8" />
|
|
5
|
-
<link rel="icon" href="/favicon.png" />
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
|
-
%svelte.head%
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<div id="svelte">%svelte.body%</div>
|
|
11
|
-
</body>
|
|
12
|
-
</html>
|
package/src/global.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/// <reference types="@sveltejs/kit" />
|
package/src/routes/index.svelte
DELETED
package/static/favicon.png
DELETED
|
Binary file
|
package/svelte.config.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import preprocess from 'svelte-preprocess';
|
|
2
|
-
|
|
3
|
-
/** @type {import('@sveltejs/kit').Config} */
|
|
4
|
-
const config = {
|
|
5
|
-
// Consult https://github.com/sveltejs/svelte-preprocess
|
|
6
|
-
// for more information about preprocessors
|
|
7
|
-
preprocess: preprocess(),
|
|
8
|
-
|
|
9
|
-
kit: {
|
|
10
|
-
// hydrate the <div id="svelte"> element in src/app.html
|
|
11
|
-
target: '#svelte'
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export default config;
|
package/tsconfig.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"moduleResolution": "node",
|
|
4
|
-
"module": "es2020",
|
|
5
|
-
"lib": ["es2020", "DOM"],
|
|
6
|
-
"target": "es2019",
|
|
7
|
-
/**
|
|
8
|
-
svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
|
|
9
|
-
to enforce using \`import type\` instead of \`import\` for Types.
|
|
10
|
-
*/
|
|
11
|
-
"importsNotUsedAsValues": "error",
|
|
12
|
-
"isolatedModules": true,
|
|
13
|
-
"resolveJsonModule": true,
|
|
14
|
-
/**
|
|
15
|
-
To have warnings/errors of the Svelte compiler at the correct position,
|
|
16
|
-
enable source maps by default.
|
|
17
|
-
*/
|
|
18
|
-
"sourceMap": true,
|
|
19
|
-
"esModuleInterop": true,
|
|
20
|
-
"skipLibCheck": true,
|
|
21
|
-
"forceConsistentCasingInFileNames": true,
|
|
22
|
-
"baseUrl": ".",
|
|
23
|
-
"allowJs": true,
|
|
24
|
-
"checkJs": true,
|
|
25
|
-
"paths": {
|
|
26
|
-
"$lib": ["src/lib"],
|
|
27
|
-
"$lib/*": ["src/lib/*"]
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
"include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.ts", "src/**/*.svelte"]
|
|
31
|
-
}
|