Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
maryia-lapata committed Jan 15, 2020
1 parent 66f706c commit c34477c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ import { useKibana } from '../../../../../plugins/kibana_react/public';
import '../flot';
import { DEFAULT_TIME_FORMAT } from '../../common/lib';

import { buildSeriesData, buildOptions, SERIES_ID_ATTR, colors } from '../helpers/panel_utils';
import {
buildSeriesData,
buildOptions,
SERIES_ID_ATTR,
colors,
Axis,
} from '../helpers/panel_utils';
import { Series, Sheet } from '../helpers/timelion_request_handler';
import { tickFormatters } from '../helpers/tick_formatters';
import { generateTicksProvider } from '../helpers/tick_generator';
import { TimelionVisDependencies } from '../plugin';

export interface PanelProps {
Expand Down Expand Up @@ -182,6 +190,20 @@ function Panel({ interval, seriesList, renderComplete }: PanelProps) {
grid
);
const updatedSeries = buildSeriesData(chartValue, options);

if (options.yaxes) {
options.yaxes.forEach((yaxis: Axis) => {
if (yaxis && yaxis.units) {
const formatters = tickFormatters();
yaxis.tickFormatter = formatters[yaxis.units.type as keyof typeof formatters];
const byteModes = ['bytes', 'bytes/s'];
if (byteModes.includes(yaxis.units.type)) {
yaxis.tickGenerator = generateTicksProvider();
}
}
});
}

const newPlot = $.plot(canvasElem, updatedSeries, options);
setPlot(newPlot);
renderComplete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import { IUiSettingsClient } from 'kibana/public';
import { calculateInterval } from '../../common/lib';
import { xaxisFormatterProvider } from './xaxis_formatter';
import { Series } from './timelion_request_handler';
import { tickFormatters } from './tick_formatters';
import { generateTicksProvider } from './tick_generator';

export interface Axis {
delta?: number;
Expand Down Expand Up @@ -108,19 +106,6 @@ function buildSeriesData(chart: Series[], options: jquery.flot.plotOptions) {
return newSeries;
});

if (options.yaxes) {
options.yaxes.forEach((yaxis: Axis) => {
if (yaxis && yaxis.units) {
const formatters = tickFormatters();
yaxis.tickFormatter = formatters[yaxis.units.type as keyof typeof formatters];
const byteModes = ['bytes', 'bytes/s'];
if (byteModes.includes(yaxis.units.type)) {
yaxis.tickGenerator = generateTicksProvider();
}
}
});
}

return compact(seriesData);
}

Expand Down Expand Up @@ -194,7 +179,7 @@ function buildOptions(
return wrapperSpan.outerHTML;
},
},
} as jquery.flot.plotOptions;
} as jquery.flot.plotOptions & { yaxes?: Axis[] };

return options;
}
Expand Down

0 comments on commit c34477c

Please sign in to comment.