How nicolaskruchten/pivottable works
Main components
• External Dependencies – Include jQuery (mandatory), jQueryUI (for interactive drag-and-drop), and optionally charting libraries (D3.js, C3.js, Google Charts, Plotly).
• PivotTable Core Engine – The central logic (written in CoffeeScript and later compiled) that handles data transformation, aggregation, and pivot table generation. This includes both the non-UI version (pivot()) and the UI-enhanced version (pivotUI()).
• UI Layer – This component wraps around the core engine and uses jQueryUI to implement the drag-and-drop interface, enabling users to build and manipulate the pivot table.
• Renderer Modules – Separate renderer plugins that convert summary data into different visual formats. For example, dedicated modules exist for c3_renderers, d3_renderers, export_renderers, gchart_renderers, and plotly_renderers. This layered approach also makes it easy for developers to add more renderers.
• Localization and Configuration – Modules located in the locales folder that provide different language translations and configuration settings.
• Build and Testing Infrastructure – Represented by files like gulpFile.js, composer.json, package.json, and the tests/ directory. This component addresses the build process (CoffeeScript compilation and minification) and automated tests (using Jasmine in tests/).
Relationships and interactions between components
• The client application (or the consuming code in an example HTML file) first loads external dependencies (jQuery, jQueryUI, and optionally chart libraries).
• The compiled PivotTable.js (taken from the dist folder) is then loaded.
• The core engine (pivot and pivotUI functions) processes raw data provided by the user and interacts with the UI Layer when pivotUI is used.
• The UI layer listens for drag-and-drop events (powered by jQueryUI) and passes configuration changes back to the core engine, which re-aggregates data accordingly.
• When rendering is required in chart formats, calls are made from the core engine to the appropriate renderer module.
• The localization modules are used throughout the UI to render language-specific messages.
• During development, the build system (gulp, invoked via gulpFile.js) watches changes in the src files, compiles them to the dist folder, and then the test suite (in tests/) validates functionality.
Architectural patterns and design principles
• Modular Design: The separation of the core pivot table logic, UI controls, and rendering plugins facilitates extensibility (for instance, adding new renderers or aggregation functions).
• UMD Pattern: The library follows the Universal Module Definition, making it compatible with various script loaders (AMD, CommonJS, direct browser inclusion).
• Layered Architecture: A clear distinction between core data processing (aggregation, transformation) and user interface (drag-and-drop, localization) simplifies maintenance and enhances reusability.