fix font-color for tables and class

This commit is contained in:
Alexander Wang 2023-02-24 20:26:40 -08:00
parent 4411fbdabc
commit 0216c8b5f0
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
14 changed files with 50 additions and 27 deletions

View file

@ -382,7 +382,7 @@ func Table(r *Runner, shape d2target.Shape) (string, error) {
textEl := d2themes.NewThemableElement("text")
textEl.X = tl.X
textEl.Y = tl.Y + float64(shape.LabelHeight)*3/4
textEl.Fill = shape.Stroke
textEl.Fill = shape.GetFontColor()
textEl.ClassName = "text"
textEl.Style = fmt.Sprintf("text-anchor:%s;font-size:%vpx",
"start", 4+shape.FontSize,
@ -532,7 +532,7 @@ func Class(r *Runner, shape d2target.Shape) (string, error) {
textEl := d2themes.NewThemableElement("text")
textEl.X = tl.X + float64(shape.LabelWidth)/2
textEl.Y = tl.Y + float64(shape.LabelHeight)*3/4
textEl.Fill = shape.Stroke
textEl.Fill = shape.GetFontColor()
textEl.ClassName = "text-mono"
textEl.Style = fmt.Sprintf("text-anchor:%s;font-size:%vpx",
"middle",

View file

@ -30,7 +30,7 @@ func classHeader(shape d2target.Shape, box *geo.Box, text string, textWidth, tex
textEl := d2themes.NewThemableElement("text")
textEl.X = tl.X + textWidth/2
textEl.Y = tl.Y + textHeight*3/4
textEl.Fill = shape.Stroke
textEl.Fill = shape.GetFontColor()
textEl.ClassName = "text-mono"
textEl.Style = fmt.Sprintf(`text-anchor:%s;font-size:%vpx;`,
"middle", 4+fontSize,

View file

@ -562,11 +562,6 @@ func drawConnection(writer io.Writer, labelMaskID string, connection d2target.Co
} else if connection.Italic {
fontClass += "-italic"
}
fontColor := color.N1
if connection.Color != color.Empty {
fontColor = connection.Color
}
if connection.Fill != color.Empty {
rectEl := d2themes.NewThemableElement("rect")
rectEl.X, rectEl.Y = labelTL.X, labelTL.Y
@ -578,7 +573,7 @@ func drawConnection(writer io.Writer, labelMaskID string, connection d2target.Co
textEl := d2themes.NewThemableElement("text")
textEl.X = labelTL.X + float64(connection.LabelWidth)/2
textEl.Y = labelTL.Y + float64(connection.FontSize)
textEl.Fill = fontColor
textEl.Fill = connection.GetFontColor()
textEl.ClassName = fontClass
textEl.Style = fmt.Sprintf("text-anchor:%s;font-size:%vpx", "middle", connection.FontSize)
textEl.Content = RenderText(connection.Label, textEl.X, float64(connection.LabelHeight))
@ -1112,10 +1107,6 @@ func drawShape(writer io.Writer, targetShape d2target.Shape, sketchRunner *d2ske
fmt.Fprint(writer, mdEl.Render())
fmt.Fprint(writer, `</foreignObject></g>`)
} else {
fontColor := color.N1
if targetShape.Color != color.Empty {
fontColor = targetShape.Color
}
if targetShape.LabelFill != "" {
rectEl := d2themes.NewThemableElement("rect")
rectEl.X = labelTL.X
@ -1129,7 +1120,7 @@ func drawShape(writer io.Writer, targetShape d2target.Shape, sketchRunner *d2ske
textEl.X = labelTL.X + float64(targetShape.LabelWidth)/2
// text is vertically positioned at its baseline which is at labelTL+FontSize
textEl.Y = labelTL.Y + float64(targetShape.FontSize)
textEl.Fill = fontColor
textEl.Fill = targetShape.GetFontColor()
textEl.ClassName = fontClass
textEl.Style = fmt.Sprintf("text-anchor:%s;font-size:%vpx", "middle", targetShape.FontSize)
textEl.Content = RenderText(targetShape.Label, textEl.X, float64(targetShape.LabelHeight))

View file

@ -31,7 +31,7 @@ func tableHeader(shape d2target.Shape, box *geo.Box, text string, textWidth, tex
textEl := d2themes.NewThemableElement("text")
textEl.X = tl.X
textEl.Y = tl.Y + textHeight*3/4
textEl.Fill = shape.Stroke
textEl.Fill = shape.GetFontColor()
textEl.ClassName = "text"
textEl.Style = fmt.Sprintf("text-anchor:%s;font-size:%vpx",
"start", 4+fontSize,

View file

@ -197,6 +197,19 @@ type Shape struct {
NeutralAccentColor string `json:"neutralAccentColor,omitempty"`
}
func (s Shape) GetFontColor() string {
if s.Type == ShapeClass || s.Type == ShapeSQLTable {
if !color.IsThemeColor(s.Color) {
return s.Color
}
return s.Stroke
}
if s.Color != color.Empty {
return s.Color
}
return color.N1
}
func (s Shape) CSSStyle() string {
out := ""
@ -302,6 +315,13 @@ func BaseConnection() *Connection {
}
}
func (c Connection) GetFontColor() string {
if c.Color != color.Empty {
return c.Color
}
return color.N1
}
func (c Connection) CSSStyle() string {
out := ""

View file

@ -37,7 +37,7 @@
svgEl.setAttribute("height", height * ratio - 16);
}
});
]]></script><g id="a"><g class="shape" ><rect x="12.000000" y="52.000000" width="117.000000" height="92.000000" class=" stroke-N1 fill-N7" style="stroke-width:2;" /><rect x="12.000000" y="52.000000" width="117.000000" height="92.000000" class="class_header fill-N1" /><text x="70.500000" y="105.750000" class="text-mono fill-N7" style="text-anchor:middle;font-size:24px;">a</text><line x1="12.000000" x2="129.000000" y1="144.000000" y2="144.000000" class=" stroke-N1" style="stroke-width:1" /></g></g><g id="(a -- )[0]"><path d="M 70.500000 146.000000 L 70.500000 213.000000" fill="none" class="connection stroke-B2" style="stroke-width:2;stroke-dasharray:12.000000,11.838767;" mask="url(#1142233560)" /></g><mask id="1142233560" maskUnits="userSpaceOnUse" x="10" y="50" width="121" height="164">
]]></script><g id="a"><g class="shape" ><rect x="12.000000" y="52.000000" width="117.000000" height="92.000000" class=" stroke-N1 fill-N7" style="stroke-width:2;" /><rect x="12.000000" y="52.000000" width="117.000000" height="92.000000" class="class_header fill-N1" /><text x="70.500000" y="105.750000" fill="red" class="text-mono" style="text-anchor:middle;font-size:24px;">a</text><line x1="12.000000" x2="129.000000" y1="144.000000" y2="144.000000" class=" stroke-N1" style="stroke-width:1" /></g></g><g id="(a -- )[0]"><path d="M 70.500000 146.000000 L 70.500000 213.000000" fill="none" class="connection stroke-B2" style="stroke-width:2;stroke-dasharray:12.000000,11.838767;" mask="url(#1142233560)" /></g><mask id="1142233560" maskUnits="userSpaceOnUse" x="10" y="50" width="121" height="164">
<rect x="10" y="50" width="121" height="164" fill="white"></rect>
</mask></svg>

Before

Width:  |  Height:  |  Size: 186 KiB

After

Width:  |  Height:  |  Size: 186 KiB

View file

@ -37,7 +37,7 @@
svgEl.setAttribute("height", height * ratio - 16);
}
});
]]></script><g id="a"><g class="shape" ><rect x="12.000000" y="52.000000" width="117.000000" height="92.000000" class=" stroke-N1 fill-N7" style="stroke-width:2;" /><rect x="12.000000" y="52.000000" width="117.000000" height="92.000000" class="class_header fill-N1" /><text x="70.500000" y="105.750000" class="text-mono fill-N7" style="text-anchor:middle;font-size:24px;">a</text><line x1="12.000000" x2="129.000000" y1="144.000000" y2="144.000000" class=" stroke-N1" style="stroke-width:1" /></g></g><g id="(a -- )[0]"><path d="M 70.500000 146.000000 L 70.500000 213.000000" fill="none" class="connection stroke-B2" style="stroke-width:2;stroke-dasharray:12.000000,11.838767;" mask="url(#1142233560)" /></g><mask id="1142233560" maskUnits="userSpaceOnUse" x="10" y="50" width="121" height="164">
]]></script><g id="a"><g class="shape" ><rect x="12.000000" y="52.000000" width="117.000000" height="92.000000" class=" stroke-N1 fill-N7" style="stroke-width:2;" /><rect x="12.000000" y="52.000000" width="117.000000" height="92.000000" class="class_header fill-N1" /><text x="70.500000" y="105.750000" fill="red" class="text-mono" style="text-anchor:middle;font-size:24px;">a</text><line x1="12.000000" x2="129.000000" y1="144.000000" y2="144.000000" class=" stroke-N1" style="stroke-width:1" /></g></g><g id="(a -- )[0]"><path d="M 70.500000 146.000000 L 70.500000 213.000000" fill="none" class="connection stroke-B2" style="stroke-width:2;stroke-dasharray:12.000000,11.838767;" mask="url(#1142233560)" /></g><mask id="1142233560" maskUnits="userSpaceOnUse" x="10" y="50" width="121" height="164">
<rect x="10" y="50" width="121" height="164" fill="white"></rect>
</mask></svg>

Before

Width:  |  Height:  |  Size: 186 KiB

After

Width:  |  Height:  |  Size: 186 KiB

View file

@ -97,7 +97,7 @@
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "B5",
"fill": "N1",
"stroke": "N7",
"shadow": false,
"3d": false,
@ -819,7 +819,7 @@
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "B5",
"fill": "N1",
"stroke": "N7",
"shadow": false,
"3d": false,

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 849 KiB

After

Width:  |  Height:  |  Size: 849 KiB

View file

@ -97,7 +97,7 @@
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "B5",
"fill": "N1",
"stroke": "N7",
"shadow": false,
"3d": false,
@ -819,7 +819,7 @@
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "B5",
"fill": "N1",
"stroke": "N7",
"shadow": false,
"3d": false,

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 849 KiB

After

Width:  |  Height:  |  Size: 849 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 517 KiB

After

Width:  |  Height:  |  Size: 517 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 517 KiB

After

Width:  |  Height:  |  Size: 517 KiB

12
testdata/d2compiler/TestCompile/near_sequence.exp.json generated vendored Normal file
View file

@ -0,0 +1,12 @@
{
"graph": null,
"err": {
"ioerr": null,
"errs": [
{
"range": "d2/testdata/d2compiler/TestCompile/near_sequence.d2,4:8:45-4:11:48",
"errmsg": "d2/testdata/d2compiler/TestCompile/near_sequence.d2:5:9: near keys cannot be set to an object within sequence diagrams"
}
]
}
}