src/charts/line.js
function cleanData({dataByTopic, dataByDate, data}) {
            if (!dataByTopic && !data) {
                throw new Error('Data needs to have a dataByTopic or data property. See more in http://eventbrite.github.io/britecharts/global.html#LineChartData__anchor');
            }

            // If dataByTopic or data are not present, we generate them
            if (!dataByTopic) {
                dataByTopic = d3Collection.nest()
                    .key(getVariableTopicName)
                    .entries(data)
                    .map(d => ({
                            topic: d.values[0]['name'],
                            topicName: d.key,
                            dates: d.values
                        })
                    );
            } else {
                data = dataByTopic.reduce((accum, topic) => {
                    topic.dates.forEach((date) => {
                        accum.push({
                            topicName: topic[topicNameLabel],
                            name: topic[topicLabel],
                            date: date[dateLabel],
                            value: date[valueLabel]
                        });
                    });

                    return accum;
                }, []);
            }

            // Nest data by date and format
            dataByDate = d3Collection.nest()
                .key(getDate)
                .entries(data)
                .map((d) => {
                    return {
                        date: new Date(d.key),
                        topics: d.values
                    }
                });

            const normalizedDataByTopic = dataByTopic.reduce((accum, topic) => {
                let {dates, ...restProps} = topic;

                let newDates = dates.map(d => ({
                       date: new Date(d[dateLabel]),
                       value: +d[valueLabel]
                }));

                accum.push({ dates: newDates, ...restProps });

                return accum;
            }, []);

            return {
                dataByTopic: normalizedDataByTopic,
                dataByDate
            };
        }
function cleanData({dataByTopic, dataByDate, data}) {
            if (!dataByTopic && !data) {
                throw new Error('Data needs to have a dataByTopic or data property. See more in http://eventbrite.github.io/britecharts/global.html#LineChartData__anchor');
            }

            // If dataByTopic or data are not present, we generate them
            if (!dataByTopic) {
                dataByTopic = d3Collection.nest()
                    .key(getVariableTopicName)
                    .entries(data)
                    .map(d => ({
                            topic: d.values[0]['name'],
                            topicName: d.key,
                            dates: d.values
                        })
                    );
            } else {
                data = dataByTopic.reduce((accum, topic) => {
                    topic.dates.forEach((date) => {
                        accum.push({
                            topicName: topic[topicNameLabel],
                            name: topic[topicLabel],
                            date: date[dateLabel],
                            value: date[valueLabel]
                        });
                    });

                    return accum;
                }, []);
            }

            // Nest data by date and format
            dataByDate = d3Collection.nest()
                .key(getDate)
                .entries(data)
                .map((d) => {
                    return {
                        date: new Date(d.key),
                        topics: d.values
                    }
                });

            const normalizedDataByTopic = dataByTopic.reduce((accum, topic) => {
                let {dates, ...restProps} = topic;

                let newDates = dates.map(d => ({
                       date: new Date(d[dateLabel]),
                       value: +d[valueLabel]
                }));

                accum.push({ dates: newDates, ...restProps });

                return accum;
            }, []);

            return {
                dataByTopic: normalizedDataByTopic,
                dataByDate
            };
        }
function cleanData ( { dataByTopic , dataByDate , data } ) { if ( ! dataByTopic && ! data ) { throw new Error ( 'Data needs to have a dataByTopic or data property. See more in http://eventbrite.github.io/britecharts/global.html#LineChartData__anchor' ) ; } // If dataByTopic or data are not present, we generate them if ( ! dataByTopic ) { dataByTopic = d3Collection . nest ( ) . key ( getVariableTopicName ) . entries ( data ) . map ( d => ( { topic : d . values [ 0 ] [ 'name' ] , topicName : d . key , dates : d . values } ) ) ; } else { data = dataByTopic . reduce ( ( accum , topic ) => { topic . dates . forEach ( ( date ) => { accum . push ( { topicName : topic [ topicNameLabel ] , name : topic [ topicLabel ] , date : date [ dateLabel ] , value : date [ valueLabel ] } ) ; } ) ; return accum ; } , [ ] ) ; } // Nest data by date and format dataByDate = d3Collection . nest ( ) . key ( getDate ) . entries ( data ) . map ( ( d ) => { return { date : new Date ( d . key ) , topics : d . values } } ) ; const normalizedDataByTopic = dataByTopic . reduce ( ( accum , topic ) => { let { dates , ... restProps } = topic ; let newDates = dates . map ( d => ( { date : new Date ( d [ dateLabel ] ) , value : + d [ valueLabel ] } ) ) ; accum . push ( { dates : newDates , ... restProps } ) ; return accum ; } , [ ] ) ; return { dataByTopic : normalizedDataByTopic , dataByDate } ; }
Parses dates and values into JS Date objects and numbers
@param  {obj} dataByTopic    Raw data grouped by topic
@return {obj}                Parsed data with dataByTopic and dataByDate
Parses dates and values into JS Date objects and numbers