@matdata/yasgui-chart-plugin 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,124 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # YASGUI Chart Plugin
2
+
3
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
4
+ [![npm version](https://img.shields.io/npm/v/@matdata/yasgui-chart-plugin.svg)](https://www.npmjs.com/package/@matdata/yasgui-chart-plugin)
5
+
6
+ A YASGUI (YASR) plugin that visualises SPARQL **SELECT** results as charts: bar (grouped, stacked, horizontal), line, area, pie, donut, scatter and histogram. It is built on [Apache ECharts](https://echarts.apache.org/) and is part of [MatGUI](https://github.com/Matdata-eu/MatGUI).
7
+
8
+ **Online demo:** https://matdata-eu.github.io/yasgui-chart-plugin/
9
+
10
+ ## ✨ Features
11
+
12
+ - **📊 Chart types**: bar, stacked bar, horizontal bar, line, area, pie, donut, scatter and histogram
13
+ - **🪄 Automatic choice**: a label/IRI column plus numbers gives a bar chart, a date column plus numbers a line chart, numbers against numbers a scatter plot, and a single numeric column a histogram
14
+ - **🎛️ Controls**: pick the chart type and the category, value and series columns. The choice is saved per tab; a different query (other variables) starts from the automatic chart again
15
+ - **🧮 Long results**: a second category-like column (e.g. `?country ?type ?count`) is split into series automatically; rows that repeat a category are summed
16
+ - **🏷️ Readable labels**: IRIs are shown with their label column (`?x` with `?xLabel`) or as prefixed names
17
+ - **🔎 Ctrl+click describe**: Ctrl+click a bar, slice or point to see the triples of its IRI (Ctrl+Shift+click for the triples where it is the object), with the same modal as the table and geo plugins
18
+ - **🌓 Light and dark theme**: follows the YASGUI theme and switches live
19
+ - **🖼️ Export**: download the chart as PNG or SVG
20
+ - **🔍 Zoom**: a zoom slider appears for long category axes
21
+ - Only offered when the results contain at least one numeric column
22
+
23
+ ## 📦 Installation
24
+
25
+ ### NPM
26
+
27
+ ```bash
28
+ npm install @matdata/yasgui-chart-plugin
29
+ ```
30
+
31
+ ```javascript
32
+ import Yasgui from '@matdata/yasgui';
33
+ import ChartPlugin from '@matdata/yasgui-chart-plugin';
34
+ import '@matdata/yasgui-chart-plugin/dist/yasgui-chart-plugin.min.css';
35
+
36
+ Yasgui.Yasr.registerPlugin('Chart', ChartPlugin);
37
+
38
+ const yasgui = new Yasgui(document.getElementById('yasgui'), {
39
+ yasr: { pluginOrder: ['Table', 'response', 'Chart'] },
40
+ });
41
+ ```
42
+
43
+ MatGUI ([@matdata/yasgui](https://www.npmjs.com/package/@matdata/yasgui)) already includes the chart plugin.
44
+
45
+ ### CDN (UMD)
46
+
47
+ ```html
48
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@matdata/yasgui/build/yasgui.min.css" />
49
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@matdata/yasgui-chart-plugin/dist/yasgui-chart-plugin.min.css" />
50
+ <script src="https://cdn.jsdelivr.net/npm/@matdata/yasgui/build/yasgui.min.js"></script>
51
+ <script src="https://cdn.jsdelivr.net/npm/@matdata/yasgui-chart-plugin/dist/yasgui-chart-plugin.min.js"></script>
52
+ <script>
53
+ // The plugin registers itself as 'Chart' when window.Yasgui exists
54
+ const yasgui = new Yasgui(document.getElementById('yasgui'));
55
+ </script>
56
+ ```
57
+
58
+ ## 🚀 Usage
59
+
60
+ Run a SELECT query with at least one numeric column and open the **Chart** tab. For example:
61
+
62
+ ```sparql
63
+ PREFIX era: <http://data.europa.eu/949/>
64
+ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
65
+
66
+ SELECT ?country (COUNT(?op) AS ?operationalPoints) WHERE {
67
+ ?op a era:OperationalPoint ;
68
+ era:inCountry ?country .
69
+ }
70
+ GROUP BY ?country
71
+ ORDER BY DESC(?operationalPoints)
72
+ ```
73
+
74
+ ### Toolbar
75
+
76
+ | Control | What it does |
77
+ | --- | --- |
78
+ | **Chart** | Chart type |
79
+ | **X axis** / **Slices** | Column used for the categories (bars, slices) or the x axis |
80
+ | **Values** / **Size** | Numeric column(s) to plot; pie, donut and histogram use one |
81
+ | **Series** | Column whose values split the data into series (grouped or stacked bars, several lines) |
82
+ | **Auto** | Go back to the automatic chart for these results |
83
+ | **PNG** / **SVG** | Download the chart |
84
+
85
+ The YASR download button also saves the chart as PNG.
86
+
87
+ ### How columns are read
88
+
89
+ | Column kind | Recognised when every bound value is |
90
+ | --- | --- |
91
+ | number | an `xsd` numeric literal, or a plain literal that reads as a number |
92
+ | date | an `xsd:date`, `xsd:dateTime`, `xsd:gYear` or `xsd:gYearMonth` literal |
93
+ | IRI | an IRI |
94
+ | text | anything else |
95
+
96
+ A text column is used as the label of an IRI column when it is named after it (`?line` with `?lineLabel`, `?line_label` or `?lineName`), or when it is the only text column and maps 1:1 onto the only IRI column.
97
+
98
+ ### Options
99
+
100
+ ```javascript
101
+ Yasgui.Yasr.registerPlugin('Chart', ChartPlugin);
102
+ Yasgui.Yasr.defaults.plugins.Chart = { enabled: true, options: { maxRows: 10000 } };
103
+ ```
104
+
105
+ | Option | Default | Description |
106
+ | --- | --- | --- |
107
+ | `maxRows` | `5000` | Maximum number of result rows plotted; a note says when results are cut |
108
+
109
+ ## 🛠️ Development
110
+
111
+ ```bash
112
+ npm install
113
+ npm run dev # demo with live reload at http://localhost:5173
114
+ npm test # unit tests (jest)
115
+ npm run typecheck # TypeScript
116
+ npm run build # dist/ bundles (ESM, CJS, IIFE), CSS and type declarations
117
+ npm run build:demo # static demo in demo/dist
118
+ ```
119
+
120
+ The demo is deployed to GitHub Pages on every push to `main`. Publishing a GitHub release publishes the package to npm (version taken from the tag) and attaches the minified bundles to the release.
121
+
122
+ ## 📄 License
123
+
124
+ Apache 2.0
@@ -0,0 +1,73 @@
1
+ /**
2
+ * YASR plugin that visualises SPARQL SELECT results as charts
3
+ */
4
+ import type { ChartPluginOptions, Yasr } from './types';
5
+ declare class ChartPlugin {
6
+ /** Below the table (10), so SELECT results still open in the table */
7
+ priority: number;
8
+ label: string;
9
+ helpReference: string;
10
+ private yasr;
11
+ private options;
12
+ private chart;
13
+ private chartEl;
14
+ private option;
15
+ private data;
16
+ private columns;
17
+ private results;
18
+ private saved;
19
+ private resolved;
20
+ private resizeObserver;
21
+ private themeObserver;
22
+ private outsideClickHandler;
23
+ private windowResizeHandler;
24
+ private fullscreenObserver;
25
+ private describeModal;
26
+ private describeAbortController;
27
+ constructor(yasr: Yasr, options?: ChartPluginOptions);
28
+ static get label(): string;
29
+ static get priority(): number;
30
+ getIcon(): Element | undefined;
31
+ /** Offered for SELECT results with at least one numeric column */
32
+ canHandleResults(): boolean;
33
+ /** Name this plugin was registered under in YASR (normally "Chart") */
34
+ private getPluginName;
35
+ draw(persistentConfig?: unknown): void;
36
+ private renderMessage;
37
+ private getYasqe;
38
+ /** Prefixes of the Yasr config, overridden by those declared in the query */
39
+ private getPrefixes;
40
+ /** Build the toolbar and chart for the current results and settings */
41
+ private render;
42
+ /**
43
+ * Size the chart to the rest of the viewport. The results area grows with
44
+ * its content, so its own height can't be used without a feedback loop.
45
+ */
46
+ private updateHeight;
47
+ private applyOption;
48
+ private updateSettings;
49
+ private handleChartClick;
50
+ /**
51
+ * Run a background query for the triples where `iri` is the subject (or
52
+ * object) and show them in the describe modal, as the table and geo plugins do.
53
+ */
54
+ private runResourceQuery;
55
+ private fileName;
56
+ /** PNG data URL of the chart, with the theme background */
57
+ getPngDataUrl(): string | null;
58
+ /** SVG markup of the chart, rendered off-screen with the SVG renderer */
59
+ getSvgString(): string | null;
60
+ private exportImage;
61
+ /** YASR's download button saves the chart as a PNG image */
62
+ download(filename?: string): {
63
+ getData: () => string;
64
+ contentType: string;
65
+ filename: string;
66
+ title: string;
67
+ } | undefined;
68
+ private disposeChart;
69
+ private cleanup;
70
+ destroy(): void;
71
+ }
72
+ export default ChartPlugin;
73
+ //# sourceMappingURL=ChartPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChartPlugin.d.ts","sourceRoot":"","sources":["../src/ChartPlugin.ts"],"names":[],"mappings":"AAAA;;GAEG;AAwBH,OAAO,KAAK,EACV,kBAAkB,EAKlB,IAAI,EACL,MAAM,SAAS,CAAC;AAsBjB,cAAM,WAAW;IACf,sEAAsE;IACtE,QAAQ,SAAK;IACb,KAAK,SAAW;IAChB,aAAa,SAAgE;IAE7E,OAAO,CAAC,IAAI,CAAO;IACnB,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,MAAM,CAAoC;IAClD,OAAO,CAAC,IAAI,CAA0B;IACtC,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,OAAO,CAAoC;IACnD,OAAO,CAAC,KAAK,CAAqB;IAClC,OAAO,CAAC,QAAQ,CAAsC;IACtD,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,aAAa,CAAiC;IACtD,OAAO,CAAC,mBAAmB,CAA0C;IACrE,OAAO,CAAC,mBAAmB,CAA6B;IACxD,OAAO,CAAC,kBAAkB,CAAiC;IAC3D,OAAO,CAAC,aAAa,CAA8B;IACnD,OAAO,CAAC,uBAAuB,CAAgC;gBAEnD,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,kBAAuB;IAMxD,MAAM,KAAK,KAAK,IAAI,MAAM,CAEzB;IAED,MAAM,KAAK,QAAQ,IAAI,MAAM,CAE5B;IAED,OAAO,IAAI,OAAO,GAAG,SAAS;IAQ9B,kEAAkE;IAClE,gBAAgB,IAAI,OAAO;IAM3B,uEAAuE;IACvE,OAAO,CAAC,aAAa;IAQrB,IAAI,CAAC,gBAAgB,CAAC,EAAE,OAAO,GAAG,IAAI;IAsBtC,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,QAAQ;IAOhB,6EAA6E;IAC7E,OAAO,CAAC,WAAW;IAgBnB,uEAAuE;IACvE,OAAO,CAAC,MAAM;IAgGd;;;OAGG;IACH,OAAO,CAAC,YAAY;IAYpB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,cAAc;IActB,OAAO,CAAC,gBAAgB;IAQxB;;;OAGG;YACW,gBAAgB;IAgD9B,OAAO,CAAC,QAAQ;IAKhB,2DAA2D;IAC3D,aAAa,IAAI,MAAM,GAAG,IAAI;IAS9B,yEAAyE;IACzE,YAAY,IAAI,MAAM,GAAG,IAAI;IAkB7B,OAAO,CAAC,WAAW;IAqBnB,4DAA4D;IAC5D,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM;;;;;;IAU1B,OAAO,CAAC,YAAY;IAuBpB,OAAO,CAAC,OAAO;IAMf,OAAO,IAAI,IAAI;CAKhB;AAED,eAAe,WAAW,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * ECharts option builder
3
+ *
4
+ * Pure function from chart data, settings and theme colours to an ECharts
5
+ * option object, kept free of DOM and chart instances so it can be tested.
6
+ */
7
+ import type { ChartData } from './dataModel';
8
+ import type { ChartThemeColors } from './theme';
9
+ import type { ResolvedChartSettings } from './types';
10
+ /** Show a zoom slider when a category axis has more entries than this */
11
+ export declare const ZOOM_THRESHOLD = 40;
12
+ export declare const DESCRIBE_HINT = "Ctrl+click to show its triples";
13
+ export declare function escapeHtml(value: string): string;
14
+ export declare function formatNumber(value: number | null | undefined): string;
15
+ /** Build the ECharts option for the chart data */
16
+ export declare function buildChartOption(data: ChartData, settings: ResolvedChartSettings, colors: ChartThemeColors): Record<string, any>;
17
+ /**
18
+ * The IRI behind a clicked chart element, if any: the category (or point)
19
+ * first, then the series.
20
+ */
21
+ export declare function iriForClick(data: ChartData, params: {
22
+ seriesIndex?: number;
23
+ dataIndex?: number;
24
+ data?: any;
25
+ }): string | undefined;
26
+ //# sourceMappingURL=chartOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chartOptions.d.ts","sourceRoot":"","sources":["../src/chartOptions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAuC,MAAM,aAAa,CAAC;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAErD,yEAAyE;AACzE,eAAO,MAAM,cAAc,KAAK,CAAC;AAKjC,eAAO,MAAM,aAAa,mCAAmC,CAAC;AAE9D,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOhD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAIrE;AAkQD,kDAAkD;AAClD,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,qBAAqB,EAC/B,MAAM,EAAE,gBAAgB,GACvB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAIrB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,SAAS,EACf,MAAM,EAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,GAAG,CAAA;CAAE,GAC/D,MAAM,GAAG,SAAS,CAmBpB"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Column analysis
3
+ *
4
+ * Classifies each SELECT variable by the values it holds so the plugin can
5
+ * decide whether it can chart the results and pick sensible defaults:
6
+ *
7
+ * - `numeric`: every bound value is a number (xsd numeric datatypes, or plain
8
+ * literals that read as a number)
9
+ * - `date`: every bound value is an xsd:date / xsd:dateTime / xsd:gYear(Month)
10
+ * - `iri`: every bound value is an IRI
11
+ * - `text`: anything else (strings, mixed values, blank nodes)
12
+ *
13
+ * A text column can also be recognised as the label of an IRI column, e.g.
14
+ * `?line ?lineLabel`, so the chart can show readable names but still describe
15
+ * the IRI on Ctrl+click.
16
+ */
17
+ import type { SparqlSelectResults, SparqlTerm } from './types';
18
+ export type ColumnKind = 'numeric' | 'date' | 'iri' | 'text';
19
+ export interface ColumnInfo {
20
+ name: string;
21
+ kind: ColumnKind;
22
+ /** Number of rows in which the variable is bound */
23
+ bound: number;
24
+ /** Number of distinct values */
25
+ distinct: number;
26
+ /** For an IRI column: the text column holding its labels, if any */
27
+ labelColumn?: string;
28
+ /** True when this text column is the label of an IRI column */
29
+ isLabel?: boolean;
30
+ }
31
+ /** Is this term a number? */
32
+ export declare function isNumericTerm(term: SparqlTerm | undefined): boolean;
33
+ /** Is this term a date or date-time? */
34
+ export declare function isDateTerm(term: SparqlTerm | undefined): boolean;
35
+ /** Numeric value of a term, or `null` when it isn't a number */
36
+ export declare function toNumber(term: SparqlTerm | undefined): number | null;
37
+ /** Timestamp (ms since epoch, UTC) of a date term, or `null` */
38
+ export declare function toTimestamp(term: SparqlTerm | undefined): number | null;
39
+ /** Get the SELECT results from YASR's results object, or null */
40
+ export declare function getSelectResults(results: any): SparqlSelectResults | null;
41
+ /** Analyse all columns of a SELECT result */
42
+ export declare function analyzeColumns(data: SparqlSelectResults): ColumnInfo[];
43
+ /** True when the results have at least one numeric column */
44
+ export declare function hasNumericColumn(columns: ColumnInfo[]): boolean;
45
+ //# sourceMappingURL=columns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"columns.d.ts","sourceRoot":"","sources":["../src/columns.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAiB,mBAAmB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE9E,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;AAE7D,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;IACjB,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,oEAAoE;IACpE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+DAA+D;IAC/D,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AA+BD,6BAA6B;AAC7B,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CASnE;AAED,wCAAwC;AACxC,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAGhE;AAED,gEAAgE;AAChE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAIpE;AAED,gEAAgE;AAChE,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAYvE;AAED,iEAAiE;AACjE,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,GAAG,GAAG,mBAAmB,GAAG,IAAI,CAqBzE;AAoDD,6CAA6C;AAC7C,wBAAgB,cAAc,CAAC,IAAI,EAAE,mBAAmB,GAAG,UAAU,EAAE,CAyBtE;AAED,6DAA6D;AAC7D,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,OAAO,CAE/D"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Chart toolbar
3
+ *
4
+ * Pickers for the chart type, category, value and series columns, a button
5
+ * that goes back to the automatic choice, and PNG/SVG export buttons.
6
+ */
7
+ import type { ColumnInfo } from './columns';
8
+ import type { ChartSettings, ResolvedChartSettings } from './types';
9
+ export interface ToolbarCallbacks {
10
+ onChange: (settings: ChartSettings) => void;
11
+ onReset: () => void;
12
+ onExport: (format: 'png' | 'svg') => void;
13
+ }
14
+ export interface ToolbarState {
15
+ columns: ColumnInfo[];
16
+ resolved: ResolvedChartSettings;
17
+ /** True when the user has saved choices (so "Auto" can reset them) */
18
+ customised: boolean;
19
+ }
20
+ /** Render the toolbar for the current columns and settings */
21
+ export declare function renderToolbar(state: ToolbarState, callbacks: ToolbarCallbacks): HTMLElement;
22
+ //# sourceMappingURL=controls.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controls.d.ts","sourceRoot":"","sources":["../src/controls.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,KAAK,EAAE,aAAa,EAAa,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAE/E,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAI,CAAC;IAC5C,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,EAAE,CAAC,MAAM,EAAE,KAAK,GAAG,KAAK,KAAK,IAAI,CAAC;CAC3C;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,QAAQ,EAAE,qBAAqB,CAAC;IAChC,sEAAsE;IACtE,UAAU,EAAE,OAAO,CAAC;CACrB;AA2DD,8DAA8D;AAC9D,wBAAgB,aAAa,CAAC,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,gBAAgB,GAAG,WAAW,CAmI3F"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Chart data model
3
+ *
4
+ * Turns SELECT bindings and resolved settings into chart-library-neutral data:
5
+ *
6
+ * - `category`: an ordered list of categories (bar, pie, and line/area over
7
+ * text or IRIs) with one value per category for each series. Rows that
8
+ * repeat a category (and series) are summed.
9
+ * - `xy`: points on a numeric or time x axis (scatter, and line/area over
10
+ * numbers or dates), sorted by x for lines.
11
+ * - `histogram`: the distribution of one numeric column in equal-width bins.
12
+ *
13
+ * Every category, series and point remembers the IRI it came from (if any),
14
+ * so a click on it can describe that IRI.
15
+ */
16
+ import type { ColumnInfo } from './columns';
17
+ import type { PrefixMap, ResolvedChartSettings, SparqlBinding, SparqlTerm } from './types';
18
+ export interface CategoryItem {
19
+ key: string;
20
+ label: string;
21
+ iri?: string;
22
+ }
23
+ export interface CategorySeries {
24
+ name: string;
25
+ iri?: string;
26
+ values: (number | null)[];
27
+ }
28
+ export interface CategoryData {
29
+ kind: 'category';
30
+ categories: CategoryItem[];
31
+ series: CategorySeries[];
32
+ }
33
+ export interface XYPoint {
34
+ x: number;
35
+ y: number;
36
+ /** Label of the row's category-like value, shown in the tooltip */
37
+ label?: string;
38
+ iri?: string;
39
+ }
40
+ export interface XYSeries {
41
+ name: string;
42
+ iri?: string;
43
+ points: XYPoint[];
44
+ }
45
+ export interface XYData {
46
+ kind: 'xy';
47
+ xAxis: 'value' | 'time';
48
+ xName: string;
49
+ series: XYSeries[];
50
+ }
51
+ export interface HistogramBin {
52
+ from: number;
53
+ to: number;
54
+ count: number;
55
+ }
56
+ export interface HistogramData {
57
+ kind: 'histogram';
58
+ column: string;
59
+ bins: HistogramBin[];
60
+ }
61
+ export type ChartData = CategoryData | XYData | HistogramData;
62
+ /** How a term is shown: its label column, a prefixed name, or its value */
63
+ export declare function termLabel(term: SparqlTerm | undefined, row: SparqlBinding, column: ColumnInfo | undefined, prefixes: PrefixMap): string;
64
+ /** Number of histogram bins for `n` values (Sturges' rule, capped) */
65
+ export declare function binCount(n: number): number;
66
+ export declare function buildHistogram(values: number[], column: string): HistogramData;
67
+ /**
68
+ * Build the chart data.
69
+ * @param bindings result rows
70
+ * @param columns analysed columns
71
+ * @param settings resolved settings
72
+ * @param prefixes prefixes used to shorten IRIs
73
+ */
74
+ export declare function buildChartData(bindings: SparqlBinding[], columns: ColumnInfo[], settings: ResolvedChartSettings, prefixes: PrefixMap): ChartData;
75
+ //# sourceMappingURL=dataModel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataModel.d.ts","sourceRoot":"","sources":["../src/dataModel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAG5C,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE3F,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,EAAE,YAAY,EAAE,CAAC;IAC3B,MAAM,EAAE,cAAc,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,OAAO;IACtB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,mEAAmE;IACnE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,QAAQ,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,YAAY,EAAE,CAAC;CACtB;AAED,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,MAAM,GAAG,aAAa,CAAC;AAE9D,2EAA2E;AAC3E,wBAAgB,SAAS,CACvB,IAAI,EAAE,UAAU,GAAG,SAAS,EAC5B,GAAG,EAAE,aAAa,EAClB,MAAM,EAAE,UAAU,GAAG,SAAS,EAC9B,QAAQ,EAAE,SAAS,GAClB,MAAM,CASR;AAWD,sEAAsE;AACtE,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAG1C;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAuB9E;AAYD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,aAAa,EAAE,EACzB,OAAO,EAAE,UAAU,EAAE,EACrB,QAAQ,EAAE,qBAAqB,EAC/B,QAAQ,EAAE,SAAS,GAClB,SAAS,CA6HX"}