axes_editor.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { getValueFormats } from '@grafana/ui';
  2. export class AxesEditorCtrl {
  3. panel: any;
  4. panelCtrl: any;
  5. unitFormats: any;
  6. logScales: any;
  7. xAxisModes: any;
  8. xAxisStatOptions: any;
  9. xNameSegment: any;
  10. /** @ngInject */
  11. constructor(private $scope, private $q) {
  12. this.panelCtrl = $scope.ctrl;
  13. this.panel = this.panelCtrl.panel;
  14. this.$scope.ctrl = this;
  15. this.unitFormats = getValueFormats();
  16. this.logScales = {
  17. linear: 1,
  18. 'log (base 2)': 2,
  19. 'log (base 10)': 10,
  20. 'log (base 32)': 32,
  21. 'log (base 1024)': 1024,
  22. };
  23. this.xAxisModes = {
  24. Time: 'time',
  25. Series: 'series',
  26. Histogram: 'histogram',
  27. // 'Data field': 'field',
  28. };
  29. this.xAxisStatOptions = [
  30. { text: 'Avg', value: 'avg' },
  31. { text: 'Min', value: 'min' },
  32. { text: 'Max', value: 'max' },
  33. { text: 'Total', value: 'total' },
  34. { text: 'Count', value: 'count' },
  35. { text: 'Current', value: 'current' },
  36. ];
  37. if (this.panel.xaxis.mode === 'custom') {
  38. if (!this.panel.xaxis.name) {
  39. this.panel.xaxis.name = 'specify field';
  40. }
  41. }
  42. }
  43. setUnitFormat(axis, subItem) {
  44. axis.format = subItem.value;
  45. this.panelCtrl.render();
  46. }
  47. render() {
  48. this.panelCtrl.render();
  49. }
  50. xAxisModeChanged() {
  51. this.panelCtrl.processor.setPanelDefaultsForNewXAxisMode();
  52. this.panelCtrl.onDataReceived(this.panelCtrl.dataList);
  53. }
  54. xAxisValueChanged() {
  55. this.panelCtrl.onDataReceived(this.panelCtrl.dataList);
  56. }
  57. getDataFieldNames(onlyNumbers) {
  58. const props = this.panelCtrl.processor.getDataFieldNames(this.panelCtrl.dataList, onlyNumbers);
  59. const 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. }