@uwdata/mosaic-inputs 0.5.0 → 0.6.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.
@@ -12311,8 +12311,7 @@ var arrayAgg = aggf("ARRAY_AGG");
12311
12311
 
12312
12312
  // ../sql/src/datetime.js
12313
12313
  var epoch_ms = (expr) => {
12314
- const d = asColumn(expr);
12315
- return sql`(1000 * (epoch(${d}) - second(${d})) + millisecond(${d}))::DOUBLE`;
12314
+ return sql`epoch_ms(${asColumn(expr)})`;
12316
12315
  };
12317
12316
 
12318
12317
  // ../sql/src/spatial.js
@@ -12719,6 +12718,89 @@ function isDoubleQuoted(s) {
12719
12718
  return s[0] === '"' && s[s.length - 1] === '"';
12720
12719
  }
12721
12720
 
12721
+ // ../sql/src/scales.js
12722
+ var identity = (x2) => x2;
12723
+ function scaleLinear() {
12724
+ return {
12725
+ apply: identity,
12726
+ invert: identity,
12727
+ sqlApply: asColumn,
12728
+ sqlInvert: identity
12729
+ };
12730
+ }
12731
+ function scaleLog({ base } = {}) {
12732
+ if (base == null || base === Math.E) {
12733
+ return {
12734
+ apply: Math.log,
12735
+ invert: Math.exp,
12736
+ sqlApply: (c) => sql`LN(${asColumn(c)})`,
12737
+ sqlInvert: (c) => sql`EXP(${c})`
12738
+ };
12739
+ } else if (base === 10) {
12740
+ return {
12741
+ apply: Math.log10,
12742
+ invert: (x2) => Math.pow(10, x2),
12743
+ sqlApply: (c) => sql`LOG(${asColumn(c)})`,
12744
+ sqlInvert: (c) => sql`POW(10, ${c})`
12745
+ };
12746
+ } else {
12747
+ const b = +base;
12748
+ return {
12749
+ apply: (x2) => Math.log(x2) / Math.log(b),
12750
+ invert: (x2) => Math.pow(b, x2),
12751
+ sqlApply: (c) => sql`LN(${asColumn(c)}) / LN(${b})`,
12752
+ sqlInvert: (c) => sql`POW(${b}, ${c})`
12753
+ };
12754
+ }
12755
+ }
12756
+ function scaleSymlog({ constant = 1 } = {}) {
12757
+ const _ = +constant;
12758
+ return {
12759
+ apply: (x2) => Math.sign(x2) * Math.log1p(Math.abs(x2)),
12760
+ invert: (x2) => Math.sign(x2) * Math.exp(Math.abs(x2) - _),
12761
+ sqlApply: (c) => (c = asColumn(c), sql`SIGN(${c}) * LN(${_} + ABS(${c}))`),
12762
+ sqlInvert: (c) => sql`SIGN(${c}) * (EXP(ABS(${c})) - ${_})`
12763
+ };
12764
+ }
12765
+ function scaleSqrt() {
12766
+ return {
12767
+ apply: (x2) => Math.sign(x2) * Math.sqrt(Math.abs(x2)),
12768
+ invert: (x2) => Math.sign(x2) * x2 * x2,
12769
+ sqlApply: (c) => (c = asColumn(c), sql`SIGN(${c}) * SQRT(ABS(${c}))`),
12770
+ sqlInvert: (c) => sql`SIGN(${c}) * (${c}) ** 2`
12771
+ };
12772
+ }
12773
+ function scalePow({ exponent = 1 } = {}) {
12774
+ const e = +exponent;
12775
+ return {
12776
+ apply: (x2) => Math.sign(x2) * Math.pow(Math.abs(x2), e),
12777
+ invert: (x2) => Math.sign(x2) * Math.pow(Math.abs(x2), 1 / e),
12778
+ sqlApply: (c) => (c = asColumn(c), sql`SIGN(${c}) * POW(ABS(${c}), ${e})`),
12779
+ sqlInvert: (c) => sql`SIGN(${c}) * POW(ABS(${c}), 1/${e})`
12780
+ };
12781
+ }
12782
+ function scaleTime() {
12783
+ return {
12784
+ apply: (x2) => +x2,
12785
+ invert: (x2) => new Date(x2),
12786
+ sqlApply: (c) => c instanceof Date ? +c : epoch_ms(asColumn(c)),
12787
+ sqlInvert: identity
12788
+ };
12789
+ }
12790
+ var scales = {
12791
+ linear: scaleLinear,
12792
+ log: scaleLog,
12793
+ symlog: scaleSymlog,
12794
+ sqrt: scaleSqrt,
12795
+ pow: scalePow,
12796
+ time: scaleTime,
12797
+ utc: scaleTime
12798
+ };
12799
+ function scaleTransform(options) {
12800
+ const scale = scales[options.type];
12801
+ return scale ? { ...options, ...scale(options) } : null;
12802
+ }
12803
+
12722
12804
  // ../sql/src/load/create.js
12723
12805
  function create(name, query, {
12724
12806
  replace = false,
@@ -12878,7 +12960,6 @@ function fnv_mix(a) {
12878
12960
  }
12879
12961
 
12880
12962
  // ../core/src/DataCubeIndexer.js
12881
- var identity = (x2) => x2;
12882
12963
  var DataCubeIndexer = class {
12883
12964
  /**
12884
12965
  *
@@ -12971,10 +13052,10 @@ function getActiveView(clause) {
12971
13052
  let columns = clause.predicate?.columns;
12972
13053
  if (!schema || !columns)
12973
13054
  return null;
12974
- const { type, scales, pixelSize = 1 } = schema;
13055
+ const { type, scales: scales2, pixelSize = 1 } = schema;
12975
13056
  let predicate;
12976
- if (type === "interval" && scales) {
12977
- const bins = scales.map((s) => binInterval(s, pixelSize));
13057
+ if (type === "interval" && scales2) {
13058
+ const bins = scales2.map((s) => binInterval(s, pixelSize));
12978
13059
  if (bins.some((b) => b == null))
12979
13060
  return null;
12980
13061
  if (bins.length === 1) {
@@ -12987,7 +13068,7 @@ function getActiveView(clause) {
12987
13068
  );
12988
13069
  }
12989
13070
  } else if (type === "point") {
12990
- predicate = identity;
13071
+ predicate = (x2) => x2;
12991
13072
  columns = Object.fromEntries(columns.map((col) => [col.toString(), col]));
12992
13073
  } else {
12993
13074
  return null;
@@ -12995,39 +13076,15 @@ function getActiveView(clause) {
12995
13076
  return { source, columns, predicate };
12996
13077
  }
12997
13078
  function binInterval(scale, pixelSize) {
12998
- const { type, domain, range } = scale;
12999
- let lift, toSql;
13000
- switch (type) {
13001
- case "linear":
13002
- lift = identity;
13003
- toSql = asColumn;
13004
- break;
13005
- case "log":
13006
- lift = Math.log;
13007
- toSql = (c) => sql`LN(${asColumn(c)})`;
13008
- break;
13009
- case "symlog":
13010
- lift = (x2) => Math.sign(x2) * Math.log1p(Math.abs(x2));
13011
- toSql = (c) => (c = asColumn(c), sql`SIGN(${c}) * LN(1 + ABS(${c}))`);
13012
- break;
13013
- case "sqrt":
13014
- lift = Math.sqrt;
13015
- toSql = (c) => sql`SQRT(${asColumn(c)})`;
13016
- break;
13017
- case "utc":
13018
- case "time":
13019
- lift = (x2) => +x2;
13020
- toSql = (c) => c instanceof Date ? +c : epoch_ms(asColumn(c));
13021
- break;
13079
+ const { apply, sqlApply } = scaleTransform(scale);
13080
+ if (apply) {
13081
+ const { domain, range } = scale;
13082
+ const lo = apply(Math.min(...domain));
13083
+ const hi = apply(Math.max(...domain));
13084
+ const a = Math.abs(range[1] - range[0]) / (hi - lo) / pixelSize;
13085
+ const s = pixelSize === 1 ? "" : `${pixelSize}::INTEGER * `;
13086
+ return (value) => sql`${s}FLOOR(${a}::DOUBLE * (${sqlApply(value)} - ${lo}::DOUBLE))::INTEGER`;
13022
13087
  }
13023
- return lift ? binFunction(domain, range, pixelSize, lift, toSql) : null;
13024
- }
13025
- function binFunction(domain, range, pixelSize, lift, toSql) {
13026
- const lo = lift(Math.min(domain[0], domain[1]));
13027
- const hi = lift(Math.max(domain[0], domain[1]));
13028
- const a = Math.abs(lift(range[1]) - lift(range[0])) / (hi - lo) / pixelSize;
13029
- const s = pixelSize === 1 ? "" : `${pixelSize}::INTEGER * `;
13030
- return (value) => sql`${s}FLOOR(${a}::DOUBLE * (${toSql(value)} - ${lo}::DOUBLE))::INTEGER`;
13031
13088
  }
13032
13089
  var NO_INDEX = { from: NaN };
13033
13090
  function getIndexColumns(client) {