You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,23 +57,21 @@ See the examples dir for more examples.
57
57
58
58
## Structure
59
59
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/).
61
61
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.
65
63
66
64
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`.
67
65
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.
69
67
70
68
## Tested
71
69
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.
73
71
74
72
## Testing
75
73
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.
77
75
78
76
Said that, I'm thinking about adding some integration testing with Docker, but for now, I've enough if the examples are working.
79
77
@@ -93,18 +91,20 @@ In python, the component is called graph_objects, like in this package, but that
93
91
94
92
### How are the graph_object files generated?
95
93
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!!
97
95
98
96
### What are the usecases?
99
97
100
98
1. Send plotly figures to the frontend ready to be drawn, avoiding possible mistakes in JS thanks to types!
101
99
102
100
2. Generate an awesome dynamic plot in a local file with offline package.
103
101
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.
105
103
106
104
### Why are the String and Bool types defined?
107
105
106
+
> I'm thinking about defining everything as a pointer, it should be better in the long run
107
+
108
108
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.
109
109
110
110
For bool, the solution is as simple as defining the types again inside graph_objects and it feels like using normal bool values.
0 commit comments