axes_editor.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. histogramValues: any;
  12. /** @ngInject **/
  13. constructor(private $scope, private $q) {
  14. this.panelCtrl = $scope.ctrl;
  15. this.panel = this.panelCtrl.panel;
  16. $scope.ctrl = this;
  17. this.unitFormats = kbn.getUnitFormats();
  18. this.logScales = {
  19. 'linear': 1,
  20. 'log (base 2)': 2,
  21. 'log (base 10)': 10,
  22. 'log (base 32)': 32,
  23. 'log (base 1024)': 1024
  24. };
  25. this.xAxisModes = {
  26. 'Time': 'time',
  27. 'Series': 'series',
  28. 'Histogram': 'histogram'
  29. // 'Data field': 'field',
  30. };
  31. this.histogramValues = {
  32. 'Percent': 'percent',
  33. 'Count': 'count'
  34. };
  35. this.xAxisStatOptions = [
  36. {text: 'Avg', value: 'avg'},
  37. {text: 'Min', value: 'min'},
  38. {text: 'Max', value: 'max'},
  39. {text: 'Total', value: 'total'},
  40. {text: 'Count', value: 'count'},
  41. {text: 'Current', value: 'current'},
  42. ];
  43. if (this.panel.xaxis.mode === 'custom') {
  44. if (!this.panel.xaxis.name) {
  45. this.panel.xaxis.name = 'specify field';
  46. }
  47. }
  48. }
  49. setUnitFormat(axis, subItem) {
  50. axis.format = subItem.value;
  51. this.panelCtrl.render();
  52. }
  53. render() {
  54. this.panelCtrl.render();
  55. }
  56. xAxisOptionChanged() {
  57. if (!this.panel.xaxis.values || !this.panel.xaxis.values[0]){
  58. this.panelCtrl.processor.setPanelDefaultsForNewXAxisMode();
  59. }
  60. this.panelCtrl.onDataReceived(this.panelCtrl.dataList);
  61. }
  62. getDataFieldNames(onlyNumbers) {
  63. var props = this.panelCtrl.processor.getDataFieldNames(this.panelCtrl.dataList, onlyNumbers);
  64. var items = props.map(prop => {
  65. return {text: prop, value: prop};
  66. });
  67. return this.$q.when(items);
  68. }
  69. }
  70. /** @ngInject **/
  71. export function axesEditorComponent() {
  72. 'use strict';
  73. return {
  74. restrict: 'E',
  75. scope: true,
  76. templateUrl: 'public/app/plugins/panel/graph/axes_editor.html',
  77. controller: AxesEditorCtrl,
  78. };
  79. }