diff --git a/src/components/BarChart/HorizontalBarChart.js b/src/components/BarChart/HorizontalBarChart.js index 43dd70a5..a02bcfdd 100644 --- a/src/components/BarChart/HorizontalBarChart.js +++ b/src/components/BarChart/HorizontalBarChart.js @@ -194,9 +194,6 @@ const HorizontalBarChart = ({ const yScale = scaleLinear().domain(yDomain).range([height - margins.bottom, margins.top]).nice(); const yStackScale = yScale.copy().range([0, height - margins.bottom - margins.top]); - - - // let { values: xAxisValues } = axisPropsFromTickScale(xScale); const xAxisValues = xTickSpan ? range(xDomain[0], xDomain[xDomain.length - 1], xTickSpan) : xValues; let { values: yAxisValues } = axisPropsFromTickScale(yScale, 10); diff --git a/src/components/BarChart/VerticalBarChart.js b/src/components/BarChart/VerticalBarChart.js index a39ece07..79d58739 100644 --- a/src/components/BarChart/VerticalBarChart.js +++ b/src/components/BarChart/VerticalBarChart.js @@ -195,7 +195,7 @@ const VerticalBarChart = ({ return 1 * multiplier; }) ]) - , [data, y.field, autoSort, sortYAscending, sortYField, sortYType, sortXAscending, sortXField, sortXType, color.field, colorModalities]); + , [data, y, autoSort, sortYAscending, sortYField, sortYType, sortXAscending, sortXField, sortXType, color, colorModalities]); const xDomain = initialXDomain || layout === 'stack' ? // stack -> max = max sum for a given x modality diff --git a/src/components/BoatsIllustration/BoatsIllustration.js b/src/components/BoatsIllustration/BoatsIllustration.js index a9a3955c..9d946c0a 100644 --- a/src/components/BoatsIllustration/BoatsIllustration.js +++ b/src/components/BoatsIllustration/BoatsIllustration.js @@ -10,6 +10,12 @@ import './BoatsIllustration.scss'; const PASS_DURATION = 100000; const UPDATE_RATE = 4000; +/** + * Returns a boat hull shape + * @param {number} width + * @param {number} height + * @returns {React.ReactElement} - React component + */ const Hull = ({ width, height, @@ -25,6 +31,14 @@ const Hull = ({ } +/** + * Returns a boat sail shape + * @param {number} width + * @param {number} height + * @param {number} sailSpeed - period in miliseconds + * @param {number} distance - factor in [0,1] + * @returns {React.ReactElement} - React component + */ const Sail = ({ width, height, @@ -62,6 +76,14 @@ const Sail = ({ ) } +/** + * Returns a boat matt shape + * @param {number} width + * @param {number} height + * @param {number} sailSpeed - period in miliseconds + * @param {number} distance - factor in [0,1] + * @returns {React.ReactElement} - React component + */ const Matt = ({ width, height, @@ -87,6 +109,13 @@ const Matt = ({ ) } +/** + * Returns a boat shape + * @param {number} x + * @param {number} height + * @param {number} distance - factor in [0,1] + * @returns {React.ReactElement} - React component + */ const Boat = ({ x, height, @@ -159,6 +188,13 @@ const Boat = ({ ) } +/** + * Returns a bird shape + * @param {number} boatHeight + * @param {number} containerHeight + * @param {number} distance - factor in [0,1] + * @returns {React.ReactElement} - React component + */ const Bird = ({ boatHeight, containerHeight, @@ -207,6 +243,16 @@ const Bird = ({ ) } +/** + * Returns a moving boat + optional birds + * @param {number} containerHeight + * @param {number} containerWidth + * @param {boolean} rightToLeft + * @param {number} startAt - starting point in pixels + * @param {number} size - factor for defining height relative to container height + * @param {number} distance - factor in [0,1] + * @returns {React.ReactElement} - React component + */ const MovingBoat = ({ containerHeight, containerWidth, @@ -274,6 +320,12 @@ const MovingBoat = ({ } +/** + * Returns moving boats + * @param {number} width + * @param {number} height + * @returns {React.ReactElement} - React component + */ const BoatsIllustration = ({ width: inputWidth = 1200, height: inputHeight = 100, diff --git a/src/components/BoatsIllustration/BoatsIllustration.scss b/src/components/BoatsIllustration/BoatsIllustration.scss index a1c1045b..475db7d6 100644 --- a/src/components/BoatsIllustration/BoatsIllustration.scss +++ b/src/components/BoatsIllustration/BoatsIllustration.scss @@ -1,17 +1,15 @@ - - - .BoatsIllustration { .boat { line { stroke: grey; } - polygon, path { + polygon, + path { fill: lightgrey; } .sail { - opacity: .9; + opacity: 0.9; } .hull { @@ -21,4 +19,4 @@ .bird { fill: grey; } -} \ No newline at end of file +} diff --git a/src/components/Caller/Caller.js b/src/components/Caller/Caller.js index 508ea599..63ddc770 100644 --- a/src/components/Caller/Caller.js +++ b/src/components/Caller/Caller.js @@ -5,18 +5,28 @@ import {v4 as genId} from 'uuid'; import {VisualizationControlContext} from '../../helpers/contexts'; +/** + * Visulization caller to place in contents + * @param {string} id - visualization id used by visualization context to map caller with a specific vis + * @param {object} props - visualization parameters passed as payload to visualization context + * @returns {React.ReactElement} - React component + */ const Caller = ({id: visualizationId, ...props}) => { const ref = useRef(null); + // we differentiate caller id and visualization id as their rel can theoretically be n-1 const [id] = useState(genId()); const { + // used to define whether caller is active activeVisualization, onBlockClick, + // callbacks used to register/unregister visualization data & HTML ref in upstream state onRegisterVisualization, onUnregisterVisualization, } = useContext(VisualizationControlContext); + // register vis on caller's mount, unregister it on unmount useEffect(() => { - // on wrappe dans un setTimeout pour avoir une ref non-nulle vers le composant + // we wrap callback in a setTimeout in order to have a non-null ref to the HTML element setTimeout(() => { let payload = {...props}; payload = { @@ -43,6 +53,7 @@ const Caller = ({id: visualizationId, ...props}) => { className={cx("Caller", { 'is-active': activeVisualization && id === activeVisualization.id, 'is-clearfix': !visualizationId, + // currently is-hidden and is-devmode are logically symetrical, but this can be useful to differentiate the 2 in dev 'is-hidden': process.env.NODE_ENV !== 'development', 'is-devmode': process.env.NODE_ENV === 'development', })} diff --git a/src/components/CircularAlluvialChart/CircularAlluvialChart.js b/src/components/CircularAlluvialChart/CircularAlluvialChart.js index 56b85feb..16eeebd2 100644 --- a/src/components/CircularAlluvialChart/CircularAlluvialChart.js +++ b/src/components/CircularAlluvialChart/CircularAlluvialChart.js @@ -14,51 +14,29 @@ import { min } from 'd3-array'; import { uniq } from 'lodash-es'; import { cartesian2Polar, fixSvgDimension, trimText } from '../../helpers/misc'; import ReactTooltip from 'react-tooltip'; -import { useSpring, animated } from 'react-spring' -const colorSchemes = [colorScheme1, colorScheme2, colorScheme3]; +import {G, Text, Line, Circle, Rect, Path} from './animatedPrimities'; -const G =({children, className, onClick, ...inputProps}) => { - const props = useSpring(inputProps); - return ( - - {children} - - ) -} -const Text =({children, onClick, className, style, ...inputProps}) => { - const props = useSpring(inputProps); - return ( - - {children} - - ) -} -const Line = ({style, className, onClick, ...inputProps}) => { - const props = useSpring(inputProps); - return ( - - ) -} -const Circle = ({style, className, onClick, ...inputProps}) => { - const props = useSpring(inputProps); - return ( - - ) -} -const Rect = ({style, className, onClick, ...inputProps}) => { - const props = useSpring(inputProps); - return ( - - ) -} -const Path = ({style, className, onClick, ...inputProps}) => { - const props = useSpring(inputProps); - return ( - - ) -} +const colorSchemes = [colorScheme1, colorScheme2, colorScheme3]; +/** + * Renders a circular alluvial diagram (duh) + * @param {array} data + * @param {string} sumBy - field in data to use to quantify flows + * @param {array} steps - arrow of steps in the form: {field: [string], labels: {fr: [string], en: [string]}, filters: [{key: [string], value: [string]}]} + * @param {number} width + * @param {number} height + * @param {array} filters - objects in the form {key, value} to highlight some flows in the vis + * @param {boolean} debug + * @param {string} title + * @param {object} colorsPalettes + * @param {boolean} centerHorizontalLabels + * @param {boolean} displaceHorizontalLabels - avoid labels overlap (at the cost of invadint the center of the vis) + * @param {object} tooltips - tooltips of nested functions in the form {node: {fr: [fn], en: [fn]}, flow: {fr: [fn], en: [fn]}} + * @param {string} lang - enum ['fr', 'en'] + * @param {string} align - enum ['left', 'center'] + * @returns {React.ReactElement} - React component + */ const CircularAlluvialChart = ({ data: inputData = [], sumBy, @@ -403,17 +381,6 @@ const CircularAlluvialChart = ({ data-for="alluvial-tooltip" data-tip={tContent} > - {/* */} } data + * @param {string} sumBy + * @param {array} steps + * @param {number} width + * @param {number} height + * @param {array} filters + * @returns {React.ReactElement} - React component + */ const LinearAlluvialChart = ({ data : inputData = [], sumBy, diff --git a/src/components/CircularAlluvialChart/animatedPrimities.js b/src/components/CircularAlluvialChart/animatedPrimities.js new file mode 100644 index 00000000..8968edd9 --- /dev/null +++ b/src/components/CircularAlluvialChart/animatedPrimities.js @@ -0,0 +1,43 @@ +import { useSpring, animated } from 'react-spring' + + +export const G =({children, className, onClick, ...inputProps}) => { + const props = useSpring(inputProps); + return ( + + {children} + + ) +} +export const Text =({children, onClick, className, style, ...inputProps}) => { + const props = useSpring(inputProps); + return ( + + {children} + + ) +} +export const Line = ({style, className, onClick, ...inputProps}) => { + const props = useSpring(inputProps); + return ( + + ) +} +export const Circle = ({style, className, onClick, ...inputProps}) => { + const props = useSpring(inputProps); + return ( + + ) +} +export const Rect = ({style, className, onClick, ...inputProps}) => { + const props = useSpring(inputProps); + return ( + + ) +} +export const Path = ({style, className, onClick, ...inputProps}) => { + const props = useSpring(inputProps); + return ( + + ) +} \ No newline at end of file diff --git a/src/components/CitationWidget/CitationWidget.js b/src/components/CitationWidget/CitationWidget.js index 03e86be1..a77fde18 100644 --- a/src/components/CitationWidget/CitationWidget.js +++ b/src/components/CitationWidget/CitationWidget.js @@ -21,6 +21,12 @@ const CONTENTS = { } } + +/** + * Description + * @param {string} lang + * @returns {React.ReactElement} - React component + */ const CitationWidget = ({ lang = 'fr', }) => { @@ -93,6 +99,7 @@ const CitationWidget = ({ : null } + {/* disabled: copy on click (gadget) */} {/*
{copyClicked ? messages.citationCopied[lang] : messages.copyCitation[lang]}
*/} diff --git a/src/components/DataProvider/DataProvider.js b/src/components/DataProvider/DataProvider.js index 05e9ac8a..6491f4df 100644 --- a/src/components/DataProvider/DataProvider.js +++ b/src/components/DataProvider/DataProvider.js @@ -2,6 +2,12 @@ import { useEffect, useState } from "react"; import { csvParse } from 'd3-dsv'; import get from 'axios'; +/** + * Fetches data and provides it to children (used for tests) + * @param {string} data + * @param {function} children + * @returns {React.ReactElement} - React component + */ const DataProvider = ({ data: dataFilename, children diff --git a/src/components/DeclineChart/DeclineChart.js b/src/components/DeclineChart/DeclineChart.js index e098dda2..c396305f 100644 --- a/src/components/DeclineChart/DeclineChart.js +++ b/src/components/DeclineChart/DeclineChart.js @@ -5,6 +5,20 @@ import ProductsDistributionChart from './ProductsDistributionChart'; import './DeclineChart.scss'; import { fixSvgDimension } from '../../helpers/misc'; + +/** + * Configurable wrapper for main viz #1 + * @param {number} width + * @param {number} height + * @param {string} lang + * @param {number} startYear + * @param {number} endYear + * @param {number} productTradePartThreshold + * @param {array} rows - list of visualization rows to display at a certain time + * @param {datasets} object + * @param {boolean} atlasMode + * @returns {React.ReactElement} - React component + */ const DeclineChart = (props) => { const { width: inputWidth, diff --git a/src/components/DeclineChart/DeclineChart.scss b/src/components/DeclineChart/DeclineChart.scss index 9ba02dcf..58f7132b 100644 --- a/src/components/DeclineChart/DeclineChart.scss +++ b/src/components/DeclineChart/DeclineChart.scss @@ -1,10 +1,10 @@ - +@import '../../variables.scss'; .DeclineChart { position: relative; // @todo externalize scss variables - font-family: "IBM Plex Sans", sans-serif; + font-family: $font-family-1; max-height:100%; .row { @@ -22,8 +22,6 @@ h3 { margin-top: 0; margin-bottom: .5rem; - // color: grey; - // font-weight: 500; font-size: 1rem; } @@ -229,4 +227,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/components/DeclineChart/LongitudinalTradeChart.js b/src/components/DeclineChart/LongitudinalTradeChart.js index 069b73b6..c230ebc3 100644 --- a/src/components/DeclineChart/LongitudinalTradeChart.js +++ b/src/components/DeclineChart/LongitudinalTradeChart.js @@ -10,7 +10,11 @@ import ReactTooltip from 'react-tooltip'; import colorsPalettes from "../../colorPalettes"; import { fixSvgDimension } from "../../helpers/misc"; - +/** + * Improve the display of numbers + * @param {string|number} str - the number to prettify + * @returns {string} + */ const prettifyValue = str => { const inted = Math.round(+str) + ''; let finalStr = ''; @@ -22,7 +26,7 @@ const prettifyValue = str => { finalStr = char + finalStr; if (count === 3) { count = 0; - finalStr = ',' + finalStr; + finalStr = ' ' + finalStr; } } if (finalStr[0] === ',') { @@ -32,6 +36,28 @@ const prettifyValue = str => { return finalStr; } +/** + * Displays a double diagram displaying a histogram and a linechart, with optional additional annotations + * @param {array} data + * @param {string} absoluteField + * @param {string} shareField + * @param {string} herfindhalField + * @param {number} width + * @param {number} height + * @param {string} axisLeftTitle + * @param {string} axisRightTitle + * @param {number} startYear + * @param {number} endYear + * @param {boolean} fillGaps - whether to display a line between two datapoints distant by more than one year + * @param {function} barTooltipFn + * @param {string} cityName + * @param {array} highlightYears + * @param {string} title + * @param {object} colorScaleMessages + * @param {array} annotations - in the form of {startYear: [int], endYear: [int], label: [string], row: [int], labelPosition: [string in ['left', 'right']]} + * @param {object} margins - in the form {'left': [number],'right': [number],'top': [number],'bottom': [number]} + * @returns {React.ReactElement} - React component + */ const LongitudinalTradeChart = ({ data: inputData, // fields: if null, viz will not show the corresponding data @@ -380,14 +406,6 @@ const LongitudinalTradeChart = ({ } return -1; }) - // .filter((d, index) => { - // const next = data[index + 1]; - // if (+d.year === 1787 && !barTooltipFn) { - // console.log('2 next for 1787', d.year, +next.year, next) - // } - // return index < data.length - 1 - // && (fillGaps ? true : +next.year === +d.year + 1) - // }) .map((datum, index) => { const next = data[index + 1]; if (index === data.length - 1 || fillGaps ? false : +next.year !== +datum.year + 1) { diff --git a/src/components/DeclineChart/ProductsDistributionChart.js b/src/components/DeclineChart/ProductsDistributionChart.js index 7e2ff9ae..4f220adf 100644 --- a/src/components/DeclineChart/ProductsDistributionChart.js +++ b/src/components/DeclineChart/ProductsDistributionChart.js @@ -12,6 +12,24 @@ import { fixSvgDimension } from '../../helpers/misc'; // - click on products highlight same product on all years ? // - click on products make label bigger for small ones ? + +/** + * Displays a comparison of exported products totalizing n% of total shares of exports + * @param {array} data + * @param {array} tradeData + * @param {string} field + * @param {number} partTreshold - limit of the total cumulated share of exports from which to display products - in [0,1] + * @param {number} height + * @param {number} barWidth + * @param {string} herfindhalField + * @param {array} years - two years to compare + * @param {number} width + * @param {string} title + * @param {object} margins + * @param {function} productTooltipFn + * @param {boolean} compareFrom + * @returns {React.ReactElement} - React component + */ const ProductsDistributionChart = ({ data: allData, tradeData = [], diff --git a/src/components/Footer/Footer.js b/src/components/Footer/Footer.js index 0bd93c30..590b86c2 100644 --- a/src/components/Footer/Footer.js +++ b/src/components/Footer/Footer.js @@ -2,6 +2,11 @@ import FooterFr from '!babel-loader!mdx-loader!../../contents/fr/footer.mdx'; import FooterEn from '!babel-loader!mdx-loader!../../contents/fr/footer.mdx'; +/** + * Displays the footer from attached mdx contents + * @param {string} lang + * @returns {React.ReactElement} - React component + */ const Footer = ({lang}) => { return (