@uwdata/mosaic-plot 0.5.0 → 0.6.1
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/mosaic-plot.js +6667 -6136
- package/dist/mosaic-plot.min.js +14 -14
- package/package.json +4 -4
- package/src/index.js +1 -1
- package/src/marks/ConnectedMark.js +21 -22
- package/src/marks/ContourMark.js +16 -10
- package/src/marks/DenseLineMark.js +8 -13
- package/src/marks/Density1DMark.js +11 -13
- package/src/marks/Density2DMark.js +27 -25
- package/src/marks/Grid2DMark.js +105 -52
- package/src/marks/RasterMark.js +188 -64
- package/src/marks/RasterTileMark.js +54 -100
- package/src/marks/util/arrow.js +55 -0
- package/src/marks/util/bin-expr.js +30 -0
- package/src/marks/util/channel-scale.js +27 -0
- package/src/marks/util/density.js +26 -7
- package/src/marks/util/grid.js +94 -29
- package/src/marks/util/interpolate.js +196 -0
- package/src/marks/util/raster.js +113 -26
- package/src/marks/util/to-data-array.js +2 -22
- package/src/plot-attributes.js +18 -0
- package/src/plot.js +7 -2
- package/src/transforms/bin.js +18 -20
- package/src/marks/util/bin-field.js +0 -17
- package/src/marks/util/is-arrow-table.js +0 -3
package/src/plot.js
CHANGED
|
@@ -39,9 +39,14 @@ export class Plot {
|
|
|
39
39
|
return this.getAttribute('width') - left - right;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
innerHeight() {
|
|
42
|
+
innerHeight(defaultValue = 400) {
|
|
43
43
|
const { top, bottom } = this.margins();
|
|
44
|
-
|
|
44
|
+
let h = this.getAttribute('height');
|
|
45
|
+
if (h == null && defaultValue != null) {
|
|
46
|
+
h = defaultValue; // TODO could apply more nuanced logic here
|
|
47
|
+
this.setAttribute('height', h, { silent: true });
|
|
48
|
+
}
|
|
49
|
+
return h - top - bottom;
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
pending(mark) {
|
package/src/transforms/bin.js
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
import { asColumn } from '@uwdata/mosaic-sql';
|
|
2
1
|
import { Transform } from '../symbols.js';
|
|
2
|
+
import { channelScale } from '../marks/util/channel-scale.js';
|
|
3
3
|
|
|
4
|
-
const EXTENT = [
|
|
5
|
-
'rectY-x', 'rectX-y', 'rect-x', 'rect-y'
|
|
6
|
-
];
|
|
7
|
-
|
|
8
|
-
function hasExtent(channel, type) {
|
|
9
|
-
return EXTENT.includes(`${type}-${channel}`);
|
|
10
|
-
}
|
|
4
|
+
const EXTENT = new Set(['rectY-x', 'rectX-y', 'rect-x', 'rect-y']);
|
|
11
5
|
|
|
12
6
|
export function bin(field, options = { steps: 25 }) {
|
|
13
7
|
const fn = (mark, channel) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
if (EXTENT.has(`${mark.type}-${channel}`)) {
|
|
9
|
+
return {
|
|
10
|
+
[`${channel}1`]: binField(mark, channel, field, options),
|
|
11
|
+
[`${channel}2`]: binField(mark, channel, field, { ...options, offset: 1 })
|
|
12
|
+
};
|
|
13
|
+
} else {
|
|
14
|
+
return {
|
|
15
|
+
[channel]: binField(mark, channel, field, options)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
22
18
|
};
|
|
23
19
|
fn[Transform] = true;
|
|
24
20
|
return fn;
|
|
25
21
|
}
|
|
26
22
|
|
|
27
|
-
function binField(mark, column, options) {
|
|
23
|
+
function binField(mark, channel, column, options) {
|
|
28
24
|
return {
|
|
29
25
|
column,
|
|
30
26
|
label: column,
|
|
@@ -32,13 +28,15 @@ function binField(mark, column, options) {
|
|
|
32
28
|
get columns() { return [column]; },
|
|
33
29
|
get basis() { return column; },
|
|
34
30
|
toString() {
|
|
31
|
+
const { apply, sqlApply, sqlInvert } = channelScale(mark, channel);
|
|
35
32
|
const { min, max } = mark.stats[column];
|
|
36
|
-
const b = bins(min, max, options);
|
|
37
|
-
const col =
|
|
33
|
+
const b = bins(apply(min), apply(max), options);
|
|
34
|
+
const col = sqlApply(column);
|
|
38
35
|
const base = b.min === 0 ? col : `(${col} - ${b.min})`;
|
|
39
36
|
const alpha = `${(b.max - b.min) / b.steps}::DOUBLE`;
|
|
40
37
|
const off = options.offset ? `${options.offset} + ` : '';
|
|
41
|
-
|
|
38
|
+
const expr = `${b.min} + ${alpha} * (${off}FLOOR(${base} / ${alpha}))`;
|
|
39
|
+
return `${sqlInvert(expr)}`;
|
|
42
40
|
}
|
|
43
41
|
};
|
|
44
42
|
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { epoch_ms, sql } from '@uwdata/mosaic-sql';
|
|
2
|
-
|
|
3
|
-
export function binField(mark, channel, expr) {
|
|
4
|
-
if (!mark.stats) return field;
|
|
5
|
-
const { field } = mark.channelField(channel);
|
|
6
|
-
const { type } = mark.stats[field.column];
|
|
7
|
-
expr = expr ?? field;
|
|
8
|
-
return type === 'date' ? epoch_ms(expr) : expr;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function bin1d(x, x0, x1, n, reverse = false, pad = 1) {
|
|
12
|
-
const d = (n - pad) / (x1 - x0);
|
|
13
|
-
const f = d !== 1 ? ` * ${d}::DOUBLE` : '';
|
|
14
|
-
return reverse
|
|
15
|
-
? sql`(${+x1} - ${x}::DOUBLE)${f}`
|
|
16
|
-
: sql`(${x}::DOUBLE - ${+x0})${f}`;
|
|
17
|
-
}
|