mirror of
https://github.com/dolanmiu/docx.git
synced 2026-11-30 16:47:55 +01:00
* feat: live examples in the docs, which run, draw the document next to the code, and can be edited and downloaded The docs' code examples were plain snippets, often fragments that couldn't run. A code block marked ```ts live is now an example readers can see and change: the page runs it with docx, draws the document it makes next to the code with docx-preview, and offers the .docx to download. Clicking the code opens an editor (Monaco) that knows docx's types, the pages are drawn again as the code changes, and View closes the editor. Split, Code and Preview show the code and the pages side by side, or one of them. The demos a page includes are live too. Every example in the docs that builds or patches a document is now live: 443 of them, each a whole file with its imports, so it runs as written. Code about other things, such as installing, bundlers or servers, stays plain. Running them showed docs that were wrong, fixed here: - Landscape: docx swaps a landscape page's width and height itself, so the docs' swapped sizes made a tall page marked as landscape - Comments: `comments.children` takes plain objects, not `new Comment(...)` - Custom properties are text only - APIs that no longer exist: MathText, Row, `.then` on Packer.toStream, patchDocument(buffer, ...), createParagraph().heading1(), a border's `value`, TextRun's `.break()` - The templates and patcher examples read files that aren't in the repository. They now patch the templates in demo/assets, or make their own `npm run build.docs` copies docx's browser builds into docs/live-examples/lib, so the docs use the docx they describe, and the Pages workflow runs it. The folder is gitignored, and cspell and ESLint skip it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ * docs: the bullet examples draw a bullet, and the patcher's usage writes the patched document "ὠ" is U+1F60, a Greek omega, since \u takes four hex digits, so the two live bullet examples on the numbering page drew it as each item's bullet. They use "•" now. The patcher's usage example now awaits patchDocument and writes the document it makes, as the example after it does. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
9.1 KiB
9.1 KiB
Bubble Charts
A bubble chart is a scatter chart whose points are bubbles of different sizes, so it shows three numbers for each point: where it is across, where it is up, and how big it is.
Charts shows how to import ChartRun and add a chart to a document.
A Bubble Chart
import { Document, Paragraph } from "docx";
import { ChartRun } from "docx/charts";
const doc = new Document({
sections: [
{
children: [
new Paragraph({
children: [
new ChartRun({
type: "bubble",
title: "Markets",
series: [
{
name: "Europe",
points: [
{ x: 12, y: 4.5, size: 740 },
{ x: 18, y: 3.1, size: 330 },
],
},
{ name: "Asia", points: [{ x: 24, y: 6.8, size: 1400 }] },
],
xAxis: { title: "Market share (%)" },
yAxis: { title: "Growth (%)" },
}),
],
}),
],
},
],
});
- Like a scatter chart, a bubble chart has no categories. Each series has
points, and each point has anx, ayand asize. - Sizes are compared with each other: the biggest bubble is drawn at Office's largest size, and the others in proportion. They can't be negative.
- Bubbles are drawn in their series' colour, a quarter see-through, so bubbles behind them show.
Bubble Sizes
bubbleScalemakes every bubble bigger or smaller, as a percentage of Office's size, from0to300. The default is100.sizeRepresentssays whether a point'ssizeis the bubble's area ("area", the default) or its width ("width"). By area, a bubble of size 4 looks twice as wide as one of size 1; by width, four times as wide.
import { Document, Paragraph } from "docx";
import { ChartRun } from "docx/charts";
const doc = new Document({
sections: [
{
children: [
new Paragraph({
children: [
new ChartRun({
type: "bubble",
series: [
{
name: "Europe",
points: [
{ x: 12, y: 4.5, size: 740 },
{ x: 18, y: 3.1, size: 330 },
],
},
{ name: "Asia", points: [{ x: 24, y: 6.8, size: 1400 }] },
],
bubbleScale: 60,
sizeRepresents: "width",
}),
],
}),
],
},
],
});
Labels
A bubble's label can show its size, as well as what any label shows:
import { Document, Paragraph } from "docx";
import { ChartRun } from "docx/charts";
const doc = new Document({
sections: [
{
children: [
new Paragraph({
children: [
new ChartRun({
type: "bubble",
series: [
{
name: "Europe",
points: [
{ x: 12, y: 4.5, size: 740 },
{ x: 18, y: 3.1, size: 330 },
],
},
{ name: "Asia", points: [{ x: 24, y: 6.8, size: 1400 }] },
],
dataLabels: { bubbleSize: true },
}),
],
}),
],
},
],
});
See Chart Data Labels.
Options
| Property | Type | Notes | Description |
|---|---|---|---|
type |
"bubble" |
Required | |
series |
BubbleChartSeries[] |
Required | { name, points, color?, dataLabels?, pointLabels?, trendlines?, xErrorBars?, yErrorBars? }, where a point is { x, y, size }. See Chart Data Labels and Chart Trendlines and Error Bars |
bubbleScale |
number |
Optional | The bubbles' size, as a percentage of Office's, from 0 to 300. Default 100 |
sizeRepresents |
"area" | "width" |
Optional | Whether a size is a bubble's area or width. Default "area" |
xAxis |
ChartValueAxis |
Optional | The horizontal axis. See Chart Axes |
yAxis |
ChartValueAxis |
Optional | The vertical axis. See Chart Axes |
dataLabels |
BubbleChartDataLabels |
Optional | { value?, category?, seriesName?, bubbleSize?, ... }. See Chart Data Labels |
title |
string | ChartTitle |
Optional | See Chart Titles and Legends |
legend |
false | ChartLegend |
Optional | See Chart Titles and Legends |
transformation |
{ width, height } |
Optional | See Chart Size and Position |
floating |
IFloating |
Optional | See Chart Size and Position |
altText |
DocPropertiesOptions |
Optional | See Chart Size and Position |
Chart Fonts and Fills shows the options every chart has for its text, background and border.