diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2bc58a5..63e3d0b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,3 +64,69 @@ jobs: with: name: gallery-${{ matrix.release }} path: gallery/ + + package-toolbox: + runs-on: ubuntu-24.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + + # R2023a is the oldest release with matlab.addons.toolbox.ToolboxOptions + - name: Set up MATLAB + uses: matlab-actions/setup-matlab@v3 + with: + release: R2023a + cache: true + + - name: Package toolbox + uses: matlab-actions/run-command@v3 + with: + command: buildtool package + + - name: Upload toolbox + uses: actions/upload-artifact@v4 + with: + name: toolbox + path: release/*.mltbx + + install-toolbox: + name: install-toolbox (${{ matrix.release }}) + needs: package-toolbox + runs-on: ubuntu-24.04 + strategy: + fail-fast: false + matrix: + release: [R2021a, R2026a] + steps: + # no checkout: fig2plotly must come from the installed toolbox + - name: Download toolbox + uses: actions/download-artifact@v4 + with: + name: toolbox + path: release + + - name: Set up MATLAB + uses: matlab-actions/setup-matlab@v3 + with: + release: ${{ matrix.release }} + cache: true + + - name: Install, use and uninstall the toolbox + uses: matlab-actions/run-command@v3 + with: + command: | + mltbx = dir(fullfile("release", "*.mltbx")); + assert(isscalar(mltbx), "expected one .mltbx in release/"); + installed = matlab.addons.toolbox.installToolbox(fullfile(mltbx.folder, mltbx.name)); + disp(installed); + location = which("fig2plotly"); + assert(~isempty(location), "fig2plotly is not on the path after installing"); + disp(location); + assert(isfile(fullfile(fileparts(location), "LICENSE")), "the toolbox has no LICENSE"); + fig = figure("Visible", "off"); + plot(1:3); + p = plotlyfig(fig, "visible", "off"); + assert(numel(p.data) == 1, "plotlyfig converted %d traces, expected 1", numel(p.data)); + addtheme(struct("layout", struct()), "ggplot2"); + matlab.addons.toolbox.uninstallToolbox(installed); + assert(isempty(which("fig2plotly")), "fig2plotly is still on the path after uninstalling"); diff --git a/.gitignore b/.gitignore index a3e48acb..0f98db54 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ dev/ *.asv untitled.html +release/ diff --git a/buildfile.m b/buildfile.m new file mode 100644 index 00000000..6813a167 --- /dev/null +++ b/buildfile.m @@ -0,0 +1,49 @@ +function plan = buildfile + plan = buildplan(localfunctions); +end + +function packageTask(~) + % Package the plotly folder as a toolbox in release/ + root = fileparts(mfilename('fullpath')); + + % only tracked files: a working copy also holds downloads such as the + % Kaleido binaries under plotly/kaleido + [status, listing] = system(sprintf('git -C "%s" ls-files plotly', root)); + if status ~= 0 + error('buildfile:git', 'git ls-files failed:\n%s', listing); + end + files = string(splitlines(strtrim(listing))); + files = files(~startsWith(files, "plotly/testing/") & ~contains(files, "/Test_")); + folders = unique(regexprep(files(endsWith(files, ".m")), '/[^/]*$', '')); + + version = regexp(fileread(fullfile(root, 'plotly', 'plotly_aux', 'plotly_version.m')), ... + '"(\d+\.\d+\.\d+)"', 'tokens', 'once'); + version = string(version{1}); + + % ship the license at the toolbox root; the copy only lives for the build + licenseCopy = fullfile(root, 'plotly', 'LICENSE'); + copyfile(fullfile(root, 'LICENSE'), licenseCopy); + removeLicense = onCleanup(@() delete(licenseCopy)); %#ok + + opts = matlab.addons.toolbox.ToolboxOptions(fullfile(root, 'plotly'), ... + "e59f316c-4a80-11e4-9553-005056977bd0"); + opts.ToolboxName = "Plotly Graphing Library for MATLAB"; + opts.ToolboxVersion = version; + opts.Summary = "Convert MATLAB figures into interactive plotly.js charts"; + if isprop(opts, 'Description') % removed in R2026b + opts.Description = "fig2plotly converts MATLAB figures into interactive " + ... + "plotly.js web charts that open in your browser, fully offline. " + ... + "Run getplotlyoffline() once after installing to download plotly.js."; + end + opts.AuthorCompany = "Plotly"; + opts.ToolboxFiles = [root + "/" + files; string(licenseCopy)]; + opts.ToolboxMatlabPath = root + "/" + folders; + opts.MinimumMatlabRelease = "R2021a"; + opts.MaximumMatlabRelease = ""; + opts.OutputFile = fullfile(root, "release", "plotly_matlab-" + version + ".mltbx"); + + if ~isfolder(fullfile(root, "release")) + mkdir(fullfile(root, "release")); + end + matlab.addons.toolbox.packageToolbox(opts); +end diff --git a/plotly/addtheme.m b/plotly/addtheme.m index e7aed3b3..3799362a 100644 --- a/plotly/addtheme.m +++ b/plotly/addtheme.m @@ -1,19 +1,8 @@ function f = addtheme(f, theme) %-validate theme name-% - themePath = 'plotly/themes'; - S = dir(themePath); - - if isempty(S) - paths = split(path, ':'); - for p = 1:length(paths) - if ~isempty(strfind(paths{p}, themePath)) - themePath = paths{p}; - break; - end - end - S = dir(themePath); - end + themePath = fullfile(fileparts(mfilename('fullpath')), 'themes'); + S = dir(fullfile(themePath, '*.json')); N = {S.name}; @@ -28,8 +17,7 @@ %-add theme to figure-% - fname = sprintf('%s/%s.json', themePath, theme); - % fname = strcat('plotly/themes/', theme, '.json'); + fname = fullfile(themePath, sprintf('%s.json', theme)); fid = fopen(fname); raw = fread(fid,inf); str = char(raw'); diff --git a/plotly/plotly_aux/plotly_version.m b/plotly/plotly_aux/plotly_version.m index f56f5497..fa4ee25f 100644 --- a/plotly/plotly_aux/plotly_version.m +++ b/plotly/plotly_aux/plotly_version.m @@ -1,3 +1,3 @@ function version = plotly_version() - version = "3.0.0"; + version = "3.1.0"; end