Permalink
Browse files

1-indexed.

  • Loading branch information...
1 parent 7bbcefd commit 4b0884c61ab5a5c18d05d93d55ac64b2b655ef63 Matthew Gerring committed Aug 5, 2011
@@ -7,8 +7,8 @@
<h3>Cluster <%= cluster.id %>, containing <%= count %> documents</h3>
<ul id="doc-list" data-cluster-total=<%= count %>>
<% for (var i = 0; i < docs.length; i++) { %>
- <li id="doc-<%= i %>">
- <a class="doc-link" href="<%= State.cleanUrl+'/'+i %>"><%= docs[i].text %></a><br />
+ <li id="doc-<%= i+1 %>">
+ <a class="doc-link" href="<%= State.cleanUrl+'/'+(i+1) %>"><%= docs[i].text %></a><br />
<cite><%= docs[i].name %>, <%= docs[i].org %></cite>
</li>
<% } %>
@@ -2,21 +2,21 @@
{% load static %}
{% block main %}
- <input id="slider" type="range" step="1" min="1" max="{{step.count.steps}}" class="slider" value="{{step.params.step}}">
+ <input id="slider" type="range" step="1" min="1" max="{{step.count.steps}}" class="slider" value="{{params.step}}">
<div id="cluster_info">
- <h2>Step <span id="currentStep">{{ step.params.step }}</span> of {{ step.count.steps }}, containing <span id="currentClusters">{{ step.count.clusters }}</span> clusters</h2>
+ <h2>Step <span id="currentStep">{{ params.step }}</span> of {{ step.count.steps }}, containing <span id="currentClusters">{{ step.count.clusters }}</span> clusters</h2>
</div>
<div id="chart"></div>
<div id="cluster_overlay" {% if cluster %}class="show"{% endif %}>
<div id="close">Close</div>
<div id="overlay_inner">
{% if cluster %}
- <h3>Cluster {{ cluster.id }}, containing {{ count }} documents</h3>
+ <h3>Cluster {{ cluster.id }}, containing {{ cluster.docs|length }} documents</h3>
<ul id="doc-list" data-cluster-total={{ cluster.count }}>
{% for docs in cluster.docs %}
<li id="doc-{{ forloop.counter0 }}">
- <a class="doc-link" href="/{{params.step}}/{{params.cluster}}/{{forloop.counter0}}">{{ docs.text }}</a><br />
- {% if doc %}{% if params.doc == forloop.counter0 %}
+ <a class="doc-link" href="/{{params.step}}/{{params.cluster}}/{{forloop.counter}}">{{ docs.text }}</a><br />
+ {% if doc %}{% if params.doc == forloop.counter %}
{% for d in doc.docs %}
<div class="doc-info">
<span class="date">{{ d.date }}</span>
@@ -1,6 +1,6 @@
<%
var clusters = c.step.clusters;
- var params = c.step.params;
+ var params = params;
var count = c.step.count;
%>
-<h2>Step <span id="currentStep"><%= params.step-1 %></span> of <%= count.steps %>, containing <span id="currentClusters"><%= count.clusters %></span> clusters</h2>
+<h2>Step <span id="currentStep"><%= params.step %></span> of <%= count.steps %>, containing <span id="currentClusters"><%= count.clusters %></span> clusters</h2>
View
@@ -8,9 +8,9 @@
url(r'api/(?P<step>\d+)/?$', 'explorer.views.api', name='home'),
url(r'api/?$', 'explorer.views.api', name='home'),
#index
- url(r'(?P<step>\d+)/(?P<cluster>\d+)/(?P<doc>\d+)$', 'explorer.views.index', name='home'),
- url(r'(?P<step>\d+)/(?P<cluster>\d+)$', 'explorer.views.index', name='home'),
- url(r'(?P<step>\d+)$', 'explorer.views.index', name='home'),
+ url(r'(?P<step>\d+)/(?P<cluster>\d+)/(?P<doc>\d+)/?$', 'explorer.views.index', name='home'),
+ url(r'(?P<step>\d+)/(?P<cluster>\d+)/?$', 'explorer.views.index', name='home'),
+ url(r'(?P<step>\d+)/?$', 'explorer.views.index', name='home'),
url(r'$', 'explorer.views.index', name='home'),
)
View
@@ -10,32 +10,30 @@
def _get_params(step = None, cluster=None, doc=None):
if step:
step = int(step)
+ else:
+ step = 1
if cluster:
cluster = int(cluster)
if doc:
doc = int(doc)
return {'step':step,'cluster':cluster,'doc':doc}
-def _get_step(step = 0, cluster = 0):
+def _get_step(step = 1, cluster = 1):
count = { # You can probably do this in the template
"steps" : len(all_docs),
- "clusters" : len(all_docs[int(step)]),
- }
- params = { #this is available with a RequestContext, get rid of it probably
- "step" : int(step)+1,
- "cluster" : cluster,
+ "clusters" : len(all_docs[int(step)-1]),
}
- clusters = [doc_to_dict(i,1,20) for i in all_docs[int(step)]]
- return {"clusters":clusters, "params":params, "count":count}
+ clusters = [doc_to_dict(i,1,20) for i in all_docs[int(step)-1]]
+ return {"clusters":clusters, "count":count}
-def _get_cluster(step = 0, cluster = 0, limit = 0):
+def _get_cluster(step = 1, cluster = 1, limit = 0):
- return_dict = doc_to_dict(all_docs[int(step)][int(cluster)],limit,20)
+ return_dict = doc_to_dict(all_docs[int(step)-1][int(cluster)-1],limit,20)
return_dict['id'] = cluster
return return_dict
-def _get_doc(step = 0, cluster = 0, doc = 0):
- return_dict = doc_to_dict( [all_docs[int(step)][int(cluster)][int(doc)]] )
+def _get_doc(step = 1, cluster = 1, doc = 1):
+ return_dict = doc_to_dict( [all_docs[int(step)-1][int(cluster)-1][int(doc)-1]] )
return_dict['id'] = doc
return return_dict
@@ -45,13 +43,10 @@ def index(request, step = None, cluster = None, doc = None):
if doc:
response_dict['doc'] = _get_doc(int(step),int(cluster),int(doc))
if cluster:
- try:
- limit = int(request.GET['limit'])
- except:
- limit = 10
+ #limit = int(request.GET.get('limit', 10))
response_dict['cluster'] = _get_cluster(int(step),int(cluster))
if step:
- response_dict['step'] = _get_step(int(step)-1)
+ response_dict['step'] = _get_step(int(step))
else:
response_dict['step'] = _get_step()
@@ -69,7 +64,7 @@ def api(request, step = None, cluster = None, doc = None):
limit = 0
response_dict['cluster'] = _get_cluster(int(step),int(cluster), limit)
elif step:
- response_dict['step'] = _get_step(int(step)-1)
+ response_dict['step'] = _get_step(int(step))
else:
response_dict['step'] = _get_step()
@@ -40,7 +40,7 @@ function drawIt(someData, params) {
.html(function(d, i) {
var ret = ""
if (d.children == null) {
- ret += "<a href='/"+params.step+'/'+(i-1)+"'>"+d.count+" documents</a>";
+ ret += "<a href='/"+params.step+'/'+i+"'>"+d.count+" documents</a>";
if (d.dx-1 > 80 || d.dy-1 > 80) {
ret += "<p>"+d.docs[0].text+"</p>";
}
View
@@ -91,7 +91,7 @@
ajax : {
step : function(data, hash) {
- $('#cluster_info').html(clusterExplore.templates.step({c : data}));
+ $('#cluster_info').html(clusterExplore.templates.step({c : data, params : data.params}));
$('#loader').delay(500).fadeOut('fast');
$("#cluster_overlay #overlay_inner").empty();
$("#cluster_overlay").attr('style','').attr('class','');

0 comments on commit 4b0884c

Please sign in to comment.