Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

startAt funcionando \o/

  • Loading branch information...
commit 119504c0343dc7c2a63a11e9b0cd73d965f186cb 1 parent 11be0b8
@jonasabreu authored
View
22 src/main/scala/contasrefeitas/Orcamento.scala
@@ -15,7 +15,7 @@ import java.text.DecimalFormat
case class Gasto(subfuncao : String, natureza : String, destino : String, valor : Double)
@BeanInfo
-case class Child(label : String, value : Double, formattedValue : String, childs : List[Child], rootPercent : String, percent : String)
+case class Child(label : String, value : Double, formattedValue : String, childs : List[Child], rootPercent : String, percent : String, maxChilds : Int)
object Child {
@@ -24,8 +24,8 @@ object Child {
def percentOf(reference : Double) = "%1.2f".format(value * 100 / reference) + "%"
}
- def apply(label : String, value : Double, childs : List[Child], root : Double, total : Double) : Child = {
- Child(label, value, value.asBrl, childs, value.percentOf(root), value.percentOf(total))
+ def apply(label : String, value : Double, childs : List[Child], root : Double, total : Double, maxChilds : Int) : Child = {
+ Child(label, value, value.asBrl, childs, value.percentOf(root), value.percentOf(total), maxChilds)
}
}
@@ -46,20 +46,22 @@ class Orcamento {
val total = gastos.soma
def join(list : List[(Gasto) => String], limit : Int, startAt : Int) : Child = {
- Child("root", total, join(gastos, list, limit.orDefault(10), startAt.orDefault(0), total, total), total, total)
+ val (innerChilds, maxChilds) = join(gastos, list, limit.orDefault(10), startAt.orDefault(0), total, total)
+ Child("root", total, innerChilds, total, total, maxChilds)
}
- private def join(gastos : List[Gasto], filters : List[(Gasto) => String], limit : Int, startAt : Int, root : Double, total : Double) : List[Child] = {
+ private def join(gastos : List[Gasto], filters : List[(Gasto) => String], limit : Int, startAt : Int, root : Double, total : Double) : (List[Child], Int) = {
if (!filters.isEmpty) {
val items = gastos.map(filters.head).distinct
- items.map(item => {
+ val aux = items.map(item => {
val filteredItems = gastos.filter(elem => filters.head(elem) == item)
val soma = filteredItems.soma
- val innerItems = join(filteredItems, filters.tail, limit, startAt, soma, total)
- Child(item, soma, innerItems, root, total)
- }).sortWith((a, b) => a.value > b.value).slice(startAt, startAt + limit)
+ val (innerItems, maxChilds) = join(filteredItems, filters.tail, limit, startAt, soma, total)
+ Child(item, soma, innerItems, root, total, maxChilds)
+ }).sortWith((a, b) => a.value > b.value)
+ (aux.slice(startAt, startAt + limit), aux.length)
} else {
- List()
+ (List(), 0)
}
}
View
4 src/main/webapp/WEB-INF/jsp/main/index.jsp
@@ -11,6 +11,8 @@
<script src="/javascript/alluvial.js"></script>
<script src="/javascript/events.js"></script>
<script src="/javascript/jquery.qtip.min.js"></script>
+ <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
+ <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<link type="text/css" rel="stylesheet" media="screen" href="/bootstrap/css/bootstrap.css">
<link type="text/css" rel="stylesheet" media="screen" href="/stylesheets/style.css">
<link type="text/css" rel="stylesheet" media="screen" href="/stylesheets/jquery.qtip.min.css">
@@ -49,7 +51,7 @@
<li class="item"><a href="#">15</a></li>
<li class="item"><a href="#">20</a></li>
</ul>
-
+ Come&ccedil;ando em <div id="slider"></div>
</article>
</section>
<section>
View
3  src/main/webapp/javascript/alluvial-settings.js
@@ -1,4 +1,7 @@
function drawAlluvial(json) {
+
+ $("#slider").slider( "option", "max", json.maxChilds);
+
var data = createAlluvialData(json);
var nodeMap = createNodeMap(data);
View
12 src/main/webapp/javascript/events.js
@@ -1,6 +1,7 @@
var json;
var hystory = [];
var limit = 10;
+var startAt = 0;
$("rect").live('click', function() {
$("article svg").remove();
@@ -14,7 +15,7 @@ $("rect").live('click', function() {
function loadAlluvial() {
$.ajax({
- url: "/filtros/destino/natureza?limit=" + limit + "&startAt=0",
+ url: "/filtros/destino/natureza?limit=" + limit + "&startAt=" + startAt,
method: "GET",
success: function(data) {
json = data;
@@ -49,4 +50,13 @@ $(document).ready(function() {
$("article svg").remove();
loadAlluvial();
});
+
+ $('#slider').slider({
+ min: 0,
+ change: function(event, ui) {
+ startAt = $('#slider').slider('value');
+ $("article svg").remove();
+ loadAlluvial();
+ }
+ });
});
Please sign in to comment.
Something went wrong with that request. Please try again.