Skip to content

Commit

Permalink
enable using all features of array types
Browse files Browse the repository at this point in the history
  • Loading branch information
pafo committed May 18, 2024
1 parent ba1ab36 commit 8017dac
Show file tree
Hide file tree
Showing 46 changed files with 910 additions and 710 deletions.
190 changes: 190 additions & 0 deletions examples/go.sum

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions generator/typefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,23 @@ func (file *typeFile) parseAttributes(namePrefix string, typePrefix string, attr
}

attr := attr[name]
// if arrays are allowed, example marker sizes, then javascript allows multiple different inputs hard to map in golang:
// [100,50,25,25,50,100] -> use different sizes for the markers
// [100] -> only the first marker will have size 100, all others have 0 size
// 100 -> all markers have size 100
// this can only be captures by using interface and allowing the user to define the used type themselves.
// this sadly means that there is no more type checking on those entries
var adjust = func(typename string) string { return typename }
if attr.ArrayOK {
adjust = func(typename string) string { return "interface{}" }
}

switch {
case attr.Role == RoleObject && len(attr.Items) > 0:
fields = append(fields, structField{
Name: xstrings.ToCamelCase(attr.Name),
JSONName: attr.Name,
Type: "interface{}",
Type: adjust("interface{}"),
Description: []string{
"It's an items array and what goes inside it's... messy... check the docs",
"I will be happy if you want to contribute by implementing this",
Expand All @@ -109,7 +119,7 @@ func (file *typeFile) parseAttributes(namePrefix string, typePrefix string, attr
fields = append(fields, structField{
Name: xstrings.ToCamelCase(attr.Name),
JSONName: attr.Name,
Type: "*" + name,
Type: adjust("*" + name),
Description: []string{
"role: Object",
},
Expand All @@ -124,7 +134,7 @@ func (file *typeFile) parseAttributes(namePrefix string, typePrefix string, attr
fields = append(fields, structField{
Name: xstrings.ToCamelCase(attr.Name),
JSONName: attr.Name,
Type: typePrefix + xstrings.ToCamelCase(attr.Name),
Type: adjust(typePrefix + xstrings.ToCamelCase(attr.Name)),
Description: []string{
fmt.Sprintf("default: %s", attr.Dflt),
fmt.Sprintf("type: %s", attr.ValType),
Expand All @@ -142,7 +152,7 @@ func (file *typeFile) parseAttributes(namePrefix string, typePrefix string, attr
fields = append(fields, structField{
Name: xstrings.ToCamelCase(attr.Name),
JSONName: attr.Name,
Type: typeName,
Type: adjust(typeName),
Description: []string{
fmt.Sprintf("default: %s", attr.Dflt),
fmt.Sprintf("type: %s", attr.ValType),
Expand All @@ -154,7 +164,7 @@ func (file *typeFile) parseAttributes(namePrefix string, typePrefix string, attr
fields = append(fields, structField{
Name: xstrings.ToCamelCase(attr.Name),
JSONName: attr.Name,
Type: "ColorScale",
Type: adjust("ColorScale"),
Description: []string{
fmt.Sprintf("default: %s", attr.Dflt),
fmt.Sprintf("type: %s", attr.ValType),
Expand All @@ -167,7 +177,7 @@ func (file *typeFile) parseAttributes(namePrefix string, typePrefix string, attr
fields = append(fields, structField{
Name: xstrings.ToCamelCase(attr.Name),
JSONName: attr.Name,
Type: ty,
Type: adjust(ty),
Description: []string{
fmt.Sprintf("arrayOK: %t", attr.ArrayOK),
fmt.Sprintf("type: %s", attr.ValType),
Expand Down
24 changes: 12 additions & 12 deletions graph_objects/area_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8017dac

Please sign in to comment.