Skip to content

Commit

Permalink
allow redirecting outputstream of create plot
Browse files Browse the repository at this point in the history
  • Loading branch information
pafo committed May 12, 2024
1 parent 1492cb7 commit 1640d4c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions generated/v2.19.0/graph_objects/plot_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
Expand All @@ -23,6 +24,14 @@ type Options struct {
Addr string
}

// ToWriter saves the figure as standalone HTML. It still requires internet to load plotly.js from CDN.
func ToWriter(fig *Fig, w io.Writer, options ...FigOptions) {
_, err := w.Write(figToBuffer(fig, options...).Bytes())
if err != nil {
panic(errors.New(fmt.Sprintf("failed to write figure to passed writer: %v", err)))
}
}

// ToHtml saves the figure as standalone HTML. It still requires internet to load plotly.js from CDN.
func ToHtml(fig *Fig, path string, options ...FigOptions) {
buf := figToBuffer(fig, options...)
Expand Down
9 changes: 9 additions & 0 deletions generated/v2.29.1/graph_objects/plot_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
Expand All @@ -23,6 +24,14 @@ type Options struct {
Addr string
}

// ToWriter saves the figure as standalone HTML. It still requires internet to load plotly.js from CDN.
func ToWriter(fig *Fig, w io.Writer, options ...FigOptions) {
_, err := w.Write(figToBuffer(fig, options...).Bytes())
if err != nil {
panic(errors.New(fmt.Sprintf("failed to write figure to passed writer: %v", err)))
}
}

// ToHtml saves the figure as standalone HTML. It still requires internet to load plotly.js from CDN.
func ToHtml(fig *Fig, path string, options ...FigOptions) {
buf := figToBuffer(fig, options...)
Expand Down
9 changes: 9 additions & 0 deletions generated/v2.31.1/graph_objects/plot_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
Expand All @@ -23,6 +24,14 @@ type Options struct {
Addr string
}

// ToWriter saves the figure as standalone HTML. It still requires internet to load plotly.js from CDN.
func ToWriter(fig *Fig, w io.Writer, options ...FigOptions) {
_, err := w.Write(figToBuffer(fig, options...).Bytes())
if err != nil {
panic(errors.New(fmt.Sprintf("failed to write figure to passed writer: %v", err)))
}
}

// ToHtml saves the figure as standalone HTML. It still requires internet to load plotly.js from CDN.
func ToHtml(fig *Fig, path string, options ...FigOptions) {
buf := figToBuffer(fig, options...)
Expand Down
9 changes: 9 additions & 0 deletions generator/templates/plot.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
Expand All @@ -23,6 +24,14 @@ type Options struct {
Addr string
}

// ToWriter saves the figure as standalone HTML. It still requires internet to load plotly.js from CDN.
func ToWriter(fig *Fig, w io.Writer, options ...FigOptions) {
_, err := w.Write(figToBuffer(fig, options...).Bytes())
if err != nil {
panic(errors.New(fmt.Sprintf("failed to write figure to passed writer: %v", err)))
}
}

// ToHtml saves the figure as standalone HTML. It still requires internet to load plotly.js from CDN.
func ToHtml(fig *Fig, path string, options ...FigOptions) {
buf := figToBuffer(fig, options...)
Expand Down

0 comments on commit 1640d4c

Please sign in to comment.