formatting fixed

This commit is contained in:
Axel Müller
2024-01-07 07:33:32 +01:00
parent 17426f0a97
commit 39d175314c
5 changed files with 53 additions and 63 deletions

View File

@@ -42,7 +42,7 @@ export class BarPlot {
fill: barData.fill, fill: barData.fill,
strokeWidth: 0, strokeWidth: 0,
strokeFill: barData.fill, strokeFill: barData.fill,
} };
}), }),
}; };
} }

View File

@@ -57,11 +57,11 @@ export class BasePlot implements Plot {
throw Error('Axes must be passed to render Plots'); throw Error('Axes must be passed to render Plots');
} }
const drawableElem: DrawableElem[] = []; const drawableElem: DrawableElem[] = [];
const linePlots = this.chartData.plots.filter(plot => plot.type === 'line') as LinePlotData[]; const linePlots = this.chartData.plots.filter((plot) => plot.type === 'line') as LinePlotData[];
const barPlots = this.chartData.plots.filter(plot => plot.type === 'bar') as BarPlotData[]; const barPlots = this.chartData.plots.filter((plot) => plot.type === 'bar') as BarPlotData[];
let plotIndex = 0; let plotIndex = 0;
if(linePlots.length) { if (linePlots.length) {
const linePlot = new LinePlot( const linePlot = new LinePlot(
linePlots[0], linePlots[0],
this.xAxis, this.xAxis,
@@ -71,7 +71,7 @@ export class BasePlot implements Plot {
); );
drawableElem.push(...linePlot.getDrawableElement()); drawableElem.push(...linePlot.getDrawableElement());
} }
if(barPlots.length) { if (barPlots.length) {
const barPlot = new BarPlot( const barPlot = new BarPlot(
barPlots, barPlots,
this.boundingRect, this.boundingRect,

View File

@@ -335,10 +335,9 @@ describe('Testing xychart jison file', () => {
expect(parserFnConstructor(str)).not.toThrow(); expect(parserFnConstructor(str)).not.toThrow();
expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' }); expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' });
expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', type: 'text' }); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', type: 'text' });
expect(mockDB.setBarData).toHaveBeenCalledWith([[ expect(mockDB.setBarData).toHaveBeenCalledWith([
{ text: 'barTitle', type: 'text' }, [{ text: 'barTitle', type: 'text' }, [23, 45, 56.6, 0.22]],
[23, 45, 56.6, 0.22] ]);
]]);
}); });
it('parse bar Data spaces and +,- symbol', () => { it('parse bar Data spaces and +,- symbol', () => {
const str = const str =
@@ -346,10 +345,9 @@ describe('Testing xychart jison file', () => {
expect(parserFnConstructor(str)).not.toThrow(); expect(parserFnConstructor(str)).not.toThrow();
expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' }); expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' });
expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', type: 'text' }); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', type: 'text' });
expect(mockDB.setBarData).toHaveBeenCalledWith([[ expect(mockDB.setBarData).toHaveBeenCalledWith([
{ text: 'barTitle with space', type: 'text' }, [{ text: 'barTitle with space', type: 'text' }, [23, -45, 56.6]],
[23, -45, 56.6] ]);
]]);
}); });
it('parse bar Data without plot title', () => { it('parse bar Data without plot title', () => {
const str = const str =
@@ -392,18 +390,12 @@ describe('Testing xychart jison file', () => {
expect(parserFnConstructor(str)).not.toThrow(); expect(parserFnConstructor(str)).not.toThrow();
expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' }); expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' });
expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', type: 'text' }); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', type: 'text' });
expect(mockDB.setBarData).toHaveBeenCalledWith([[ expect(mockDB.setBarData).toHaveBeenCalledWith([
{ text: 'barTitle1', type: 'text' }, [{ text: 'barTitle1', type: 'text' }, [23, 45, 56.6]],
[23, 45, 56.6] ]);
]]); expect(mockDB.setBarData).toHaveBeenCalledWith([
expect(mockDB.setBarData).toHaveBeenCalledWith( [{ text: 'barTitle2', type: 'text' }, [13, 42, 56.89]],
[ ]);
[
{ text: 'barTitle2', type: 'text' },
[13, 42, 56.89]
],
],
);
expect(mockDB.setLineData).toHaveBeenCalledWith( expect(mockDB.setLineData).toHaveBeenCalledWith(
{ text: 'lineTitle1', type: 'text' }, { text: 'lineTitle1', type: 'text' },
[11, 45.5, 67, 23] [11, 45.5, 67, 23]
@@ -432,14 +424,12 @@ describe('Testing xychart jison file', () => {
{ text: 'category 2', type: 'text' }, { text: 'category 2', type: 'text' },
{ text: 'category3', type: 'text' }, { text: 'category3', type: 'text' },
]); ]);
expect(mockDB.setBarData).toHaveBeenCalledWith([[ expect(mockDB.setBarData).toHaveBeenCalledWith([
{ text: 'barTitle1', type: 'text' }, [{ text: 'barTitle1', type: 'text' }, [23, 45, 56.6]],
[23, 45, 56.6] ]);
]]); expect(mockDB.setBarData).toHaveBeenCalledWith([
expect(mockDB.setBarData).toHaveBeenCalledWith([[ [{ text: 'barTitle2', type: 'text' }, [13, 42, 56.89]],
{ text: 'barTitle2', type: 'text' }, ]);
[13, 42, 56.89]
]]);
expect(mockDB.setLineData).toHaveBeenCalledWith( expect(mockDB.setLineData).toHaveBeenCalledWith(
{ text: 'lineTitle1', type: 'text' }, { text: 'lineTitle1', type: 'text' },
[11, 45.5, 67, 23] [11, 45.5, 67, 23]

View File

@@ -172,7 +172,7 @@ function setLineData(title: NormalTextType, data: number[]) {
type NamedDataset = [title: NormalTextType, data: number[]]; type NamedDataset = [title: NormalTextType, data: number[]];
function setBarData(datasets: NamedDataset[]) { function setBarData(datasets: NamedDataset[]) {
datasets.forEach(dataset => { datasets.forEach((dataset) => {
const plotData = transformDataWithoutCategory(dataset[1]); const plotData = transformDataWithoutCategory(dataset[1]);
xyChartData.plots.push({ xyChartData.plots.push({
type: 'bar', type: 'bar',