@model SortExample.HomeViewModel
ViewBag.Title = "Home Page";
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="https://rawgithub.com/DmitryBaranovskiy/raphael/master/raphael-min.js"></script>
<script type="text/javascript">
function Draw(array, step, item1, item2, change) {
var items = currentArray.split(' ');
var sorted = items.length - step;
for (var i = 0; i < items.length; i++) {
var circle = paper.circle(50 * (i + 1), 40, 20);
circle.attr({ fill: "#DA81F5" });
circle.attr({ fill: "red" });
if (change == true) circle.attr({ fill: "green" });
circle.attr({ fill: "red" });
if (change == true) circle.attr({ fill: "green" });
paper.text(50 * (i + 1), 40, items[i]);
if (array != currentArray) {
setTimeout(function() { Draw(array, step, item1, item2, true); }, 500);
function dostep(iteration, step) {
"@Url.Content("~/Home/SortStep")",
iteration: iteration ? iteration : 0,
setTimeout(function () { handleResponse(data.array, data.item1, data.item2, data.iteration, data.step); }, 2000);
setTimeout(function () { Draw(data.array, data.array.split(' ').length, 100, 100, false); }, 2000);
function handleResponse(array, item1, item2, iteration, step) {
Draw(array, iteration, item1, item2);
$(document).ready(function () {
paper = Raphael(10, 150, 520, 200);
$("#ArraySize").attr("disabled", "disabled");
var array = $("#Array").val();
originalArray = currentArray = array;
handleResponse(originalArray);
<span style="background-color: #DA81F5"> </span> - Sorted; <br />
<span style="background-color: red"> </span> - Compare; <br />
<span style="background-color: green"> </span> - Swap; <br />
<div style="z-index:10;position: absolute;">
@using (Html.BeginForm("Index2", "Home", FormMethod.Get))
@Html.LabelFor(model => model.ArraySize) <br />
@Html.TextBoxFor(model=>model.ArraySize) <br />
@Html.ValidationMessageFor(model=>model.ArraySize) <br />
if (!string.IsNullOrEmpty(Model.Array))
@Html.HiddenFor(model => model.Array)
@Html.HiddenFor(model => model.Start)
<input value="Go" type="submit" />