-
Notifications
You must be signed in to change notification settings - Fork 666
feat: add ability to fade multiple #2509
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
base: master
Are you sure you want to change the base?
Changes from 7 commits
af5b671
9ea469a
faa8c41
da130c7
7e3fbd7
e73a58d
871978c
8bacca9
8083fb2
45f038c
8fb989d
ffb39df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -756,6 +756,13 @@ func (c *compiler) compileStyleField(styles *d2graph.Style, f *d2ir.Field) { | |||||||||||||
| c.errorf(f.LastRef().AST(), `invalid style keyword: "%s"`, f.Name.ScalarString()) | ||||||||||||||
| return | ||||||||||||||
| } | ||||||||||||||
| if f.Map() != nil { | ||||||||||||||
| fields := f.Map().Fields | ||||||||||||||
| for i := 0; i < len(fields); i++ { | ||||||||||||||
| field := fields[i] | ||||||||||||||
| c.compileCompositeStyle(styles, field, f.Name.ScalarString()) | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+760
to
+786
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should be a code smell to you that you need this much extra code. There's a more precise place to make these changes
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, we can simplify the process by modifying Lines 788 to 792 in b2841d5
as: func (c *compiler) compileStyle(styles *d2graph.Style, m *d2ir.Map) {
for _, f := range m.Fields {
c.compileStyleField(styles, f)
if f.Map() != nil {
for _, ff := range f.Map().Fields {
c.compileStyleField(styles, ff)
}
}
}
}However, as it’s not possible to get the parent field of a particular field, we need to pass a new parameter to Line 794 in b2841d5
to identify the parent field for opacity. |
||||||||||||||
| if f.Primary() == nil { | ||||||||||||||
| return | ||||||||||||||
| } | ||||||||||||||
|
|
@@ -768,6 +775,31 @@ func (c *compiler) compileStyleField(styles *d2graph.Style, f *d2ir.Field) { | |||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| func (c *compiler) compileCompositeStyle(styles *d2graph.Style, f *d2ir.Field, parent string) { | ||||||||||||||
| if _, ok := d2ast.CompositeStyleKeywords[strings.ToLower(parent)]; !(ok && f.Name.IsUnquoted()) { | ||||||||||||||
| c.errorf(f.LastRef().AST(), `invalid composite style keyword: "%s"`, f.Name.ScalarString()) | ||||||||||||||
| return | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| allowedStyle := d2ast.CompositeStyleKeywords[strings.ToLower(parent)] | ||||||||||||||
|
|
||||||||||||||
| if allowedStyle != strings.ToLower(f.Name.ScalarString()) { | ||||||||||||||
| c.errorf(f.LastRef().AST(), `invalid style "%s" for composite style keyword: "%s"`, f.Name.ScalarString(), parent) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if f.Primary() == nil { | ||||||||||||||
| return | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| compileCompositeStyleFieldInit(styles, f, parent) | ||||||||||||||
| scalar := f.Primary().Value | ||||||||||||||
| err := styles.ApplyComposite(f.Name.ScalarString(), scalar.ScalarString(), parent) | ||||||||||||||
| if err != nil { | ||||||||||||||
| c.errorf(scalar, err.Error()) | ||||||||||||||
| return | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| func compileStyleFieldInit(styles *d2graph.Style, f *d2ir.Field) { | ||||||||||||||
| switch f.Name.ScalarString() { | ||||||||||||||
| case "opacity": | ||||||||||||||
|
|
@@ -813,6 +845,15 @@ func compileStyleFieldInit(styles *d2graph.Style, f *d2ir.Field) { | |||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| func compileCompositeStyleFieldInit(styles *d2graph.Style, f *d2ir.Field, parent string) { | ||||||||||||||
| switch f.Name.ScalarString() { | ||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I coundn't find an way to fetch parent value for current keyword, so defined a new function instead of using the existing func
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the other comment, since nested keywords are already implemented elsewhere, you should question why you'd need a new function for this case. |
||||||||||||||
| case "opacity": | ||||||||||||||
| if parent == "multiple" { | ||||||||||||||
| styles.MultipleOpacity = &d2graph.Scalar{MapKey: f.LastPrimaryKey()} | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| func (c *compiler) compileEdge(obj *d2graph.Object, e *d2ir.Edge) { | ||||||||||||||
| edge, err := obj.Connect(e.ID.SrcPath, e.ID.DstPath, e.ID.SrcArrow, e.ID.DstArrow, "") | ||||||||||||||
| if err != nil { | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -281,26 +281,27 @@ func (r Reference) InEdge() bool { | |
| } | ||
|
|
||
| type Style struct { | ||
| Opacity *Scalar `json:"opacity,omitempty"` | ||
| Stroke *Scalar `json:"stroke,omitempty"` | ||
| Fill *Scalar `json:"fill,omitempty"` | ||
| FillPattern *Scalar `json:"fillPattern,omitempty"` | ||
| StrokeWidth *Scalar `json:"strokeWidth,omitempty"` | ||
| StrokeDash *Scalar `json:"strokeDash,omitempty"` | ||
| BorderRadius *Scalar `json:"borderRadius,omitempty"` | ||
| Shadow *Scalar `json:"shadow,omitempty"` | ||
| ThreeDee *Scalar `json:"3d,omitempty"` | ||
| Multiple *Scalar `json:"multiple,omitempty"` | ||
| Font *Scalar `json:"font,omitempty"` | ||
| FontSize *Scalar `json:"fontSize,omitempty"` | ||
| FontColor *Scalar `json:"fontColor,omitempty"` | ||
| Animated *Scalar `json:"animated,omitempty"` | ||
| Bold *Scalar `json:"bold,omitempty"` | ||
| Italic *Scalar `json:"italic,omitempty"` | ||
| Underline *Scalar `json:"underline,omitempty"` | ||
| Filled *Scalar `json:"filled,omitempty"` | ||
| DoubleBorder *Scalar `json:"doubleBorder,omitempty"` | ||
| TextTransform *Scalar `json:"textTransform,omitempty"` | ||
| Opacity *Scalar `json:"opacity,omitempty"` | ||
| Stroke *Scalar `json:"stroke,omitempty"` | ||
| Fill *Scalar `json:"fill,omitempty"` | ||
| FillPattern *Scalar `json:"fillPattern,omitempty"` | ||
| StrokeWidth *Scalar `json:"strokeWidth,omitempty"` | ||
| StrokeDash *Scalar `json:"strokeDash,omitempty"` | ||
| BorderRadius *Scalar `json:"borderRadius,omitempty"` | ||
| Shadow *Scalar `json:"shadow,omitempty"` | ||
| ThreeDee *Scalar `json:"3d,omitempty"` | ||
| Multiple *Scalar `json:"multiple,omitempty"` | ||
| MultipleOpacity *Scalar `json:"multipleOpacity,omitempty"` | ||
| Font *Scalar `json:"font,omitempty"` | ||
| FontSize *Scalar `json:"fontSize,omitempty"` | ||
| FontColor *Scalar `json:"fontColor,omitempty"` | ||
| Animated *Scalar `json:"animated,omitempty"` | ||
| Bold *Scalar `json:"bold,omitempty"` | ||
| Italic *Scalar `json:"italic,omitempty"` | ||
| Underline *Scalar `json:"underline,omitempty"` | ||
| Filled *Scalar `json:"filled,omitempty"` | ||
| DoubleBorder *Scalar `json:"doubleBorder,omitempty"` | ||
| TextTransform *Scalar `json:"textTransform,omitempty"` | ||
| } | ||
|
|
||
| // NoneTextTransform will return a boolean if the text should not have any | ||
|
|
@@ -493,6 +494,25 @@ func (s *Style) Apply(key, value string) error { | |
| return nil | ||
| } | ||
|
|
||
| func (s *Style) ApplyComposite(key, value, parent string) error { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to |
||
| switch key { | ||
| case "opacity": | ||
| f, err := strconv.ParseFloat(value, 64) | ||
| if err != nil || (f < 0 || f > 1) { | ||
| return errors.New(`expected "opacity" to be a number between 0.0 and 1.0`) | ||
| } | ||
| if parent == "multiple" { | ||
| if s.MultipleOpacity == nil { | ||
| break | ||
| } | ||
| s.MultipleOpacity.Value = value | ||
| } | ||
| default: | ||
| return fmt.Errorf("unknown style key: %s", key) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| type ContainerLevel int | ||
|
|
||
| func (l ContainerLevel) LabelSize() int { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, CompositeStyleKeywords is of type
map[string]string, but in future if we support more styles undermultiplewe can convert it tomap[string][]stringto hold more values under one style.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we shouldn't need this. for example, the ability to do
label.nearis implemented, but there's no special map for that.