Files
jube-fork/Jube.App/wwwroot/kendo/examples/drawing/paths.html
2022-11-04 13:24:24 +02:00

133 lines
3.7 KiB
HTML
Executable File

<!DOCTYPE html>
<html>
<head>
<title>Manipulating Paths</title>
<meta charset="utf-8">
<link href="../content/shared/styles/examples-offline.css" rel="stylesheet">
<link href="../../styles/kendo.common.min.css" rel="stylesheet">
<link href="../../styles/kendo.rtl.min.css" rel="stylesheet">
<link href="../../styles/kendo.default.min.css" rel="stylesheet">
<link href="../../styles/kendo.default.mobile.min.css" rel="stylesheet">
<script src="../../js/jquery.min.js"></script>
<script src="../../js/jszip.min.js"></script>
<script src="../../js/kendo.all.min.js"></script>
<script src="../content/shared/js/console.js"></script>
<script>
</script>
</head>
<body>
<a class="offline-button" href="../index.html">Back</a>
<div id="example">
<div class="box wide">
<div id="info" class="box-col"></div>
<div class="box-col select-col">
<h4>Surface type</h4>
<ul id="select-type">
<li>SVG</li>
<li>Canvas</li>
</ul>
</div>
</div>
<div id="surface-container">
<div id="surface" style="width: 100%; height: 100%;"></div>
</div>
<script>
var dataviz = kendo.dataviz;
var geom = kendo.geometry;
var Point = geom.Point;
var draw = kendo.drawing;
var Path = draw.Path;
var points = 15;
var distance = 20;
function initSurface(type) {
return draw.Surface.create($("#surface"), { type: type });
}
// Based on Follow3 example by Processing
function renderPath() {
var path = new Path({
stroke: {
color: '#E4141B',
width: 20,
lineCap: "round",
lineJoin: "round"
}
});
var start = new Point(100, 100);
for (var i = 0; i < points; i++) {
path.lineTo(start.clone().translate(i * distance, 0));
}
return path;
}
var path = renderPath();
$("#surface-container")
.on("mousemove", function(e) {
var offset = $(this).offset();
path.segments[0].anchor().move(e.pageX - offset.left, e.pageY - offset.top);
for (var i = 0; i < points - 1; i++) {
var point = path.segments[i].anchor();
var nextPoint = path.segments[i + 1].anchor();
var vector = point.clone().translate(-nextPoint.x, -nextPoint.y);
vector.scale(distance / vector.distanceTo(Point.ZERO));
nextPoint.move(point.x - vector.x, point.y - vector.y);
}
})
.on("mousedown", function(e) {
path.options.stroke.set("width", 2);
})
.on("mouseup", function(e) {
path.options.stroke.set("width", 20);
})
$(document).ready(function() {
var surface = initSurface();
surface.draw(path);
$("#select-type li").each(function() {
var type = $(this).text().toLowerCase();
if (!kendo.support[type]) {
$(this).addClass("k-state-disabled");
}
});
$("#select-type").kendoMobileButtonGroup({
select: function(e) {
var option = $("li", e.sender.element).eq(e.index);
var type = option.text().toLowerCase();
surface.destroy();
surface = initSurface(type);
surface.draw(path);
},
index: $("#select-type li:not(.k-state-disabled)").index()
});
});
</script>
<style>
#surface-container {
text-align: center;
margin: 0 auto;
width: 100%;
height: 600px;
}
</style>
</div>
</body>
</html>