~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/gopkg.in/juju/jujusvg.v1/canvas_test.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
                                },
36
36
                                iconUrl: "foo",
37
37
                        },
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)" >
 
39
<title>foo</title>
 
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" />
 
43
</clipPath>
 
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>
42
47
</g>
43
48
`,
44
49
                },
53
58
                                },
54
59
                                iconSrc: []byte("<svg>bar</svg>"),
55
60
                        },
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)" >
 
62
<title>bar</title>
 
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" />
 
66
</clipPath>
 
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>
60
70
</g>
61
71
`,
62
72
                },
71
81
                                },
72
82
                                iconSrc: []byte("<svg>bar</svg>"),
73
83
                        },
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)" >
 
85
<title>baz</title>
 
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" />
 
89
</clipPath>
 
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>
78
93
</g>
79
94
`,
80
95
                },
87
102
                svg := svg.New(&buf)
88
103
                test.service.definition(svg, iconsRendered, iconIds)
89
104
                test.service.usage(svg, iconIds)
 
105
                c.Log(test.about)
 
106
                c.Log(buf.String())
90
107
                c.Assert(buf.String(), gc.Equals, test.expected)
91
108
        }
92
109
}
97
114
        var buf bytes.Buffer
98
115
        svg := svg.New(&buf)
99
116
        relation := serviceRelation{
 
117
                name: "foo",
100
118
                serviceA: &service{
101
119
                        point: image.Point{
102
120
                                X: 0,
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" />
 
134
                `<g >
 
135
<title>foo</title>
 
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" />
 
140
</g>
118
141
`)
119
142
}
120
143
 
122
145
        // Ensure that the SVG is sized exactly around the positioned services.
123
146
        canvas := Canvas{}
124
147
        canvas.addService(&service{
 
148
                name: "service1",
125
149
                point: image.Point{
126
150
                        X: 0,
127
151
                        Y: 0,
128
152
                },
129
153
        })
130
154
        canvas.addService(&service{
 
155
                name: "service2",
131
156
                point: image.Point{
132
157
                        X: 100,
133
158
                        Y: 100,
134
159
                },
135
160
        })
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{
 
165
                name: "service3",
140
166
                point: image.Point{
141
167
                        X: -100,
142
168
                        Y: -100,
143
169
                },
144
170
        })
145
171
        canvas.addService(&service{
 
172
                name: "service4",
146
173
                point: image.Point{
147
174
                        X: -100,
148
175
                        Y: 100,
149
176
                },
150
177
        })
151
178
        canvas.addService(&service{
 
179
                name: "service5",
152
180
                point: image.Point{
153
181
                        X: 200,
154
182
                        Y: -100,
155
183
                },
156
184
        })
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)
160
188
}
161
189
 
162
190
func (s *CanvasSuite) TestMarshal(c *gc.C) {
186
214
        canvas.addService(serviceA)
187
215
        canvas.addService(serviceB)
188
216
        canvas.addRelation(&serviceRelation{
 
217
                name:     "relation",
189
218
                serviceA: serviceA,
190
219
                serviceB: serviceB,
191
220
        })
192
221
        canvas.Marshal(&buf)
193
 
        c.Logf("%s", 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">
201
230
<defs>
202
 
<g id="serviceBlock" transform="scale(0.8)" >`+assets.ServiceModule+`
203
 
</g>
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+`
207
232
</g>
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>
210
 
</svg>
211
 
</defs>
 
234
&#x9;&#x9;&#x9;&#x9;<circle cx="20" cy="20" r="20" style="fill:#000"></circle>
 
235
&#x9;&#x9;&#x9;</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" />
 
237
<g>
 
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" />
 
243
</g>
215
244
</g>
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" />
 
251
</clipPath>
 
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>
221
255
</g>
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" />
 
261
</clipPath>
 
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>
226
265
</g>
227
266
</g>
228
267
</svg>