bezel-charts 1.2.0 → 1.4.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/src/index.js CHANGED
@@ -3,24 +3,21 @@
3
3
  * Small, polished charts as web components. Zero dependencies, pure SVG.
4
4
  * Created by Shaz Moghaddam, London · https://shazmoghaddam.github.io
5
5
  */
6
- import { TYPES, render, toSVG } from './render.js';
6
+ // Each entry registers its chart and defines its tag. Pages that only need a few charts can import those entries instead.
7
+ import './entries/spark.js';
8
+ import './entries/line.js';
9
+ import './entries/area.js';
10
+ import './entries/bars.js';
11
+ import './entries/scatter.js';
12
+ import './entries/ring.js';
13
+ import './entries/donut.js';
14
+ import './entries/gauge.js';
15
+ import './entries/progress.js';
16
+ import './entries/heatmap.js';
17
+ import { NAMES, render, toSVG } from './render.js';
7
18
  import { THEMES } from './core/themes.js';
8
19
  import { BezelChart } from './element.js';
9
20
 
10
- export const version = '1.2.0';
11
- export const types = Object.keys(TYPES);
21
+ export const version = '1.4.0';
22
+ export const types = NAMES.slice();
12
23
  export { render, toSVG, BezelChart, THEMES as themes };
13
-
14
- if (typeof customElements !== 'undefined' && typeof HTMLElement !== 'undefined') {
15
- for (const type of types) {
16
- const tag = `bezel-${type}`;
17
- if (!customElements.get(tag)) {
18
- customElements.define(tag, class extends BezelChart {
19
- get chartType() {
20
- return type;
21
- }
22
- });
23
- }
24
- }
25
- if (!customElements.get('bezel-chart')) customElements.define('bezel-chart', class extends BezelChart {});
26
- }
package/src/render.js CHANGED
@@ -1,17 +1,16 @@
1
1
  /** Pure rendering: options in, SVG string out. No DOM needed, so it runs in browsers, Node and build scripts. */
2
2
  import { THEMES } from './core/themes.js';
3
3
  import { bool } from './core/util.js';
4
- import spark from './charts/spark.js';
5
- import line from './charts/line.js';
6
- import bars from './charts/bars.js';
7
- import ring from './charts/ring.js';
8
- import donut from './charts/donut.js';
9
- import gauge from './charts/gauge.js';
10
- import progress from './charts/progress.js';
11
- import heatmap from './charts/heatmap.js';
12
- import scatter from './charts/scatter.js';
13
-
14
- export const TYPES = { spark, line, bars, scatter, ring, donut, gauge, progress, heatmap };
4
+ /** Every chart type, in the order the full bundle loads them. */
5
+ export const NAMES = ['spark', 'line', 'area', 'bars', 'scatter', 'ring', 'donut', 'gauge', 'progress', 'heatmap'];
6
+
7
+ /** The renderers loaded so far. Each chart's entry file adds its own, so a page only loads the charts it uses. */
8
+ export const TYPES = {};
9
+
10
+ /** Makes a chart type available to render(), toSVG() and the elements. */
11
+ export function register(type, fn) {
12
+ TYPES[type] = fn;
13
+ }
15
14
 
16
15
  const camel = (k) => k.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
17
16
 
@@ -22,7 +21,9 @@ const camel = (k) => k.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
22
21
  */
23
22
  function prepare(type, options) {
24
23
  if (!TYPES[type]) {
25
- throw new Error(`Bezel Charts: unknown chart type "${type}". Choose one of: ${Object.keys(TYPES).join(', ')}.`);
24
+ throw new Error(NAMES.includes(type)
25
+ ? `Bezel Charts: the ${type} chart isn't loaded. Add import 'bezel-charts/${type}', or load dist/charts/${type}.js.`
26
+ : `Bezel Charts: unknown chart type "${type}". Choose one of: ${NAMES.join(', ')}.`);
26
27
  }
27
28
  const o = {};
28
29
  for (const [k, v] of Object.entries(options)) o[camel(k)] = v;