React Package

Add terra graphs to your react project. We also provide a react package, a simple react wrapper.

A wrapper is available on https://www.npmjs.com/package/terra-graphs

Installation

npm -i terra-graphs

Example usage

import { TerraGraph } from 'terra-graphs';
import { BarLoader } from 'react-spinners';

function App() {
  const token = 'valid_token';
  return (
    <div className="p-12 bg-sky-100">
      <div className="text-3xl font-bold mb-10">Sample Dashboard</div>
      <div className="flex flex-row flex-wrap justify-start">
        {['SLEEP_HR_SUMMARY', 'SLEEP_HRV_SUMMARY', 'SLEEP_ASLEEP_DURATION', 'DAILY_STEPS_SUMMARY'].map((t, i) => (
          <TerraGraph
            key={i}
            type={t}
            token={token}
            test={i === 0}
            className="md:w-1/3 h-[350px] w-full"
            loadingComponent={
              <div className="w-full h-full flex flex-col">
                <div className="m-auto">
                  <BarLoader />
                </div>
              </div>
            }
          />
        ))}
      </div>
    </div>
  );
}

Component Properties

PropertyTypeDescription
typeTerraGraphTypeThe graph type desired. See valid types on https://docs.tryterra.co/reference/using-graphs#graph-types
tokenstringAn access token for a particular user to enable data access and graph rendering. Generate a token using https://docs.tryterra.co/reference/generate-token
stylesCSSPropertiesCustom css properties for the graph container
classNamestringClassname for the graph container
testbooleanWhether to use a test graph. Test graphs don't require a valid token as they are intended to test the UI / UX
loadingComponentJSX.ElementCustom element displayed when the graph is loading. Default is null
startDatestring (dateTime)(optional) If start_date is not specified, the data will be spanned across the last week, two weeks, or month (respectively) from today. If start_date is specified, the data will be spanned across the week following the specified start date. (e.g. 2023-02-03)
endDatestringCustomize the time period more by specifying an exact end date for the graph. This param overrides the timepeirod.
timePeriodenumIf start_date is not specified, the data will be spanned across the last week, two weeks, or month (respectively) from today. If start_date is specified, the data will be spanned across the week following the specified start date. For time period more than three months, the data will be spanned across a longer range of time with lower sample points.
getImgbooleanSet this parameter to True to get an png image of the graph instead of a frontend html.
imgWidthintSet return image width
imgHeightintSet return image height
getSmallTemplatebooleanWether to use a small widget template.