-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74a979b
commit 97a98bf
Showing
7 changed files
with
147 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,83 @@ | ||
// importing the json data | ||
/* | ||
*Purpose: Helper functions for the charts. | ||
*/ | ||
|
||
/* | ||
*importing the json data | ||
*/ | ||
import data from '../assets/Wine-Data.json' | ||
|
||
/* | ||
*importing the interface | ||
*/ | ||
import type { ChartDataType } from '../interfaces/interface' | ||
|
||
/* | ||
*function to get the data for the first chart | ||
*/ | ||
const getChart1Data = (): ChartDataType => { | ||
/* | ||
*logic to convert the string data to number for Flavanoids, if there is one, and return the data | ||
*/ | ||
|
||
const flavanoids = data.map((item) => { | ||
if (typeof item.Flavanoids === 'string') { | ||
return parseFloat(item.Flavanoids) | ||
} | ||
|
||
return item.Flavanoids | ||
}) | ||
|
||
/* | ||
*logic to convert the string data to number for Ash, if there is one, and return the data | ||
*/ | ||
const ash = data.map((item) => { | ||
if (typeof item.Ash === 'string') { | ||
return parseFloat(item.Ash) | ||
} | ||
|
||
return item.Ash | ||
}) | ||
return { horizontal: flavanoids, vertical: ash, nameX: 'Flavanoids', nameY: 'Ash' } | ||
return { | ||
horizontal: flavanoids, | ||
vertical: ash, | ||
nameX: 'Flavanoids', | ||
nameY: 'Ash' | ||
} | ||
} | ||
|
||
/* | ||
*function to get the data for the second chart | ||
*/ | ||
const getChart2Data = (): ChartDataType => { | ||
/* | ||
*logic to convert the string data to number for *minimum* Alcohol, if there is one, and return the data | ||
*/ | ||
|
||
const alcohol = data.map((item) => { | ||
if (typeof item.Alcohol === 'string') { | ||
return parseFloat(item.Alcohol) | ||
} | ||
|
||
return item.Alcohol | ||
}) | ||
|
||
/* | ||
*logic to convert the string data to number for *minimum* Magnesium, if there is one, and return the data | ||
*/ | ||
const magnesium = data.map((item) => { | ||
if (typeof item.Magnesium === 'string') { | ||
return parseFloat(item.Magnesium) | ||
return Math.floor(parseFloat(item.Magnesium)) | ||
} | ||
|
||
return item.Magnesium | ||
return Math.floor(item.Magnesium) | ||
}) | ||
return { horizontal: alcohol, vertical: magnesium, nameX: 'Alcohol', nameY: 'Magnesium' } | ||
return { | ||
horizontal: alcohol, | ||
vertical: magnesium, | ||
nameX: 'Alcohol', | ||
nameY: 'Magnesium' | ||
} | ||
} | ||
|
||
export { getChart1Data, getChart2Data } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters