axes_editor.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import kbn from 'app/core/utils/kbn';
  3. export class AxesEditorCtrl {
  4. panel: any;
  5. panelCtrl: any;
  6. unitFormats: any;
  7. logScales: any;
  8. xAxisModes: any;
  9. xAxisStatOptions: any;
  10. xNameSegment: any;
  11. /** @ngInject **/
  12. constructor(private $scope, private $q) {
  13. this.panelCtrl = $scope.ctrl;
  14. this.panel = this.panelCtrl.panel;
  15. $scope.ctrl = this;
  16. this.unitFormats = kbn.getUnitFormats();
  17. this.logScales = {
  18. 'linear': 1,
  19. 'log (base 2)': 2,
  20. 'log (base 10)': 10,
  21. 'log (base 32)': 32,
  22. 'log (base 1024)': 1024
  23. };
  24. this.xAxisModes = {
  25. 'Time': 'time',
  26. 'Series': 'series',
  27. 'Custom': 'custom'
  28. };
  29. this.xAxisStatOptions = [
  30. {text: 'Avg', value: 'avg'},
  31. {text: 'Min', value: 'min'},
  32. {text: 'Max', value: 'min'},
  33. {text: 'Total', value: 'total'},
  34. {text: 'Count', value: 'count'},
  35. ];
  36. if (this.panel.xaxis.mode === 'custom') {
  37. if (!this.panel.xaxis.name) {
  38. this.panel.xaxis.name = 'specify field';
  39. }
  40. }
  41. }
  42. setUnitFormat(axis, subItem) {
  43. axis.format = subItem.value;
  44. this.panelCtrl.render();
  45. }
  46. render() {
  47. this.panelCtrl.render();
  48. }
  49. xAxisOptionChanged() {
  50. switch (this.panel.xaxis.mode) {
  51. case 'time': {
  52. this.panel.bars = false;
  53. this.panel.lines = true;
  54. this.panel.points = false;
  55. this.panel.legend.show = true;
  56. this.panel.tooltip.shared = true;
  57. this.panel.xaxis.values = [];
  58. this.panelCtrl.onDataReceived(this.panelCtrl.dataList);
  59. break;
  60. }
  61. case 'series': {
  62. this.panel.bars = true;
  63. this.panel.lines = false;
  64. this.panel.points = false;
  65. this.panel.stack = false;
  66. this.panel.legend.show = false;
  67. this.panel.tooltip.shared = false;
  68. this.panelCtrl.processor.validateXAxisSeriesValue();
  69. this.panelCtrl.onDataReceived(this.panelCtrl.dataList);
  70. break;
  71. }
  72. }
  73. }
  74. getDataPropertyNames() {
  75. var props = this.panelCtrl.processor.getDocProperties(this.panelCtrl.dataList);
  76. var items = props.map(prop => {
  77. return {text: prop};
  78. });
  79. console.log(items);
  80. return this.$q.when(items);
  81. }
  82. }
  83. /** @ngInject **/
  84. export function axesEditorComponent() {
  85. 'use strict';
  86. return {
  87. restrict: 'E',
  88. scope: true,
  89. templateUrl: 'public/app/plugins/panel/graph/axes_editor.html',
  90. controller: AxesEditorCtrl,
  91. };
  92. }