Permalink
Browse files

Poprawki w skalowaniu <canvas>.

  • Loading branch information...
1 parent 3ab8736 commit caf256ddb9a2b31c9ffe0beb5f9aa268256594c5 @ciembor committed Mar 16, 2012
Showing with 63 additions and 38 deletions.
  1. +38 −16 index.html
  2. +25 −22 js/generator.js
View
54 index.html
@@ -8,14 +8,21 @@
<meta name="author" content="Maciej Ciemborowicz">
<link href="js/google-code-prettify/prettify.css" rel="stylesheet">
- <link href="css/bootstrap.css" rel="stylesheet">
+ <link href="css/bootstrap.min.css" rel="stylesheet">
+ <link href="css/bootstrap-responsive.css" rel="stylesheet">
+
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
+ #refresh {
+ width: 100%;
+ padding: 8px 0px
+ }
+
.sidebar-nav {
padding: 9px 0;
}
@@ -27,16 +34,35 @@
.S {
display: inline;
}
+
+ .nav-tabs.nav-stacked > .first-tab > a {
+ -webkit-border-radius: 4px 4px 0 0;
+ -moz-border-radius: 4px 4px 0 0;
+ border-radius: 4px 4px 0 0;
+ }
+ .nav-tabs.nav-stacked > .last-tab > a {
+ -webkit-border-radius: 0 0 4px 4px;
+ -moz-border-radius: 0 0 4px 4px;
+ border-radius: 0 0 4px 4px;
+ }
+ .nav-tabs.nav-stacked > .only-tab > a {
+ -webkit-border-radius: 4px 4px 4px 4px;
+ -moz-border-radius: 4px 4px 4px 4px;
+ border-radius: 4px 4px 4px 4px;
+ }
+
+ #output {
+ width: 100%;
+ }
</style>
- <link href="css/bootstrap-responsive.css" rel="stylesheet">
-
+
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
- <script type="text/javascript" src="js/generator.js"></script>
+ <script type="text/javascript" src="js/generator.js"></script>
</head>
@@ -52,16 +78,12 @@
</a>
<div class="nav-collapse">
<ul class="nav">
- <!-- <li class="">
- <a href="./index.html">O programie</a>
- </li>
- <li class="">
- <a href="./gramatyka.html">Gramatyka</a>
- </li>
- -->
<li class="active">
<a href="./index.html">Generator</a>
</li>
+ <li>
+ <a href="http://github.com/ciembor/Metody-lingwistyczne">Repozytorium</a>
+ </li>
</ul>
</div>
</div>
@@ -96,14 +118,14 @@
<li class="production Z"><a href="#">Z → ×z+</a></li>
</ul>
- <a id="refresh" style="width: 100%; padding: 8px 0px; " class="btn btn-large disabled" href="#"><i class="icon-refresh"></i> Wyczyść</a>
+ <a id="refresh" class="btn btn-large disabled" href="#"><i class="icon-refresh"></i> Wyczyść</a>
</div>
<div class="span9">
<h2>Wywód</h2>
- <pre id="formula" class="prettyprint" style="font-size: 120%">rotfl match klop lazy finall 123+((a*rotfl+(~b)+c)+b+(A C B))+a*B</pre>
- <div id="output-container" class="well">
- <canvas id="output" width=900 height=215></canvas>
- </div>
+ <pre id="formula" class="prettyprint" style="font-size: 120%">S</pre>
+ <div id="output-container" class="well">
+ <canvas id="output" width=829 height=266></canvas>
+ </div>
</div>
</div>
<hr/>
View
47 js/generator.js
@@ -46,7 +46,7 @@ function Point(x, y) {
if (x === undefined || x === null || y === undefined || y === null) {
this.x = 10;
- this.y = 210;
+ this.y = 260;
} else {
this.x = x;
this.y = y;
@@ -62,7 +62,6 @@ function Group() {
function draw(ctx) {
for(var i = 0, len = childs.length; i < len ; i++) {
- console.log("drawing group... [("+getTail().x+","+getTail().y+"), ("+getHead().x+","+getHead().y+")]");
childs[i].draw(ctx);
}
}
@@ -94,12 +93,6 @@ function Group() {
}
}
- function alertEdges() {
- for(var i = 0, len = childs.length; i < len ; i++) {
- alert(i + ' tail: ' + childs[i].getTail().x + '/' + childs[i].getTail().y + " | head: " + childs[i].getHead().x + '/' + childs[i].getHead().y)
- }
- }
-
function invert() {
inverted = inverted ? false : true;
}
@@ -108,7 +101,6 @@ function Group() {
draw: draw,
getTail: getTail,
getHead: getHead,
- alertEdges: alertEdges,
moveTail: moveTail,
moveHead: moveHead,
invert: invert
@@ -187,27 +179,27 @@ var symbols = {
// vertical line (|)
a: {
x: 0,
- y: -100,
+ y: -125,
drawable: true
},
// horizontal line (-)
b: {
- x: 100,
+ x: 125,
y: 0,
drawable: true
},
// diagonal line (\)
c: {
- x: 100,
- y: 100,
+ x: 125,
+ y: 125,
drawable: true
},
// space
z: {
- x: 135,
+ x: 170,
y: 0,
drawable: false
}
@@ -229,9 +221,7 @@ var grammar = {
"CZAZBZA",
"CZAZBZC"
],
-
- // syllabes
-
+
// letters
A: [
@@ -318,7 +308,6 @@ var Formula = function(string) {
function draw(ctx) {
var postfix = infixToRPN(infix); // it's an array, not string
- // var operators = ["×", "+", "-", "~"];
var stack = [];
var operator;
var primitive;
@@ -353,7 +342,6 @@ var Formula = function(string) {
}
} else if ($.inArray(operator, Object.keys(operators)) !== -1) {
- console.log("dwuargumentowy operator");
try {
// put result into begin of postfix
var arg2 = stack.pop();
@@ -368,7 +356,6 @@ var Formula = function(string) {
}
}
- // console.log(postfix[0]);
postfix[0].draw(ctx);
}
@@ -391,7 +378,7 @@ $(document).ready(function() {
var canvas = $("#output")[0];
var ctx = canvas.getContext('2d');
ctx.strokeStyle = "#dd1144";
- ctx.lineWidth = 10;
+ ctx.lineWidth = 12;
ctx.lineCap = "round";
var nonterminal;
@@ -414,6 +401,12 @@ $(document).ready(function() {
$("#formula").text(formula.get());
+ $(".first-tab").removeClass("first-tab");
+ $(".last-tab").removeClass("last-tab");
+ $(".last-tab").removeClass("only-tab");
+ $("#grammar > .S").first().addClass("first-tab");
+ $("#grammar > .S").last().addClass("last-tab");
+
$(".production").hide();
$(".S").show();
$("#grammar").show();
@@ -431,6 +424,17 @@ $(document).ready(function() {
formula.replaceNonterminal(consequent);
$(".production").hide();
+
+ $(".first-tab").removeClass("first-tab");
+ $(".last-tab").removeClass("last-tab");
+ $(".last-tab").removeClass("only-tab");
+
+ var tabs = $("#grammar > ." + formula.getNonterminal());
+ if (tabs.size() > 1) {
+ tabs.first().addClass("first-tab");
+ tabs.last().addClass("last-tab");
+ } else {
+ tabs.first().addClass("only-tab");
}
$("." + formula.getNonterminal()).show();
@@ -447,7 +451,6 @@ $(document).ready(function() {
$("#refresh").removeClass("disabled");
window.prettyPrint && prettyPrint();
- // #refresh?
});
$("#refresh").click(function() {

0 comments on commit caf256d

Please sign in to comment.