jobtracker_heap.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. App.JobTrackerHeapPieChartView = App.DashboardWidgetView.extend({
  20. title: Em.I18n.t('dashboard.widgets.JobTrackerHeap'),
  21. id: '6',
  22. isPieChart: true,
  23. isText: false,
  24. isProgressBar: false,
  25. model_type: 'mapreduce',
  26. hiddenInfo: function () {
  27. var heapUsed = this.get('model').get('jobTrackerHeapUsed') || 0;
  28. var heapMax = this.get('model').get('jobTrackerHeapMax') || 0;
  29. var percent = heapMax > 0 ? 100 * heapUsed / heapMax : 0;
  30. var result = [];
  31. result.pushObject(heapUsed.bytesToSize(1, "parseFloat") + ' of ' + heapMax.bytesToSize(1, "parseFloat"));
  32. result.pushObject(percent.toFixed(1) + '% used');
  33. return result;
  34. }.property('model.jobTrackerHeapUsed', 'model.jobTrackerHeapMax'),
  35. thresh1: 40,// can be customized
  36. thresh2: 70,
  37. maxValue: 100,
  38. isPieExist: function () {
  39. var total = this.get('model.jobTrackerHeapMax') * 1000000;
  40. return total > 0 ;
  41. }.property('model.jobTrackerHeapMax'),
  42. template: Ember.Handlebars.compile([
  43. '<div class="has-hidden-info">',
  44. '<li class="thumbnail row">',
  45. '<a class="corner-icon" href="#" {{action deleteWidget target="view"}}>','<i class="icon-remove-sign icon-large"></i>','</a>',
  46. '<div class="caption span10">', '{{view.title}}','</div>',
  47. '<a class="corner-icon span1" href="#" {{action editWidget target="view"}}>','<i class="icon-edit"></i>','</a>',
  48. '<div class="hidden-info">', '<table align="center">{{#each line in view.hiddenInfo}}', '<tr><td>{{line}}</td></tr>','{{/each}}</table>','</div>',
  49. '{{#if view.isPieExist}}',
  50. '<div class="widget-content" >','{{view view.content modelBinding="view.model" thresh1Binding="view.thresh1" thresh2Binding="view.thresh2"}}','</div>',
  51. '{{else}}',
  52. '<div class="widget-content-isNA" >','{{t services.service.summary.notAvailable}}','</div>',
  53. '{{/if}}',
  54. '</li>',
  55. '</div>'
  56. ].join('\n')),
  57. content: App.ChartPieView.extend({
  58. model: null, //data bind here
  59. id: 'widget-jt-heap', // id in html
  60. stroke: '#D6DDDF', //light grey
  61. thresh1: null,
  62. thresh2: null,
  63. innerR: 25,
  64. existCenterText: true,
  65. centerTextColor: function (){
  66. return this.get('contentColor');
  67. }.property('contentColor'),
  68. palette: new Rickshaw.Color.Palette({
  69. scheme: [ '#FFFFFF', '#D6DDDF'].reverse()
  70. }),
  71. data: function () {
  72. var used = this.get('model.jobTrackerHeapUsed') * 1000000;
  73. var total = this.get('model.jobTrackerHeapMax') * 1000000;
  74. var percent = total > 0 ? ((used)*100 / total).toFixed() : 0;
  75. return [ percent, 100 - percent];
  76. }.property('model.jobTrackerHeapUsed', 'model.jobTrackerHeapMax'),
  77. contentColor: function (){
  78. var used = parseFloat(this.get('data')[0]);
  79. var thresh1 = parseFloat(this.get('thresh1'));
  80. var thresh2 = parseFloat(this.get('thresh2'));
  81. var color_green = '#95A800';
  82. var color_red = '#B80000';
  83. var color_orange = '#FF8E00';
  84. if (used <= thresh1) {
  85. this.set('palette', new Rickshaw.Color.Palette({
  86. scheme: [ '#FFFFFF', color_green ].reverse()
  87. }))
  88. return color_green;
  89. } else if (used <= thresh2) {
  90. this.set('palette', new Rickshaw.Color.Palette({
  91. scheme: [ '#FFFFFF', color_orange ].reverse()
  92. }))
  93. return color_orange;
  94. } else {
  95. this.set('palette', new Rickshaw.Color.Palette({
  96. scheme: [ '#FFFFFF', color_red ].reverse()
  97. }))
  98. return color_red;
  99. }
  100. }.property('data', 'this.thresh1', 'this.thresh2'),
  101. refreshSvg: function () {
  102. // remove old svg
  103. var old_svg = $("#" + this.id);
  104. old_svg.remove();
  105. // draw new svg
  106. this.appendSvg();
  107. }.observes('model.jobTrackerHeapUsed', 'model.jobTrackerHeapMax', 'this.thresh1', 'this.thresh2')
  108. })
  109. })