@dxvis/flatbi 0.1.0 → 0.2.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.
- package/dist/cli/bin.mjs +142 -23
- package/dist/runtime/index.html +4 -4
- package/docs/recipes.md +42 -0
- package/docs/spec-reference.md +8 -1
- package/package.json +1 -1
- package/schema/dash.schema.json +36 -1
- package/skills/flatbi/SKILL.md +1 -1
package/dist/cli/bin.mjs
CHANGED
|
@@ -5,14 +5,14 @@ import { parseArgs } from "node:util";
|
|
|
5
5
|
import { DuckDBDecimalValue, DuckDBInstance, quotedIdentifier, quotedString } from "@duckdb/node-api";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { LineCounter, isAlias, isMap, isScalar, isSeq, parseDocument, visit } from "yaml";
|
|
8
|
-
import { gunzipSync, gzipSync } from "node:zlib";
|
|
8
|
+
import { gunzipSync, gzipSync, inflateRawSync } from "node:zlib";
|
|
9
9
|
import { createHash } from "node:crypto";
|
|
10
10
|
import { fileURLToPath } from "node:url";
|
|
11
11
|
import { constants, watch } from "node:fs";
|
|
12
12
|
import { createServer } from "node:http";
|
|
13
13
|
import { homedir } from "node:os";
|
|
14
14
|
//#region package.json
|
|
15
|
-
var version = "0.
|
|
15
|
+
var version = "0.2.0";
|
|
16
16
|
//#endregion
|
|
17
17
|
//#region src/engine/csv.ts
|
|
18
18
|
/** Escapes a text field per RFC 4180 when it contains quotes, commas, or line breaks. */
|
|
@@ -2008,7 +2008,8 @@ function mapColumns(dashboard, map) {
|
|
|
2008
2008
|
...model.asOf !== void 0 && { asOf: model.asOf },
|
|
2009
2009
|
...model.dateDimensions && { dateDimensions: model.dateDimensions },
|
|
2010
2010
|
...model.dimensionOrders && { dimensionOrders: model.dimensionOrders },
|
|
2011
|
-
...model.formats && { formats: model.formats }
|
|
2011
|
+
...model.formats && { formats: model.formats },
|
|
2012
|
+
...model.measureLabels && { measureLabels: model.measureLabels }
|
|
2012
2013
|
}));
|
|
2013
2014
|
return {
|
|
2014
2015
|
...dashboard,
|
|
@@ -2100,8 +2101,9 @@ const source = z.union([fileSource, sqlSource]).describe("A named input dataset.
|
|
|
2100
2101
|
const sql = (description) => z.string().min(1).describe(description);
|
|
2101
2102
|
/** A measure's optional row filter, folded into its stored column at build time. */
|
|
2102
2103
|
const where = z.string().min(1).optional().describe("Row-level DuckDB predicate, such as `status = 'paid'`. Only rows where it is true count toward the measure.");
|
|
2103
|
-
/** Number formatting shared by aggregate and formula measures. */
|
|
2104
|
+
/** Number formatting and display options shared by aggregate and formula measures. */
|
|
2104
2105
|
const measureFormat = {
|
|
2106
|
+
label: z.string().min(1).optional().describe("Display name shown in chart legends, tooltips, table headers and default tile titles."),
|
|
2105
2107
|
format: z.enum(FORMATS).optional().describe("How the measure's numbers display: `integer`, `number`, `percent`, `currency` or `compact`."),
|
|
2106
2108
|
decimals: z.number().int().min(0).max(20).optional().describe("Number of decimal places to show (0 to 20).")
|
|
2107
2109
|
};
|
|
@@ -2137,7 +2139,7 @@ const dimensionObject = z.strictObject({
|
|
|
2137
2139
|
const dimension = z.union([z.string().min(1).describe("A column of the source."), dimensionObject]).describe("A column name, or a mapping with `name`, optional `sql` and optional `order`.");
|
|
2138
2140
|
const model = z.strictObject({
|
|
2139
2141
|
source: ref("The source the model reads."),
|
|
2140
|
-
time: ref("The model's main date dimension, enabling time grains, date-range filters and KPI comparisons.").optional(),
|
|
2142
|
+
time: ref("The model's main date dimension (a source column or a computed `{ name, sql }` dimension), enabling time grains, date-range filters and KPI comparisons.").optional(),
|
|
2141
2143
|
dimensions: z.array(dimension).optional().describe("Dimensions of the model that tiles and filters may group or filter by."),
|
|
2142
2144
|
measures: z.record(id("Measure"), measure).optional().describe("The model's measures, by measure ID.")
|
|
2143
2145
|
}).describe("A named, flat table built from one source.");
|
|
@@ -3296,9 +3298,11 @@ function resolveModels(spec, sources, report) {
|
|
|
3296
3298
|
if (!source) continue;
|
|
3297
3299
|
const measures = {};
|
|
3298
3300
|
const formats = {};
|
|
3301
|
+
const measureLabels = {};
|
|
3299
3302
|
for (const [measureId, measure] of Object.entries(model.measures ?? {})) {
|
|
3300
3303
|
if (RESERVED_IDS.has(measureId)) continue;
|
|
3301
3304
|
if ("agg" in measure) measures[measureId] = measure;
|
|
3305
|
+
if (measure.label !== void 0) measureLabels[measureId] = measure.label;
|
|
3302
3306
|
if (measure.format !== void 0 || measure.decimals !== void 0) formats[measureId] = {
|
|
3303
3307
|
...measure.format !== void 0 && { format: measure.format },
|
|
3304
3308
|
...measure.decimals !== void 0 && { decimals: measure.decimals }
|
|
@@ -3316,7 +3320,8 @@ function resolveModels(spec, sources, report) {
|
|
|
3316
3320
|
dimensions,
|
|
3317
3321
|
measures,
|
|
3318
3322
|
formulas: resolveFormulas(id, model, report),
|
|
3319
|
-
formats
|
|
3323
|
+
formats,
|
|
3324
|
+
measureLabels
|
|
3320
3325
|
};
|
|
3321
3326
|
}
|
|
3322
3327
|
return models;
|
|
@@ -3450,6 +3455,7 @@ function resolveTiles(spec, report) {
|
|
|
3450
3455
|
const model = spec.models[modelId];
|
|
3451
3456
|
const measures = Object.keys(model?.measures ?? {});
|
|
3452
3457
|
const dimensions = modelDimensions(model);
|
|
3458
|
+
const measureTitle = (name) => model?.measures?.[name]?.label ?? titleFrom(name);
|
|
3453
3459
|
const measure = (key, name) => {
|
|
3454
3460
|
if (measures.includes(name)) return;
|
|
3455
3461
|
const message = `Tile \`${id}\` shows the measure \`${name}\`, which model \`${modelId}\` does not define.`;
|
|
@@ -3536,7 +3542,7 @@ function resolveTiles(spec, report) {
|
|
|
3536
3542
|
const where = resolveWhere(tile.where);
|
|
3537
3543
|
tiles[id] = {
|
|
3538
3544
|
type: "kpi",
|
|
3539
|
-
title: tile.title ??
|
|
3545
|
+
title: tile.title ?? measureTitle(tile.value),
|
|
3540
3546
|
model: modelId,
|
|
3541
3547
|
value: tile.value,
|
|
3542
3548
|
...tile.compare !== void 0 && { compare: tile.compare },
|
|
@@ -3576,7 +3582,7 @@ function resolveTiles(spec, report) {
|
|
|
3576
3582
|
], `Tile \`${id}\` sets \`color\` together with multiple \`y\` measures. Choose either \`color\` or a list of measures.`);
|
|
3577
3583
|
}
|
|
3578
3584
|
const where = resolveWhere(tile.where);
|
|
3579
|
-
const defaultTitle = `${yMeasures.map(
|
|
3585
|
+
const defaultTitle = `${yMeasures.map(measureTitle).join(" & ")} by ${titleFrom(parsedX.field).toLowerCase()}`;
|
|
3580
3586
|
if (tile.type === "bar") {
|
|
3581
3587
|
const sort = resolveSort(tile.sort, parsedX.field, yMeasures);
|
|
3582
3588
|
tiles[id] = {
|
|
@@ -3642,7 +3648,7 @@ function resolveTiles(spec, report) {
|
|
|
3642
3648
|
const compiledY = yMeasures.length === 1 && yMeasures[0] !== void 0 ? yMeasures[0] : yMeasures;
|
|
3643
3649
|
const compiledY2 = y2Measures.length === 1 && y2Measures[0] !== void 0 ? y2Measures[0] : y2Measures;
|
|
3644
3650
|
const where = resolveWhere(tile.where);
|
|
3645
|
-
const heading = `${[...yMeasures, ...y2Measures].map(
|
|
3651
|
+
const heading = `${[...yMeasures, ...y2Measures].map(measureTitle).join(" & ")} by ${titleFrom(parsedX.field).toLowerCase()}`;
|
|
3646
3652
|
tiles[id] = {
|
|
3647
3653
|
type: "combo",
|
|
3648
3654
|
title: tile.title ?? heading,
|
|
@@ -3664,7 +3670,7 @@ function resolveTiles(spec, report) {
|
|
|
3664
3670
|
if (tile.size !== void 0) measure("size", tile.size);
|
|
3665
3671
|
if (tile.color !== void 0) dimension("color", tile.color);
|
|
3666
3672
|
const where = resolveWhere(tile.where);
|
|
3667
|
-
const heading = `${
|
|
3673
|
+
const heading = `${measureTitle(tile.y)} vs ${measureTitle(tile.x)} by ${titleFrom(tile.by).toLowerCase()}`;
|
|
3668
3674
|
tiles[id] = {
|
|
3669
3675
|
type: "scatter",
|
|
3670
3676
|
title: tile.title ?? heading,
|
|
@@ -3696,7 +3702,7 @@ function resolveTiles(spec, report) {
|
|
|
3696
3702
|
const where = resolveWhere(tile.where);
|
|
3697
3703
|
tiles[id] = {
|
|
3698
3704
|
type: "donut",
|
|
3699
|
-
title: tile.title ?? `${
|
|
3705
|
+
title: tile.title ?? `${measureTitle(tile.value)} by ${titleFrom(parsedBy.field).toLowerCase()}`,
|
|
3700
3706
|
model: modelId,
|
|
3701
3707
|
by: parsedBy.field,
|
|
3702
3708
|
...parsedBy.grain !== void 0 && { grain: parsedBy.grain },
|
|
@@ -3736,7 +3742,7 @@ function resolveTiles(spec, report) {
|
|
|
3736
3742
|
const where = resolveWhere(tile.where);
|
|
3737
3743
|
tiles[id] = {
|
|
3738
3744
|
type: "heatmap",
|
|
3739
|
-
title: tile.title ?? `${
|
|
3745
|
+
title: tile.title ?? `${measureTitle(tile.color)} by ${titleFrom(parsedX.field).toLowerCase()} & ${titleFrom(parsedY.field).toLowerCase()}`,
|
|
3740
3746
|
model: modelId,
|
|
3741
3747
|
x: parsedX.field,
|
|
3742
3748
|
...parsedX.grain !== void 0 && { xGrain: parsedX.grain },
|
|
@@ -3834,7 +3840,7 @@ function resolveTiles(spec, report) {
|
|
|
3834
3840
|
}
|
|
3835
3841
|
}
|
|
3836
3842
|
const where = resolveWhere(tile.where);
|
|
3837
|
-
const heading = columns.length > 0 ? columns.map((c) => titleFrom(c.field)).join(", ") : titleFrom(id);
|
|
3843
|
+
const heading = columns.length > 0 ? columns.map((c) => c.label ?? (c.kind === "measure" ? measureTitle(c.field) : titleFrom(c.field))).join(", ") : titleFrom(id);
|
|
3838
3844
|
tiles[id] = {
|
|
3839
3845
|
type: "table",
|
|
3840
3846
|
title: tile.title ?? heading,
|
|
@@ -4419,11 +4425,13 @@ async function inspectSources(sources, baseDir) {
|
|
|
4419
4425
|
for (const source of Object.values(sources)) {
|
|
4420
4426
|
const columns = loaded.get(source.id);
|
|
4421
4427
|
if (!columns) continue;
|
|
4428
|
+
const sheets = source.kind === "xlsx" ? await listXlsxSheets(resolve(baseDir, source.file)) : void 0;
|
|
4422
4429
|
inspected.push(await inspectTable(connection, `memory.main.${quotedIdentifier(source.id)}`, columns, {
|
|
4423
4430
|
id: source.id,
|
|
4424
4431
|
kind: source.kind,
|
|
4425
4432
|
...source.kind !== "sql" && { file: source.file },
|
|
4426
|
-
...(source.kind === "duckdb" || source.kind === "sqlite") && source.table !== void 0 && { table: source.table }
|
|
4433
|
+
...(source.kind === "duckdb" || source.kind === "sqlite") && source.table !== void 0 && { table: source.table },
|
|
4434
|
+
...sheets !== void 0 && { sheets }
|
|
4427
4435
|
}));
|
|
4428
4436
|
}
|
|
4429
4437
|
return {
|
|
@@ -4538,12 +4546,14 @@ async function inspectDataFile(filePath, displayPath, options = {}) {
|
|
|
4538
4546
|
sources: [],
|
|
4539
4547
|
findings: [loaded]
|
|
4540
4548
|
};
|
|
4549
|
+
const sheets = kind === "xlsx" ? await listXlsxSheets(filePath) : void 0;
|
|
4541
4550
|
return {
|
|
4542
4551
|
sources: [await inspectTable(connection, `memory.main.${quotedIdentifier("source")}`, loaded, {
|
|
4543
4552
|
id: options.table ?? displayPath,
|
|
4544
4553
|
kind,
|
|
4545
4554
|
file: displayPath,
|
|
4546
|
-
...options.table !== void 0 && { table: options.table }
|
|
4555
|
+
...options.table !== void 0 && { table: options.table },
|
|
4556
|
+
...sheets !== void 0 && { sheets }
|
|
4547
4557
|
})],
|
|
4548
4558
|
findings: []
|
|
4549
4559
|
};
|
|
@@ -4563,6 +4573,7 @@ async function inspectTable(connection, tableRef, columnTypes, meta) {
|
|
|
4563
4573
|
const col = quotedIdentifier(name);
|
|
4564
4574
|
statExprs.push(`count(DISTINCT ${col})`, `count(*) - count(${col})`);
|
|
4565
4575
|
if (isDateType(type)) statExprs.push(`CAST(min(${col}) AS VARCHAR)`, `CAST(max(${col}) AS VARCHAR)`);
|
|
4576
|
+
else if (isNumericType(type)) statExprs.push(`min(${col})`, `max(${col})`);
|
|
4566
4577
|
}
|
|
4567
4578
|
const statCols = (await run(connection, `SELECT ${statExprs.join(", ")} FROM ${tableRef}`)).getColumns();
|
|
4568
4579
|
let idx = 0;
|
|
@@ -4572,6 +4583,7 @@ async function inspectTable(connection, tableRef, columnTypes, meta) {
|
|
|
4572
4583
|
const cardinality = typeof cardRaw === "bigint" ? Number(cardRaw) : Number(cardRaw ?? 0);
|
|
4573
4584
|
const nulls = typeof nullRaw === "bigint" ? Number(nullRaw) : Number(nullRaw ?? 0);
|
|
4574
4585
|
let dateRange;
|
|
4586
|
+
let range;
|
|
4575
4587
|
if (isDateType(type)) {
|
|
4576
4588
|
const minRaw = statCols[idx++]?.[0];
|
|
4577
4589
|
const maxRaw = statCols[idx++]?.[0];
|
|
@@ -4579,15 +4591,40 @@ async function inspectTable(connection, tableRef, columnTypes, meta) {
|
|
|
4579
4591
|
min: String(minRaw),
|
|
4580
4592
|
max: String(maxRaw)
|
|
4581
4593
|
};
|
|
4594
|
+
} else if (isNumericType(type)) {
|
|
4595
|
+
const minVal = toSampleValue(statCols[idx++]?.[0] ?? null);
|
|
4596
|
+
const maxVal = toSampleValue(statCols[idx++]?.[0] ?? null);
|
|
4597
|
+
if (typeof minVal === "number" && typeof maxVal === "number") range = {
|
|
4598
|
+
min: minVal,
|
|
4599
|
+
max: maxVal
|
|
4600
|
+
};
|
|
4582
4601
|
}
|
|
4583
4602
|
columns.push({
|
|
4584
4603
|
name,
|
|
4585
4604
|
type,
|
|
4586
4605
|
cardinality,
|
|
4587
4606
|
nulls,
|
|
4588
|
-
...dateRange !== void 0 && { dateRange }
|
|
4607
|
+
...dateRange !== void 0 && { dateRange },
|
|
4608
|
+
...range !== void 0 && { range }
|
|
4589
4609
|
});
|
|
4590
4610
|
}
|
|
4611
|
+
for (const column of columns) {
|
|
4612
|
+
if (!isStringType(column.type) || column.cardinality < 1 || column.cardinality > 20) continue;
|
|
4613
|
+
const col = quotedIdentifier(column.name);
|
|
4614
|
+
const valReader = await run(connection, `SELECT ${col} AS val, count(*) AS cnt FROM ${tableRef} WHERE ${col} IS NOT NULL GROUP BY ${col} ORDER BY cnt DESC, val ASC LIMIT 20`);
|
|
4615
|
+
const [rawVals = [], rawCounts = []] = valReader.getColumns();
|
|
4616
|
+
const values = [];
|
|
4617
|
+
for (let i = 0; i < valReader.currentRowCount; i++) {
|
|
4618
|
+
const v = rawVals[i];
|
|
4619
|
+
const c = rawCounts[i];
|
|
4620
|
+
if (v === null || v === void 0) continue;
|
|
4621
|
+
values.push({
|
|
4622
|
+
value: String(v),
|
|
4623
|
+
count: typeof c === "bigint" ? Number(c) : Number(c ?? 0)
|
|
4624
|
+
});
|
|
4625
|
+
}
|
|
4626
|
+
if (values.length > 0) column.values = values;
|
|
4627
|
+
}
|
|
4591
4628
|
}
|
|
4592
4629
|
const sample = [];
|
|
4593
4630
|
if (entries.length > 0 && rowCount > 0) {
|
|
@@ -4614,6 +4651,72 @@ async function inspectTable(connection, tableRef, columnTypes, meta) {
|
|
|
4614
4651
|
function isDateType(type) {
|
|
4615
4652
|
return /^(DATE|TIMESTAMP)/i.test(type);
|
|
4616
4653
|
}
|
|
4654
|
+
function isNumericType(type) {
|
|
4655
|
+
return /^(TINYINT|SMALLINT|INTEGER|BIGINT|HUGEINT|UTINYINT|USMALLINT|UINTEGER|UBIGINT|UHUGEINT|FLOAT|DOUBLE|DECIMAL)\b/i.test(type);
|
|
4656
|
+
}
|
|
4657
|
+
function isStringType(type) {
|
|
4658
|
+
return /^VARCHAR\b/i.test(type);
|
|
4659
|
+
}
|
|
4660
|
+
/** Extracts worksheet names from an `.xlsx` workbook's `xl/workbook.xml` without extra dependencies. */
|
|
4661
|
+
async function listXlsxSheets(filePath) {
|
|
4662
|
+
try {
|
|
4663
|
+
const buf = await readFile(filePath);
|
|
4664
|
+
const minOffset = Math.max(0, buf.length - 65557);
|
|
4665
|
+
let eocd = -1;
|
|
4666
|
+
for (let i = buf.length - 22; i >= minOffset; i--) if (buf.readUInt32LE(i) === 101010256 && i + 22 + buf.readUInt16LE(i + 20) <= buf.length) {
|
|
4667
|
+
eocd = i;
|
|
4668
|
+
break;
|
|
4669
|
+
}
|
|
4670
|
+
if (eocd === -1) return void 0;
|
|
4671
|
+
const cdSize = buf.readUInt32LE(eocd + 12);
|
|
4672
|
+
const cdOffset = buf.readUInt32LE(eocd + 16);
|
|
4673
|
+
const cdEnd = Math.min(buf.length, cdOffset + cdSize);
|
|
4674
|
+
for (let pos = cdOffset; pos + 46 <= cdEnd;) {
|
|
4675
|
+
if (buf.readUInt32LE(pos) !== 33639248) break;
|
|
4676
|
+
const compression = buf.readUInt16LE(pos + 10);
|
|
4677
|
+
const compressedSize = buf.readUInt32LE(pos + 20);
|
|
4678
|
+
const nameLen = buf.readUInt16LE(pos + 28);
|
|
4679
|
+
const extraLen = buf.readUInt16LE(pos + 30);
|
|
4680
|
+
const commentLen = buf.readUInt16LE(pos + 32);
|
|
4681
|
+
const localOffset = buf.readUInt32LE(pos + 42);
|
|
4682
|
+
const entryName = buf.subarray(pos + 46, pos + 46 + nameLen).toString("utf8").replace(/^\.?\//, "").toLowerCase();
|
|
4683
|
+
pos += 46 + nameLen + extraLen + commentLen;
|
|
4684
|
+
if (entryName !== "xl/workbook.xml") continue;
|
|
4685
|
+
if (localOffset + 30 > buf.length || buf.readUInt32LE(localOffset) !== 67324752) return;
|
|
4686
|
+
const localNameLen = buf.readUInt16LE(localOffset + 26);
|
|
4687
|
+
const localExtraLen = buf.readUInt16LE(localOffset + 28);
|
|
4688
|
+
const dataStart = localOffset + 30 + localNameLen + localExtraLen;
|
|
4689
|
+
const dataEnd = dataStart + compressedSize;
|
|
4690
|
+
if (dataEnd > buf.length) return void 0;
|
|
4691
|
+
const payload = buf.subarray(dataStart, dataEnd);
|
|
4692
|
+
const xml = compression === 8 ? inflateRawSync(payload).toString("utf8") : compression === 0 ? payload.toString("utf8") : "";
|
|
4693
|
+
if (!xml) return void 0;
|
|
4694
|
+
const sheets = [];
|
|
4695
|
+
for (const match of xml.matchAll(/<(?:\w+:)?sheet\b[^>]*\bname=(?:"([^"]+)"|'([^']+)')/g)) {
|
|
4696
|
+
const rawName = match[1] ?? match[2] ?? "";
|
|
4697
|
+
if (rawName) sheets.push(unescapeXml(rawName));
|
|
4698
|
+
}
|
|
4699
|
+
return sheets.length > 0 ? sheets : void 0;
|
|
4700
|
+
}
|
|
4701
|
+
} catch {
|
|
4702
|
+
return;
|
|
4703
|
+
}
|
|
4704
|
+
}
|
|
4705
|
+
function unescapeXml(text) {
|
|
4706
|
+
return text.replaceAll(/&(#x[0-9a-fA-F]+|#\d+|amp|lt|gt|quot|apos);/g, (_, entity) => {
|
|
4707
|
+
switch (entity) {
|
|
4708
|
+
case "amp": return "&";
|
|
4709
|
+
case "lt": return "<";
|
|
4710
|
+
case "gt": return ">";
|
|
4711
|
+
case "quot": return "\"";
|
|
4712
|
+
case "apos": return "'";
|
|
4713
|
+
default: {
|
|
4714
|
+
const code = entity.startsWith("#x") ? Number.parseInt(entity.slice(2), 16) : Number.parseInt(entity.slice(1), 10);
|
|
4715
|
+
return Number.isFinite(code) ? String.fromCodePoint(code) : `&${entity};`;
|
|
4716
|
+
}
|
|
4717
|
+
}
|
|
4718
|
+
});
|
|
4719
|
+
}
|
|
4617
4720
|
/** Converts a DuckDB decimal value into an exact JS number when no decimal digits are lost. */
|
|
4618
4721
|
function decimalToSafeNumber(value) {
|
|
4619
4722
|
const raw = value.toString();
|
|
@@ -4718,7 +4821,8 @@ async function snapshot(spec, baseDir) {
|
|
|
4718
4821
|
...asOf !== void 0 && { asOf },
|
|
4719
4822
|
...kept.dateDimensions.length > 0 && { dateDimensions: kept.dateDimensions },
|
|
4720
4823
|
...Object.keys(kept.dimensionOrders).length > 0 && { dimensionOrders: kept.dimensionOrders },
|
|
4721
|
-
...Object.keys(kept.formats).length > 0 && { formats: kept.formats }
|
|
4824
|
+
...Object.keys(kept.formats).length > 0 && { formats: kept.formats },
|
|
4825
|
+
...Object.keys(kept.measureLabels).length > 0 && { measureLabels: kept.measureLabels }
|
|
4722
4826
|
};
|
|
4723
4827
|
if (result.stats) modelStats[modelId] = result.stats;
|
|
4724
4828
|
}
|
|
@@ -4826,6 +4930,8 @@ function used(spec, modelId, dimTypes) {
|
|
|
4826
4930
|
for (const dim of keptDimensions) if (dim.order !== void 0) dimensionOrders[dim.name] = dim.order;
|
|
4827
4931
|
const formats = {};
|
|
4828
4932
|
for (const [name, format] of Object.entries(model?.formats ?? {})) if (measures.has(name)) formats[name] = format;
|
|
4933
|
+
const measureLabels = {};
|
|
4934
|
+
for (const [name, label] of Object.entries(model?.measureLabels ?? {})) if (measures.has(name)) measureLabels[name] = label;
|
|
4829
4935
|
return {
|
|
4830
4936
|
dimensions: keptDimensions,
|
|
4831
4937
|
dateDimensions,
|
|
@@ -4833,7 +4939,8 @@ function used(spec, modelId, dimTypes) {
|
|
|
4833
4939
|
measures: Object.entries(model?.measures ?? {}).filter(([name]) => measures.has(name)),
|
|
4834
4940
|
formulas: Object.fromEntries(Object.entries(formulas).filter(([name]) => measures.has(name)).map(([name, { formula }]) => [name, formula])),
|
|
4835
4941
|
dimensionOrders,
|
|
4836
|
-
formats
|
|
4942
|
+
formats,
|
|
4943
|
+
measureLabels
|
|
4837
4944
|
};
|
|
4838
4945
|
}
|
|
4839
4946
|
function finestGrain(grains) {
|
|
@@ -6370,9 +6477,12 @@ async function inspectVisualFindings(page) {
|
|
|
6370
6477
|
if (!b) continue;
|
|
6371
6478
|
const ix = Math.min(a.rect.right, b.rect.right) - Math.max(a.rect.left, b.rect.left);
|
|
6372
6479
|
const iy = Math.min(a.rect.bottom, b.rect.bottom) - Math.max(a.rect.top, b.rect.top);
|
|
6373
|
-
if (ix >
|
|
6480
|
+
if (ix > 0 && iy > 0) {
|
|
6374
6481
|
const minArea = Math.min(a.rect.width * a.rect.height, b.rect.width * b.rect.height);
|
|
6375
|
-
|
|
6482
|
+
const minHeight = Math.min(a.rect.height, b.rect.height);
|
|
6483
|
+
const sameRowHorizontal = ix > 1.5 && iy > minHeight * .5;
|
|
6484
|
+
const crossRowOverlap = minArea > 0 && ix > 2.5 && iy > 2.5 && ix * iy / minArea > .15;
|
|
6485
|
+
if (sameRowHorizontal || crossRowOverlap) pushOnce({
|
|
6376
6486
|
code: "text-clipped",
|
|
6377
6487
|
tileId,
|
|
6378
6488
|
message: `Tile \`${tileId}\` has overlapping chart labels ("${a.text}" and "${b.text}").`
|
|
@@ -6581,7 +6691,7 @@ Usage: flatbi <command> [options]
|
|
|
6581
6691
|
|
|
6582
6692
|
Commands:
|
|
6583
6693
|
init [<dir>] Create a starter dashboard and sample data
|
|
6584
|
-
inspect [<target>...] Inspect sources (columns, types, sample rows, cardinality, nulls,
|
|
6694
|
+
inspect [<target>...] Inspect sources (columns, types, sample rows, cardinality, nulls, ranges, values)
|
|
6585
6695
|
check [<spec>...] Validate specs and run every tile against its data
|
|
6586
6696
|
build [<spec>...] Check specs, then write each dashboard as one HTML file
|
|
6587
6697
|
dev [<spec>] Serve a dashboard locally with live reload and findings overlay
|
|
@@ -6699,7 +6809,7 @@ ${COMMON_HELP}
|
|
|
6699
6809
|
}];
|
|
6700
6810
|
const INSPECT_USAGE = `Usage: flatbi inspect [<target>...] [options]
|
|
6701
6811
|
|
|
6702
|
-
Print each source's columns, types, sample rows, cardinality, null counts and
|
|
6812
|
+
Print each source's columns, types, sample rows, cardinality, null counts, ranges and values.
|
|
6703
6813
|
Each <target> is a *.dash.yaml spec, a data file (${INSPECTABLE_EXTENSIONS.join(", ")}), or a
|
|
6704
6814
|
quoted glob. With none, every *.dash.yaml under the working directory is inspected.
|
|
6705
6815
|
|
|
@@ -7153,15 +7263,24 @@ async function runRender(args, json, io) {
|
|
|
7153
7263
|
function printInspectedSource(io, source) {
|
|
7154
7264
|
const origin = source.spec ? ` [${source.spec}]` : source.file ? ` [${source.file}]` : "";
|
|
7155
7265
|
io.stdout(`${source.id}${origin} (${source.rowCount} rows)\n`);
|
|
7266
|
+
if (source.sheets && source.sheets.length > 0) io.stdout(` sheets: ${source.sheets.join(", ")}\n`);
|
|
7156
7267
|
for (const column of source.columns) {
|
|
7157
|
-
const range = column.dateRange ? ` ${column.dateRange.min} .. ${column.dateRange.max}` : "";
|
|
7268
|
+
const range = column.dateRange ? ` ${column.dateRange.min} .. ${column.dateRange.max}` : column.range ? ` ${column.range.min} .. ${column.range.max}` : "";
|
|
7158
7269
|
io.stdout(` ${column.name} ${column.type} ${column.cardinality} distinct ${column.nulls} nulls${range}\n`);
|
|
7270
|
+
if (column.values && column.values.length > 0) {
|
|
7271
|
+
const formatted = column.values.map((v) => `${formatInspectValue(v.value)} (${v.count})`);
|
|
7272
|
+
io.stdout(` values: ${formatted.join(", ")}\n`);
|
|
7273
|
+
}
|
|
7159
7274
|
}
|
|
7160
7275
|
if (source.sample.length > 0) {
|
|
7161
7276
|
io.stdout(" sample:\n");
|
|
7162
7277
|
for (const row of source.sample) io.stdout(` ${JSON.stringify(row)}\n`);
|
|
7163
7278
|
}
|
|
7164
7279
|
}
|
|
7280
|
+
function formatInspectValue(raw) {
|
|
7281
|
+
const clipped = raw.length > 60 ? `${raw.slice(0, 59)}…` : raw;
|
|
7282
|
+
return clipped === "" || /[,()]/.test(clipped) ? JSON.stringify(clipped) : clipped;
|
|
7283
|
+
}
|
|
7165
7284
|
function exitCode(findings, strict) {
|
|
7166
7285
|
const { errors, warnings } = summarize(findings);
|
|
7167
7286
|
return errors > 0 || strict && warnings > 0 ? EXIT.errors : EXIT.clean;
|