This project enables dynamic generation of chart-ready, parametric visualizations for sustainable energy education. The backend pipeline takes structured CSV inputs and generates:
- Model JSON files (
/public/outputs/*.json
) for each model - A single
functions.js
script containing JavaScriptcompute_*()
functions for frontend use
These are rendered dynamically in a chart-agnostic React frontend using ECharts.
The system allows you to define simple mathematical models through two inputs:
- Parameter CSV: defines user-adjustable variables
- Function CSV: defines output expressions and chart usage
The Python pipeline then compiles these into frontend-ready visualizations with parametric sliders linked to the charts.
interactive-models/
│
├── 01_Inputs/
│ ├── models.csv # Registry of all models
│ ├── parameters/<code>.csv # Parameters per model
│ └── functions/<code>.csv # Output expressions per model
│
├── 02_Processing/
│ └── generate.py # Main processing pipeline
│
├── 01_App/
│ └── public/
│ ├── functions.js # All compute_* functions
│ └── outputs/*.json # Chart metadata + config per model
code | title | summary |
---|---|---|
access001 | Energy Access Model | Shows relationship between electrification and hours of supply |
This defines all user inputs for the model.
symbol | title | type | min | max | default | interval | description | unit |
---|---|---|---|---|---|---|---|---|
A | Access % | discrete | 0 | 100 | 60 | 10 | % population access | % |
B | Hours/Day | discrete | 0 | 24 | 10 | 1 | Daily supply | hrs |
Supported type
values:
discrete
: Single slider with stepscontinuous
: Slider with fine controlrange
: Defines bothsymbol_min
andsymbol_max
x-axis
: Used as domain in line/multiline charts (automatically generates an array of values)
This defines each output equation and how it is visualized.
output_symbol | title | js_equation | chart_usage | unit | target | direction | description |
---|---|---|---|---|---|---|---|
AI | Access Index | (A / 100) * (B / 24) | bar_category | 0-1 | 0.8 | above | Combined access metric |
RI | Reliability Index | Math.min(1, B / 12) | bar_category | 0-1 | 0.75 | above | Supply regularity |
Valid chart_usage
options:
bar_category
: Single bar per valuebar_stack_component
: Stacked bar charty_value
: Generates line chart over x-axissegment_value
: For pie charts
{
"template_id": "model",
"color_scheme": "dark",
"content": {
"functionName": "compute_access001",
"title": "Energy Access Model",
"description": "Shows relationship between electrification and hours of supply",
"latex-functions": ["AI = \frac{A}{100} \cdot \frac{B}{24}"],
"option": {
"xAxis": { "type": "category" },
"yAxis": { "type": "value" },
"tooltip": { "trigger": "axis" },
"series": []
},
"parameters": [ ... ],
"outputs": [ ... ]
}
}
function compute_access001(params) {
const series = [];
series.push({ name: 'Access Index', type: 'bar', data: [ (params.A / 100) * (params.B / 24) ] });
series.push({ name: 'Reliability Index', type: 'bar', data: [ Math.min(1, params.B / 12) ] });
return { series};
}
Line or multiline models with an x-axis
input generate:
const xs = [0, 5, 10, ..., 100];
const y_Access = xs.map(x => [x, (params.A / 100) * Math.sin(Math.PI * x / 100)]);
- Renders dropdown to choose model
- Dynamically builds sliders from parameter list
- Runs
compute_<code>()
fromfunctions.js
on parameter change - Injects returned series and
xAxis
(if present) into ECharts config
- navigate in command prompt to the 01_App folder
- run: npm install npm start
- Open the ipynb notebook and run the main cell
- Add new models by simply creating CSVs for parameters and functions and registering them in
models.csv
access001
: Basic bar chartmulti005
: Multiline chart with 2 expressions overx
pie003
: Pie chart showing energy mixstack004
: Stacked bar components