Skip to content

Commit 032565e

Browse files
committed
fix: function doc improvements
1 parent f1a9b09 commit 032565e

File tree

3 files changed

+90
-27
lines changed

3 files changed

+90
-27
lines changed

CLAUDE.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,14 @@ Textplot is a DuckDB extension that provides text-based data visualization funct
1010

1111
```bash
1212
# Build release version
13-
make release
13+
VCPKG_TOOLCHAIN_PATH=`pwd`/vcpkg/scripts/buildsystems/vcpkg.cmake GEN=ninja make release
1414

1515
# Build debug version
16-
make debug
16+
VCPKG_TOOLCHAIN_PATH=`pwd`/vcpkg/scripts/buildsystems/vcpkg.cmake GEN=ninja make debug
1717

1818
# Run tests (requires build first)
1919
make test # runs against release build
2020
make test_debug # runs against debug build
21-
22-
# Format code
23-
make format
24-
25-
# Clean build artifacts
26-
make clean
2721
```
2822

2923
The build uses CMake under the hood. Build outputs go to `build/release/` or `build/debug/`.

duckdb

Submodule duckdb updated 3104 files

src/textplot_extension.cpp

Lines changed: 87 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,98 @@
55
#include "textplot_qr.hpp"
66
#include "duckdb.hpp"
77
#include "duckdb/function/scalar_function.hpp"
8+
#include "duckdb/parser/parsed_data/create_scalar_function_info.hpp"
89
#include "query_farm_telemetry.hpp"
910

1011
namespace duckdb {
1112

1213
static void LoadInternal(ExtensionLoader &loader) {
13-
auto bar_function = ScalarFunction("tp_bar", {LogicalType::DOUBLE}, LogicalType::VARCHAR, TextplotBar,
14-
TextplotBarBind, nullptr, nullptr, nullptr, LogicalType(LogicalTypeId::ANY));
15-
loader.RegisterFunction(bar_function);
16-
17-
auto qr_function = ScalarFunction("tp_qr", {LogicalType::VARCHAR}, LogicalType::VARCHAR, TextplotQR, TextplotQRBind,
18-
nullptr, nullptr, nullptr, LogicalType(LogicalTypeId::ANY));
19-
loader.RegisterFunction(qr_function);
20-
21-
// Lets register a density function.
22-
auto density_function =
23-
ScalarFunction("tp_density", {LogicalType::LIST(LogicalType::DOUBLE)}, LogicalType::VARCHAR, TextplotDensity,
24-
TextplotDensityBind, nullptr, nullptr, nullptr, LogicalType(LogicalTypeId::ANY));
25-
loader.RegisterFunction(density_function);
26-
27-
auto sparkline_function = ScalarFunction("tp_sparkline", {LogicalType::LIST(LogicalType::DOUBLE)},
28-
LogicalType::VARCHAR, TextplotSparkline, TextplotSparklineBind, nullptr,
29-
nullptr, nullptr, LogicalType(LogicalTypeId::ANY));
30-
loader.RegisterFunction(sparkline_function);
14+
// tp_bar: Horizontal bar charts with thresholds and colors
15+
{
16+
auto bar_function = ScalarFunction("tp_bar", {LogicalType::DOUBLE}, LogicalType::VARCHAR, TextplotBar,
17+
TextplotBarBind, nullptr, nullptr, nullptr, LogicalType(LogicalTypeId::ANY));
18+
CreateScalarFunctionInfo info(std::move(bar_function));
19+
20+
FunctionDescription desc;
21+
desc.description = "Creates a horizontal bar chart visualization from a numeric value. "
22+
"Supports customizable width, colors, shapes (square/circle/heart), and color thresholds.";
23+
desc.parameter_names = {"value", "min", "max", "width", "on", "off", "on_color", "off_color", "shape",
24+
"filled", "thresholds"};
25+
desc.examples = {"tp_bar(0.75)",
26+
"tp_bar(score, min := 0, max := 100, width := 20)",
27+
"tp_bar(value, on := '#', off := '-', width := 10)",
28+
"tp_bar(pct, shape := 'heart', on_color := 'red')",
29+
"tp_bar(temp, thresholds := [{'threshold': 80, 'color': 'red'}, "
30+
"{'threshold': 50, 'color': 'yellow'}])"};
31+
info.descriptions.push_back(std::move(desc));
32+
33+
info.on_conflict = OnCreateConflict::ALTER_ON_CONFLICT;
34+
loader.RegisterFunction(std::move(info));
35+
}
36+
37+
// tp_qr: QR code generation
38+
{
39+
auto qr_function = ScalarFunction("tp_qr", {LogicalType::VARCHAR}, LogicalType::VARCHAR, TextplotQR,
40+
TextplotQRBind, nullptr, nullptr, nullptr, LogicalType(LogicalTypeId::ANY));
41+
CreateScalarFunctionInfo info(std::move(qr_function));
42+
43+
FunctionDescription desc;
44+
desc.description = "Generates a text-based QR code from a string or blob. "
45+
"Supports configurable error correction levels and custom on/off characters.";
46+
desc.parameter_names = {"data", "ecc", "on", "off"};
47+
desc.examples = {"tp_qr('https://duckdb.org')",
48+
"tp_qr(url, ecc := 'high')",
49+
"tp_qr(message, on := '##', off := ' ')"};
50+
info.descriptions.push_back(std::move(desc));
51+
52+
info.on_conflict = OnCreateConflict::ALTER_ON_CONFLICT;
53+
loader.RegisterFunction(std::move(info));
54+
}
55+
56+
// tp_density: Density plots/histograms from arrays
57+
{
58+
auto density_function =
59+
ScalarFunction("tp_density", {LogicalType::LIST(LogicalType::DOUBLE)}, LogicalType::VARCHAR, TextplotDensity,
60+
TextplotDensityBind, nullptr, nullptr, nullptr, LogicalType(LogicalTypeId::ANY));
61+
CreateScalarFunctionInfo info(std::move(density_function));
62+
63+
FunctionDescription desc;
64+
desc.description = "Creates a density plot (histogram) visualization from an array of numeric values. "
65+
"Supports multiple styles: shaded, dots, ascii, height, circles, safety, rainbow_circle, "
66+
"rainbow_square, moon, sparse, and white.";
67+
desc.parameter_names = {"values", "width", "style", "marker", "graph_chars"};
68+
desc.examples = {"tp_density(list(value))",
69+
"tp_density(array_agg(score), width := 40)",
70+
"tp_density(data, style := 'height')",
71+
"tp_density(temps, style := 'rainbow_square', width := 30)"};
72+
info.descriptions.push_back(std::move(desc));
73+
74+
info.on_conflict = OnCreateConflict::ALTER_ON_CONFLICT;
75+
loader.RegisterFunction(std::move(info));
76+
}
77+
78+
// tp_sparkline: Compact trend lines with multiple modes
79+
{
80+
auto sparkline_function = ScalarFunction("tp_sparkline", {LogicalType::LIST(LogicalType::DOUBLE)},
81+
LogicalType::VARCHAR, TextplotSparkline, TextplotSparklineBind, nullptr,
82+
nullptr, nullptr, LogicalType(LogicalTypeId::ANY));
83+
CreateScalarFunctionInfo info(std::move(sparkline_function));
84+
85+
FunctionDescription desc;
86+
desc.description = "Creates a sparkline visualization from an array of numeric values. "
87+
"Supports three modes: 'absolute' (height-based), 'delta' (up/down/same direction), "
88+
"and 'trend' (direction with magnitude). Multiple themes available per mode.";
89+
desc.parameter_names = {"values", "width", "mode", "theme"};
90+
desc.examples = {"tp_sparkline(list(value))",
91+
"tp_sparkline(array_agg(price), width := 20)",
92+
"tp_sparkline(data, mode := 'delta', theme := 'arrows')",
93+
"tp_sparkline(temps, mode := 'absolute', theme := 'utf8_blocks')",
94+
"tp_sparkline(stocks, mode := 'trend', theme := 'faces')"};
95+
info.descriptions.push_back(std::move(desc));
96+
97+
info.on_conflict = OnCreateConflict::ALTER_ON_CONFLICT;
98+
loader.RegisterFunction(std::move(info));
99+
}
31100

32101
QueryFarmSendTelemetry(loader, "textplot", TextplotExtension().Version());
33102
}

0 commit comments

Comments
 (0)