We're working on making a reusable rendering library for Malloy that does smart things with your data. Features include:
Fixed column heading
Various sizing of visualizations
Shared axis on visualizations embedded in tables
To turn on add the Tag
Usage. Normal results will display differently and better.
source: flights is duckdb.table('../data/flights.parquet') extend { measure: flight_count is count() avg_dist is distance.avg() }
run: flights -> origin + flight_count + avg_dist + { nest: destination + flight_count + {limit: 3} limit: 10 }
[ { "origin": "ATL", "flight_count": 17875, "avg_dist": 487.9485314685315, "destination": [ { "destination": "PFN", "flight_count": 787 }, { "destination": "AGS", "flight_count": 697 }, { "destination": "CHA", "flight_count": 670 } ] }, { "origin": "DFW", "flight_count": 17782, "avg_dist": 691.2868068833652, "destination": [ { "destination": "ORD", "flight_count": 567 }, { "destination": "ACT", "flight_count": 492 }, { "destination": "TYR", "flight_count": 482 } ] }, { "origin": "ORD", "flight_count": 14214, "avg_dist": 987.7716336006754, "destination": [ { "destination": "LGA", "flight_count": 607 }, { "destination": "DEN", "flight_count": 588 }, { "destination": "LAX", "flight_count": 555 } ] }, { "origin": "PHX", "flight_count": 12476, "avg_dist": 826.4276210323821, "destination": [ { "destination": "LAX", "flight_count": 819 }, { "destination": "LAS", "flight_count": 788 }, { "destination": "SAN", "flight_count": 567 } ] }, { "origin": "LAS", "flight_count": 11096, "avg_dist": 791.4647620764239, "destination": [ { "destination": "LAX", "flight_count": 1039 }, { "destination": "PHX", "flight_count": 777 }, { "destination": "SAN", "flight_count": 495 } ] } ]
WITH __stage0 AS ( SELECT group_set, base."origin" as "origin__0", CASE WHEN group_set=0 THEN COUNT(1) END as "flight_count__0", CASE WHEN group_set=0 THEN AVG(base."distance") END as "avg_dist__0", CASE WHEN group_set=1 THEN base."destination" END as "destination__1", CASE WHEN group_set=1 THEN COUNT(1) END as "flight_count__1" FROM '../data/flights.parquet' as base CROSS JOIN (SELECT UNNEST(GENERATE_SERIES(0,1,1)) as group_set ) as group_set GROUP BY 1,2,5 ) SELECT "origin__0" as "origin", MAX(CASE WHEN group_set=0 THEN "flight_count__0" END) as "flight_count", MAX(CASE WHEN group_set=0 THEN "avg_dist__0" END) as "avg_dist", COALESCE(LIST({ "destination": "destination__1", "flight_count": "flight_count__1"} ORDER BY "flight_count__1" desc NULLS LAST) FILTER (WHERE group_set=1)[1:3],[]) as "destination" FROM __stage0 GROUP BY 1 ORDER BY 2 desc NULLS LAST LIMIT 10