Skip to content

Commit

Permalink
Fix y1 axis parse
Browse files Browse the repository at this point in the history
  • Loading branch information
tbidne committed Dec 17, 2024
1 parent aecf4f6 commit 3ea3752
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions backend/data/input/example/chart-requests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ y-axis = 'distance'
title = 'Marathons'
filters = ['label marathon']
y-axis = 'duration'
y1-axis = 'pace'

# Takes runs w/ label 'official' but __not__ marathon.
[[charts]]
Expand Down
2 changes: 1 addition & 1 deletion backend/src/Pacer/Chart/Data/ChartRequest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ instance DecodeTOML ChartRequest where
filters <- Utils.getFieldOptArrayOf "filters"
title <- TOML.getFieldWith tomlDecoder "title"
yAxis <- TOML.getFieldWith tomlDecoder "y-axis"
yAxis1 <- TOML.getFieldOptWith tomlDecoder "y-axis1"
yAxis1 <- TOML.getFieldOptWith tomlDecoder "y1-axis"
pure
$ MkChartRequest
{ filters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ y-axis = 'distance'
[[charts]]
title = 'Runs by duration'
y-axis = 'duration'
y-axis1 = 'distance'
y1-axis = 'distance'

[[charts]]
title = 'Runs by pace'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ y-axis = 'distance'
[[charts]]
title = 'Chart 2'
y-axis = 'duration'
y-axis1 = 'distance'
y1-axis = 'distance'
filters = ['label label1']

[[charts]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ y-axis = 'distance'
[[charts]]
title = 'Chart 2'
y-axis = 'duration'
y-axis1 = 'distance'
y1-axis = 'distance'
filters = ['label label1']

[[charts]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ y-axis = 'distance'
[[charts]]
title = 'Runs by duration'
y-axis = 'duration'
y-axis1 = 'distance'
y1-axis = 'distance'

[[charts]]
title = 'Runs by pace'
Expand Down
7 changes: 7 additions & 0 deletions backend/test/functional/goldens/testExampleChart.golden
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
12000,
18900
]
},
"y1": {
"label": "/km",
"values": [
284.3938855314611,
447.9203697120512
]
}
},
"title": "Marathons"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ MkChartRequests
]
, title = "Marathons"
, yAxis = YAxisDuration
, yAxis1 = Nothing
, yAxis1 = Just YAxisPace
}
, MkChartRequest
{ filters =
Expand Down
23 changes: 21 additions & 2 deletions web/src/build_charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,30 @@ function mkDataSet(x: { values: number[]; label: string }) {
};
}

for (var i = 0; i <= charts.length; i++) {
/**
* We widen charts to charts_typed since if charts.json does not have any
* charts with a y1 axis, ts will infer the y1 prop does not exist,
* hence the y1 access will fail.
*/
const charts_typed = charts as {
data: {
x: string[];
y: {
label: string; values: number[];
};
y1: {
label: string; values: number[];
};
};
title: string;
}[];


for (var i = 0; i <= charts_typed.length; i++) {
const elemId = `chart${i}`;
appendCanvasId(elemId);

const chart = charts[i];
const chart = charts_typed[i];
const title = chart.title;

let opts: ChartOptions<"line"> = null;
Expand Down

0 comments on commit 3ea3752

Please sign in to comment.