axes_editor.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. 'Histogram': 'histogram'
  28. // 'Data field': 'field',
  29. };
  30. this.xAxisStatOptions = [
  31. {text: 'Avg', value: 'avg'},
  32. {text: 'Min', value: 'min'},
  33. {text: 'Max', value: 'max'},
  34. {text: 'Total', value: 'total'},
  35. {text: 'Count', value: 'count'},
  36. {text: 'Current', value: 'current'},
  37. ];
  38. if (this.panel.xaxis.mode === 'custom') {
  39. if (!this.panel.xaxis.name) {
  40. this.panel.xaxis.name = 'specify field';
  41. }
  42. }
  43. }
  44. setUnitFormat(axis, subItem) {
  45. axis.format = subItem.value;
  46. this.panelCtrl.render();
  47. }
  48. render() {
  49. this.panelCtrl.render();
  50. }
  51. xAxisOptionChanged() {
  52. if (!this.panel.xaxis.values || !this.panel.xaxis.values[0]){
  53. this.panelCtrl.processor.setPanelDefaultsForNewXAxisMode();
  54. }
  55. this.panelCtrl.onDataReceived(this.panelCtrl.dataList);
  56. }
  57. getDataFieldNames(onlyNumbers) {
  58. var props = this.panelCtrl.processor.getDataFieldNames(this.panelCtrl.dataList, onlyNumbers);
  59. var items = props.map(prop => {
  60. return {text: prop, value: prop};
  61. });
  62. return this.$q.when(items);
  63. }
  64. }
  65. /** @ngInject **/
  66. export function axesEditorComponent() {
  67. 'use strict';
  68. return {
  69. restrict: 'E',
  70. scope: true,
  71. templateUrl: 'public/app/plugins/panel/graph/axes_editor.html',
  72. controller: AxesEditorCtrl,
  73. };
  74. }