Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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");
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dev/
*.asv
untitled.html
release/
49 changes: 49 additions & 0 deletions buildfile.m
Original file line number Diff line number Diff line change
@@ -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<NASGU>

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
18 changes: 3 additions & 15 deletions plotly/addtheme.m
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion plotly/plotly_aux/plotly_version.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function version = plotly_version()
version = "3.0.0";
version = "3.1.0";
end
Loading