fastapi-voyager 0.4.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,580 @@
1
+ +(function ($) {
2
+ "use strict";
3
+
4
+ // GRAPHVIZSVG PUBLIC CLASS DEFINITION
5
+ // ===================================
6
+
7
+ var GraphvizSvg = function (element, options) {
8
+ this.type = null;
9
+ this.options = null;
10
+ this.enabled = null;
11
+ this.$element = null;
12
+
13
+ this.init("graphviz.svg", element, options);
14
+ };
15
+
16
+ GraphvizSvg.VERSION = "1.0.1";
17
+
18
+ GraphvizSvg.GVPT_2_PX = 32.5; // used to ease removal of extra space
19
+
20
+ GraphvizSvg.DEFAULTS = {
21
+ url: null,
22
+ svg: null,
23
+ shrink: "0.125pt",
24
+ tooltips: {
25
+ init: function ($graph) {
26
+ var $a = $(this);
27
+ $a.tooltip({
28
+ container: $graph,
29
+ placement: "left",
30
+ animation: false,
31
+ viewport: null,
32
+ }).on("hide.bs.tooltip", function () {
33
+ // keep them visible even if you acidentally mouse over
34
+ if ($a.attr("data-tooltip-keepvisible")) {
35
+ return false;
36
+ }
37
+ });
38
+ },
39
+ show: function () {
40
+ var $a = $(this);
41
+ $a.attr("data-tooltip-keepvisible", true);
42
+ $a.tooltip("show");
43
+ },
44
+ hide: function () {
45
+ var $a = $(this);
46
+ $a.removeAttr("data-tooltip-keepvisible");
47
+ $a.tooltip("hide");
48
+ },
49
+ update: function () {
50
+ var $this = $(this);
51
+ if ($this.attr("data-tooltip-keepvisible")) {
52
+ $this.tooltip("show");
53
+ return;
54
+ }
55
+ },
56
+ },
57
+ zoom: true,
58
+ highlight: {
59
+ selected: function (col, bg) {
60
+ return col;
61
+ },
62
+ unselected: function (col, bg) {
63
+ return jQuery.Color(col).transition(bg, 0.9);
64
+ },
65
+ },
66
+ ready: null,
67
+ };
68
+
69
+ GraphvizSvg.prototype.init = function (type, element, options) {
70
+ this.enabled = true;
71
+ this.type = type;
72
+ this.$element = $(element);
73
+ this.options = this.getOptions(options);
74
+
75
+ if (options.url) {
76
+ var that = this;
77
+ $.get(
78
+ options.url,
79
+ null,
80
+ function (data) {
81
+ var svg = $("svg", data);
82
+ that.$element.html(document.adoptNode(svg[0]));
83
+ that.setup();
84
+ },
85
+ "xml"
86
+ );
87
+ } else {
88
+ if (options.svg) {
89
+ this.$element.html(options.svg);
90
+ }
91
+ this.setup();
92
+ }
93
+ };
94
+
95
+ GraphvizSvg.prototype.getDefaults = function () {
96
+ return GraphvizSvg.DEFAULTS;
97
+ };
98
+
99
+ GraphvizSvg.prototype.getOptions = function (options) {
100
+ options = $.extend({}, this.getDefaults(), this.$element.data(), options);
101
+
102
+ if (options.shrink) {
103
+ if (typeof options.shrink != "object") {
104
+ options.shrink = {
105
+ x: options.shrink,
106
+ y: options.shrink,
107
+ };
108
+ }
109
+ options.shrink.x = this.convertToPx(options.shrink.x);
110
+ options.shrink.y = this.convertToPx(options.shrink.y);
111
+ }
112
+ return options;
113
+ };
114
+
115
+ GraphvizSvg.prototype.setup = function () {
116
+ var options = this.options;
117
+
118
+ // save key elements in the graph for easy access
119
+ var $svg = $(this.$element.children("svg"));
120
+ var $graph = $svg.children("g:first");
121
+ this.$svg = $svg;
122
+ this.$graph = $graph;
123
+ this.$background = $graph.children("polygon:first"); // might not exist
124
+ this.$nodes = $graph.children(".node");
125
+ this.$edges = $graph.children(".edge");
126
+ this.$clusters = $graph.children(".cluster");
127
+ this._nodesByName = {};
128
+ this._edgesByName = {};
129
+ this._clustersByName = {};
130
+
131
+ // add top level class and copy background color to element
132
+ this.$element.addClass("graphviz-svg");
133
+ if (this.$background.length) {
134
+ this.$element.css("background", this.$background.attr("fill"));
135
+ }
136
+
137
+ // setup all the nodes and edges
138
+ var that = this;
139
+ this.$nodes.each(function () {
140
+ $(this).attr({
141
+ "pointer-events": "visible",
142
+ });
143
+ that.setupNodesEdges($(this), "node");
144
+ });
145
+ this.$edges.each(function () {
146
+ that.setupNodesEdges($(this), "edge");
147
+ });
148
+ this.$clusters.each(function () {
149
+ that.setupNodesEdges($(this), "cluster");
150
+ });
151
+
152
+ // remove the graph title element
153
+ var $title = this.$graph.children("title");
154
+ this.$graph.attr("data-name", $title.text());
155
+ $title.remove();
156
+
157
+ if (options.zoom) {
158
+ this.setupZoom();
159
+ }
160
+
161
+ // tell people we're done
162
+ if (options.ready) {
163
+ options.ready.call(this);
164
+ }
165
+ };
166
+
167
+ GraphvizSvg.prototype.setupNodesEdges = function ($el, type) {
168
+ var that = this;
169
+ var options = this.options;
170
+
171
+ // save the colors of the paths, ellipses and polygons
172
+ $el.find("polygon, ellipse, path").each(function () {
173
+ var $this = $(this);
174
+ // save original colors
175
+ $this.data("graphviz.svg.color", {
176
+ fill: $this.attr("fill"),
177
+ stroke: $this.attr("stroke"),
178
+ });
179
+
180
+ // shrink it if it's a node
181
+ if (type === "node" && options.shrink) {
182
+ that.scaleNode($this);
183
+ }
184
+ });
185
+
186
+ // save the node name and check if theres a comment above; save it
187
+ var $title = $el.children("title");
188
+ if ($title[0]) {
189
+ // remove any compass points:
190
+ var title = $title.text().replace(/:[snew][ew]?/g, "");
191
+ $el.attr("data-name", title);
192
+ $title.remove();
193
+ if (type === "node") {
194
+ this._nodesByName[title] = $el[0];
195
+ } else if (type === "edge") {
196
+ if (!this._edgesByName[title]) {
197
+ this._edgesByName[title] = [];
198
+ }
199
+ this._edgesByName[title].push($el[0]);
200
+ } else if (type === "cluster") {
201
+ this._clustersByName[title] = $el[0];
202
+ }
203
+ // without a title we can't tell if its a user comment or not
204
+ var previousSibling = $el[0].previousSibling;
205
+ while (previousSibling && previousSibling.nodeType != 8) {
206
+ previousSibling = previousSibling.previousSibling;
207
+ }
208
+ if (previousSibling != null && previousSibling.nodeType == 8) {
209
+ var htmlDecode = function (input) {
210
+ var e = document.createElement("div");
211
+ e.innerHTML = input;
212
+ return e.childNodes[0].nodeValue;
213
+ };
214
+ var value = htmlDecode(previousSibling.nodeValue.trim());
215
+ if (value != title) {
216
+ // user added comment
217
+ $el.attr("data-comment", value);
218
+ }
219
+ }
220
+ }
221
+
222
+ // remove namespace from a[xlink:title]
223
+ $el
224
+ .find("a")
225
+ .filter(function () {
226
+ return $(this).attr("xlink:title");
227
+ })
228
+ .each(function () {
229
+ var $a = $(this);
230
+ $a.attr("title", $a.attr("xlink:title"));
231
+ $a.removeAttr("xlink:title");
232
+ if (options.tooltips) {
233
+ options.tooltips.init.call(this, that.$element);
234
+ }
235
+ });
236
+ };
237
+
238
+ GraphvizSvg.prototype.setupZoom = function () {
239
+ var that = this;
240
+ var $element = this.$element;
241
+ var $svg = this.$svg;
242
+ this.zoom = {
243
+ width: $svg.attr("width"),
244
+ height: $svg.attr("height"),
245
+ percentage: null,
246
+ };
247
+ this.scaleView(100.0);
248
+ $element.mousewheel(function (evt) {
249
+ if (evt.shiftKey) {
250
+ var percentage = that.zoom.percentage;
251
+ percentage -= evt.deltaY * evt.deltaFactor;
252
+ if (percentage < 100.0) {
253
+ percentage = 100.0;
254
+ }
255
+ // get pointer offset in view
256
+ // ratio offset within svg
257
+ var dx = evt.pageX - $svg.offset().left;
258
+ var dy = evt.pageY - $svg.offset().top;
259
+ var rx = dx / $svg.width();
260
+ var ry = dy / $svg.height();
261
+
262
+ // offset within frame ($element)
263
+ var px = evt.pageX - $element.offset().left;
264
+ var py = evt.pageY - $element.offset().top;
265
+
266
+ that.scaleView(percentage);
267
+ // scroll so pointer is still in same place
268
+ $element.scrollLeft(rx * $svg.width() + 0.5 - px);
269
+ $element.scrollTop(ry * $svg.height() + 0.5 - py);
270
+ return false; // stop propogation
271
+ }
272
+ });
273
+ };
274
+
275
+ GraphvizSvg.prototype.scaleView = function (percentage) {
276
+ var that = this;
277
+ var $svg = this.$svg;
278
+ $svg.attr("width", percentage + "%");
279
+ $svg.attr("height", percentage + "%");
280
+ this.zoom.percentage = percentage;
281
+ // now callback to update tooltip position
282
+ var $everything = this.$nodes.add(this.$edges);
283
+ $everything.children("a[title]").each(function () {
284
+ that.options.tooltips.update.call(this);
285
+ });
286
+ };
287
+
288
+ GraphvizSvg.prototype.scaleNode = function ($node) {
289
+ var dx = this.options.shrink.x;
290
+ var dy = this.options.shrink.y;
291
+ var tagName = $node.prop("tagName");
292
+ if (tagName == "ellipse") {
293
+ $node.attr("rx", parseFloat($node.attr("rx")) - dx);
294
+ $node.attr("ry", parseFloat($node.attr("ry")) - dy);
295
+ } else if (tagName == "polygon") {
296
+ // this is more complex - we need to scale it manually
297
+ var bbox = $node[0].getBBox();
298
+ var cx = bbox.x + bbox.width / 2;
299
+ var cy = bbox.y + bbox.height / 2;
300
+ var pts = $node.attr("points").split(" ");
301
+ var points = ""; // new value
302
+ for (var i in pts) {
303
+ var xy = pts[i].split(",");
304
+ var ox = parseFloat(xy[0]);
305
+ var oy = parseFloat(xy[1]);
306
+ points +=
307
+ ((cx - ox) / (bbox.width / 2)) * dx +
308
+ ox +
309
+ "," +
310
+ (((cy - oy) / (bbox.height / 2)) * dy + oy) +
311
+ " ";
312
+ }
313
+ $node.attr("points", points);
314
+ }
315
+ };
316
+
317
+ GraphvizSvg.prototype.convertToPx = function (val) {
318
+ var retval = val;
319
+ if (typeof val == "string") {
320
+ var end = val.length;
321
+ var factor = 1.0;
322
+ if (val.endsWith("px")) {
323
+ end -= 2;
324
+ } else if (val.endsWith("pt")) {
325
+ end -= 2;
326
+ factor = GraphvizSvg.GVPT_2_PX;
327
+ }
328
+ retval = parseFloat(val.substring(0, end)) * factor;
329
+ }
330
+ return retval;
331
+ };
332
+
333
+ GraphvizSvg.prototype.findEdge = function (nodeName, testEdge, $retval) {
334
+ var retval = [];
335
+ for (var name in this._edgesByName) {
336
+ var match = testEdge(nodeName, name);
337
+ if (match) {
338
+ if ($retval) {
339
+ this._edgesByName[name].forEach((edge) => {
340
+ $retval.push(edge);
341
+ });
342
+ }
343
+ retval.push(match);
344
+ }
345
+ }
346
+ return retval;
347
+ };
348
+
349
+ GraphvizSvg.prototype.findLinked = function (
350
+ node,
351
+ includeEdges,
352
+ testEdge,
353
+ $retval
354
+ ) {
355
+ var that = this;
356
+ var $node = $(node);
357
+ var $edges = null;
358
+ if (includeEdges) {
359
+ $edges = $retval;
360
+ }
361
+ var names = this.findEdge($node.attr("data-name"), testEdge, $edges);
362
+ for (var i in names) {
363
+ var n = this._nodesByName[names[i]];
364
+ if (!$retval.is(n)) {
365
+ $retval.push(n);
366
+ that.findLinked(n, includeEdges, testEdge, $retval);
367
+ }
368
+ }
369
+ };
370
+
371
+ GraphvizSvg.prototype.colorElement = function ($el, getColor) {
372
+ var bg = this.$element.css("background");
373
+ $el.find("polygon, ellipse, path").each(function () {
374
+ var $this = $(this);
375
+ var color = $this.data("graphviz.svg.color");
376
+ if (color.fill && color.fill != "none") {
377
+ $this.attr("fill", getColor(color.fill, bg)); // don't set fill if it's a path
378
+ }
379
+ if (color.stroke && color.stroke != "none") {
380
+ $this.attr("stroke", getColor(color.stroke, bg));
381
+ }
382
+ $this.attr('stroke-width', 1.6)
383
+ });
384
+ };
385
+
386
+ GraphvizSvg.prototype.restoreElement = function ($el) {
387
+ $el.find("polygon, ellipse, path").each(function () {
388
+ var $this = $(this);
389
+ var color = $this.data("graphviz.svg.color");
390
+ if (color.fill && color.fill != "none") {
391
+ $this.attr("fill", color.fill); // don't set fill if it's a path
392
+ }
393
+ if (color.stroke && color.stroke != "none") {
394
+ $this.attr("stroke", color.stroke);
395
+ }
396
+ $this.attr('stroke-width', 1)
397
+ });
398
+ };
399
+
400
+ // methods users can actually call
401
+ GraphvizSvg.prototype.nodes = function () {
402
+ return this.$nodes;
403
+ };
404
+
405
+ GraphvizSvg.prototype.edges = function () {
406
+ return this.$edges;
407
+ };
408
+
409
+ GraphvizSvg.prototype.clusters = function () {
410
+ return this.$clusters;
411
+ };
412
+
413
+ GraphvizSvg.prototype.nodesByName = function () {
414
+ return this._nodesByName;
415
+ };
416
+
417
+ GraphvizSvg.prototype.edgesByName = function () {
418
+ return this._edgesByName;
419
+ };
420
+
421
+ GraphvizSvg.prototype.clustersByName = function () {
422
+ return this._clustersByName;
423
+ };
424
+
425
+ GraphvizSvg.prototype.linkedTo = function (node, includeEdges) {
426
+ var $retval = $();
427
+ this.findLinked(
428
+ node,
429
+ includeEdges,
430
+ function (nodeName, edgeName) {
431
+ var other = null;
432
+
433
+ const connection = edgeName.split("->");
434
+ if (
435
+ connection.length > 1 &&
436
+ (connection[1] === nodeName ||
437
+ connection[1].startsWith(nodeName + ":"))
438
+ ) {
439
+ return connection[0].split(":")[0];
440
+ }
441
+
442
+ return other;
443
+ },
444
+ $retval
445
+ );
446
+ return $retval;
447
+ };
448
+
449
+ GraphvizSvg.prototype.linkedFrom = function (node, includeEdges) {
450
+ var $retval = $();
451
+ this.findLinked(
452
+ node,
453
+ includeEdges,
454
+ function (nodeName, edgeName) {
455
+ var other = null;
456
+
457
+ const connection = edgeName.split("->");
458
+ if (
459
+ connection.length > 1 &&
460
+ (connection[0] === nodeName ||
461
+ connection[0].startsWith(nodeName + ":"))
462
+ ) {
463
+ return connection[1].split(":")[0];
464
+ }
465
+ return other;
466
+ },
467
+ $retval
468
+ );
469
+ return $retval;
470
+ };
471
+
472
+ GraphvizSvg.prototype.linked = function (node, includeEdges) {
473
+ var $retval = $();
474
+ this.findLinked(
475
+ node,
476
+ includeEdges,
477
+ function (nodeName, edgeName) {
478
+ return "^" + name + "--(.*)$";
479
+ },
480
+ $retval
481
+ );
482
+ this.findLinked(
483
+ node,
484
+ includeEdges,
485
+ function (nodeName, edgeName) {
486
+ return "^(.*)--" + name + "$";
487
+ },
488
+ $retval
489
+ );
490
+ return $retval;
491
+ };
492
+
493
+ GraphvizSvg.prototype.tooltip = function ($elements, show) {
494
+ var that = this;
495
+ var options = this.options;
496
+ $elements.each(function () {
497
+ $(this)
498
+ .find("a[title]")
499
+ .each(function () {
500
+ if (show) {
501
+ options.tooltips.show.call(this);
502
+ } else {
503
+ options.tooltips.hide.call(this);
504
+ }
505
+ });
506
+ });
507
+ };
508
+
509
+ GraphvizSvg.prototype.bringToFront = function ($elements) {
510
+ $elements.detach().appendTo(this.$graph);
511
+ };
512
+
513
+ GraphvizSvg.prototype.sendToBack = function ($elements) {
514
+ if (this.$background.length) {
515
+ $element.insertAfter(this.$background);
516
+ } else {
517
+ $elements.detach().prependTo(this.$graph);
518
+ }
519
+ };
520
+
521
+ GraphvizSvg.prototype.highlight = function ($nodesEdges, tooltips) {
522
+ var that = this;
523
+ var options = this.options;
524
+ var $everything = this.$nodes.add(this.$edges).add(this.$clusters);
525
+ if ($nodesEdges && $nodesEdges.length > 0) {
526
+ // create set of all other elements and dim them
527
+ $everything.not($nodesEdges).each(function () {
528
+ that.colorElement($(this), options.highlight.unselected);
529
+ that.tooltip($(this));
530
+ });
531
+ $nodesEdges.each(function () {
532
+ that.colorElement($(this), options.highlight.selected);
533
+ });
534
+ if (tooltips) {
535
+ this.tooltip($nodesEdges, true);
536
+ }
537
+ } else {
538
+ $everything.each(function () {
539
+ that.restoreElement($(this));
540
+ });
541
+ this.tooltip($everything);
542
+ }
543
+ };
544
+
545
+ GraphvizSvg.prototype.destroy = function () {
546
+ var that = this;
547
+ this.hide(function () {
548
+ that.$element.off("." + that.type).removeData(that.type);
549
+ });
550
+ };
551
+
552
+ // GRAPHVIZSVG PLUGIN DEFINITION
553
+ // =============================
554
+
555
+ function Plugin(option) {
556
+ return this.each(function () {
557
+ var $this = $(this);
558
+ var data = $this.data("graphviz.svg");
559
+ var options = typeof option == "object" && option;
560
+
561
+ if (!data && /destroy/.test(option)) return;
562
+ if (!data)
563
+ $this.data("graphviz.svg", (data = new GraphvizSvg(this, options)));
564
+ if (typeof option == "string") data[option]();
565
+ });
566
+ }
567
+
568
+ var old = $.fn.graphviz;
569
+
570
+ $.fn.graphviz = Plugin;
571
+ $.fn.graphviz.Constructor = GraphvizSvg;
572
+
573
+ // GRAPHVIZ NO CONFLICT
574
+ // ====================
575
+
576
+ $.fn.graphviz.noConflict = function () {
577
+ $.fn.graphviz = old;
578
+ return this;
579
+ };
580
+ })(jQuery);