Skip to content

Instantly share code, notes, and snippets.

@evaldosantos
Created November 28, 2017 15:25
Show Gist options
  • Save evaldosantos/ccc853e8449c4d63a3093f338d1b45e3 to your computer and use it in GitHub Desktop.
Save evaldosantos/ccc853e8449c4d63a3093f338d1b45e3 to your computer and use it in GitHub Desktop.
<div ng-controller="MyCtrl">
<div id="memory">
<div class="block"
ng-repeat="block in memory.blocks"
ng-class="{used: !block.free}"
ng-style="getWidth(block)"
>{{block.id}}</div>
</div>
</div>
var myApp = angular.module('myApp',[]);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
function MyCtrl($scope) {
$scope.memory = {blocks: [
{id: 1, size: 1, free: true},
{id: 2, size: 2, free: false},
{id: 3, size: 4, free: true},
{id: 4, size: 8, free: true},
{id: 5, size: 16, free: false},
{id: 6, size: 32, free: true},
{id: 7, size: 64, free: true},
{id: 8, size: 128, free: true},
{id: 9, size: 256, free: false},
{id: 10, size: 512, free: true},
], size: 1024};
$scope.getWidth = function(block) {
var width = block.size/1024*100;
return {'width': width + '%'};
}
}
#memory {
width: 100%;
background-color: green;
height: 100px;
white-space:nowrap; /*added*/
}
#memory .block {
display: inline-block;
height: 100%;
}
#memory .block.used {
background-color: red;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment