Skip to content

Commit 267a535

Browse files
committed
graph style
1 parent 40db391 commit 267a535

File tree

3 files changed

+73
-13
lines changed

3 files changed

+73
-13
lines changed

scaladoc/resources/dotty_res/scripts/ux.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ function showGraph() {
171171
if (dotNode) {
172172
var svg = d3.select("#graph");
173173
var radialGradient = svg.append("defs").append("radialGradient").attr("id", "Gradient");
174-
radialGradient.append("stop").attr("stop-color", "var(--aureole)").attr("offset", "20%");
175-
radialGradient.append("stop").attr("stop-color", "var(--code-bg)").attr("offset", "100%");
174+
radialGradient.append("stop").attr("stop-color", "var(--yellow9)").attr("offset", "30%");
175+
radialGradient.append("stop").attr("stop-color", "var(--background-default)").attr("offset", "100%");
176176

177177
var inner = svg.append("g");
178178

@@ -190,8 +190,10 @@ function showGraph() {
190190
g.setNode(v, {
191191
labelType: "html",
192192
label: g.node(v).label,
193-
style: g.node(v).style,
194-
id: g.node(v).id
193+
class: g.node(v).class,
194+
id: g.node(v).id,
195+
rx: "4px",
196+
ry: "4px"
195197
});
196198
});
197199
g.setNode("node0Cluster", {
@@ -202,9 +204,30 @@ function showGraph() {
202204

203205
g.edges().forEach(function (v) {
204206
g.setEdge(v, {
205-
arrowhead: "vee"
207+
arrowhead: "hollowPoint",
206208
});
207209
});
210+
211+
render.arrows().hollowPoint = function normal(parent, id, edge, type) {
212+
var marker = parent.append("marker")
213+
.attr("id", id)
214+
.attr("viewBox", "0 0 10 10")
215+
.attr("refX", 9)
216+
.attr("refY", 5)
217+
.attr("markerUnits", "strokeWidth")
218+
.attr("markerWidth", 12)
219+
.attr("markerHeight", 12)
220+
.attr("orient", "auto");
221+
222+
var path = marker.append("path")
223+
.attr("d", "M 0 0 L 10 5 L 0 10 z")
224+
.style("stroke-width", 1)
225+
.style("stroke-dasharray", "1,0")
226+
.style("fill", "var(--grey12)")
227+
.style("stroke", "var(--grey12)");
228+
dagreD3.util.applyStyle(path, edge[type + "Style"]);
229+
};
230+
208231
render(inner, g);
209232

210233
// Set the 'fit to content graph' upon landing on the page

scaladoc/resources/dotty_res/styles/theme/components/diagram.css

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,38 @@
3535
width: 100%;
3636
height: calc(50 * var(--base-spacing));
3737
}
38+
39+
#inheritance-diagram .vertex {
40+
border-radius: 4px;
41+
}
42+
43+
/* Colors */
44+
45+
#inheritance-diagram span, #inheritance-diagram a {
46+
color: var(--grey1) !important;
47+
}
48+
49+
#inheritance-diagram .edgePath {
50+
stroke: var(--grey12);
51+
}
52+
53+
#inheritance-diagram .class {
54+
fill: var(--mint11);
55+
}
56+
57+
#inheritance-diagram .trait {
58+
fill: var(--sky11);
59+
}
60+
61+
#inheritance-diagram .object {
62+
fill: var(--indigo11);
63+
}
64+
65+
#inheritance-diagram .enum {
66+
fill: var(--orange11);
67+
}
68+
69+
#inheritance-diagram .enumcase {
70+
fill: var(--orange11);
71+
}
72+

scaladoc/src/dotty/tools/scaladoc/renderers/DotDiagramBuilder.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@ import util.HTML._
55

66
object DotDiagramBuilder:
77
def build(diagram: HierarchyGraph, renderer: SignatureRenderer)(using DocContext): String =
8-
def getStyle(kind: Kind) = kind match
9-
case _ : Kind.Class => "fill: #45AD7D;"
10-
case Kind.Object => "fill: #285577;"
11-
case _ : Kind.Trait => "fill: #1CAACF;"
12-
case e if e.isInstanceOf[Kind.Enum] => "fill: #B66722;"
13-
case e if e.isInstanceOf[Kind.EnumCase] => "fill: #B66722;"
14-
case other => report.error(s"unexpected value: $other")
8+
def getClasses(kind: Kind): String =
9+
val kindClass = kind match
10+
case _ : Kind.Class => "class"
11+
case Kind.Object => "object"
12+
case _ : Kind.Trait => "trait"
13+
case e if e.isInstanceOf[Kind.Enum] => "enum"
14+
case e if e.isInstanceOf[Kind.EnumCase] => "enumcase"
15+
case other => report.error(s"unexpected value: $other")
16+
s"$kindClass vertex"
1517

1618
val vWithId = diagram.verteciesWithId
1719
val sealedNodes = diagram.sealedNodes
1820
val vertecies = vWithId.toList.sortBy((_, id) => id).map { (vertex, id) =>
19-
s"""node${id} [id=node${id}, label="${getHtmlLabel(vertex, renderer, sealedNodes)}", style="${getStyle(vertex.kind)}"];\n"""
21+
s"""node${id} [id=node${id}, label="${getHtmlLabel(vertex, renderer, sealedNodes)}", class="${getClasses(vertex.kind)}"];\n"""
2022
}.mkString
2123

2224
val edges = diagram.edges.map { (from, to) =>

0 commit comments

Comments
 (0)