eleventy-plugin-uncharted 0.1.0 → 0.1.1

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/README.md CHANGED
@@ -5,14 +5,14 @@ A CSS-based charting plugin for Eleventy. Renders charts as pure HTML/CSS with n
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install uncharted
8
+ npm install eleventy-plugin-uncharted
9
9
  ```
10
10
 
11
11
  ## Setup
12
12
 
13
13
  ```javascript
14
14
  // eleventy.config.js
15
- import uncharted from 'uncharted';
15
+ import uncharted from 'eleventy-plugin-uncharted';
16
16
 
17
17
  export default function(eleventyConfig) {
18
18
  eleventyConfig.addPlugin(uncharted);
@@ -40,13 +40,13 @@ If you set `injectCss: false`, you'll need to manually include the stylesheet in
40
40
 
41
41
  ## Chart Types
42
42
 
43
- | Type | Description |
44
- |------|-------------|
45
- | `donut` | Pie/donut chart using conic-gradient |
46
- | `stacked-bar` | Horizontal bars with stacked segments |
47
- | `stacked-column` | Vertical columns with stacked segments |
48
- | `dot` | Categorical dot chart with Y-axis positioning |
49
- | `scatter` | XY scatter plot with continuous axes |
43
+ | Type | Description | Negative Values |
44
+ |------|-------------|-----------------|
45
+ | `donut` | Pie/donut chart using conic-gradient | No |
46
+ | `stacked-bar` | Horizontal bars with stacked segments | No |
47
+ | `stacked-column` | Vertical columns with stacked segments | Yes |
48
+ | `dot` | Categorical dot chart with Y-axis positioning | Yes |
49
+ | `scatter` | XY scatter plot with continuous axes | Yes (X and Y) |
50
50
 
51
51
  ## Usage
52
52
 
@@ -128,6 +128,22 @@ Point B,25,78,alpha
128
128
  Point C,15,32,beta
129
129
  ```
130
130
 
131
+ ## Negative Values
132
+
133
+ Stacked column, dot, and scatter charts support negative values. When negative values are present, a zero axis line appears automatically and values are positioned relative to it.
134
+
135
+ For stacked columns, positive values stack upward from zero and negative values stack downward:
136
+
137
+ ```csv
138
+ label,Cost,Profit
139
+ Q1,20,10
140
+ Q2,25,-10
141
+ Q3,15,25
142
+ Q4,30,-10
143
+ ```
144
+
145
+ The chart automatically calculates the range from the maximum positive stack to the minimum negative stack, ensuring proper scaling.
146
+
131
147
  ## Configuration Options
132
148
 
133
149
  | Option | Type | Description |
@@ -137,9 +153,12 @@ Point C,15,32,beta
137
153
  | `subtitle` | string | Subtitle below title |
138
154
  | `file` | string | Path to CSV file (relative to dataDir) |
139
155
  | `data` | array | Inline data array |
140
- | `max` | number | Maximum value for scaling |
156
+ | `max` | number | Maximum Y value for scaling |
157
+ | `min` | number | Minimum Y value for scaling (column, dot) |
141
158
  | `maxX` | number | Maximum X value (scatter only) |
142
159
  | `maxY` | number | Maximum Y value (scatter only) |
160
+ | `minX` | number | Minimum X value (scatter only) |
161
+ | `minY` | number | Minimum Y value (scatter only) |
143
162
  | `legend` | array | Custom legend labels |
144
163
  | `center` | object | Donut center content (`value`, `label`) |
145
164
  | `animate` | boolean | Override global animation setting |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eleventy-plugin-uncharted",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "An Eleventy plugin that renders CSS-based charts from CSV data using shortcodes",
5
5
  "main": "eleventy.config.js",
6
6
  "type": "module",
@@ -8,12 +8,13 @@ import { slugify, escapeHtml, getSeriesNames } from '../utils.js';
8
8
  * @param {string} [config.subtitle] - Chart subtitle
9
9
  * @param {Object[]} config.data - Chart data with label column and value columns
10
10
  * @param {number} [config.max] - Maximum Y value (defaults to max in data)
11
+ * @param {number} [config.min] - Minimum Y value (defaults to min in data or 0)
11
12
  * @param {string[]} [config.legend] - Legend labels (defaults to series names)
12
13
  * @param {boolean} [config.animate] - Enable animations
13
14
  * @returns {string} - HTML string
14
15
  */
15
16
  export function renderDot(config) {
16
- const { title, subtitle, data, max, legend, animate } = config;
17
+ const { title, subtitle, data, max, min, legend, animate } = config;
17
18
 
18
19
  if (!data || data.length === 0) {
19
20
  return `<!-- Dot chart: no data provided -->`;
@@ -34,7 +35,7 @@ export function renderDot(config) {
34
35
  const dataMax = Math.max(...allValues);
35
36
  const dataMin = Math.min(...allValues);
36
37
  const maxValue = max ?? dataMax;
37
- const minValue = dataMin < 0 ? dataMin : 0;
38
+ const minValue = min ?? (dataMin < 0 ? dataMin : 0);
38
39
  const range = maxValue - minValue;
39
40
  const hasNegativeY = minValue < 0;
40
41
 
@@ -8,12 +8,14 @@ import { slugify, escapeHtml } from '../utils.js';
8
8
  * @param {Object[]} config.data - Chart data (with label, x, y, and optionally series)
9
9
  * @param {number} [config.maxX] - Maximum X value (defaults to max in data)
10
10
  * @param {number} [config.maxY] - Maximum Y value (defaults to max in data)
11
+ * @param {number} [config.minX] - Minimum X value (defaults to min in data or 0)
12
+ * @param {number} [config.minY] - Minimum Y value (defaults to min in data or 0)
11
13
  * @param {string[]} [config.legend] - Legend labels for series
12
14
  * @param {boolean} [config.animate] - Enable animations
13
15
  * @returns {string} - HTML string
14
16
  */
15
17
  export function renderScatter(config) {
16
- const { title, subtitle, data, maxX, maxY, legend, animate } = config;
18
+ const { title, subtitle, data, maxX, maxY, minX, minY, legend, animate } = config;
17
19
 
18
20
  if (!data || data.length === 0) {
19
21
  return `<!-- Scatter chart: no data provided -->`;
@@ -51,8 +53,8 @@ export function renderScatter(config) {
51
53
 
52
54
  const calcMaxX = maxX ?? dataMaxX;
53
55
  const calcMaxY = maxY ?? dataMaxY;
54
- const calcMinX = dataMinX < 0 ? dataMinX : 0;
55
- const calcMinY = dataMinY < 0 ? dataMinY : 0;
56
+ const calcMinX = minX ?? (dataMinX < 0 ? dataMinX : 0);
57
+ const calcMinY = minY ?? (dataMinY < 0 ? dataMinY : 0);
56
58
  const rangeX = calcMaxX - calcMinX;
57
59
  const rangeY = calcMaxY - calcMinY;
58
60
 
@@ -6,13 +6,14 @@ import { slugify, getSeriesNames, escapeHtml } from '../utils.js';
6
6
  * @param {string} config.title - Chart title
7
7
  * @param {string} [config.subtitle] - Chart subtitle
8
8
  * @param {Object[]} config.data - Chart data
9
- * @param {number} [config.max] - Maximum value for percentage calculation
9
+ * @param {number} [config.max] - Maximum value for Y-axis scaling
10
+ * @param {number} [config.min] - Minimum value for Y-axis scaling (for negative values)
10
11
  * @param {string[]} [config.legend] - Legend labels (defaults to series names)
11
12
  * @param {boolean} [config.animate] - Enable animations
12
13
  * @returns {string} - HTML string
13
14
  */
14
15
  export function renderStackedColumn(config) {
15
- const { title, subtitle, data, max, legend, animate } = config;
16
+ const { title, subtitle, data, max, min, legend, animate } = config;
16
17
 
17
18
  if (!data || data.length === 0) {
18
19
  return `<!-- Stacked column chart: no data provided -->`;
@@ -45,9 +46,9 @@ export function renderStackedColumn(config) {
45
46
  minNegativeStack = Math.min(minNegativeStack, negativeSum);
46
47
  });
47
48
 
48
- const hasNegativeY = minNegativeStack < 0;
49
+ const hasNegativeY = minNegativeStack < 0 || min < 0;
49
50
  const maxValue = max ?? maxPositiveStack;
50
- const minValue = minNegativeStack;
51
+ const minValue = min ?? minNegativeStack;
51
52
  const range = maxValue - minValue;
52
53
  const zeroPct = hasNegativeY ? ((0 - minValue) / range) * 100 : 0;
53
54