This could be just:

```
return ($scope.widgets.length + $scope.active + by) % $scope.widgets.length;
```

...but not sure if that's better or worse :)