Skip to content

Commit

Permalink
jheer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
frtennis1 committed Jan 1, 2024
1 parent 4b835b6 commit 3ea0883
Showing 2 changed files with 12 additions and 26 deletions.
20 changes: 8 additions & 12 deletions packages/vgplot/src/spec/parse-spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Param, Selection, coordinator } from '@uwdata/mosaic-core';
import { menu, search, slider, table } from '@uwdata/mosaic-inputs';
import {
sql, agg, avg, count, max, median, min, mode, quantile, sum,
sql, avg, count, max, median, min, mode, quantile, sum,
row_number, rank, dense_rank, percent_rank, cume_dist, ntile,
lag, lead, first_value, last_value, nth_value,
dateMonth, dateMonthDay, dateDay
@@ -155,10 +155,9 @@ export class ParseContext {

maybeTransform(value) {
if (isObject(value)) {
return value.expr
? parseExpression(value, this) :
(value.agg ? parseAggregation(value, this)
: parseTransform(value, this));
return value.expr ? parseExpression(value, this)
: value.agg ? parseAggregation(value, this)
: parseTransform(value, this);
}
}

@@ -364,7 +363,7 @@ function parseInteractor(spec, ctx) {
return fn(options);
}

function parseExprOrAgg(spec, ctx, key, func) {
function parseExpression(spec, ctx, key = 'expr') {
const { label } = spec;
const expr = spec[key];
const tokens = expr.split(/(\\'|\\"|"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|\$\w+)/g);
@@ -381,17 +380,14 @@ function parseExprOrAgg(spec, ctx, key, func) {
}
}

return func(spans, ...exprs).annotate({ label });
}

function parseExpression(spec, ctx) {
return parseExprOrAgg(spec, ctx, "expr", sql);
return sql(spans, ...exprs).annotate({ label });
}

function parseAggregation(spec, ctx) {
return parseExprOrAgg(spec, ctx, "agg", agg);
return parseExpression(spec, ctx, 'agg').annotate({aggregate: true});
}


function parseTransform(spec, ctx) {
const { transforms } = ctx;
let name;
18 changes: 4 additions & 14 deletions packages/vgplot/src/spec/to-module.js
Original file line number Diff line number Diff line change
@@ -143,10 +143,8 @@ class CodegenContext extends ParseContext {

maybeTransform(value) {
if (isObject(value)) {
return value.expr
? parseExpression(value, this)
: value.agg ?
parseAggregation(value, this)
return value.expr ? parseExpression(value, this)
: value.agg ? parseExpression(value, this, 'agg', 'agg')
: parseTransform(value, this);
}
}
@@ -164,7 +162,7 @@ class CodegenContext extends ParseContext {
}
}

function parseExprOrAgg(spec, ctx, key, func_name) {
function parseExpression(spec, ctx, key = 'expr', method = 'sql') {
const { label } = spec;
const expr = spec[key]
const tokens = expr.split(/(\\'|\\"|"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|\$\w+)/g);
@@ -179,18 +177,10 @@ function parseExprOrAgg(spec, ctx, key, func_name) {
}
}

return `${func_name}\`${str}\``
return `vg.${method}\`${str}\``
+ (label ? `.annotate({ label: ${JSON.stringify(label)} })` : '');
}

function parseExpression(spec, ctx) {
return parseExprOrAgg(spec, ctx, "expr", "vg.sql");
}

function parseAggregation(spec, ctx) {
return parseExprOrAgg(spec, ctx, "agg", "vg.agg");
}

function parseTransform(spec, ctx) {
const { transforms } = ctx;
let name;

0 comments on commit 3ea0883

Please sign in to comment.