axes_editor.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { selectors } from '@grafana/e2e-selectors';
  2. import { GraphCtrl } from './module';
  3. export class AxesEditorCtrl {
  4. panel: any;
  5. panelCtrl: GraphCtrl;
  6. logScales: any;
  7. xAxisModes: any;
  8. xAxisStatOptions: any;
  9. xNameSegment: any;
  10. selectors: typeof selectors.components.Panels.Visualization.Graph.VisualizationTab;
  11. /** @ngInject */
  12. constructor(private $scope: any) {
  13. this.panelCtrl = $scope.ctrl as GraphCtrl;
  14. this.panel = this.panelCtrl.panel;
  15. this.$scope.ctrl = this;
  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. this.selectors = selectors.components.Panels.Visualization.Graph.VisualizationTab;
  43. }
  44. setUnitFormat(axis: { format: any }) {
  45. return (unit: string) => {
  46. axis.format = unit;
  47. // if already set via field config we clear that
  48. if (this.panel.fieldConfig.defaults.unit) {
  49. this.panel.fieldConfig.defaults.unit = undefined;
  50. this.panelCtrl.refresh();
  51. } else {
  52. this.panelCtrl.render();
  53. }
  54. };
  55. }
  56. render() {
  57. this.panelCtrl.render();
  58. }
  59. xAxisModeChanged() {
  60. this.panelCtrl.processor.setPanelDefaultsForNewXAxisMode();
  61. this.panelCtrl.onDataFramesReceived(this.panelCtrl.dataList);
  62. }
  63. xAxisValueChanged() {
  64. this.panelCtrl.onDataFramesReceived(this.panelCtrl.dataList);
  65. }
  66. }
  67. /** @ngInject */
  68. export function axesEditorComponent() {
  69. 'use strict';
  70. return {
  71. restrict: 'E',
  72. scope: true,
  73. templateUrl: 'public/app/plugins/panel/graph/axes_editor.html',
  74. controller: AxesEditorCtrl,
  75. };
  76. }