Skip to content

Commit

Permalink
Adds support for boolean time series data,
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Smart <jlsmart@meta.com>
  • Loading branch information
anagrd-ai committed Jan 3, 2025
1 parent d5928c1 commit 2f29f7b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
11 changes: 11 additions & 0 deletions packages/malloy-render/src/component/render-result-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
getFieldKey,
valueIsDateTime,
valueIsNumber,
valueIsBoolean,
valueIsString,
} from './util';
import {
Expand Down Expand Up @@ -187,6 +188,16 @@ const populateFieldMeta = (data: DataArray, metadata: RenderResultMetadata) => {
fieldMeta.values.add(n);
fieldSet.add(n);
}
} else if (valueIsBoolean(f, value)) {
const bool:boolean = value;

Check failure on line 192 in packages/malloy-render/src/component/render-result-metadata.ts

View workflow job for this annotation

GitHub Actions / test-all (18.x)

Insert `·`
if (f.isAtomicField() && f.sourceWasDimension()) {
fieldMeta.values.add(bool);
fieldSet.add(bool);
}
if (!fieldMeta.minString || fieldMeta.minString.length > 4)
fieldMeta.minString = "true";

Check failure on line 198 in packages/malloy-render/src/component/render-result-metadata.ts

View workflow job for this annotation

GitHub Actions / test-all (18.x)

Replace `"true"` with `'true'`

Check warning on line 198 in packages/malloy-render/src/component/render-result-metadata.ts

View workflow job for this annotation

GitHub Actions / test-all (18.x)

Strings must use singlequote
if (!fieldMeta.maxString || fieldMeta.maxString.length < 5)
fieldMeta.maxString = "false";

Check failure on line 200 in packages/malloy-render/src/component/render-result-metadata.ts

View workflow job for this annotation

GitHub Actions / test-all (18.x)

Replace `"false"` with `'false'`

Check warning on line 200 in packages/malloy-render/src/component/render-result-metadata.ts

View workflow job for this annotation

GitHub Actions / test-all (18.x)

Strings must use singlequote
} else if (valueIsString(f, value)) {
const s = value;
fieldMeta.values.add(s);
Expand Down
2 changes: 1 addition & 1 deletion packages/malloy-render/src/component/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface FieldRenderMetadata {
max: number | null;
minString: string | null;
maxString: string | null;
values: Set<string | number>;
values: Set<string | number | boolean>;
maxRecordCt: number | null;
maxUniqueFieldValueCounts: Map<string, number>;
vegaChartProps?: VegaChartProps;
Expand Down
4 changes: 4 additions & 0 deletions packages/malloy-render/src/component/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export function valueIsNumber(f: Field, v: unknown): v is number {
return f.isAtomicField() && f.isNumber() && v !== null;
}

export function valueIsBoolean(f: Field, v: unknown): v is boolean {
return f.isAtomicField() && f.isBoolean() && v !== null;
}

export function valueIsString(f: Field, s: unknown): s is string {
return f.isAtomicField() && f.isString() && s !== null;
}
Expand Down
30 changes: 23 additions & 7 deletions packages/malloy-render/src/stories/line_charts.stories.malloy
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ source: products is duckdb.table("static/data/products.parquet") extend {
product_count_by_gender is count(id)

#(story)
view: line_chart_with_boolean is {
view: line_chart_boolean_xaxis is {
nest: product_sales_by_gender is {
group_by: is_female
aggregate: product_count_by_gender
Expand All @@ -255,7 +255,7 @@ source: products is duckdb.table("static/data/products.parquet") extend {
}

dimension:
`the_date` is @2001-02-03 + id day
`date_of_sale` is @2001-02-03 + id day
bool_series is pick true when brand = 'Lucky Brand'
pick false when brand = 'Calvin Klein'
else true
Expand All @@ -265,17 +265,33 @@ source: products is duckdb.table("static/data/products.parquet") extend {

#(story)
# line_chart
view: product_brand_broken is {
view: line_chart_time_series is {
# x
group_by: the_date
group_by: date_of_sale

# series
group_by: text_series_with_null
group_by: brand

# y
aggregate: `Sales $` is retail_price.avg()*500
where: date_of_sale >= @2001-02-01 and date_of_sale < @2001-04-01
order_by: date_of_sale
limit: 20
}

#(story)
# line_chart
view: line_chart_bool_time_series is {
# x
group_by: date_of_sale

# series
group_by: bool_series

# y
aggregate: `Sales $` is retail_price.avg()*500
where: the_date >= @2001-02-01 and the_date < @2001-04-01
order_by: the_date
where: date_of_sale >= @2001-02-01 and date_of_sale < @2001-04-01
order_by: date_of_sale
}
}

Expand Down

0 comments on commit 2f29f7b

Please sign in to comment.