Skip to content

Commit

Permalink
Refresh only updated data
Browse files Browse the repository at this point in the history
  • Loading branch information
Maigo Erit committed Apr 16, 2016
1 parent 338c813 commit d887fe6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 47 deletions.
58 changes: 35 additions & 23 deletions plugins/main-window/app/timeline/timeline.directive.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ angular.module('angularDemoApp')
ctrl.addItemsToTimeline = addItemsToTimeline;
ctrl.removeItemsFromTimeline = removeItemsFromTimeline;
ctrl.changeDay = changeDay;
ctrl.updateDomain = updateDomain;

// constants
var margin = {
Expand Down Expand Up @@ -53,51 +54,59 @@ angular.module('angularDemoApp')
if (!day) {
return;
}
console.log('Changing day: '+ day);
console.log('Changing day: ' + day);
//Remove everything
vis.selectAll('.trackItem').remove();
updateDomain(day)

}

function updateDomain(day){
// Update time domain
var timeDomainStart = day;
console.log("Update time domain: ", timeDomainStart)
//console.log("Update time domain: ", timeDomainStart)
var timeDomainEnd = d3.time.day.offset(timeDomainStart, 1);
xScale.domain([timeDomainStart, timeDomainEnd]);
}

function removeItemsFromTimeline(trackItems){
function removeItemsFromTimeline(trackItems) {
console.log('removeItemsFromTimeline', trackItems.length);
layersGroup.selectAll(".trackItem").data(trackItems, function (d) {
return d.id;
}).exit().remove();
return d.id;
}).exit().remove();
}

function addItemsToTimeline(trackItems) {
console.log('addItemsToTimeline', trackItems.length);

// Update data
layersGroup.selectAll("g.layer").data(trackItems, function (d) {
return d.id;
})
.enter()
var insertedItems = layersGroup.selectAll(".trackItem").data(trackItems, function (d) {
return d.id;
});
insertedItems.enter()
.append("rect")
.attr('class', 'trackItem')
.style("fill", function (d) {
return d.color;
}).attr("y", 0).attr("x", function (d) {
.attr('class', 'trackItem');

insertedItems.style("fill", function (d) {
return d.color;
}).attr("y", 0);

insertedItems.attr("x", function (d) {
return xScale(d.beginDate);
}).attr("transform", function (d) {
return "translate(" + 0 + "," + yScale(d.taskName) + ")";
}).attr("height", function (d) {
return yScale.rangeBand();
}).attr("width", function (d) {
if ((xScale(d.endDate) - xScale(d.beginDate)) < 0) {
console.error("Negative value, error with dates.");
console.log(d);
return 0;
}
return (xScale(d.endDate) - xScale(d.beginDate));
})
.on('click', onClickTrackItem)
if ((xScale(d.endDate) - xScale(d.beginDate)) < 0) {
console.error("Negative value, error with dates.");
console.log(d);
return 0;
}
return (xScale(d.endDate) - xScale(d.beginDate));
});


insertedItems.on('click', onClickTrackItem)
.on('mouseover', tip.show)
.on('mouseout', tip.hide);

Expand Down Expand Up @@ -180,6 +189,9 @@ angular.module('angularDemoApp')
d3.select(".brush").call(selectionTool);

ctrl.onZoomChanged(scale, x);

//refresh domain scale, so when zooming and later refreshing data, update item would not be error offset
ctrl.updateDomain(ctrl.startDate);
};

var zoom = d3.behavior.zoom().scaleExtent([1, 100])
Expand Down Expand Up @@ -306,7 +318,7 @@ angular.module('angularDemoApp')
if (ctrl.zoomX && ctrl.zoomScale) {
// using timeout to prevent xAxis update bug (ticks not scaled evenly)
$timeout(function () {
// changeZoom(ctrl.zoomScale, ctrl.zoomX);
changeZoom(ctrl.zoomScale, ctrl.zoomX);
}, 100);
}
}
Expand Down
50 changes: 27 additions & 23 deletions plugins/main-window/app/timeline/timeline.view.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,32 @@ angular.module('angularDemoApp')
}
};

//ctrl.maxDate = new Date();

function getTomorrow(d) {
return new Date(d.getFullYear(), d.getMonth(), d.getDate() + 1)
}

var today = new Date();
var tomorrow = getTomorrow(today);
ctrl.searchDate = today;

today.setHours(0, 0, 0, 0);
console.log(today, tomorrow);

ctrl.dayBack = function () {
ctrl.searchDate = moment(ctrl.searchDate).subtract(1, 'days').toDate();
ctrl.list();
ctrl.list(ctrl.searchDate);

};
ctrl.dayForward = function () {
ctrl.searchDate = moment(ctrl.searchDate).add(1, 'days').toDate();
ctrl.list();
ctrl.list(ctrl.searchDate);
};

ctrl.refresh = function () {
var searchFrom = _.chain(ctrl.trackItems).filter(function (item) {
return item.taskName !== 'LogTrackItem';
}).last().valueOf().beginDate;
console.log('Refreshing from:', searchFrom);
ctrl.list(searchFrom);
};

ctrl.loading = false;
ctrl.list = function () {
console.log("Refresh data");

ctrl.list = function (startDate) {
console.log("Load data from:", startDate);
ctrl.zoomScale = $sessionStorage.zoomScale || 0;
ctrl.zoomX = $sessionStorage.zoomX || 0;
ctrl.loading = true;
Expand All @@ -79,8 +79,8 @@ angular.module('angularDemoApp')
['beginDate', 'ASC']
], where: {
beginDate: {
'>=': ctrl.searchDate,
'<': getTomorrow(ctrl.searchDate)
'>=': startDate,
'<': getTomorrow(startDate)
}
}
}).then(function (items) {
Expand Down Expand Up @@ -124,26 +124,26 @@ angular.module('angularDemoApp')
};

ctrl.pieDataApp = _.chain(items).filter(function (item) {
return item.taskName === 'AppTrackItem';
})
return item.taskName === 'AppTrackItem';
})
.groupBy('app')
.map(function (b) {
return b.reduce(sumApp, {app: b[0].app, timeDiffInMs: 0, color: b[0].color})
})
.valueOf();

ctrl.pieDataLog = _.chain(items).filter(function (item) {
return item.taskName === 'LogTrackItem';
})
return item.taskName === 'LogTrackItem';
})
.groupBy('title')
.map(function (b) {
return b.reduce(sumApp, {app: b[0].app, title: b[0].title, timeDiffInMs: 0, color: b[0].color})
})
.valueOf();

ctrl.pieDataStatus = _.chain(items).filter(function (item) {
return item.taskName === 'StatusTrackItem';
})
return item.taskName === 'StatusTrackItem';
})
.groupBy('app')
.map(function (b) {
return b.reduce(sumApp, {app: b[0].app, timeDiffInMs: 0, color: b[0].color})
Expand All @@ -153,7 +153,7 @@ angular.module('angularDemoApp')
setWorkStatsForDay(items.filter(function (item) {
return item.taskName === 'AppTrackItem';
}));
// $rootScope.$apply();
// $rootScope.$apply();

});

Expand Down Expand Up @@ -246,6 +246,10 @@ angular.module('angularDemoApp')
ctrl.selectedTrackItem = null;
};

ctrl.list();
// Initialy load todays data
var today = new Date();
today.setHours(0, 0, 0, 0);
ctrl.searchDate = today;
ctrl.list(today);

});
2 changes: 1 addition & 1 deletion plugins/main-window/app/timeline/timeline.view.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
style="margin: 90px auto; position: absolute; top: 0; left: 0; bottom: 0; right: 0;"
></md-progress-circular>
<div layout="row">
<md-button class="md-icon-button" aria-label="Refresh" ng-click="timelineCtrl.list()">
<md-button class="md-icon-button" aria-label="Refresh" ng-click="timelineCtrl.refresh()">
<md-icon md-font-set="material-icons">refresh</md-icon>
</md-button>
<md-button class="md-icon-button" ng-click="timelineCtrl.dayBack()">
Expand Down

0 comments on commit d887fe6

Please sign in to comment.