Skip to content

Conversation

@Delen0828
Copy link

Introduces export_vega.m to enable exporting gramm plots to interactive Vega visualizations, including support for various chart types (geom_* methods), color grouping, tooltips, and interactive legends.

Adds a corresponding test file export_vega_test.m and updates functionSignatures.json to register the new export function.

Introduces export_vega.m to enable exporting gramm plots to interactive Vega visualizations, including support for various chart types, color grouping, tooltips, and interactive legends. Adds a corresponding test file and updates functionSignatures.json to register the new export function.
Replaces the old stat handle detection in export_vega.m with a new implementation that extracts actual computed statistics from gramm objects. Adds robust extraction functions for GLM, smooth, bin, summary, boxplot, density, violin, QQ, and bin2d statistics, and updates chart layer creation to use these extracted statistics for accurate Vega layer generation. This enables more reliable and flexible export of statistical layers, including regression lines, confidence intervals, histograms, and more.
@piermorel
Copy link
Owner

Hi, thanks for the pull request, the use of Vega seems like a great idea. I will be able to test things out and hopefully merge next week. In the meantime, have you looked at the gh-pages branch to see whether it would be easy to add a webpage demoing vega output to the new gramm page https://piermorel.github.io/gramm/ ?

@slahoti1
Copy link

Hi,

I'm Shivam, part of the MathWorks team focused on software development workflows. It’s great to connect with you.

I tried out your changes and really appreciate the extensive example you provided to demonstrate the feature. As a general best practice, we usually recommend writing tests for new feature implementations. Since you’ve already put together a thorough example, you might consider leveraging it as a test using the ExamplesDrivenTester toolbox. This approach can help ensure your examples are automatically tested and make it easier to catch any issues.

To get the most out of the toolbox, it’s helpful to separate each example into its own MATLAB file. This way, if something fails, it’s easier to pinpoint the exact example.

You can also generate a code coverage report to verify that all functionalities are being tested. Here’s a quick illustration of how you might do this:

reportFormat = matlab.unittest.plugins.codecoverage.CoverageReport('coverage-report'); 
covPlugin = matlab.unittest.plugins.CodeCoveragePlugin.forFolder("gramm", "Producing", reportFormat); 
obj = examplesTester("gramm/export_vega_test.m", CodeCoveragePlugin = covPlugin); 
obj.executeTests; 

Following is a screenshot of the code coverage report for the “export_vega_test.m”:

image

Please refer the following page for more details on the Examples Driven Tester Toolbox:
https://www.mathworks.com/matlabcentral/fileexchange/156374-examplesdriventester

@slahoti1
Copy link

Additionally, I noticed that the changes for method declaration of “export_vega.m” in “gramm.m” has not been committed in the Pull Request. Could you please double-check if those changes are included?

@piermorel
Copy link
Owner

piermorel commented Oct 10, 2025

Hi @Delen0828 , as @slahoti1 mentioned the export_vega declaration in gramm.m is not there. I added it manually and am able to generate the html and json files on my computer. However when I open the html in my browser I just get a blank page (tried on Safari and Firefox), is that normal behaviour ?
EDIT : I do get the visualizations working if I copy-paste the content in https://vega.github.io/editor/#/edited

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants