Skip to content

Add L.chart and LChart for bar charts - #82

Merged
codesensedev merged 3 commits into
mainfrom
686-bar-charts
Nov 25, 2026
Merged

codesensedev merged 3 commits into
mainfrom
686-bar-charts

Conversation

@codesensedev

@codesensedev codesensedev commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Core adds a <chart> element with bar charts (lpdfio/lpdf#195). This adds its builders, so a chart can be built in code as in XML.

What changes

  • L.chart(ChartAttr, parts) builds a chart, and LChart.series, LChart.category and LChart.value its parts, with their nodes.
  • LChart.value(NoAttr, [41200]) takes ints, floats, Decimals and strs. A float is written from its shortest digits (repr) in full, without an exponent, and a whole float without its .0, as the other SDKs write it: 1e23 is 100000000000000000000000. A Decimal keeps its decimals (0.250) and is written without an exponent (1E+3 is 1000). A bool is a TypeError, and a float or a Decimal that is not finite a ValueError.
  • One class per file: ChartNode, ChartSeriesNode, ChartCategoryNode and ChartValueNode each have their own, as the markdown's nodes do.
  • ChartAttr, ChartSeriesAttr and ChartCategoryAttr, and the constants ChartType, ChartDirection and ChartLegend, generated from the schema (make gen-sdk-api).

How it was checked

  • make test-sdk-python: 265 pass, with tests for the nodes, the numbers, the PDF of a chart built in code against the PDF of its XML, and a category with the wrong count of values.
  • make check-codegen-sdk-python against the engine and schema of core's branch: 1047 of 1047 documents render the PDF of their XML, the chart fixtures and corpus documents among them.
  • This repository's CI builds against the last core release, which has no chart, so it fails until a release candidate carries core's change.

Work: 686

L.chart builds a chart, and LChart.series, LChart.category and
LChart.value its parts. LChart.value takes an int, a float or a str,
and writes a float in full, without an exponent.

Work: 686
The SDK keeps one class per file, as the markdown's nodes have, and the
four chart nodes were in one.

A whole float past 2**53 was written from its binary value, so 1e23
became 99999999999999991611392 in the XML `L.to_xml` writes, where the
other SDKs write 100000000000000000000000. The PDF was the same, since
the engine reads both as the same float.

Work: 686
Python often holds money as a Decimal, which LChart.value refused, and
str() of one can write an exponent the engine refuses (1E+3).

Work: 686
@codesensedev
codesensedev merged commit 1e42936 into main Nov 25, 2026
1 of 2 checks passed
@codesensedev
codesensedev deleted the 686-bar-charts branch November 25, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant