Skip to content

Commit e6386c1

Browse files
committed
refactor: updates the loadClientConfig destructuring assignment to instead store object array in result. result is mapped to data and label fields. This was due to the shape of the calc var chart_data
1 parent 4c792a3 commit e6386c1

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 096328464c287f4c0f2436c88d0a4b44a7ac25c9

data.js

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import {
55
} from "@formsort/custom-question-api";
66

77
async function loadClientConfig() {
8-
const urlParams = new URLSearchParams(window.location.search);
9-
const answerLabel = urlParams.get('answerLabel');
8+
const urlParams = new URLSearchParams(window.location.search);
9+
const answerLabel = urlParams.get("answerLabel");
1010

11-
const answers = await getAllAnswerValues();
11+
const answers = await getAllAnswerValues();
1212

13-
return answers[answerLabel] || {};
13+
return answers[answerLabel] || {};
1414
}
1515

1616
/**
@@ -27,15 +27,6 @@ async function loadClientConfig() {
2727
* }
2828
*/
2929

30-
// Need a function that can transform: current weight, goal weight, and weight loss time horizon into a fields for data.datasets.data
31-
async function getAllAnswers() {
32-
const answers = await getAllAnswerValues();
33-
const values = Object.values(answers);
34-
35-
console.log(`values: ${values}`);
36-
}
37-
getAllAnswers();
38-
3930
const options = {
4031
pointStyle: false,
4132
fill: true,
@@ -44,17 +35,11 @@ const options = {
4435
borderWidth: 3,
4536
scales: {
4637
x: {
47-
// type: "time",
48-
max: 2,
49-
labels: ["January", "February", "March", "April", "May"],
50-
// min: "February",
5138
grid: {
5239
display: false
5340
},
5441
ticks: {
55-
align: "start",
56-
crossAlign: "far",
57-
count: 2
42+
display: false
5843
}
5944
},
6045
y: {
@@ -74,26 +59,40 @@ const options = {
7459
}
7560
};
7661

77-
const defaultData = {
78-
datasets: [
79-
{
80-
data: [300, 300, 200]
81-
}
82-
]
83-
};
62+
// const defaultData = {
63+
// datasets: [
64+
// {
65+
// data: [1, 10]
66+
// }
67+
// ]
68+
// };
8469

8570
(async function () {
86-
const { data = defaultData, labels } = await loadClientConfig();
71+
const result = await loadClientConfig();
8772

88-
if (labels) {
89-
options.scales.x.labels = labels;
90-
}
73+
const res = await getAllAnswerValues();
74+
const clientConfig = await loadClientConfig();
75+
76+
console.log(res);
77+
console.log(clientConfig);
78+
79+
// chart_data will have labels hard-coded in
80+
// if (labels) {
81+
// options.scales.x.labels = labels;
82+
// }
9183

9284
const ctx = document.getElementById("data");
9385

9486
new Chart(ctx, {
9587
type: "line",
96-
data: data,
97-
options: options
88+
options: options,
89+
data: {
90+
labels: result.map((item) => item.labels),
91+
datasets: [
92+
{
93+
data: result.map((item) => item.data)
94+
}
95+
]
96+
}
9897
});
9998
})();

0 commit comments

Comments
 (0)