Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement tooling to generate multiple plotly schemas #18

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7b2a11a
update to plotly version 2.29.0
Feb 9, 2024
29541a0
fix typos
Feb 9, 2024
7cdb932
update to go 1.22, fix review comments
Apr 13, 2024
0571e9c
reduce number of changes
MetalBlueberry Apr 14, 2024
612c969
add downloader script, improve readme
Apr 20, 2024
78a13f9
run go generate
MetalBlueberry May 1, 2024
ee89afd
create definition to support multiple versions of plotly
May 2, 2024
2293e99
update dependencies
May 11, 2024
e60c99f
complete full generation for each version separately
May 11, 2024
2a3e744
update notes
May 11, 2024
da906d6
enable offline plots
May 12, 2024
6aa6e62
allow arrays when the schema definition states 'arrayOK'
May 12, 2024
1492cb7
allow usage of frames
May 12, 2024
1640d4c
allow redirecting outputstream of create plot
May 12, 2024
3b1fe76
keep the offline folder, generate for each version
May 18, 2024
c85ba65
remove array enabling
May 18, 2024
ef4579f
Merge branch 'master' into feature/plotly_v2.29.0
PatrickVienne May 19, 2024
c3272da
fix typo
MetalBlueberry May 22, 2024
e9d5fa0
Refactor
MetalBlueberry May 22, 2024
b452fc1
Test the packages build
MetalBlueberry May 22, 2024
9411066
remove frames
May 24, 2024
49edb2b
remove change on offline package
MetalBlueberry May 25, 2024
1cd3708
cleanup readme
MetalBlueberry May 25, 2024
92f38a9
fix template syntax
MetalBlueberry May 25, 2024
2682f35
regenerate
MetalBlueberry May 25, 2024
8277e26
fix build issue with import path
MetalBlueberry May 25, 2024
f737784
fix CDN
MetalBlueberry May 25, 2024
bfe1851
fix go mod
MetalBlueberry May 25, 2024
4ced1cd
fix examples output
MetalBlueberry May 25, 2024
b55db8a
clarify the purpose of the schema
MetalBlueberry May 25, 2024
b95b94d
fix loading the schema from embed
MetalBlueberry May 25, 2024
b0c12cd
remove unused code
MetalBlueberry May 25, 2024
fd02e0d
readme update
MetalBlueberry May 25, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
with:
go-version: "1.22"

- name: Test
run: go test -v ./...

- name: Check Generated Schema
run: |
go generate ./...
git diff --exit-code

- name: Test
run: go test -v ./...

- name: Build all packages
run: go build -v ./...
28 changes: 0 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,6 @@ The local paths are relative to the project root.
> go generate ./...
> ```

#### changing schemas.yaml locations

Be aware, that the template file [plotly.tmpl](generator%2Ftemplates%2Fplotly.tmpl) also has a go generate directive.
This directive has relative paths, based on the assumed final path within the project

#### embedding a downloaded plotly js source

In the example: [main.go](examples%2Fbar%2Fmain.go) you find an example to reuse a static plotly js file and pass that reference to the generated html, instead of using a hardcoded CDN reference which would require internet connection.
```go
abs, err := filepath.Abs("asset/plotly-2.29.1.min.js")
if err != nil {
return
}
grob.ToHtml(fig, "bar.html", grob.FigOptions{HeadContent: fmt.Sprintf(`<title>Offline Bars</title><script src="%s"></script>`, abs)})
grob.Show(fig, grob.FigOptions{HeadContent: fmt.Sprintf(`<title>Offline Bars</title><script src="%s"></script>`, abs)})
```

#### Missing Files?

if in doubt whether all types and traces have been generated, you can use the jsonviewer tool to introspect the json:
Expand All @@ -187,17 +170,6 @@ http://plotly-json-editor.getforge.io/

[![Star History Chart](https://api.star-history.com/svg?repos=Metalblueberry/go-plotly&type=Date)](https://star-history.com/#Metalblueberry/go-plotly&Date)

## Update Notes:

### Add version v2.29.1 and v2.31.1
- Added Downloader for schema file
- added generator for different packages based on plotly version in subfolders for each version
- enable easier use for different plotly version by new import paths which include the version generated. Example: `grob "github.com/MetalBlueberry/go-plotly/generated/v2.31.1/graph_objects"`
- removed go generate directive from the templates which are no longer necessary
- removed offline package, as each version package needs its own **plot.go**.
- Replaced all `offline` imports in the examples packages by just calling the `grob` package of the specified version
- all html's will now refer to the correct plotly version's cdn in the html's head
- allow defining your own head for the plot, which allows embedding the plotly.js source instead of referencing the CDN. This enables generation of offline plots

## Official Plotly Release Notes
For detailed changes please follow the release notes of the original JS repo: https://github.com/plotly/plotly.js/releases
8 changes: 0 additions & 8 deletions examples/asset/plotly-2.29.1.min.js

This file was deleted.

6 changes: 3 additions & 3 deletions examples/bar/bar.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

<head>
<script src="https://cdn.plot.ly/plotly-1.58.4.min.js"></script>
<script src="https://cdn.plot.ly/plotly-2.31.1.min.js"></script>
</head>
</body>
<body>
<div id="plot"></div>
<script>
data = JSON.parse('{"data":[{"type":"bar","x":[1,2,3],"y":[1,2,3]}],"layout":{"title":{"text":"A Figure Specified By Go Struct"}}}')
Plotly.newPlot('plot', data);
</script>
<body>
</body>

12 changes: 0 additions & 12 deletions examples/bar/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package main

import (
"fmt"
"path/filepath"

grob "github.com/MetalBlueberry/go-plotly/generated/v2.31.1/graph_objects"
"github.com/MetalBlueberry/go-plotly/generated/v2.31.1/offline"
)
Expand Down Expand Up @@ -32,15 +29,6 @@ func main() {
},
}

// by default, using the cdn reference, downloading the plotly js on demand
offline.ToHtml(fig, "bar.html")
offline.Show(fig)

// example for using static assets, which can be embedded into the golang application
abs, err := filepath.Abs("asset/plotly-2.29.1.min.js")
if err != nil {
return
}
offline.ToHtml(fig, "bar.html", offline.FigOptions{HeadContent: fmt.Sprintf(`<title>Offline Bars</title><script src="%s"></script>`, abs)})
offline.Show(fig, offline.FigOptions{HeadContent: fmt.Sprintf(`<title>Offline Bars</title><script src="%s"></script>`, abs)})
}
6 changes: 3 additions & 3 deletions examples/bar_custom/bar_custom.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

<head>
<script src="https://cdn.plot.ly/plotly-1.58.4.min.js"></script>
<script src="https://cdn.plot.ly/plotly-2.31.1.min.js"></script>
</head>
</body>
<body>
<div id="plot"></div>
<script>
data = JSON.parse('{"data":[{"type":"bar","hoverinfo":"none","marker":{"color":"#9ec9e0","line":{"color":"rgb(8,48,107)","width":1.5},"opacity":0.6},"text":["20","14","23"],"textposition":"auto","x":["Product A","Product B","Product C"],"y":[20,14,23]}],"layout":{"title":{"text":"A Figure Specified By Go Struct"}}}')
Plotly.newPlot('plot', data);
</script>
<body>
</body>

3 changes: 1 addition & 2 deletions examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ require (
github.com/MetalBlueberry/go-plotly v0.4.0
github.com/go-gota/gota v0.12.0
github.com/lucasb-eyer/go-colorful v1.2.0
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
)

require (
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
gonum.org/v1/gonum v0.15.0 // indirect
Expand Down
Loading
Loading