Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Commit

Permalink
Load Graph automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrés González committed Sep 1, 2015
1 parent 50d0198 commit a94e455
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ define([
initialize: function() {
this.constructor.__super__.initialize.apply(this);
this.model = CountryModel;
console.log('init');

this._getData();
this.render();
Expand Down Expand Up @@ -158,37 +159,17 @@ var self = this;


var index = Math.round(x.invert(d3.mouse(this)[0]));
console.log(index);
// cy = h - y_scale(data[index].alerts) + marginTop;
// date = new Date(data[index].date),
// formattedDate = that.helper.config.MONTHNAMES[date.getUTCMonth()] + ' ' + date.getUTCFullYear();
//
console.log(self.ticks);
var currentYear = moment(index).format('YYYY');
var xPos;
switch(currentYear) {

case '2006':
xPos = Number(1100000000000);
break;
case '2008':
xPos = 1150000000000;
break;
case '2010':
xPos = 1200000000000;
break;
}


console.log(d3.mouse(this)[0] - margin.left);


// console.log(d3.mouse(this)[0] - margin.left);

// marker
// .attr('cx', cx)
// .attr('cy', cy);

positioner
.attr('x1', xPos)
.attr('x2', xPos);
// positioner
// .attr('x1', d3.mouse(this)[0] - margin.left)
// .attr('x2', d3.mouse(this)[0] - margin.left);

// if (d && d.loss) {
// tooltip.html('<span class="data">' + d.loss + '</span>' + ' ha in ' + d.year.format('YYYY'))
Expand Down Expand Up @@ -219,7 +200,6 @@ var self = this;

render: function() {


this.$el.html(this.template({}));

this._drawGraph();
Expand Down
5 changes: 5 additions & 0 deletions app/assets/javascripts/countries/views/show/WidgetGridView.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ define([
this.presenter = new WidgetGridPresenter(this);

this._setListeners();
this.renderWidgets();
},

_setListeners: function() {},
Expand Down Expand Up @@ -52,6 +53,8 @@ define([
var enabledWidgets = this._checkEnabledWidgets(),
newWidgets = arg;

var defaultWidgets = [2];

if (enabledWidgets.length > 0) {

// Add only new widgets, don't touch the current ones
Expand All @@ -65,6 +68,8 @@ define([
}
}

newWidgets = newWidgets ? newWidgets : defaultWidgets;

newWidgets.forEach(_.bind(function(widget) {
this.render(new WidgetView({id: widget}));
}, this));
Expand Down
4 changes: 3 additions & 1 deletion app/assets/javascripts/views/WidgetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ define([
this.indicators = [];

this._setIndicators();
this._loadIndicator();
},

_setCurrentIndicator: function(e) {
Expand All @@ -42,7 +43,7 @@ define([
},

_loadIndicator: function(indicator) {
var indicatorType = indicator.getAttribute('data-name');
// var indicatorType = indicator.getAttribute('data-name');
// TO-DO: API call
var graphChart = new GraphChartIndicator();

Expand Down Expand Up @@ -81,6 +82,7 @@ define([

render: function() {
this.$el.html(this.template({indicators: this.indicators}))
$('.indicators-grid__item:first-child').trigger('click');

// $(this.el).html(this.template({id: this.id}));
// return this;
Expand Down

0 comments on commit a94e455

Please sign in to comment.