|
| 1 | +# VueCore: Project Structure and Workflow |
| 2 | + |
| 3 | +This file provides an overview of the directory structure and general workflow for VueCore. |
| 4 | + |
| 5 | +## Directory Structure |
| 6 | + |
| 7 | +VueCore is organized into several subpackages (a directory with an `__init__.py` file) |
| 8 | +that serve to different purposes, including **user-facing API**, **plotting engines**, **data validation schemas**, and **general utilities**. Here is a brief overview of the main directories with files for the scatter plot example: |
| 9 | + |
| 10 | +``` |
| 11 | +├── vuecore/ # The main source code package |
| 12 | +│ ├── __init__.py # Package initialization |
| 13 | +│ ├── constants.py # Global constants and enums (e.g., plot types, engine types) |
| 14 | +│ ├── engines/ # Plotting backends (e.g., Plotly, Matplotlib) |
| 15 | +│ │ ├── __init__.py # Manages engine registration and loading |
| 16 | +│ │ └── plotly/ |
| 17 | +│ │ ├── __init__.py # Registers Plotly engine |
| 18 | +│ │ ├── saver.py # Functions for saving plots |
| 19 | +│ │ ├── theming.py # Applies styles and themes |
| 20 | +│ │ └── scatter.py # Generates Plotly scatter plots from a DataFrame and schema |
| 21 | +│ ├── plots/ # User-facing API for creating plots |
| 22 | +│ │ └── basic/ |
| 23 | +│ │ └── scatter.py # User API for creating scatter plots |
| 24 | +│ ├── schemas/ # Pydantic models for plot configuration validation |
| 25 | +│ │ └── basic/ |
| 26 | +│ │ └── scatter.py # Schema for scatter plot configuration |
| 27 | +│ └── utils/ # Shared helper functions |
| 28 | +│ │ ├── __init__.py |
| 29 | +│ ├── statistics.py # Data transformation and statistical functions |
| 30 | +│ └── doc_utils.py # Documentation utilities |
| 31 | +├── tests/ # Unit and integration tests |
| 32 | +│ └── test_scatter.py # Tests for the scatter plot functionality |
| 33 | +└── docs/ # Documentation scripts and plot examples |
| 34 | + └── api_examples/ |
| 35 | +│ │ ├── scatter_plot.ipynb # Notebook demonstrating how to create scatter plots |
| 36 | + └── scatter_plot.py # Script demonstrating how to create scatter plots |
| 37 | +``` |
| 38 | + |
| 39 | +## Plot Generation Workflow |
| 40 | + |
| 41 | +The process for generating a plot in VueCore follows a clear, sequential path, ensuring data is validated and rendered efficiently: |
| 42 | + |
| 43 | +1. **User Interaction:** A user calls the main entry-point function from the `plots/` directory, for example, `plots.basic.scatter.create_scatter_plot`. They provide the data and any optional keyword arguments to define the plot's appearance. This can be done from any **Python script** or **Jupyter Notebook**, such as the examples provided in the `docs/api_examples` folder. |
| 44 | +2. **Configuration Validation:** The function uses a **Pydantic schema** from the `schemas/` directory to validate the user's input. This step ensures all parameters are correctly typed and configured. |
| 45 | +3. **Engine Selection:** The validated **configuration**, along with the **data** and chosen **engine** (e.g., Plotly), is passed to the `create_plot` factory function. This function selects the correct plotting engine and its corresponding `build` function. |
| 46 | +4. **Plot Generation:** The engine's `build` function handles the steps of creating a plot: |
| 47 | + |
| 48 | + * It runs any necessary **preprocessing steps** (e.g., calculating density for color mapping). |
| 49 | + * It calls the appropriate **plotting function** (e.g., `px.scatter`) to generate the initial figure. |
| 50 | + * It applies **theming and styling** by calling a specific function (e.g., `apply_scatter_theme`). |
| 51 | +5. **Return and Save:** The `build_plot` utility returns a `plotly.graph_objects.Figure` object, which is passed to the **user-facing function**. If a `file_path` was provided, the plot is saved to the specified location |
| 52 | + |
| 53 | +Here is a visual representation of the workflow: |
| 54 | + |
| 55 | +``` |
| 56 | +User Calls API |
| 57 | + â–Ľ |
| 58 | + `vuecore/plots/basic/scatter.py` |
| 59 | + │ |
| 60 | + â–Ľ Validates configuration |
| 61 | + `vuecore/schemas/basic/scatter.py` |
| 62 | + │ |
| 63 | + â–Ľ Calls engine-specific build function |
| 64 | + `vuecore/engines/plotly/scatter.py:build` |
| 65 | + │ |
| 66 | + â–Ľ Delegates to generic plot builder |
| 67 | + `vuecore/engines/plotly/plot_builder.py:build_plot` |
| 68 | + ├───► Preprocessing (`scatter_preprocess`) |
| 69 | + └───► Theming (`apply_scatter_theme`) |
| 70 | + │ |
| 71 | + â–Ľ Returns final plot object |
| 72 | + `plotly.graph_objects.Figure` |
| 73 | + │ |
| 74 | + â–Ľ Saves the final plot |
| 75 | + `vuecore/engines/plotly/saver.py` |
| 76 | +``` |
| 77 | + |
| 78 | +## Tasks to Add a New Plot |
| 79 | + |
| 80 | +We created a [new plot PR template][new-plot-pr-template] with a checklist of all the steps to follow, which you can use with a query paramter by clicking [here][new-plot-pr-query-param]. |
| 81 | + |
| 82 | +[new-plot-pr-template]: https://github.com/Multiomics-Analytics-Group/vuecore/blob/main/.github/PULL_REQUEST_TEMPLATE/new_plot.md |
| 83 | +[new-plot-pr-query-param]: https://github.com/Multiomics-Analytics-Group/vuecore/compare/main...my-branch?quick_pull=1&template=new_plot.md |
0 commit comments