@pixerate/editor 0.166.0 → 0.167.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/THIRD_PARTY_NOTICES.md +11 -0
- package/dist/agent/index.cjs +34 -34
- package/dist/agent/index.js +5 -5
- package/dist/canvas/index.cjs +6 -6
- package/dist/canvas/index.js +2 -2
- package/dist/chart/index.cjs +236 -185
- package/dist/chart/index.d.cts +1 -0
- package/dist/chart/index.d.ts +1 -0
- package/dist/chart/index.js +57 -6
- package/dist/chart/layout-families.d.cts +8 -0
- package/dist/chart/layout-families.d.ts +8 -0
- package/dist/chart/maps.d.cts +43 -0
- package/dist/chart/maps.d.ts +43 -0
- package/dist/chart/spec.d.cts +1 -1
- package/dist/chart/spec.d.ts +1 -1
- package/dist/chart/types.d.cts +10 -2
- package/dist/chart/types.d.ts +10 -2
- package/dist/chart-maps/europe.d.cts +7 -0
- package/dist/chart-maps/europe.d.ts +7 -0
- package/dist/chart-maps/index.cjs +66 -0
- package/dist/chart-maps/index.d.cts +1 -0
- package/dist/chart-maps/index.d.ts +1 -0
- package/dist/chart-maps/index.js +66 -0
- package/dist/{chunk-V5L2G22R.cjs → chunk-2F4GAZL5.cjs} +109 -95
- package/dist/{chunk-5UNQDC3Q.js → chunk-34UCPHYO.js} +5 -2
- package/dist/{chunk-HXOBOHH2.cjs → chunk-E45AIIWY.cjs} +8 -8
- package/dist/{chunk-NQQDGGXY.js → chunk-FKYGM35R.js} +2 -2
- package/dist/{chunk-6FYIFGBW.cjs → chunk-GD34ICEX.cjs} +16 -16
- package/dist/{chunk-MZFZSVUJ.cjs → chunk-GTF4RYXJ.cjs} +25 -22
- package/dist/{chunk-ITANXMZD.js → chunk-M52UCHVZ.js} +127 -3
- package/dist/{chunk-YUFTVNLX.js → chunk-N3ACT6VJ.js} +16 -2
- package/dist/{chunk-XNU45TYA.js → chunk-OLCHKGGO.js} +4 -1
- package/dist/{chunk-FR432ROA.js → chunk-ORZF4JOO.js} +23 -4
- package/dist/{chunk-BPX4Z3N3.cjs → chunk-OUO3DSRT.cjs} +23 -4
- package/dist/{chunk-CHLV7UFP.cjs → chunk-SBAPXFPB.cjs} +51 -51
- package/dist/{chunk-VB2CY6EG.js → chunk-T62BRXMS.js} +3 -3
- package/dist/{chunk-SZWVMB3B.cjs → chunk-VKHJJUBK.cjs} +21 -18
- package/dist/{chunk-UUUTEVX6.cjs → chunk-WOIXNDHV.cjs} +172 -48
- package/dist/{chunk-DFCAR7AW.js → chunk-ZUPP4NKM.js} +3 -3
- package/dist/export/index.cjs +4 -4
- package/dist/export/index.js +3 -3
- package/dist/extensions/index.cjs +7 -7
- package/dist/extensions/index.js +6 -6
- package/dist/index.cjs +13 -13
- package/dist/index.js +7 -7
- package/package.json +11 -1
- package/skills/pixerate-chart/SKILL.md +18 -2
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
CHART_STACKINGS,
|
|
19
19
|
CHART_TRENDLINE_TYPES,
|
|
20
20
|
CHART_TYPES
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-ORZF4JOO.js";
|
|
22
22
|
|
|
23
23
|
// src/chart/schemas.ts
|
|
24
24
|
var VALUE = { type: ["number", "string", "null"], description: 'A number, numeric text ("1,200", "12%", "$40", "(3)") or null for a gap.' };
|
|
@@ -158,7 +158,7 @@ var SERIES_PROPS = {
|
|
|
158
158
|
xErrorBars: ERROR_BARS("Error bars along the x axis (scatter and bubble charts with numeric x values; amounts in x units).")
|
|
159
159
|
};
|
|
160
160
|
var CHART_UPDATE_PROPERTIES = {
|
|
161
|
-
type: { type: "string", enum: [...CHART_TYPES], description: "Chart type. slope joins each category from the first series (before) to the second (after); likert reads each category as a question and the series as answers from most negative to most positive; parliament draws the first series as seats; sunburst draws the grouped data (set_chart_tree) as rings, and a treemap with grouped data nests its groups; sankey draws the flows (set_chart_links); barrace reads categories as time points and series as names, and animates their ranking." },
|
|
161
|
+
type: { type: "string", enum: [...CHART_TYPES], description: "Chart type. slope joins each category from the first series (before) to the second (after); likert reads each category as a question and the series as answers from most negative to most positive; parliament draws the first series as seats; sunburst draws the grouped data (set_chart_tree) as rings, and a treemap with grouped data nests its groups; sankey draws the flows (set_chart_links); barrace reads categories as time points and series as names, and animates their ranking; choropleth shades the regions of a map, each category naming a region by code (FRA) or name (France)." },
|
|
162
162
|
title: { type: "string", description: 'Title ("" for none).' },
|
|
163
163
|
subtitle: { type: "string", description: 'Subtitle ("" for none).' },
|
|
164
164
|
xAxis: AXIS("Category axis (or numeric x axis of scatter / bubble charts)."),
|
|
@@ -196,6 +196,9 @@ var CHART_UPDATE_PROPERTIES = {
|
|
|
196
196
|
parliamentLabel: { type: "string", description: 'Parliament: caption under the seat total ("" writes "seats").' },
|
|
197
197
|
sunburstLabel: { type: "string", description: 'Sunburst: caption under the total in the centre ("" for none).' },
|
|
198
198
|
sankeyLinkColor: { type: "string", enum: [...CHART_SANKEY_LINK_COLORS], description: "Sankey: colour each flow by its source node (default), its target node, or grey." },
|
|
199
|
+
map: { type: "string", description: 'Choropleth: the registered map to draw (list_chart_map_regions lists them; "europe" by default).' },
|
|
200
|
+
mapSteps: { type: "integer", minimum: 2, maximum: 9, description: "Choropleth: number of equal colour classes between the smallest and largest value (default 5)." },
|
|
201
|
+
mapThresholds: { type: "array", items: { type: "number" }, maxItems: 8, description: "Choropleth: class breaks in ascending order, e.g. [100, 250, 500], used instead of mapSteps; [] goes back to equal classes." },
|
|
199
202
|
raceTopN: { type: "integer", minimum: 1, maximum: 30, description: "Bar race: how many bars each moment shows (default 10)." },
|
|
200
203
|
sankeyNodes: { type: "array", items: { type: "string" }, description: "Sankey: node names in the order to stack them within their columns (reorder to untangle crossing flows); nodes left out follow in the order the flows name them." }
|
|
201
204
|
};
|
|
@@ -11,10 +11,10 @@ var _chunkYN6JKAUEcjs = require('./chunk-YN6JKAUE.cjs');
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _chunkVKHJJUBKcjs = require('./chunk-VKHJJUBK.cjs');
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
var
|
|
17
|
+
var _chunkOUO3DSRTcjs = require('./chunk-OUO3DSRT.cjs');
|
|
18
18
|
|
|
19
19
|
// src/export/images.ts
|
|
20
20
|
var DOCX_IMAGE_TYPES = {
|
|
@@ -1028,12 +1028,12 @@ var DocxBuilder = (_class2 = class {
|
|
|
1028
1028
|
this.drop("node", "chart", "chart has no spec");
|
|
1029
1029
|
return;
|
|
1030
1030
|
}
|
|
1031
|
-
const spec =
|
|
1032
|
-
const written =
|
|
1031
|
+
const spec = _chunkOUO3DSRTcjs.normalizeChartSpec.call(void 0, raw).spec;
|
|
1032
|
+
const written = _chunkVKHJJUBKcjs.chartToOoxml.call(void 0, spec);
|
|
1033
1033
|
for (const issue of written.issues) this.drop("node", "chart", issue);
|
|
1034
1034
|
const name = `chart${this.charts.length + 1}.xml`;
|
|
1035
1035
|
this.charts.push(written.xml);
|
|
1036
|
-
const relId = this.rels.add(
|
|
1036
|
+
const relId = this.rels.add(_chunkVKHJJUBKcjs.CHART_OOXML_RELATIONSHIP, `charts/${name}`);
|
|
1037
1037
|
let width = _nullishCoalesce(pixelAttr(_optionalChain([node, 'access', _91 => _91.attrs, 'optionalAccess', _92 => _92.width])), () => ( MAX_IMAGE_WIDTH_PX));
|
|
1038
1038
|
let height = _nullishCoalesce(pixelAttr(_optionalChain([node, 'access', _93 => _93.attrs, 'optionalAccess', _94 => _94.height])), () => ( 320));
|
|
1039
1039
|
if (width > MAX_IMAGE_WIDTH_PX) {
|
|
@@ -1050,8 +1050,8 @@ var DocxBuilder = (_class2 = class {
|
|
|
1050
1050
|
drawing.empty("wp:extent", { cx, cy }).empty("wp:effectExtent", { l: 0, t: 0, r: 0, b: 0 });
|
|
1051
1051
|
drawing.empty("wp:docPr", { id, name: `Chart ${id}`, descr: title || void 0, title: title || void 0 });
|
|
1052
1052
|
drawing.empty("wp:cNvGraphicFramePr");
|
|
1053
|
-
drawing.open("a:graphic").open("a:graphicData", { uri:
|
|
1054
|
-
drawing.empty("c:chart", { "xmlns:c":
|
|
1053
|
+
drawing.open("a:graphic").open("a:graphicData", { uri: _chunkVKHJJUBKcjs.CHART_OOXML_NS });
|
|
1054
|
+
drawing.empty("c:chart", { "xmlns:c": _chunkVKHJJUBKcjs.CHART_OOXML_NS, "r:id": relId });
|
|
1055
1055
|
drawing.close("a:graphicData").close("a:graphic").close("wp:inline").close("w:drawing").close("w:r");
|
|
1056
1056
|
this.report.written.paragraphs++;
|
|
1057
1057
|
w.open("w:p");
|
|
@@ -1384,7 +1384,7 @@ var DocxBuilder = (_class2 = class {
|
|
|
1384
1384
|
if (people) add("word/people.xml", people, `${CT_WML}people+xml`);
|
|
1385
1385
|
parts.push({ name: "word/_rels/document.xml.rels", data: this.rels.xml() });
|
|
1386
1386
|
for (const file of this.media) parts.push({ name: `word/media/${file.name}`, data: file.bytes });
|
|
1387
|
-
this.charts.forEach((xml, i) => add(`word/charts/chart${i + 1}.xml`, xml,
|
|
1387
|
+
this.charts.forEach((xml, i) => add(`word/charts/chart${i + 1}.xml`, xml, _chunkVKHJJUBKcjs.CHART_OOXML_CONTENT_TYPE));
|
|
1388
1388
|
add("docProps/core.xml", this.coreXml(now), "application/vnd.openxmlformats-package.core-properties+xml");
|
|
1389
1389
|
const app = new XmlWriter();
|
|
1390
1390
|
app.open("Properties", { xmlns: "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" });
|
|
@@ -11,10 +11,10 @@ import {
|
|
|
11
11
|
CHART_OOXML_NS,
|
|
12
12
|
CHART_OOXML_RELATIONSHIP,
|
|
13
13
|
chartToOoxml
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-OLCHKGGO.js";
|
|
15
15
|
import {
|
|
16
16
|
normalizeChartSpec
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-ORZF4JOO.js";
|
|
18
18
|
|
|
19
19
|
// src/export/images.ts
|
|
20
20
|
var DOCX_IMAGE_TYPES = {
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunk2F4GAZL5cjs = require('./chunk-2F4GAZL5.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkWOIXNDHVcjs = require('./chunk-WOIXNDHV.cjs');
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkOUO3DSRTcjs = require('./chunk-OUO3DSRT.cjs');
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
var _chunkG43MNQ4Ccjs = require('./chunk-G43MNQ4C.cjs');
|
|
@@ -1211,7 +1211,7 @@ var ChartNodeView = (_class = class {
|
|
|
1211
1211
|
this.dom.contentEditable = "false";
|
|
1212
1212
|
this.syncAttributes();
|
|
1213
1213
|
this.key = specKey(this.node.attrs.spec);
|
|
1214
|
-
this.controller = new (0,
|
|
1214
|
+
this.controller = new (0, _chunk2F4GAZL5cjs.ChartController)({ spec: this.node.attrs.spec });
|
|
1215
1215
|
this.unsubscribe = this.controller.subscribe((state) => {
|
|
1216
1216
|
if (!state.gesture) this.writeBack();
|
|
1217
1217
|
});
|
|
@@ -1444,7 +1444,7 @@ function readSpec(value) {
|
|
|
1444
1444
|
}
|
|
1445
1445
|
}
|
|
1446
1446
|
if (!input || typeof input !== "object" || Array.isArray(input)) return null;
|
|
1447
|
-
return
|
|
1447
|
+
return _chunkOUO3DSRTcjs.normalizeChartSpec.call(void 0, input).spec;
|
|
1448
1448
|
}
|
|
1449
1449
|
var readSize = (value) => {
|
|
1450
1450
|
const n = value === null ? NaN : Number(value);
|
|
@@ -1470,10 +1470,10 @@ function staticChartSvg(node, options) {
|
|
|
1470
1470
|
const spec = node.attrs.spec;
|
|
1471
1471
|
const width = _nullishCoalesce(node.attrs.width, () => ( options.defaultWidth));
|
|
1472
1472
|
const height = _nullishCoalesce(node.attrs.height, () => ( options.defaultHeight));
|
|
1473
|
-
const scene =
|
|
1474
|
-
return
|
|
1473
|
+
const scene = _chunkWOIXNDHVcjs.layoutChart.call(void 0, spec, { width, height, theme: options.theme, selection: null });
|
|
1474
|
+
return _chunk2F4GAZL5cjs.chartSceneToDomSpec.call(void 0, scene, {
|
|
1475
1475
|
ariaLabel: spec.title || "Chart",
|
|
1476
|
-
description:
|
|
1476
|
+
description: _chunk2F4GAZL5cjs.describeChart.call(void 0, spec),
|
|
1477
1477
|
attrs: { style: "max-width: 100%; height: auto; display: block" }
|
|
1478
1478
|
});
|
|
1479
1479
|
}
|
|
@@ -1489,7 +1489,7 @@ var Chart = _core.Node.create({
|
|
|
1489
1489
|
return {
|
|
1490
1490
|
HTMLAttributes: {},
|
|
1491
1491
|
nodeView: null,
|
|
1492
|
-
theme:
|
|
1492
|
+
theme: _chunkOUO3DSRTcjs.DEFAULT_CHART_THEME,
|
|
1493
1493
|
defaultWidth: 640,
|
|
1494
1494
|
defaultHeight: 320,
|
|
1495
1495
|
generateId: () => generateStructureId("chart")
|
|
@@ -1503,7 +1503,7 @@ var Chart = _core.Node.create({
|
|
|
1503
1503
|
renderHTML: (attributes) => attributes.id ? { "data-chart-id": attributes.id } : {}
|
|
1504
1504
|
},
|
|
1505
1505
|
spec: {
|
|
1506
|
-
default:
|
|
1506
|
+
default: _chunkOUO3DSRTcjs.normalizeChartSpec.call(void 0, {}).spec,
|
|
1507
1507
|
// null (no `data-chart`) keeps what the parse rule found, e.g. a mermaid block's spec.
|
|
1508
1508
|
parseHTML: (element) => readSpec(element.getAttribute("data-chart")),
|
|
1509
1509
|
renderHTML: (attributes) => ({
|
|
@@ -1541,7 +1541,7 @@ var Chart = _core.Node.create({
|
|
|
1541
1541
|
const code = element.querySelector("code");
|
|
1542
1542
|
const language = _nullishCoalesce(_nullishCoalesce(_optionalChain([code, 'optionalAccess', _34 => _34.getAttribute, 'call', _35 => _35("class")]), () => ( element.getAttribute("data-language"))), () => ( ""));
|
|
1543
1543
|
if (!/(?:^|\s)language-mermaid(?:\s|$)/.test(language) && language !== "mermaid") return false;
|
|
1544
|
-
const result =
|
|
1544
|
+
const result = _chunk2F4GAZL5cjs.chartFromMermaid.call(void 0, _nullishCoalesce((_nullishCoalesce(code, () => ( element))).textContent, () => ( "")));
|
|
1545
1545
|
return result.family ? { spec: result.spec } : false;
|
|
1546
1546
|
}
|
|
1547
1547
|
}
|
|
@@ -1565,7 +1565,7 @@ var Chart = _core.Node.create({
|
|
|
1565
1565
|
return {
|
|
1566
1566
|
markdown: {
|
|
1567
1567
|
serialize(state, node) {
|
|
1568
|
-
const text =
|
|
1568
|
+
const text = _chunk2F4GAZL5cjs.chartToMermaid.call(void 0, node.attrs.spec);
|
|
1569
1569
|
const fence = "`".repeat(Math.max(3, longestBacktickRun(text) + 1));
|
|
1570
1570
|
state.write(`${fence}mermaid
|
|
1571
1571
|
`);
|
|
@@ -1587,7 +1587,7 @@ var Chart = _core.Node.create({
|
|
|
1587
1587
|
type: this.name,
|
|
1588
1588
|
attrs: {
|
|
1589
1589
|
id: _nullishCoalesce(options.id, () => ( this.options.generateId())),
|
|
1590
|
-
spec:
|
|
1590
|
+
spec: _chunkOUO3DSRTcjs.normalizeChartSpec.call(void 0, _nullishCoalesce(options.spec, () => ( {}))).spec,
|
|
1591
1591
|
width: _nullishCoalesce(options.width, () => ( null)),
|
|
1592
1592
|
height: _nullishCoalesce(options.height, () => ( this.options.defaultHeight))
|
|
1593
1593
|
}
|
|
@@ -1598,7 +1598,7 @@ var Chart = _core.Node.create({
|
|
|
1598
1598
|
if (dispatch) {
|
|
1599
1599
|
tr.setNodeMarkup(chart.pos, void 0, {
|
|
1600
1600
|
...chart.node.attrs,
|
|
1601
|
-
...changes.spec !== void 0 ? { spec:
|
|
1601
|
+
...changes.spec !== void 0 ? { spec: _chunkOUO3DSRTcjs.normalizeChartSpec.call(void 0, changes.spec).spec } : {},
|
|
1602
1602
|
...changes.width !== void 0 ? { width: changes.width } : {},
|
|
1603
1603
|
...changes.height !== void 0 ? { height: changes.height } : {}
|
|
1604
1604
|
});
|
|
@@ -1705,14 +1705,14 @@ var Sparkline = _core.Node.create({
|
|
|
1705
1705
|
return [{ tag: 'span[data-type="sparkline"]', priority: 60 }];
|
|
1706
1706
|
},
|
|
1707
1707
|
renderHTML({ node, HTMLAttributes }) {
|
|
1708
|
-
const scene =
|
|
1708
|
+
const scene = _chunk2F4GAZL5cjs.layoutSparkline.call(void 0, node.attrs.values, {
|
|
1709
1709
|
kind: node.attrs.kind,
|
|
1710
1710
|
width: node.attrs.width,
|
|
1711
1711
|
height: node.attrs.height,
|
|
1712
1712
|
color: _nullishCoalesce(node.attrs.color, () => ( this.options.color)),
|
|
1713
1713
|
negativeColor: this.options.negativeColor
|
|
1714
1714
|
});
|
|
1715
|
-
const svg =
|
|
1715
|
+
const svg = _chunk2F4GAZL5cjs.chartSceneToDomSpec.call(void 0, scene, {
|
|
1716
1716
|
ariaLabel: sparklineLabel(node),
|
|
1717
1717
|
attrs: { style: "display: inline-block; vertical-align: middle" }
|
|
1718
1718
|
});
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
var
|
|
21
|
+
var _chunkOUO3DSRTcjs = require('./chunk-OUO3DSRT.cjs');
|
|
22
22
|
|
|
23
23
|
// src/chart/schemas.ts
|
|
24
24
|
var VALUE = { type: ["number", "string", "null"], description: 'A number, numeric text ("1,200", "12%", "$40", "(3)") or null for a gap.' };
|
|
@@ -30,7 +30,7 @@ var FORMAT = {
|
|
|
30
30
|
type: "object",
|
|
31
31
|
description: "How numbers are written on this axis or series.",
|
|
32
32
|
properties: {
|
|
33
|
-
style: { type: "string", enum: [...
|
|
33
|
+
style: { type: "string", enum: [..._chunkOUO3DSRTcjs.CHART_NUMBER_STYLES], description: "number (default), percent (0.25 \u2192 25%), currency or compact (1.2K)." },
|
|
34
34
|
decimals: { type: "integer", minimum: 0, maximum: 10, description: "Fixed decimals (default: what the ticks need)." },
|
|
35
35
|
currency: { type: "string", description: 'ISO currency code for style "currency", e.g. "EUR" (default USD).' },
|
|
36
36
|
prefix: { type: "string", description: "Text before every number." },
|
|
@@ -50,10 +50,10 @@ var AXIS = (what) => ({
|
|
|
50
50
|
step: { type: ["number", "null"], exclusiveMinimum: 0, description: "Fixed distance between ticks, or null for automatic." },
|
|
51
51
|
gridlines: { type: "boolean", description: "Grid lines at each tick." },
|
|
52
52
|
format: FORMAT,
|
|
53
|
-
kind: { type: ["string", "null"], enum: [...
|
|
53
|
+
kind: { type: ["string", "null"], enum: [..._chunkOUO3DSRTcjs.CHART_AXIS_KINDS, null], description: 'Category axis only: "date" reads categories as dates and labels them by calendar steps.' },
|
|
54
54
|
scale: {
|
|
55
55
|
type: ["string", "null"],
|
|
56
|
-
enum: [...
|
|
56
|
+
enum: [..._chunkOUO3DSRTcjs.CHART_AXIS_SCALES, null],
|
|
57
57
|
description: 'Value axes and the numeric x axis of scatter / bubble charts: "log" spaces ticks by powers of logBase (values of 0 or less are skipped; min and max must be above 0; not with percent stacking). "linear" or null is the default. Ignored on a category axis.'
|
|
58
58
|
},
|
|
59
59
|
logBase: { type: ["number", "null"], minimum: 2, maximum: 1e3, description: "Base of a log axis, 2 to 1000 (default 10; null resets)." },
|
|
@@ -62,7 +62,7 @@ var AXIS = (what) => ({
|
|
|
62
62
|
additionalProperties: false
|
|
63
63
|
});
|
|
64
64
|
var TRENDLINE_PROPS = {
|
|
65
|
-
type: { type: "string", enum: [...
|
|
65
|
+
type: { type: "string", enum: [..._chunkOUO3DSRTcjs.CHART_TRENDLINE_TYPES], description: "Fit: linear, exponential, logarithmic, power, polynomial or moving-average." },
|
|
66
66
|
order: { type: "integer", minimum: 2, maximum: 6, description: "Polynomial order (default 2)." },
|
|
67
67
|
period: { type: "integer", minimum: 2, description: "Moving-average period in points (default 2)." },
|
|
68
68
|
forward: { type: "number", minimum: 0, description: "Extend the line this many x units past the last point (default 0)." },
|
|
@@ -77,7 +77,7 @@ var REFERENCE_COMMON = {
|
|
|
77
77
|
label: { type: "string", description: 'Text written on it, e.g. "Target" (default none).' },
|
|
78
78
|
axis: {
|
|
79
79
|
type: "string",
|
|
80
|
-
enum: [...
|
|
80
|
+
enum: [..._chunkOUO3DSRTcjs.CHART_REFERENCE_AXES],
|
|
81
81
|
description: "Axis it is measured on: y (default) is the value axis, y2 the secondary value axis (needs a series there), x the numeric x axis of a scatter or bubble chart."
|
|
82
82
|
},
|
|
83
83
|
color: { type: "string", description: "CSS colour (default: the text colour)." }
|
|
@@ -93,7 +93,7 @@ var REFERENCE_BAND_PROPS = {
|
|
|
93
93
|
};
|
|
94
94
|
var REFERENCE_COMMON_PATCH = {
|
|
95
95
|
label: { type: ["string", "null"], description: "Text written on it; null removes it." },
|
|
96
|
-
axis: { type: ["string", "null"], enum: [...
|
|
96
|
+
axis: { type: ["string", "null"], enum: [..._chunkOUO3DSRTcjs.CHART_REFERENCE_AXES, null], description: "Axis it is measured on (y, y2 or x); null goes back to y." },
|
|
97
97
|
color: { type: ["string", "null"], description: "CSS colour; null goes back to the text colour." }
|
|
98
98
|
};
|
|
99
99
|
var REFERENCE_LINE_PATCH = { value: REFERENCE_LINE_PROPS.value, ...REFERENCE_COMMON_PATCH };
|
|
@@ -127,13 +127,13 @@ var ERROR_BARS = (what) => ({
|
|
|
127
127
|
properties: {
|
|
128
128
|
type: {
|
|
129
129
|
type: "string",
|
|
130
|
-
enum: [...
|
|
130
|
+
enum: [..._chunkOUO3DSRTcjs.CHART_ERROR_BAR_TYPES],
|
|
131
131
|
description: "fixed: the same amount at every point; percent: a percentage of each value; stddev: value standard deviations of the series, drawn around the series mean (as Excel does); stderr: the standard error of the series at every point; custom: per-point plus / minus amounts."
|
|
132
132
|
},
|
|
133
133
|
value: { type: "number", minimum: 0, description: "Amount in data units for fixed (default 1), percent of each value for percent (default 5), number of standard deviations for stddev (default 1). Not for stderr or custom." },
|
|
134
134
|
plus: { type: "array", items: VALUE, description: "custom only: amount above each point, one per category, in data units (0 or more; null for none)." },
|
|
135
135
|
minus: { type: "array", items: VALUE, description: "custom only: amount below each point, one per category (default: the plus amounts)." },
|
|
136
|
-
direction: { type: "string", enum: [...
|
|
136
|
+
direction: { type: "string", enum: [..._chunkOUO3DSRTcjs.CHART_ERROR_BAR_DIRECTIONS], description: "both (default), plus (only above) or minus (only below)." },
|
|
137
137
|
cap: { type: "boolean", description: "Draw end caps (default true)." }
|
|
138
138
|
},
|
|
139
139
|
required: ["type"],
|
|
@@ -143,22 +143,22 @@ var SERIES_PROPS = {
|
|
|
143
143
|
name: { type: "string", description: "Series name (legend and data grid header)." },
|
|
144
144
|
values: { type: "array", items: VALUE, description: "One value per category, in category order (padded with gaps)." },
|
|
145
145
|
color: { type: ["string", "null"], description: "CSS colour, or null for the palette colour." },
|
|
146
|
-
type: { type: ["string", "null"], enum: [...
|
|
146
|
+
type: { type: ["string", "null"], enum: [..._chunkOUO3DSRTcjs.CHART_SERIES_TYPES, null], description: "Draw this series as bar, line, area or scatter (a combo chart); null follows the chart type." },
|
|
147
147
|
hidden: { type: "boolean", description: "Hide the series (its data is kept)." },
|
|
148
148
|
axis: { type: ["string", "null"], enum: ["primary", "secondary", null], description: "Value axis: secondary is drawn on the right with its own scale." },
|
|
149
149
|
x: { type: ["array", "null"], items: VALUE, description: "Numeric x per category, for scatter and bubble charts." },
|
|
150
150
|
sizes: { type: ["array", "null"], items: VALUE, description: "Bubble sizes per category (area is proportional to size)." },
|
|
151
151
|
pointColors: { type: ["array", "null"], items: { type: ["string", "null"] }, description: "Colour per category (null keeps the series colour)." },
|
|
152
152
|
callouts: { type: ["array", "null"], items: { type: ["string", "null"] }, description: "A label pinned to each point that matters, one per category (null: none); null removes them all. Bar, line, area and scatter charts. set_chart_callout sets one." },
|
|
153
|
-
marker: { type: ["string", "null"], enum: [...
|
|
154
|
-
curve: { type: ["string", "null"], enum: [...
|
|
153
|
+
marker: { type: ["string", "null"], enum: [..._chunkOUO3DSRTcjs.CHART_MARKERS, null], description: "Point marker shape for line, area and scatter series." },
|
|
154
|
+
curve: { type: ["string", "null"], enum: [..._chunkOUO3DSRTcjs.CHART_CURVES, null], description: "Line shape for this series: linear, smooth or step." },
|
|
155
155
|
dataLabels: { type: ["boolean", "null"], description: "Value labels for this series (null follows the chart)." },
|
|
156
156
|
format: { ...FORMAT, type: ["object", "null"], description: "How this series' labels are written (null follows the value axis)." },
|
|
157
157
|
errorBars: ERROR_BARS("Error bars along the value axis (bar, line, area and scatter series; on stacked charts they sit on the stack top)."),
|
|
158
158
|
xErrorBars: ERROR_BARS("Error bars along the x axis (scatter and bubble charts with numeric x values; amounts in x units).")
|
|
159
159
|
};
|
|
160
160
|
var CHART_UPDATE_PROPERTIES = {
|
|
161
|
-
type: { type: "string", enum: [...
|
|
161
|
+
type: { type: "string", enum: [..._chunkOUO3DSRTcjs.CHART_TYPES], description: "Chart type. slope joins each category from the first series (before) to the second (after); likert reads each category as a question and the series as answers from most negative to most positive; parliament draws the first series as seats; sunburst draws the grouped data (set_chart_tree) as rings, and a treemap with grouped data nests its groups; sankey draws the flows (set_chart_links); barrace reads categories as time points and series as names, and animates their ranking; choropleth shades the regions of a map, each category naming a region by code (FRA) or name (France)." },
|
|
162
162
|
title: { type: "string", description: 'Title ("" for none).' },
|
|
163
163
|
subtitle: { type: "string", description: 'Subtitle ("" for none).' },
|
|
164
164
|
xAxis: AXIS("Category axis (or numeric x axis of scatter / bubble charts)."),
|
|
@@ -167,15 +167,15 @@ var CHART_UPDATE_PROPERTIES = {
|
|
|
167
167
|
legend: {
|
|
168
168
|
type: "object",
|
|
169
169
|
description: "Legend.",
|
|
170
|
-
properties: { show: { type: "boolean", description: "Show the legend." }, position: { type: "string", enum: [...
|
|
170
|
+
properties: { show: { type: "boolean", description: "Show the legend." }, position: { type: "string", enum: [..._chunkOUO3DSRTcjs.CHART_LEGEND_POSITIONS], description: "Where the legend goes." } },
|
|
171
171
|
additionalProperties: false
|
|
172
172
|
},
|
|
173
|
-
stacking: { type: "string", enum: [...
|
|
174
|
-
orientation: { type: "string", enum: [...
|
|
175
|
-
curve: { type: "string", enum: [...
|
|
173
|
+
stacking: { type: "string", enum: [..._chunkOUO3DSRTcjs.CHART_STACKINGS], description: "none, stacked, or percent (each category scaled to 100%)." },
|
|
174
|
+
orientation: { type: "string", enum: [..._chunkOUO3DSRTcjs.CHART_ORIENTATIONS], description: "horizontal draws bars sideways." },
|
|
175
|
+
curve: { type: "string", enum: [..._chunkOUO3DSRTcjs.CHART_CURVES], description: "Line shape: linear, smooth or step." },
|
|
176
176
|
points: { type: "boolean", description: "Dots on line and area series." },
|
|
177
177
|
dataLabels: { type: "boolean", description: "Value labels on bars, points and slices." },
|
|
178
|
-
labelPosition: { type: "string", enum: [...
|
|
178
|
+
labelPosition: { type: "string", enum: [..._chunkOUO3DSRTcjs.CHART_LABEL_POSITIONS], description: "Bar label position; auto drops labels that do not fit." },
|
|
179
179
|
palette: { type: "array", items: { type: "string" }, minItems: 1, description: "Series colours in order (CSS colours)." },
|
|
180
180
|
innerRadius: { type: "number", minimum: 0, maximum: 0.9, description: "Donut hole as a fraction of the radius." },
|
|
181
181
|
gapWidth: { type: "number", minimum: 0, maximum: 0.9, description: "Space between bar groups as a fraction of the category (default 0.28)." },
|
|
@@ -183,19 +183,22 @@ var CHART_UPDATE_PROPERTIES = {
|
|
|
183
183
|
bins: { type: ["integer", "null"], minimum: 1, maximum: 500, description: "Histogram bin count, or null for \u221An." },
|
|
184
184
|
showTotal: { type: "boolean", description: "Waterfall: append a total bar." },
|
|
185
185
|
radarTicks: { type: ["integer", "null"], minimum: 1, maximum: 50, description: "Radar: number of evenly spaced rings from the value axis min to max, or null for round-number rings (default null)." },
|
|
186
|
-
radarGraticule: { type: "string", enum: [...
|
|
186
|
+
radarGraticule: { type: "string", enum: [..._chunkOUO3DSRTcjs.CHART_RADAR_GRATICULES], description: "Radar: draw rings as polygons through the spokes or as circles (default polygon)." },
|
|
187
187
|
note: { type: "string", description: 'A source or footnote written under the chart ("" for none).' },
|
|
188
188
|
highlight: { type: "array", items: { type: "string" }, description: "Category labels and series names (or ids) to draw normally while the rest are muted; [] shows everything. highlight_chart checks the names." },
|
|
189
189
|
referenceLines: { type: "array", items: { type: "object", properties: REFERENCE_LINE_PROPS, required: ["value"], additionalProperties: false }, description: "Replaces every reference line (targets, floors, averages across the plot). add_chart_reference_line adds one." },
|
|
190
190
|
referenceBands: { type: "array", items: { type: "object", properties: REFERENCE_BAND_PROPS, required: ["from", "to"], additionalProperties: false }, description: "Replaces every reference band (target ranges across the plot). add_chart_reference_band adds one." },
|
|
191
191
|
varyColors: { type: "boolean", description: "A one-series bar, line, area or scatter chart colours each category from the palette, and its legend lists the categories (default false)." },
|
|
192
|
-
likertNeutral: { type: "string", enum: [...
|
|
193
|
-
likertSort: { type: "string", enum: [...
|
|
192
|
+
likertNeutral: { type: "string", enum: [..._chunkOUO3DSRTcjs.CHART_LIKERT_NEUTRALS], description: "Likert with an odd number of answers: split (default) puts the middle answer across the centre line; separate draws it in its own column on the right." },
|
|
193
|
+
likertSort: { type: "string", enum: [..._chunkOUO3DSRTcjs.CHART_LIKERT_SORTS], description: "Likert: order the questions by agreement (positive), by disagreement (negative) or as given (none, default)." },
|
|
194
194
|
parliamentArc: { type: "number", minimum: 90, maximum: 360, description: "Parliament: sweep of the hemicycle in degrees (default 180)." },
|
|
195
195
|
parliamentMajority: { type: ["integer", "null"], minimum: 1, description: "Parliament: seats needed for a majority, drawn as a dashed line (null: half of the seats plus one)." },
|
|
196
196
|
parliamentLabel: { type: "string", description: 'Parliament: caption under the seat total ("" writes "seats").' },
|
|
197
197
|
sunburstLabel: { type: "string", description: 'Sunburst: caption under the total in the centre ("" for none).' },
|
|
198
|
-
sankeyLinkColor: { type: "string", enum: [...
|
|
198
|
+
sankeyLinkColor: { type: "string", enum: [..._chunkOUO3DSRTcjs.CHART_SANKEY_LINK_COLORS], description: "Sankey: colour each flow by its source node (default), its target node, or grey." },
|
|
199
|
+
map: { type: "string", description: 'Choropleth: the registered map to draw (list_chart_map_regions lists them; "europe" by default).' },
|
|
200
|
+
mapSteps: { type: "integer", minimum: 2, maximum: 9, description: "Choropleth: number of equal colour classes between the smallest and largest value (default 5)." },
|
|
201
|
+
mapThresholds: { type: "array", items: { type: "number" }, maxItems: 8, description: "Choropleth: class breaks in ascending order, e.g. [100, 250, 500], used instead of mapSteps; [] goes back to equal classes." },
|
|
199
202
|
raceTopN: { type: "integer", minimum: 1, maximum: 30, description: "Bar race: how many bars each moment shows (default 10)." },
|
|
200
203
|
sankeyNodes: { type: "array", items: { type: "string" }, description: "Sankey: node names in the order to stack them within their columns (reorder to untangle crossing flows); nodes left out follow in the order the flows name them." }
|
|
201
204
|
};
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
chartTreeTotal,
|
|
13
13
|
chartVariesColors,
|
|
14
14
|
shadeChartColor
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-ORZF4JOO.js";
|
|
16
16
|
import {
|
|
17
17
|
NumberFormat
|
|
18
18
|
} from "./chunk-II2WIF5Z.js";
|
|
@@ -948,7 +948,7 @@ function drawCallouts(ctx, plot) {
|
|
|
948
948
|
}
|
|
949
949
|
if (unplaced) ctx.warn("annotations-skipped", `${unplaced} callout${unplaced === 1 ? " points" : "s point"} at a gap or a hidden value and ${unplaced === 1 ? "is" : "are"} not drawn.`);
|
|
950
950
|
}
|
|
951
|
-
var MUTED = /* @__PURE__ */ new Set(["node", "bar", "line", "area", "point", "slice", "cell", "box", "whisker", "outlier", "connector", "trendline", "trendline-label", "error-bar", "data-label", "legend-swatch", "legend-label"]);
|
|
951
|
+
var MUTED = /* @__PURE__ */ new Set(["node", "region", "bar", "line", "area", "point", "slice", "cell", "box", "whisker", "outlier", "connector", "trendline", "trendline-label", "error-bar", "data-label", "legend-swatch", "legend-label"]);
|
|
952
952
|
function applyHighlight(ctx) {
|
|
953
953
|
const { spec, marks } = ctx;
|
|
954
954
|
if (!spec.highlight.length) return;
|
|
@@ -1677,6 +1677,51 @@ function trendlineLegendItems(spec, color) {
|
|
|
1677
1677
|
);
|
|
1678
1678
|
}
|
|
1679
1679
|
|
|
1680
|
+
// src/chart/maps.ts
|
|
1681
|
+
var maps = /* @__PURE__ */ new Map();
|
|
1682
|
+
function registerChartMap(map) {
|
|
1683
|
+
maps.set(map.id, map);
|
|
1684
|
+
}
|
|
1685
|
+
function getChartMap(id) {
|
|
1686
|
+
return maps.get(id);
|
|
1687
|
+
}
|
|
1688
|
+
function listChartMaps() {
|
|
1689
|
+
return [...maps.values()];
|
|
1690
|
+
}
|
|
1691
|
+
var fold = (text) => text.normalize("NFKD").replace(/[̀-ͯ]/g, "").trim().toLowerCase();
|
|
1692
|
+
function matchChartMapRegions(map, categories) {
|
|
1693
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
1694
|
+
for (const r of map.regions) {
|
|
1695
|
+
byKey.set(fold(r.id), r);
|
|
1696
|
+
byKey.set(fold(r.name), r);
|
|
1697
|
+
}
|
|
1698
|
+
const taken = /* @__PURE__ */ new Set();
|
|
1699
|
+
return categories.map((c) => {
|
|
1700
|
+
const r = byKey.get(fold(c));
|
|
1701
|
+
if (!r || taken.has(r.id)) return null;
|
|
1702
|
+
taken.add(r.id);
|
|
1703
|
+
return r;
|
|
1704
|
+
});
|
|
1705
|
+
}
|
|
1706
|
+
function chartMapBreaks(values, steps, thresholds) {
|
|
1707
|
+
if (thresholds.length) return [...thresholds];
|
|
1708
|
+
if (!values.length) return [];
|
|
1709
|
+
const lo = Math.min(...values);
|
|
1710
|
+
const hi = Math.max(...values);
|
|
1711
|
+
if (!(hi > lo)) return [];
|
|
1712
|
+
const exact = Array.from({ length: steps - 1 }, (_, k) => lo + (hi - lo) * (k + 1) / steps);
|
|
1713
|
+
for (let digits = 2; digits <= 6; digits++) {
|
|
1714
|
+
const rounded = exact.map((b) => Number(b.toPrecision(digits)));
|
|
1715
|
+
if (rounded.every((b, i) => i === 0 || b > rounded[i - 1])) return rounded;
|
|
1716
|
+
}
|
|
1717
|
+
return exact;
|
|
1718
|
+
}
|
|
1719
|
+
var chartMapClass = (value, breaks) => breaks.filter((b) => value >= b).length;
|
|
1720
|
+
function chartMapRamp(base, count) {
|
|
1721
|
+
if (count <= 1) return [base];
|
|
1722
|
+
return Array.from({ length: count }, (_, k) => shadeChartColor(base, 0.82 - 1.17 * k / (count - 1)));
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1680
1725
|
// src/chart/race.ts
|
|
1681
1726
|
function chartRaceValueAt(series, index) {
|
|
1682
1727
|
for (let i = Math.min(index, series.values.length - 1); i >= 0; i--) {
|
|
@@ -2512,11 +2557,71 @@ function layoutBarRace(ctx, area, frame) {
|
|
|
2512
2557
|
if (ranking.length > top) ctx.warn("values-skipped", `The race shows the top ${top} of ${ranking.length} names at each moment (raceTopN).`);
|
|
2513
2558
|
return { plot, valueScale: { axis: "x", domain: [0, max], range: [plot.x, plot.x + plot.width], ticks } };
|
|
2514
2559
|
}
|
|
2560
|
+
function placePath(d, s, ox, oy) {
|
|
2561
|
+
return d.replace(/(-?\d+(?:\.\d+)?),(-?\d+(?:\.\d+)?)/g, (_, x, y) => `${r2(ox + Number(x) * s)},${r2(oy + Number(y) * s)}`);
|
|
2562
|
+
}
|
|
2563
|
+
function layoutChoropleth(ctx, area, series) {
|
|
2564
|
+
const { spec, theme, marks, fs, measure } = ctx;
|
|
2565
|
+
const map = getChartMap(spec.map);
|
|
2566
|
+
const matches = matchChartMapRegions(map, spec.categories);
|
|
2567
|
+
const unmatched = spec.categories.filter((_, i) => !matches[i]);
|
|
2568
|
+
if (unmatched.length)
|
|
2569
|
+
ctx.warn("values-skipped", `${unmatched.length} categor${unmatched.length === 1 ? "y names" : "ies name"} no region of ${map.name}: ${unmatched.slice(0, 8).map((c) => `"${c}"`).join(", ")}${unmatched.length > 8 ? ", \u2026" : ""}. Use codes (such as FRA) or names (France).`);
|
|
2570
|
+
const indexOf = /* @__PURE__ */ new Map();
|
|
2571
|
+
matches.forEach((r, i) => r && indexOf.set(r.id, i));
|
|
2572
|
+
const valueAt = (i) => {
|
|
2573
|
+
const v = series.values[i];
|
|
2574
|
+
return v !== null && v !== void 0 && Number.isFinite(v) ? v : null;
|
|
2575
|
+
};
|
|
2576
|
+
const present = [...indexOf.values()].map(valueAt).filter((v) => v !== null);
|
|
2577
|
+
const breaks = chartMapBreaks(present, spec.mapSteps, spec.mapThresholds);
|
|
2578
|
+
const ramp = chartMapRamp(series.color ?? chartSeriesColor(spec, spec.series.indexOf(series)), breaks.length + 1);
|
|
2579
|
+
const format = series.format ?? spec.yAxis.format;
|
|
2580
|
+
const legendH = fs * 2.2;
|
|
2581
|
+
const s = Math.max(1e-6, Math.min(area.width / map.width, (area.height - legendH) / map.height));
|
|
2582
|
+
const ox = area.x + (area.width - map.width * s) / 2;
|
|
2583
|
+
const oy = area.y;
|
|
2584
|
+
if (map.land) marks.push({ kind: "path", key: "map-land", role: "map-land", d: placePath(map.land, s, ox, oy), fill: theme.grid, opacity: 0.55 });
|
|
2585
|
+
const markers = [];
|
|
2586
|
+
const labels = [];
|
|
2587
|
+
for (const region of map.regions) {
|
|
2588
|
+
const i = indexOf.get(region.id);
|
|
2589
|
+
const value = i === void 0 ? null : valueAt(i);
|
|
2590
|
+
const fill = i !== void 0 && series.pointColors?.[i] ? series.pointColors[i] : value === null ? theme.grid : ramp[chartMapClass(value, breaks)];
|
|
2591
|
+
const target = i === void 0 ? void 0 : { kind: "category", index: i };
|
|
2592
|
+
const selected = target ? ctx.isSelected(target) || ctx.isSelected({ kind: "point", seriesId: series.id, index: i }) : false;
|
|
2593
|
+
const [cx, cy] = [ox + region.center[0] * s, oy + region.center[1] * s];
|
|
2594
|
+
if (region.d) marks.push({ kind: "path", key: `region-${region.id}`, role: "region", d: placePath(region.d, s, ox, oy), fill, stroke: selected ? theme.selection : theme.surface, strokeWidth: selected ? 2 : 0.6, ...target ? { target, selected } : {} });
|
|
2595
|
+
if (!region.d || region.area * s * s < 30)
|
|
2596
|
+
markers.push({ kind: "circle", key: `region-marker-${region.id}`, role: "region", cx, cy, r: 3.5, fill, stroke: selected ? theme.selection : theme.text, strokeWidth: selected ? 1.5 : 0.75, ...target ? { target, selected } : {} });
|
|
2597
|
+
if (value !== null && target && (series.dataLabels ?? spec.dataLabels) && region.area * s * s > (fs * 3) ** 2) {
|
|
2598
|
+
const text = formatChartNumber(value, format);
|
|
2599
|
+
labels.push({ kind: "text", key: `label-${region.id}`, role: "data-label", x: cx, y: cy, text, anchor: "middle", baseline: "middle", size: fs - 1, weight: 600, fill: contrastingTextColor(fill), target });
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
marks.push(...markers, ...labels);
|
|
2603
|
+
const fmt = (v) => formatChartNumber(v, format);
|
|
2604
|
+
const items = ramp.map((color, k) => ({
|
|
2605
|
+
color,
|
|
2606
|
+
text: breaks.length === 0 ? present.length ? fmt(present[0]) : "" : k === 0 ? `< ${fmt(breaks[0])}` : k === breaks.length ? `\u2265 ${fmt(breaks[k - 1])}` : `${fmt(breaks[k - 1])}\u2013${fmt(breaks[k])}`
|
|
2607
|
+
}));
|
|
2608
|
+
items.push({ color: theme.grid, text: "No data" });
|
|
2609
|
+
let x = area.x;
|
|
2610
|
+
const y = area.y + area.height - fs * 0.9;
|
|
2611
|
+
items.forEach((item, k) => {
|
|
2612
|
+
marks.push({ kind: "rect", key: `legend-swatch-${k}`, role: "legend-swatch", x, y: y - 5, width: 10, height: 10, radius: 2, fill: item.color });
|
|
2613
|
+
marks.push({ kind: "text", key: `legend-label-${k}`, role: "legend-label", x: x + 14, y, text: item.text, anchor: "start", baseline: "middle", size: fs - 1, fill: theme.text });
|
|
2614
|
+
x += 14 + measure(item.text, fs - 1) + 14;
|
|
2615
|
+
});
|
|
2616
|
+
if (x > area.x + area.width) ctx.warn("legend-truncated", "The map legend is wider than the chart; widen the chart or use fewer classes.");
|
|
2617
|
+
if (map.attribution) marks.push({ kind: "text", key: "map-attribution", role: "note", x: area.x + area.width, y, text: map.attribution, anchor: "end", baseline: "middle", size: Math.max(7, fs - 3), fill: theme.mutedText });
|
|
2618
|
+
return { plot: { x: ox, y: oy, width: map.width * s, height: map.height * s } };
|
|
2619
|
+
}
|
|
2515
2620
|
|
|
2516
2621
|
// src/chart/layout.ts
|
|
2517
2622
|
function legendItems(spec, ctx) {
|
|
2518
2623
|
const family = chartFamily(spec);
|
|
2519
|
-
if (spec.type === "funnel" || spec.type === "slope" || spec.type === "sankey" || spec.type === "barrace") return [];
|
|
2624
|
+
if (spec.type === "funnel" || spec.type === "slope" || spec.type === "sankey" || spec.type === "barrace" || spec.type === "choropleth") return [];
|
|
2520
2625
|
if (chartSpecColorsByCategory(spec)) {
|
|
2521
2626
|
const first = spec.series.find((s) => !s.hidden);
|
|
2522
2627
|
const seats = (i) => Math.max(0, Math.round(first?.values[i] ?? 0));
|
|
@@ -2656,6 +2761,18 @@ function layoutChart(spec, options) {
|
|
|
2656
2761
|
return finish(layoutFunnel(ctx, area, visible[0]));
|
|
2657
2762
|
case "treemap":
|
|
2658
2763
|
return finish(spec.tree.length ? layoutTreemapTree(ctx, area, spec.series[0]) : layoutTreemap(ctx, area, visible[0]));
|
|
2764
|
+
case "choropleth": {
|
|
2765
|
+
const map = getChartMap(spec.map);
|
|
2766
|
+
if (!map) {
|
|
2767
|
+
ctx.warn("type-fallback", `The map "${spec.map}" is not registered, so the values are drawn as bars: register it with registerChartMap (the Europe outlines are EUROPE_CHART_MAP in @pixerate/editor/chart-maps).`);
|
|
2768
|
+
return finish(layoutCartesian(ctx, area, visible));
|
|
2769
|
+
}
|
|
2770
|
+
if (!matchChartMapRegions(map, spec.categories).some(Boolean)) {
|
|
2771
|
+
ctx.warn("type-fallback", `No category names a region of ${map.name}, so the values are drawn as bars: use codes (such as FRA) or names (France) as categories.`);
|
|
2772
|
+
return finish(layoutCartesian(ctx, area, visible));
|
|
2773
|
+
}
|
|
2774
|
+
return finish(layoutChoropleth(ctx, area, visible[0]));
|
|
2775
|
+
}
|
|
2659
2776
|
case "barrace":
|
|
2660
2777
|
return finish(layoutBarRace(ctx, area, options.raceFrame));
|
|
2661
2778
|
case "sankey":
|
|
@@ -2867,6 +2984,13 @@ export {
|
|
|
2867
2984
|
MAX_CHART_DATA_LABELS,
|
|
2868
2985
|
MAX_CHART_LINE_POINTS,
|
|
2869
2986
|
MAX_CHART_MARKERS,
|
|
2987
|
+
registerChartMap,
|
|
2988
|
+
getChartMap,
|
|
2989
|
+
listChartMaps,
|
|
2990
|
+
matchChartMapRegions,
|
|
2991
|
+
chartMapBreaks,
|
|
2992
|
+
chartMapClass,
|
|
2993
|
+
chartMapRamp,
|
|
2870
2994
|
chartRaceValueAt,
|
|
2871
2995
|
chartRaceMoment,
|
|
2872
2996
|
chartRaceRanking,
|
|
@@ -8,11 +8,13 @@ import {
|
|
|
8
8
|
chartSupportsTrendlines,
|
|
9
9
|
fitChartTrendline,
|
|
10
10
|
formatChartNumber,
|
|
11
|
+
getChartMap,
|
|
11
12
|
layoutChart,
|
|
13
|
+
matchChartMapRegions,
|
|
12
14
|
r2,
|
|
13
15
|
sameChartSelection,
|
|
14
16
|
summarizeChartSeries
|
|
15
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-M52UCHVZ.js";
|
|
16
18
|
import {
|
|
17
19
|
CHART_TYPE_LABELS,
|
|
18
20
|
DEFAULT_CHART_PALETTE,
|
|
@@ -45,7 +47,7 @@ import {
|
|
|
45
47
|
parseChartValue,
|
|
46
48
|
shadeChartColor,
|
|
47
49
|
uniqueChartSeriesId
|
|
48
|
-
} from "./chunk-
|
|
50
|
+
} from "./chunk-ORZF4JOO.js";
|
|
49
51
|
import {
|
|
50
52
|
parseCsv,
|
|
51
53
|
parseTsv
|
|
@@ -550,6 +552,15 @@ function describeChart(spec, series = spec.series.filter((s) => !s.hidden).map((
|
|
|
550
552
|
}
|
|
551
553
|
return parts.join(" ");
|
|
552
554
|
}
|
|
555
|
+
if (family === "choropleth") {
|
|
556
|
+
const s = spec.series.find((x) => !x.hidden);
|
|
557
|
+
const map = getChartMap(spec.map);
|
|
558
|
+
const matches = map ? matchChartMapRegions(map, spec.categories) : spec.categories.map(() => null);
|
|
559
|
+
const rows = spec.categories.flatMap((c, i) => matches[i] && s.values[i] !== null ? [{ name: matches[i].name, v: s.values[i] }] : []).sort((a, b) => b.v - a.v);
|
|
560
|
+
const missing = spec.categories.filter((_, i) => !matches[i]).length;
|
|
561
|
+
if (!rows.length) return `${head} of ${map?.name ?? spec.map} with no regions matched.`;
|
|
562
|
+
return `${head} of ${map?.name ?? spec.map} shading ${rows.length} region${rows.length === 1 ? "" : "s"} by ${s.name}: highest ${rows[0].name} (${fmt(rows[0].v)}), lowest ${rows[rows.length - 1].name} (${fmt(rows[rows.length - 1].v)}).${missing ? ` ${missing} categor${missing === 1 ? "y names" : "ies name"} no region.` : ""}`;
|
|
563
|
+
}
|
|
553
564
|
if (family === "barrace") {
|
|
554
565
|
const n = spec.categories.length;
|
|
555
566
|
const first = chartRaceRanking(spec, 0)[0];
|
|
@@ -1884,6 +1895,9 @@ function updateLabel(patch) {
|
|
|
1884
1895
|
parliamentMajority: "Change majority",
|
|
1885
1896
|
parliamentLabel: "Edit seat caption",
|
|
1886
1897
|
raceTopN: "Change bars shown",
|
|
1898
|
+
map: "Change map",
|
|
1899
|
+
mapSteps: "Change colour classes",
|
|
1900
|
+
mapThresholds: "Change class breaks",
|
|
1887
1901
|
sunburstLabel: "Edit centre caption",
|
|
1888
1902
|
tree: "Replace grouped data",
|
|
1889
1903
|
links: "Replace flows",
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
isCartesianChart,
|
|
9
9
|
normalizeChartSpec,
|
|
10
10
|
parseChartColor
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-ORZF4JOO.js";
|
|
12
12
|
|
|
13
13
|
// src/chart/ooxml.ts
|
|
14
14
|
var CHART_OOXML_NS = "http://schemas.openxmlformats.org/drawingml/2006/chart";
|
|
@@ -475,6 +475,9 @@ function chartToOoxml(spec) {
|
|
|
475
475
|
} else if (family === "sunburst") {
|
|
476
476
|
issues.push(`Sunburst charts are written as doughnut charts of the ${spec.tree.length ? "top-level group totals" : "values"}: DrawingML has no sunburst type (Office 2016 stores it as chartex).`);
|
|
477
477
|
type = "donut";
|
|
478
|
+
} else if (family === "choropleth") {
|
|
479
|
+
issues.push("Maps are written as bar charts of the values by region: DrawingML has no map chart (Office 2016 stores region maps as chartex with Bing geodata).");
|
|
480
|
+
type = "bar";
|
|
478
481
|
} else if (family === "barrace") {
|
|
479
482
|
issues.push("Bar chart races are written as clustered bar charts of every name at every time point: DrawingML has no animation.");
|
|
480
483
|
type = "bar";
|