@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/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
- return this.getAttribute('height') - top - bottom;
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) {
@@ -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
- return hasExtent(channel, mark.type)
15
- ? {
16
- [`${channel}1`]: binField(mark, field, options),
17
- [`${channel}2`]: binField(mark, field, { ...options, offset: 1 })
18
- }
19
- : {
20
- [channel]: binField(mark, field, options)
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 = asColumn(column);
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
- return `${b.min} + ${alpha} * (${off}FLOOR(${base} / ${alpha})::INTEGER)`;
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
- }
@@ -1,3 +0,0 @@
1
- export function isArrowTable(values) {
2
- return typeof values?.getChild === 'function';
3
- }