38
expected: `<use x="0" y="0" xlink:href="#serviceBlock" id="foo" />
39
<image x="46" y="46" width="96" height="96" xlink:href="foo" />
40
<g style="font-size:18px;fill:#505050;text-anchor:middle">
41
<text x="94" y="31" >foo</text>
38
expected: `<g transform="translate(0,0)" >
40
<circle cx="90" cy="90" r="90" class="service-block" fill="#f5f5f5" stroke="#888" stroke-width="1" />
41
<circle cx="47" cy="49" r="45" id="service-icon-mask-foo" fill="none" />
42
<clipPath id="clip-foo" ><use x="0" y="0" xlink:href="#service-icon-mask-foo" />
44
<image x="42" y="42" width="96" height="96" xlink:href="foo" clip-path="url(#clip-foo)" />
45
<rect x="0" y="135" width="180" height="32" rx="2" ry="2" fill="rgba(220, 220, 220, 0.8)" />
46
<text x="90" y="157" text-anchor="middle" style="font-weight:200" >foo</text>
54
59
iconSrc: []byte("<svg>bar</svg>"),
56
expected: `<svg:svg xmlns:svg="http://www.w3.org/2000/svg" id="icon-1">bar</svg:svg><use x="0" y="0" xlink:href="#serviceBlock" id="bar" />
57
<use x="46" y="46" xlink:href="#icon-1" width="96" height="96" />
58
<g style="font-size:18px;fill:#505050;text-anchor:middle">
59
<text x="94" y="31" >bar</text>
61
expected: `<svg:svg xmlns:svg="http://www.w3.org/2000/svg" id="icon-1">bar</svg:svg><g transform="translate(0,0)" >
63
<circle cx="90" cy="90" r="90" class="service-block" fill="#f5f5f5" stroke="#888" stroke-width="1" />
64
<circle cx="47" cy="49" r="45" id="service-icon-mask-bar" fill="none" />
65
<clipPath id="clip-bar" ><use x="0" y="0" xlink:href="#service-icon-mask-bar" />
67
<use x="0" y="0" xlink:href="#icon-1" transform="translate(42,42)" width="96" height="96" clip-path="url(#clip-bar)" />
68
<rect x="0" y="135" width="180" height="32" rx="2" ry="2" fill="rgba(220, 220, 220, 0.8)" />
69
<text x="90" y="157" text-anchor="middle" style="font-weight:200" >bar</text>
72
82
iconSrc: []byte("<svg>bar</svg>"),
74
expected: `<use x="0" y="0" xlink:href="#serviceBlock" id="baz" />
75
<use x="46" y="46" xlink:href="#icon-1" width="96" height="96" />
76
<g style="font-size:18px;fill:#505050;text-anchor:middle">
77
<text x="94" y="31" >baz</text>
84
expected: `<g transform="translate(0,0)" >
86
<circle cx="90" cy="90" r="90" class="service-block" fill="#f5f5f5" stroke="#888" stroke-width="1" />
87
<circle cx="47" cy="49" r="45" id="service-icon-mask-baz" fill="none" />
88
<clipPath id="clip-baz" ><use x="0" y="0" xlink:href="#service-icon-mask-baz" />
90
<use x="0" y="0" xlink:href="#icon-1" transform="translate(42,42)" width="96" height="96" clip-path="url(#clip-baz)" />
91
<rect x="0" y="135" width="180" height="32" rx="2" ry="2" fill="rgba(220, 220, 220, 0.8)" />
92
<text x="90" y="157" text-anchor="middle" style="font-weight:200" >baz</text>
113
131
relation.definition(svg)
114
132
relation.usage(svg)
115
133
c.Assert(buf.String(), gc.Equals,
116
`<line x1="94" y1="189" x2="100" y2="194" stroke="#38B44A" stroke-width="2px" stroke-dasharray="-6.09, 20" />
117
<use x="87" y="181" xlink:href="#healthCircle" />
136
<line x1="90" y1="90" x2="190" y2="190" stroke="#a7a7a7" stroke-width="1px" stroke-dasharray="62.71, 16" />
137
<use x="132" y="132" xlink:href="#healthCircle" />
138
<circle cx="153" cy="153" r="4" fill="#a7a7a7" />
139
<circle cx="126" cy="126" r="4" fill="#a7a7a7" />
122
145
// Ensure that the SVG is sized exactly around the positioned services.
123
146
canvas := Canvas{}
124
147
canvas.addService(&service{
125
149
point: image.Point{
130
154
canvas.addService(&service{
131
156
point: image.Point{
136
161
width, height := canvas.layout()
137
c.Assert(width, gc.Equals, 289)
138
c.Assert(height, gc.Equals, 289)
162
c.Assert(width, gc.Equals, 281)
163
c.Assert(height, gc.Equals, 281)
139
164
canvas.addService(&service{
140
166
point: image.Point{
145
171
canvas.addService(&service{
146
173
point: image.Point{
151
178
canvas.addService(&service{
152
180
point: image.Point{
157
185
width, height = canvas.layout()
158
c.Assert(width, gc.Equals, 489)
159
c.Assert(height, gc.Equals, 389)
186
c.Assert(width, gc.Equals, 481)
187
c.Assert(height, gc.Equals, 381)
162
190
func (s *CanvasSuite) TestMarshal(c *gc.C) {
186
214
canvas.addService(serviceA)
187
215
canvas.addService(serviceB)
188
216
canvas.addRelation(&serviceRelation{
189
218
serviceA: serviceA,
190
219
serviceB: serviceB,
192
221
canvas.Marshal(&buf)
222
c.Logf("%s", buf.Bytes())
194
223
assertXMLEqual(c, buf.Bytes(), []byte(`
195
224
<?xml version="1.0"?>
196
225
<!-- Generated by SVGo -->
197
<svg width="289" height="289"
198
style="font-family:Ubuntu, sans-serif;" viewBox="0 0 289 289"
199
xmlns="http://www.w3.org/2000/svg"
226
<svg width="281" height="281"
227
style="font-family:Ubuntu, sans-serif;" viewBox="0 0 281 281"
228
xmlns="http://www.w3.org/2000/svg"
200
229
xmlns:xlink="http://www.w3.org/1999/xlink">
202
<g id="serviceBlock" transform="scale(0.8)" >`+assets.ServiceModule+`
204
<g id="healthCircle">
205
<circle cx="10" cy="10" r="10" style="stroke:#38B44A;fill:none;stroke-width:2px"/>
206
<circle cx="10" cy="10" r="5" style="fill:#38B44A"/>
231
<g id="healthCircle" transform="scale(1.1)" >`+assets.RelationIconHealthy+`
208
233
<svg xmlns="http://www.w3.org/2000/svg" class="blah" id="icon-1">
209
<circle cx="20" cy="20" r="20" style="fill:#000"></circle>
234
				<circle cx="20" cy="20" r="20" style="fill:#000"></circle>
235
			</svg></defs>
212
236
<g id="relations">
213
<line x1="94" y1="189" x2="100" y2="194" stroke="#38B44A" stroke-width="2px" stroke-dasharray="-6.09, 20" />
214
<use x="87" y="181" xlink:href="#healthCircle" />
238
<title>relation</title>
239
<line x1="90" y1="90" x2="190" y2="190" stroke="#a7a7a7" stroke-width="1px" stroke-dasharray="62.71, 16" />
240
<use x="132" y="132" xlink:href="#healthCircle" />
241
<circle cx="153" cy="153" r="4" fill="#a7a7a7" />
242
<circle cx="126" cy="126" r="4" fill="#a7a7a7" />
216
245
<g id="services">
217
<use x="0" y="0" xlink:href="#serviceBlock" id="service-a" />
218
<use x="46" y="46" xlink:href="#icon-1" width="96" height="96" />
219
<g style="font-size:18px;fill:#505050;text-anchor:middle">
220
<text x="94" y="31" >service-a</text>
246
<g transform="translate(0,0)" >
247
<title>service-a</title>
248
<circle cx="90" cy="90" r="90" class="service-block" fill="#f5f5f5" stroke="#888" stroke-width="1" />
249
<circle cx="47" cy="49" r="45" id="service-icon-mask-service-a" fill="none" />
250
<clipPath id="clip-service-a" ><use x="0" y="0" xlink:href="#service-icon-mask-service-a" />
252
<use x="0" y="0" xlink:href="#icon-1" transform="translate(42,42)" width="96" height="96" clip-path="url(#clip-service-a)" />
253
<rect x="0" y="135" width="180" height="32" rx="2" ry="2" fill="rgba(220, 220, 220, 0.8)" />
254
<text x="90" y="157" text-anchor="middle" style="font-weight:200" >service-a</text>
222
<use x="100" y="100" xlink:href="#serviceBlock" id="service-b" />
223
<image x="146" y="146" width="96" height="96" xlink:href="" />
224
<g style="font-size:18px;fill:#505050;text-anchor:middle">
225
<text x="194" y="131" >service-b</text>
256
<g transform="translate(100,100)" >
257
<title>service-b</title>
258
<circle cx="90" cy="90" r="90" class="service-block" fill="#f5f5f5" stroke="#888" stroke-width="1" />
259
<circle cx="47" cy="49" r="45" id="service-icon-mask-service-b" fill="none" />
260
<clipPath id="clip-service-b" ><use x="0" y="0" xlink:href="#service-icon-mask-service-b" />
262
<image x="42" y="42" width="96" height="96" xlink:href="" clip-path="url(#clip-service-b)" />
263
<rect x="0" y="135" width="180" height="32" rx="2" ry="2" fill="rgba(220, 220, 220, 0.8)" />
264
<text x="90" y="157" text-anchor="middle" style="font-weight:200" >service-b</text>