Skip to content

Commit

Permalink
Merge pull request al2o3cr#1 from tonywok/master
Browse files Browse the repository at this point in the history
Add coefficient template for Obj-C (pre LLVM 4.0)
  • Loading branch information
al2o3cr committed Jun 7, 2012
2 parents 1a36bc3 + 90ef57f commit e857e6f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$(function () {
window.r = Raphael('holder');
window.rowTemplate = _.template($('script#rowTemplate').html());
window.dataTemplate = _.template($('script#dataTemplate').html());
window.dataTemplate = _.template($("script.dataTemplate[data-language='javascript']").html());

$('#values').on('change', 'input', function() {
redraw();
Expand All @@ -12,6 +12,11 @@ $(function () {
$('button#moar').click(function() {
addRow('','');
});
$('#language').change(function() {
var language = $(this).find("option:selected").val();
window.dataTemplate = _.template($("script.dataTemplate[data-language='"+language+"']").html());
redraw();
});
$('#values').on('click', 'a.remove', function(e) {
e.preventDefault();
$(e.target).parents('tr').remove();
Expand Down
22 changes: 21 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,29 @@
<td><a href='#' class='remove'>X</a></td>
</tr>
</script>
<script type="text/template" id="dataTemplate">

<script type="text/template" class="dataTemplate" data-language="javascript">
[
<% _.each(data, function(row) { %>
[<%= row[0] %>, [<% _.each(row[1], function(v) { %><%= v %>, <% }) %>]],
<% }) %>
]
</script>

<script type="text/template" class="dataTemplate" data-language="objectivec">
<% var index = 0; %>
<% var coefficients = _.map(_.range(data.length), function(num) { return "coef" + num }); %>
<% _.each(data, function(row) { %>
<%= coefficients[index] + " = " + "[NSArray initWithObjects:\n" +
" [NSNumber " + row[0] + " floatValue],\n" +
" [NSArray initWithObjects:\n" +
_.map(row[1], function(num) {
return " [NSNumber " + num + " floatValue]";
}).join(",\n").concat(", nil], nil];") %>
<% index++; %>
<% }) %>
<%= "[[NSArray alloc] initWithObjects:" + coefficients.join(", ").concat(", nil];") %>
</script>
</head>
<body>
<h1>Natural cubic spline</h1>
Expand Down Expand Up @@ -105,6 +121,10 @@ <h1>Graph</h1>
</div>
<div style="float: left">
<h1>Results</h1>
<select id="language">
<option value="javascript" selected="selected">JavaScript</option>
<option value="objectivec">Objective-C</option>
</select>
<p>
See the spline_interp function in app.js for sample code to use
this array.
Expand Down

0 comments on commit e857e6f

Please sign in to comment.