rebase and bug fix

This commit is contained in:
OneRain2333 2023-01-24 17:29:38 +08:00
parent ca08c8937d
commit c0821de872
3 changed files with 152 additions and 8 deletions

143
.idea/workspace.xml Normal file
View file

@ -0,0 +1,143 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="ALL" />
</component>
<component name="ChangeListManager">
<list default="true" id="8fbcc061-8398-43a7-b8a1-80961e4ad848" name="Changes" comment="update constant">
<change beforePath="$PROJECT_DIR$/ci/sub" beforeDir="false" afterPath="$PROJECT_DIR$/ci/sub" afterDir="false" />
<change beforePath="$PROJECT_DIR$/d2renderers/d2sketch/sketch.go" beforeDir="false" afterPath="$PROJECT_DIR$/d2renderers/d2sketch/sketch.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/d2renderers/d2svg/d2svg.go" beforeDir="false" afterPath="$PROJECT_DIR$/d2renderers/d2svg/d2svg.go" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="GOROOT" url="file:///usr/lib/go" />
<component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$/ci/sub" value="b1ec0a8d430a62b7556211ed8bcd7b6e41e2362c" />
</map>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
<option name="RESET_MODE" value="HARD" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProblemsViewState">
<option name="selectedTabId" value="ProjectErrors" />
</component>
<component name="ProjectId" id="2KfsjNCf4NHNtiSaIaVjfXpGBpJ" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.go.formatter.settings.were.checked&quot;: &quot;true&quot;,
&quot;RunOnceActivity.go.migrated.go.modules.settings&quot;: &quot;true&quot;,
&quot;RunOnceActivity.go.modules.go.list.on.any.changes.was.set&quot;: &quot;true&quot;,
&quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
&quot;go.import.settings.migrated&quot;: &quot;true&quot;,
&quot;go.sdk.automatically.set&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;/home/onerain233&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;reference.settings.ide.settings.new.ui&quot;
}
}</component>
<component name="RunManager" selected="Go Build.go build oss.terrastruct.com/d2">
<configuration default="true" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="d2" />
<working_directory value="$PROJECT_DIR$" />
<kind value="FILE" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
<configuration name="go build d2" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true">
<module name="d2" />
<working_directory value="$PROJECT_DIR$" />
<kind value="PACKAGE" />
<package value="d2" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$/main.go" />
<method v="2" />
</configuration>
<configuration name="go build github.com/OneRain233/d2" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
<module name="d2" />
<working_directory value="$PROJECT_DIR$" />
<kind value="PACKAGE" />
<package value="github.com/OneRain233/d2" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$/main.go" />
<method v="2" />
</configuration>
<configuration name="go build oss.terrastruct.com/d2" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
<module name="d2" />
<working_directory value="$PROJECT_DIR$" />
<kind value="PACKAGE" />
<package value="oss.terrastruct.com/d2" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$/main.go" />
<method v="2" />
</configuration>
<configuration default="true" type="GoTestRunConfiguration" factoryName="Go Test">
<module name="d2" />
<working_directory value="$PROJECT_DIR$" />
<kind value="DIRECTORY" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<framework value="gotest" />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Go Build.go build oss.terrastruct.com/d2" />
<item itemvalue="Go Build.go build github.com/OneRain233/d2" />
<item itemvalue="Go Build.go build d2" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State>
<option name="FILTERS">
<map>
<entry key="branch">
<value>
<list>
<option value="master" />
</list>
</value>
</entry>
</map>
</option>
</State>
</value>
</entry>
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="fix typo" />
<MESSAGE value="Use constant to define offset of double-bordered shape" />
<MESSAGE value="update constant" />
<option name="LAST_COMMIT_MESSAGE" value="update constant" />
</component>
<component name="VgoProject">
<settings-migrated>true</settings-migrated>
</component>
</project>

View file

@ -98,7 +98,7 @@ func DoubleRect(r *Runner, shape d2target.Shape) (string, error) {
strokeWidth: %d,
%s
});`, shape.Width, shape.Height, shape.Fill, shape.Stroke, shape.StrokeWidth, baseRoughProps)
pathsBigRect, err := computeRoughPaths(r, jsBigRect)
pathsBigRect, err := computeRoughPathData(r, jsBigRect)
if err != nil {
return "", err
}
@ -108,7 +108,7 @@ func DoubleRect(r *Runner, shape d2target.Shape) (string, error) {
strokeWidth: %d,
%s
});`, shape.Width-d2target.INNER_BORDER_OFFSET*2, shape.Height-d2target.INNER_BORDER_OFFSET*2, shape.Fill, shape.Stroke, shape.StrokeWidth, baseRoughProps)
pathsSmallRect, err := computeRoughPaths(r, jsSmallRect)
pathsSmallRect, err := computeRoughPathData(r, jsSmallRect)
if err != nil {
return "", err
}
@ -116,13 +116,13 @@ func DoubleRect(r *Runner, shape d2target.Shape) (string, error) {
for _, p := range pathsBigRect {
output += fmt.Sprintf(
`<path class="shape" transform="translate(%d %d)" d="%s" style="%s" />`,
shape.Pos.X, shape.Pos.Y, p, shapeStyle(shape),
shape.Pos.X, shape.Pos.Y, p, shape.CSSStyle(),
)
}
for _, p := range pathsSmallRect {
output += fmt.Sprintf(
`<path class="shape" transform="translate(%d %d)" d="%s" style="%s" />`,
shape.Pos.X+d2target.INNER_BORDER_OFFSET, shape.Pos.Y+d2target.INNER_BORDER_OFFSET, p, shapeStyle(shape),
shape.Pos.X+d2target.INNER_BORDER_OFFSET, shape.Pos.Y+d2target.INNER_BORDER_OFFSET, p, shape.CSSStyle(),
)
}
output += fmt.Sprintf(
@ -170,11 +170,11 @@ func DoubleOval(r *Runner, shape d2target.Shape) (string, error) {
strokeWidth: %d,
%s
});`, shape.Width/2, shape.Height/2, shape.Width-d2target.INNER_BORDER_OFFSET*2, shape.Height-d2target.INNER_BORDER_OFFSET*2, shape.Fill, shape.Stroke, shape.StrokeWidth, baseRoughProps)
pathsBigCircle, err := computeRoughPaths(r, jsBigCircle)
pathsBigCircle, err := computeRoughPathData(r, jsBigCircle)
if err != nil {
return "", err
}
pathsSmallCircle, err := computeRoughPaths(r, jsSmallCircle)
pathsSmallCircle, err := computeRoughPathData(r, jsSmallCircle)
if err != nil {
return "", err
}
@ -182,13 +182,13 @@ func DoubleOval(r *Runner, shape d2target.Shape) (string, error) {
for _, p := range pathsBigCircle {
output += fmt.Sprintf(
`<path class="shape" transform="translate(%d %d)" d="%s" style="%s" />`,
shape.Pos.X, shape.Pos.Y, p, shapeStyle(shape),
shape.Pos.X, shape.Pos.Y, p, shape.CSSStyle(),
)
}
for _, p := range pathsSmallCircle {
output += fmt.Sprintf(
`<path class="shape" transform="translate(%d %d)" d="%s" style="%s" />`,
shape.Pos.X, shape.Pos.Y, p, shapeStyle(shape),
shape.Pos.X, shape.Pos.Y, p, shape.CSSStyle(),
)
}
output += fmt.Sprintf(

View file

@ -794,6 +794,7 @@ func drawShape(writer io.Writer, targetShape d2target.Shape, sketchRunner *d2ske
fmt.Fprint(writer, renderOval(tl, width, height, style))
}
}
case d2target.ShapeImage:
fmt.Fprintf(writer, `<image href="%s" x="%d" y="%d" width="%d" height="%d" style="%s" />`,
html.EscapeString(targetShape.Icon.String()),