Skip to content

Commit 144da23

Browse files
add do not edit warnings
1 parent 1c560d7 commit 144da23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+134
-31
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,21 @@ See the examples dir for more examples.
5757

5858
## Structure
5959

60-
All the traces are defined in [auto_traces.go](./graph_objects/auto_traces.go) and identified by the interface "Trace". Feel free to browse that file, but I prefer to use [Plotly's documentation](https://plotly.com/python/).
60+
Each trace type has its own file on **graph_objecs (grob)** package. The file contains the main structure and all the needed nested objects. Files ending with **_gen** are automatically generated files running `go generate`. This is executing the code in **generator** package to generate the structures from the plotly schema. The types are documented, but you can find more examples and extended documentation at [Plotly's documentation](https://plotly.com/python/).
6161

62-
The values that can hold single values or arrays are defined as `interfaces{}`. Most common case are X and Y values. You can pass any number slice and it will work (`[]float64`,`[]int`,`[]int64`...). In case of Hovertext, you can provide a `[]string` to display a text for each point, a `string` to display the same for all or `[]int` to display a number.
63-
64-
Enumerated values doesn't have a special type and you can assign whatever you want to them. But for type safety and autocompletion, you can look for the const value associated. For example, in case of "visible" you have to look for the const {{Type}}Visible{{Value}}. to hide a Scatter trace. `grob.ScatterVisibleFalse`. To known if a field is Enumerated, check the field description. the second word should be **enumerated**
62+
The values that can hold single values or arrays are defined as custom types that are a type definition of `interfaces{}`. Most common case are X and Y values. You can pass any number slice and it will work (`[]float64`,`[]int`,`[]int64`...). In case of Hovertext, you can provide a `[]string` to display a text for each point, a `string` to display the same for all or `[]int` to display a number.
6563

6664
Nested Properties, are defined as new types. This is great for auto completion using vscode because you can write all the boilerplate with ctrl+space. For example, the field `Title.Text` is accessed by the property `Title` of type {{Type}}Title that contains the property `Text`. The Type is always the struct that contains the field. For Layout It is `LayoutTitle`.
6765

68-
Flaglist Properties are defined like Enumerated values as constant fields. The difference is that they can be composed. Right now there is no special tool to deal with this and you can use the const to have autocompletion but you must be careful when joining them. For example, Scatter with mode="markers+lines" is `Mode: grob.ScatterModeMarkers + "+" + grob.ScatterModeLines,`
66+
Flaglist and Enumerated fields are defined with a type and its constant values. This provides useful autocompletion. Keep in mind that you can compose multiple values for a Flaglist like `Mode: grob.ScatterModeMarkers + "+" + grob.ScatterModeLines,`. You can read de inline documentation to see the default value.
6967

7068
## Tested
7169

72-
Examples, Code generation and Offline package are based on version 1.54.0, but It should work with other versions as this library just generates standard JSON.
70+
Examples, Code generation and Offline package are based on version 1.58.4, but It should work with other versions as this library just generates standard JSON.
7371

7472
## Testing
7573

76-
The package lacks of unit testing basically because it's just build JSON to be consumed by plotly.js. This means that I do not see a clear way of building valuable unit testing that doesn't involve the usage of plotly.js. If the package compiles, It means that types are generated correctly.
74+
The package lacks of unit testing basically because it's just building JSON to be consumed by plotly.js. This means that I do not see a clear way of building valuable unit testing that doesn't involve the usage of plotly.js. If the package compiles, It means that types are generated correctly.
7775

7876
Said that, I'm thinking about adding some integration testing with Docker, but for now, I've enough if the examples are working.
7977

@@ -93,18 +91,20 @@ In python, the component is called graph_objects, like in this package, but that
9391

9492
### How are the graph_object files generated?
9593

96-
The tmpl files are parsed mainly with go templates with just a few extra functions that I've publish as a CLI tool called "[plate](https://github.com/MetalBlueberry/plate)". You can go there to read more about It. The good thing is that you don't need to use plate unless you want to contribute to this repo.
94+
I was using "[plate](https://github.com/MetalBlueberry/plate)", but it was a bad idea. Now it is just plan go code inside the **generator package**. This should be much easier to understand and to contribute. Let me know if you want to contribute!!
9795

9896
### What are the usecases?
9997

10098
1. Send plotly figures to the frontend ready to be drawn, avoiding possible mistakes in JS thanks to types!
10199

102100
2. Generate an awesome dynamic plot in a local file with offline package.
103101

104-
3. Tell me what you can do with this.
102+
3. I don't know, just do something awesome and let me know it.
105103

106104
### Why are the String and Bool types defined?
107105

106+
> I'm thinking about defining everything as a pointer, it should be better in the long run
107+
108108
This is to handle the omitempty flag in json serialization. Turns out that if the flag is set, you cannot create a json object with a flag set to `false`. For example, turn off visibility of the legend will be impossible without this.
109109

110110
For bool, the solution is as simple as defining the types again inside graph_objects and it feels like using normal bool values.

generator/renderer.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ func NewRenderer(fs Creator, root *Root) (*Renderer, error) {
4444
return r, nil
4545
}
4646

47+
var doNotEdit = "// Code generated by go-plotly/generator. DO NOT EDIT."
48+
4749
// CreateTrace creates a file with the content of a trace by name
4850
func (r *Renderer) CreateTrace(dir string, name string) error {
4951
src := &bytes.Buffer{}
@@ -101,12 +103,15 @@ func (r *Renderer) WriteTrace(traceName string, w io.Writer) error {
101103

102104
fmt.Fprintf(w, `package grob
103105
106+
%s
107+
104108
var TraceType%s TraceType = "%s"
105109
106110
func (trace *%s) GetType() TraceType {
107111
return TraceType%s
108112
}
109113
`,
114+
doNotEdit,
110115
traceFile.MainType.Name,
111116
traceName,
112117
traceFile.MainType.Name,
@@ -238,7 +243,7 @@ func (r *Renderer) WriteLayout(w io.Writer) error {
238243

239244
fmt.Fprint(w, `package grob
240245
241-
`)
246+
`, doNotEdit)
242247

243248
err = r.tmpl.ExecuteTemplate(w, "trace.tmpl", traceFile.MainType)
244249
if err != nil {
@@ -312,7 +317,7 @@ func (r *Renderer) WriteConfig(w io.Writer) error {
312317

313318
fmt.Fprint(w, `package grob
314319
315-
`)
320+
`, doNotEdit)
316321

317322
err = r.tmpl.ExecuteTemplate(w, "trace.tmpl", traceFile.MainType)
318323
if err != nil {

generator/templates/unmarshal.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package grob
22

3+
// Code generated by go-plotly/generator. DO NOT EDIT
4+
35
import (
46
"encoding/json"
57
"errors"

graph_objects/area_gen.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

graph_objects/bar_gen.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

graph_objects/barpolar_gen.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

graph_objects/box_gen.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

graph_objects/candlestick_gen.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

graph_objects/carpet_gen.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

graph_objects/choropleth_gen.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)