@rokkit/chart 1.0.0-next.16 → 1.0.0-next.160
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 +150 -46
- package/package.json +42 -45
- package/src/AnimatedPlot.svelte +383 -0
- package/src/Chart.svelte +95 -0
- package/src/ChartProvider.svelte +10 -0
- package/src/FacetPlot/Panel.svelte +37 -0
- package/src/FacetPlot.svelte +114 -0
- package/src/Plot/Arc.svelte +29 -0
- package/src/Plot/Area.svelte +32 -0
- package/src/Plot/Axis.svelte +95 -0
- package/src/Plot/Bar.svelte +54 -0
- package/src/Plot/Grid.svelte +34 -0
- package/src/Plot/Legend.svelte +233 -0
- package/src/Plot/Line.svelte +37 -0
- package/src/Plot/Point.svelte +40 -0
- package/src/Plot/Root.svelte +62 -0
- package/src/Plot/Timeline.svelte +95 -0
- package/src/Plot/Tooltip.svelte +87 -0
- package/src/Plot/index.js +9 -0
- package/src/Plot.svelte +297 -0
- package/src/PlotState.svelte.js +350 -0
- package/src/Sparkline.svelte +108 -0
- package/src/Symbol.svelte +21 -0
- package/src/Texture.svelte +18 -0
- package/src/charts/AreaChart.svelte +27 -0
- package/src/charts/BarChart.svelte +28 -0
- package/src/charts/BoxPlot.svelte +21 -0
- package/src/charts/BubbleChart.svelte +23 -0
- package/src/charts/LineChart.svelte +26 -0
- package/src/charts/PieChart.svelte +35 -0
- package/src/charts/ScatterPlot.svelte +26 -0
- package/src/charts/ViolinPlot.svelte +21 -0
- package/src/crossfilter/CrossFilter.svelte +42 -0
- package/src/crossfilter/FilterBar.svelte +24 -0
- package/src/crossfilter/FilterHistogram.svelte +290 -0
- package/src/crossfilter/FilterSlider.svelte +83 -0
- package/src/crossfilter/createCrossFilter.svelte.js +124 -0
- package/src/elements/Bar.svelte +22 -24
- package/src/elements/ColorRamp.svelte +20 -22
- package/src/elements/ContinuousLegend.svelte +20 -17
- package/src/elements/DefinePatterns.svelte +24 -0
- package/src/elements/DiscreteLegend.svelte +15 -15
- package/src/elements/Label.svelte +4 -8
- package/src/elements/SymbolGrid.svelte +22 -0
- package/src/elements/index.js +6 -0
- package/src/examples/BarChartExample.svelte +81 -0
- package/src/geoms/Arc.svelte +126 -0
- package/src/geoms/Area.svelte +78 -0
- package/src/geoms/Bar.svelte +200 -0
- package/src/geoms/Box.svelte +113 -0
- package/src/geoms/LabelPill.svelte +17 -0
- package/src/geoms/Line.svelte +123 -0
- package/src/geoms/Point.svelte +145 -0
- package/src/geoms/Violin.svelte +56 -0
- package/src/geoms/lib/areas.js +154 -0
- package/src/geoms/lib/bars.js +223 -0
- package/src/index.js +74 -16
- package/src/lib/brewer.js +25 -0
- package/src/lib/brewing/BoxBrewer.svelte.js +14 -0
- package/src/lib/brewing/CartesianBrewer.svelte.js +21 -0
- package/src/lib/brewing/PieBrewer.svelte.js +14 -0
- package/src/lib/brewing/QuartileBrewer.svelte.js +51 -0
- package/src/lib/brewing/ViolinBrewer.svelte.js +14 -0
- package/src/lib/brewing/axes.svelte.js +270 -0
- package/src/lib/brewing/bars.svelte.js +201 -0
- package/src/lib/brewing/brewer.svelte.js +277 -0
- package/src/lib/brewing/colors.js +51 -0
- package/src/lib/brewing/dimensions.svelte.js +56 -0
- package/src/lib/brewing/index.svelte.js +205 -0
- package/src/lib/brewing/legends.svelte.js +137 -0
- package/src/lib/brewing/marks/arcs.js +43 -0
- package/src/lib/brewing/marks/areas.js +72 -0
- package/src/lib/brewing/marks/bars.js +49 -0
- package/src/lib/brewing/marks/boxes.js +75 -0
- package/src/lib/brewing/marks/lines.js +55 -0
- package/src/lib/brewing/marks/points.js +105 -0
- package/src/lib/brewing/marks/violins.js +90 -0
- package/src/lib/brewing/patterns.js +45 -0
- package/src/lib/brewing/scales.js +51 -0
- package/src/lib/brewing/scales.svelte.js +82 -0
- package/src/lib/brewing/stats.js +74 -0
- package/src/lib/brewing/symbols.js +10 -0
- package/src/lib/brewing/types.js +73 -0
- package/src/lib/chart.js +221 -0
- package/src/lib/context.js +131 -0
- package/src/lib/grid.js +85 -0
- package/src/lib/keyboard-nav.js +37 -0
- package/src/lib/plot/chartProps.js +76 -0
- package/src/lib/plot/crossfilter.js +16 -0
- package/src/lib/plot/facet.js +58 -0
- package/src/lib/plot/frames.js +81 -0
- package/src/lib/plot/helpers.js +14 -0
- package/src/lib/plot/preset.js +67 -0
- package/src/lib/plot/scales.js +81 -0
- package/src/lib/plot/stat.js +92 -0
- package/src/lib/plot/types.js +65 -0
- package/src/lib/preset.js +41 -0
- package/src/lib/scales.svelte.js +151 -0
- package/src/lib/swatch.js +13 -0
- package/src/lib/ticks.js +46 -0
- package/src/lib/utils.js +111 -118
- package/src/lib/xscale.js +31 -0
- package/src/patterns/DefinePatterns.svelte +32 -0
- package/src/patterns/PatternDef.svelte +27 -0
- package/src/patterns/index.js +4 -0
- package/src/patterns/patterns.js +360 -0
- package/src/patterns/scale.js +116 -0
- package/src/spec/chart-spec.js +72 -0
- package/src/symbols/RoundedSquare.svelte +33 -0
- package/src/symbols/Shape.svelte +37 -0
- package/src/symbols/constants/index.js +4 -0
- package/src/symbols/index.js +9 -0
- package/src/symbols/outline.svelte +60 -0
- package/src/symbols/solid.svelte +60 -0
- package/LICENSE +0 -21
- package/src/chart/FacetGrid.svelte +0 -51
- package/src/chart/Grid.svelte +0 -34
- package/src/chart/Legend.svelte +0 -16
- package/src/chart/PatternDefs.svelte +0 -13
- package/src/chart/Swatch.svelte +0 -93
- package/src/chart/SwatchButton.svelte +0 -29
- package/src/chart/SwatchGrid.svelte +0 -55
- package/src/chart/Symbol.svelte +0 -37
- package/src/chart/Texture.svelte +0 -16
- package/src/chart/TexturedShape.svelte +0 -27
- package/src/chart/TimelapseChart.svelte +0 -97
- package/src/chart/Timer.svelte +0 -27
- package/src/chart.js +0 -9
- package/src/components/charts/Axis.svelte +0 -66
- package/src/components/charts/Chart.svelte +0 -35
- package/src/components/index.js +0 -23
- package/src/components/lib/axis.js +0 -0
- package/src/components/lib/chart.js +0 -187
- package/src/components/lib/color.js +0 -327
- package/src/components/lib/funnel.js +0 -204
- package/src/components/lib/index.js +0 -19
- package/src/components/lib/pattern.js +0 -190
- package/src/components/lib/rollup.js +0 -55
- package/src/components/lib/shape.js +0 -199
- package/src/components/lib/summary.js +0 -145
- package/src/components/lib/theme.js +0 -23
- package/src/components/lib/timer.js +0 -41
- package/src/components/lib/utils.js +0 -165
- package/src/components/plots/BarPlot.svelte +0 -36
- package/src/components/plots/BoxPlot.svelte +0 -54
- package/src/components/plots/ScatterPlot.svelte +0 -30
- package/src/components/store.js +0 -70
- package/src/constants.js +0 -66
- package/src/elements/PatternDefs.svelte +0 -13
- package/src/elements/PatternMask.svelte +0 -20
- package/src/elements/Symbol.svelte +0 -38
- package/src/elements/Tooltip.svelte +0 -23
- package/src/funnel.svelte +0 -35
- package/src/geom.js +0 -105
- package/src/lib/axis.js +0 -75
- package/src/lib/colors.js +0 -32
- package/src/lib/geom.js +0 -4
- package/src/lib/shapes.js +0 -144
- package/src/lib/timer.js +0 -44
- package/src/lookup.js +0 -29
- package/src/plots/BarPlot.svelte +0 -55
- package/src/plots/BoxPlot.svelte +0 -0
- package/src/plots/FunnelPlot.svelte +0 -33
- package/src/plots/HeatMap.svelte +0 -5
- package/src/plots/HeatMapCalendar.svelte +0 -129
- package/src/plots/LinePlot.svelte +0 -55
- package/src/plots/Plot.svelte +0 -25
- package/src/plots/RankBarPlot.svelte +0 -38
- package/src/plots/ScatterPlot.svelte +0 -20
- package/src/plots/ViolinPlot.svelte +0 -11
- package/src/plots/heatmap.js +0 -70
- package/src/plots/index.js +0 -10
- package/src/swatch.js +0 -11
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { summarize, heatmap } from './heatmap'
|
|
3
|
-
import { interpolateHsl } from 'd3-interpolate'
|
|
4
|
-
import { scaleLinear } from 'd3-scale'
|
|
5
|
-
import ContinuousLegend from '../elements/ContinuousLegend.svelte'
|
|
6
|
-
import DiscreteLegend from '../elements/DiscreteLegend.svelte'
|
|
7
|
-
import ColorRamp from '../elements/ColorRamp.svelte'
|
|
8
|
-
|
|
9
|
-
const dayLabelWidth = 20
|
|
10
|
-
const labelHeight = 6
|
|
11
|
-
|
|
12
|
-
export let data
|
|
13
|
-
export let dateField = 'date'
|
|
14
|
-
export let valueField = null
|
|
15
|
-
export let months = 12
|
|
16
|
-
export let colors = [transparent, '#FB8C00']
|
|
17
|
-
export let padding = 8
|
|
18
|
-
export let space = 2
|
|
19
|
-
export let size = 10
|
|
20
|
-
export let maximum = 10
|
|
21
|
-
export let tickCount = 5
|
|
22
|
-
export let discreteLegend = false
|
|
23
|
-
|
|
24
|
-
export let tooltipText = (d) => `${d.date} => ${d.value}`
|
|
25
|
-
|
|
26
|
-
let tooltip = null
|
|
27
|
-
|
|
28
|
-
function showToolTip(event, d) {
|
|
29
|
-
tooltip = d
|
|
30
|
-
}
|
|
31
|
-
function hideToolTip() {
|
|
32
|
-
tooltip = null
|
|
33
|
-
}
|
|
34
|
-
$: scale = scaleLinear()
|
|
35
|
-
.domain([0, maximum])
|
|
36
|
-
.range(colors)
|
|
37
|
-
.interpolate(interpolateHsl)
|
|
38
|
-
|
|
39
|
-
$: legendHeight = 2 * size + space * 3
|
|
40
|
-
$: sizeWithSpace = size + space
|
|
41
|
-
$: summary = summarize(data, dateField, valueField)
|
|
42
|
-
$: datamap = heatmap(summary, months)
|
|
43
|
-
$: width =
|
|
44
|
-
datamap.numberOfWeeks * sizeWithSpace + dayLabelWidth + 2 * padding - space
|
|
45
|
-
$: height = 7 * sizeWithSpace + labelHeight + 2 * padding + legendHeight
|
|
46
|
-
</script>
|
|
47
|
-
|
|
48
|
-
<div>
|
|
49
|
-
<svg class="chart" viewBox="0 0 {width} {height}">
|
|
50
|
-
{#if tooltip}
|
|
51
|
-
<text
|
|
52
|
-
x={padding + dayLabelWidth}
|
|
53
|
-
y={padding + legendHeight - labelHeight}
|
|
54
|
-
text-anchor="start"
|
|
55
|
-
font-size={labelHeight}
|
|
56
|
-
>
|
|
57
|
-
{tooltipText(tooltip)}
|
|
58
|
-
</text>
|
|
59
|
-
{/if}
|
|
60
|
-
{#if discreteLegend}
|
|
61
|
-
<DiscreteLegend
|
|
62
|
-
{scale}
|
|
63
|
-
x={width - (tickCount + 1) * sizeWithSpace - padding - space}
|
|
64
|
-
y={padding}
|
|
65
|
-
{tickCount}
|
|
66
|
-
/>
|
|
67
|
-
{:else}
|
|
68
|
-
<ColorRamp {scale} x={width - 100 - padding} y={padding} {tickCount} />
|
|
69
|
-
<!-- <ContinuousLegend
|
|
70
|
-
{scale}
|
|
71
|
-
x={width - 100 - padding}
|
|
72
|
-
y={padding}
|
|
73
|
-
{tickCount}
|
|
74
|
-
/> -->
|
|
75
|
-
{/if}
|
|
76
|
-
{#each datamap.weekdays as name, i}
|
|
77
|
-
<text
|
|
78
|
-
x={padding + dayLabelWidth - 2 * space}
|
|
79
|
-
y={padding +
|
|
80
|
-
legendHeight +
|
|
81
|
-
i * sizeWithSpace +
|
|
82
|
-
labelHeight +
|
|
83
|
-
(size - labelHeight) / 2}
|
|
84
|
-
text-anchor="end"
|
|
85
|
-
font-size={labelHeight}>{name}</text
|
|
86
|
-
>
|
|
87
|
-
{/each}
|
|
88
|
-
|
|
89
|
-
{#each datamap.grid as d}
|
|
90
|
-
<rect
|
|
91
|
-
x={d.x * sizeWithSpace + padding + dayLabelWidth}
|
|
92
|
-
y={d.y * sizeWithSpace + padding + legendHeight}
|
|
93
|
-
width={size}
|
|
94
|
-
height={size}
|
|
95
|
-
fill={scale(d.value)}
|
|
96
|
-
rx="1"
|
|
97
|
-
ry="1"
|
|
98
|
-
on:mouseover={(e) => showToolTip(e, d)}
|
|
99
|
-
on:focus={(e) => showToolTip(e, d)}
|
|
100
|
-
on:blur={hideToolTip}
|
|
101
|
-
on:mouseout={hideToolTip}
|
|
102
|
-
/>
|
|
103
|
-
{/each}
|
|
104
|
-
|
|
105
|
-
{#each Object.keys(datamap.months) as name}
|
|
106
|
-
<text
|
|
107
|
-
x={padding + dayLabelWidth + datamap.months[name] * sizeWithSpace}
|
|
108
|
-
y={padding + legendHeight + 7 * sizeWithSpace + 3 * space}
|
|
109
|
-
text-anchor="start"
|
|
110
|
-
font-size={labelHeight}
|
|
111
|
-
fill="currentColor">{name}</text
|
|
112
|
-
>
|
|
113
|
-
{/each}
|
|
114
|
-
</svg>
|
|
115
|
-
</div>
|
|
116
|
-
|
|
117
|
-
<style>
|
|
118
|
-
div {
|
|
119
|
-
position: relative;
|
|
120
|
-
}
|
|
121
|
-
rect {
|
|
122
|
-
stroke: currentColor;
|
|
123
|
-
stroke-width: 0.5;
|
|
124
|
-
stroke-opacity: 0.1;
|
|
125
|
-
}
|
|
126
|
-
text {
|
|
127
|
-
fill: currentColor;
|
|
128
|
-
}
|
|
129
|
-
</style>
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { getContext } from 'svelte'
|
|
3
|
-
import { colorBrewer } from '../lib/colors'
|
|
4
|
-
|
|
5
|
-
let chart = getContext('chart')
|
|
6
|
-
|
|
7
|
-
export let labels = false
|
|
8
|
-
export let fontSize = $chart.height / 32
|
|
9
|
-
// export let color = 'white'
|
|
10
|
-
|
|
11
|
-
$: colors = colorBrewer($chart.data.map((d) => d.color))
|
|
12
|
-
// export let limit = 8
|
|
13
|
-
|
|
14
|
-
$: data = $chart.data.map((d) => ({
|
|
15
|
-
x: $chart.flipCoords ? $chart.scale.x(0) : $chart.scale.x(d.x),
|
|
16
|
-
y: $chart.flipCoords ? $chart.scale.y(d.y) : $chart.scale.y(d.y),
|
|
17
|
-
y0: $chart.scale.y(0),
|
|
18
|
-
width: $chart.flipCoords
|
|
19
|
-
? $chart.scale.x(d.x) - $chart.scale.x(0)
|
|
20
|
-
: $chart.scale.x.bandwidth(),
|
|
21
|
-
height: $chart.flipCoords
|
|
22
|
-
? $chart.scale.y.bandwidth()
|
|
23
|
-
: $chart.scale.y(0) - $chart.scale.y(d.y),
|
|
24
|
-
color: colors[d.color],
|
|
25
|
-
label: {
|
|
26
|
-
x: $chart.flipCoords
|
|
27
|
-
? $chart.scale.x(d.x) - $chart.scale.x(0) - 10
|
|
28
|
-
: $chart.scale.x.bandwidth() / 2,
|
|
29
|
-
y: $chart.flipCoords ? $chart.scale.y.bandwidth() / 2 : 10,
|
|
30
|
-
angle: $chart.flipCoords ? 0 : -90,
|
|
31
|
-
text: $chart.flipCoords ? d.y + ' (' + d.x + ')' : d.x + ' (' + d.y + ')'
|
|
32
|
-
}
|
|
33
|
-
}))
|
|
34
|
-
|
|
35
|
-
// $: console.log(data)
|
|
36
|
-
</script>
|
|
37
|
-
|
|
38
|
-
{#each data as { x1, y1, x2, y2, color, label }}
|
|
39
|
-
<line {x1} {y1} {x2} {y2} stroke={color} />
|
|
40
|
-
{#if labels}
|
|
41
|
-
{@const tx = x1 + label.x}
|
|
42
|
-
{@const ty = y1 + label.y}
|
|
43
|
-
<text
|
|
44
|
-
x={tx}
|
|
45
|
-
y={ty}
|
|
46
|
-
transform="rotate({label.angle},{tx},{ty})"
|
|
47
|
-
font-size={fontSize}
|
|
48
|
-
text-anchor="end"
|
|
49
|
-
alignment-baseline="middle"
|
|
50
|
-
fill={color}
|
|
51
|
-
>
|
|
52
|
-
{label.text}
|
|
53
|
-
</text>
|
|
54
|
-
{/if}
|
|
55
|
-
{/each}
|
package/src/plots/Plot.svelte
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { aggregate, getScales } from '../lib/utils'
|
|
3
|
-
|
|
4
|
-
import BoxPlot from './BoxPlot.svelte'
|
|
5
|
-
import ScatterPlot from './ScatterPlot.svelte'
|
|
6
|
-
|
|
7
|
-
export let data
|
|
8
|
-
export let width
|
|
9
|
-
export let height
|
|
10
|
-
export let x
|
|
11
|
-
export let y
|
|
12
|
-
export let plots = []
|
|
13
|
-
|
|
14
|
-
$: nested = aggregate(data, x, y)
|
|
15
|
-
$: scales = getScales(data, x, y, width, height)
|
|
16
|
-
</script>
|
|
17
|
-
|
|
18
|
-
<svg viewBox="0 0 {width} {height}">
|
|
19
|
-
{#if plots.includes('box')}
|
|
20
|
-
<BoxPlot data={nested} {...scales} />
|
|
21
|
-
{/if}
|
|
22
|
-
{#if plots.includes('scatter')}
|
|
23
|
-
<ScatterPlot {data} {x} {y} {...scales} />
|
|
24
|
-
{/if}
|
|
25
|
-
</svg>
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import Bar from '../elements/Bar.svelte'
|
|
3
|
-
import { max } from 'd3-array'
|
|
4
|
-
import { writable } from 'svelte/store'
|
|
5
|
-
import { tweened } from 'svelte/motion'
|
|
6
|
-
import { scaleLinear } from 'd3-scale'
|
|
7
|
-
|
|
8
|
-
export let data
|
|
9
|
-
export let colors
|
|
10
|
-
export let width = 800
|
|
11
|
-
export let limit = 8
|
|
12
|
-
export let duration = 300
|
|
13
|
-
const h = 50
|
|
14
|
-
let height
|
|
15
|
-
const pad = 5
|
|
16
|
-
|
|
17
|
-
const xMax = tweened(null, { duration })
|
|
18
|
-
const scales = writable({})
|
|
19
|
-
|
|
20
|
-
$: xMax.set(max(data.map((d) => d.value)))
|
|
21
|
-
$: height = pad + (h + pad) * limit
|
|
22
|
-
$: scales.set({
|
|
23
|
-
x: scaleLinear()
|
|
24
|
-
.domain([0, $xMax])
|
|
25
|
-
.range([10, width - 10]),
|
|
26
|
-
y: scaleLinear().domain([0, limit]).range([0, height])
|
|
27
|
-
})
|
|
28
|
-
</script>
|
|
29
|
-
|
|
30
|
-
<svg viewBox="0 0 {width} {height}">
|
|
31
|
-
{#if Array.isArray(data)}
|
|
32
|
-
{#each data as item, i}
|
|
33
|
-
{#if item.rank < limit}
|
|
34
|
-
<Bar {...item} fill={colors[item.name]} {scales} />
|
|
35
|
-
{/if}
|
|
36
|
-
{/each}
|
|
37
|
-
{/if}
|
|
38
|
-
</svg>
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { getContext } from 'svelte'
|
|
3
|
-
import { colorBrewer } from '../lib/colors'
|
|
4
|
-
|
|
5
|
-
let chart = getContext('chart')
|
|
6
|
-
|
|
7
|
-
export let size = $chart.height / 128
|
|
8
|
-
|
|
9
|
-
$: colors = colorBrewer($chart.data.map((d) => d.fill))
|
|
10
|
-
$: points = $chart.data.map((d) => ({
|
|
11
|
-
cx: $chart.scale.x(d.x),
|
|
12
|
-
cy: $chart.scale.y(d.y),
|
|
13
|
-
fill: colors[d.fill]
|
|
14
|
-
}))
|
|
15
|
-
// support shapes and sizes for scatter
|
|
16
|
-
</script>
|
|
17
|
-
|
|
18
|
-
{#each points as { cx, cy, fill }}
|
|
19
|
-
<circle {cx} {cy} r={size} {fill} fill-opacity="0.5" />
|
|
20
|
-
{/each}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { getContext } from 'svelte'
|
|
3
|
-
|
|
4
|
-
let chart = getContext('chart')
|
|
5
|
-
$: data = $chart.violin()
|
|
6
|
-
// $: console.log(data)
|
|
7
|
-
</script>
|
|
8
|
-
|
|
9
|
-
{#each data as { x, curve }, i}
|
|
10
|
-
<path d={curve} transform="translate({x},0)" fill="gray" stroke="none" />
|
|
11
|
-
{/each}
|
package/src/plots/heatmap.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isSunday,
|
|
3
|
-
addDays,
|
|
4
|
-
subMonths,
|
|
5
|
-
startOfMonth,
|
|
6
|
-
format,
|
|
7
|
-
previousSunday,
|
|
8
|
-
differenceInDays,
|
|
9
|
-
differenceInWeeks,
|
|
10
|
-
endOfWeek
|
|
11
|
-
} from 'date-fns'
|
|
12
|
-
import { nest } from 'd3-collection'
|
|
13
|
-
import { group } from 'd3-array'
|
|
14
|
-
|
|
15
|
-
const DATE_FORMAT = 'yyyy-MM-dd'
|
|
16
|
-
const weekdays = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
|
|
17
|
-
|
|
18
|
-
export function summarize(data, dateField = 'date', valueField) {
|
|
19
|
-
// const summary = group(data, d => d[dateField])
|
|
20
|
-
const nested = nest()
|
|
21
|
-
.key((d) => format(new Date(d[dateField]), DATE_FORMAT))
|
|
22
|
-
.rollup((d) =>
|
|
23
|
-
valueField
|
|
24
|
-
? d.map((value) => value[valueField]).reduce((a, b) => a + b, 0)
|
|
25
|
-
: d.length
|
|
26
|
-
)
|
|
27
|
-
.entries(data)
|
|
28
|
-
// console.log(Object.fromEntries(nested))
|
|
29
|
-
return nested.reduce((obj, item) => ((obj[item.key] = item.value), obj), {})
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function heatmap(data, numberOfMonths) {
|
|
33
|
-
const today = new Date()
|
|
34
|
-
const firstDay = getFirstDay(numberOfMonths, today)
|
|
35
|
-
const months = {}
|
|
36
|
-
const grid = generateGrid(firstDay, today).map((d) => ({
|
|
37
|
-
...d,
|
|
38
|
-
value: d.date in data ? data[d.date] : 0
|
|
39
|
-
}))
|
|
40
|
-
|
|
41
|
-
grid.map((d) => {
|
|
42
|
-
const month = format(endOfWeek(new Date(d.date)), 'MMM')
|
|
43
|
-
// console.log(month)
|
|
44
|
-
if (!(month in months)) {
|
|
45
|
-
months[month] = d.x
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
return {
|
|
49
|
-
grid,
|
|
50
|
-
months,
|
|
51
|
-
weekdays,
|
|
52
|
-
numberOfWeeks: differenceInWeeks(today, firstDay) + 1
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function getFirstDay(months, lastDay = new Date()) {
|
|
57
|
-
const firstDay = subMonths(startOfMonth(lastDay), months)
|
|
58
|
-
return isSunday(firstDay) ? firstDay : previousSunday(firstDay)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function generateGrid(firstDay, lastDay) {
|
|
62
|
-
const days = differenceInDays(lastDay, firstDay) + 1
|
|
63
|
-
|
|
64
|
-
const grid = [...Array(days).keys()].map((day) => ({
|
|
65
|
-
x: Math.floor(day / 7),
|
|
66
|
-
y: day % 7,
|
|
67
|
-
date: format(addDays(firstDay, day), DATE_FORMAT)
|
|
68
|
-
}))
|
|
69
|
-
return grid
|
|
70
|
-
}
|
package/src/plots/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { default as Box } from './BoxPlot.svelte'
|
|
2
|
-
export { default as BoxPlot } from './BoxPlot.svelte'
|
|
3
|
-
export { default as Bar } from './BarPlot.svelte'
|
|
4
|
-
export { default as BarPlot } from './BarPlot.svelte'
|
|
5
|
-
export { default as Line } from './LinePlot.svelte'
|
|
6
|
-
export { default as LinePlot } from './LinePlot.svelte'
|
|
7
|
-
export { default as Violin } from './ViolinPlot.svelte'
|
|
8
|
-
export { default as ViolinPlot } from './ViolinPlot.svelte'
|
|
9
|
-
export { default as Scatter } from './ScatterPlot.svelte'
|
|
10
|
-
export { default as ScatterPlot } from './ScatterPlot.svelte'
|
package/src/swatch.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { writable } from 'svelte/store'
|
|
2
|
-
|
|
3
|
-
// import { __patterns__, __colors__, __shapes__ } from './constants'
|
|
4
|
-
|
|
5
|
-
export const swatchStore = writable({})
|
|
6
|
-
|
|
7
|
-
// A set of 7 should be sufficient
|
|
8
|
-
// array of names and patterns
|
|
9
|
-
// array of names and shapes
|
|
10
|
-
// array of colors
|
|
11
|
-
// array of shades of one color.
|