Code Monkey home page Code Monkey logo

hgraph-react's Introduction

hGraph React

An open source visualization for patient health data, as a React component using d3.

View the React based demo for this repository.

See the core hGraph repo for more examples and roadmap.

Looking for React Native? Check out the port to React Native from Citizen Health.

hGraph

Installation

This package can be found on npm and installed like so:

$ yarn add hgraph-react
# or
$ npm install hgraph-react

The hGraph component is packaged using webpack.

Usage

hGraph Component Props

Most props are not required and have sensible defaults built in, as listed below.

Prop Name Type Is Required Description Default
data array true An array of objects representing the metrics to display in hGraph (see below) N/A
score number false The overall score to display in the center of hGraph N/A
width number false The width in pixels hGraph should render at. 600
height number false The height in pixels hGraph should render at. 600
margin object false An object representing the values for margins around hGraph. { top: 70, right: 100, bottom: 70, left: 100 }
thresholdMin number false A number value between 0 and 1 (percentage), determining the position the lower threshold of the healthy range renders at. .25
thresholdMax number false A number value between 0 and 1 (percentage), determining the position the upper threshold of the healthy range renders at. .75
donutHoleFactor number false A number value between 0 and 1 (percentage), determining the amount of hGraph's radius that should be cut out forming the hole in the center of the graph. .4
color string (hex color code) false The color of the points and polygon shape. '#616363'
healthyRangeFillColor string (hex color code) false The color of the healthy range band. '#98bd8e'
fontSize number false The size (in pixels) of the font for the labels. 16
fontColor string (hex color code) false The color of the labels. '#000'
showAxisLabel boolean false Whether or not axis labels should display around hGraph. true
axisLabelWrapWidth number false The width (in pixels) that the labels should wrap text at. 80 (Note: use null for no wrapping)
axisLabelOffset number false The distance (in pixels) that axis labels should be offset from the outer bounds of hGraph's 'absolute max' radius. 12
areaOpacity number false The opacity of the polygon shape. 0.25
pointRadius number false The radius (in pixels) of the points for metric values. 10
pointLabelWrapWidth number false The width (in pixels) that the point labels should wrap text at. null (no wrapping)
pointLabelOffset number false The distance (in pixels) that point labels should be offset from the point. 8
hitboxRadius number false The radius (in pixels) of the point hitboxes. (hGraph overlays a transparent hitbox over each point which can help users accurately click/touch points, particularly on mobile devices.) Defaults to props.pointRadius size.
showScore boolean false Whether or not to display the overall score in the middle of hGraph. true
scoreFontSize number false The size (in pixels) of the font for the overall hGraph score 120
scoreFontColor string (hex color code) false The color of the hGraph score. '#000'
zoomFactor number false The multiplier factor hGraph should zoom in. 2.25
zoomTransitionTime number false The amount of time (in milliseconds) the zooming animation should take. 750
zoomOnPointClick boolean false Configure if hGraph should zoom in/focus on a clicked point and display child points in the graph. true
onPointClick function false Callback function called when a point is clicked. Function is passed 2 arguments: the data object corresponding to the point clicked, and the event. N/A

hGraph Metric Object Properties

Property Name Type Is Required Description
id string true A unique (compared to all other metrics) identifier string for the metric.
label string true The axis display label for the metric.
value number true The patient's recorded value for the metric.
healthyMin number true The minimum value possible to still be considered a healthy value.
healthyMax number true The maximum value possible to still be considered a healthy value.
absoluteMin number true A reasonable minimum possible value for this metric. Note: values below this absolute minimum will be clamped to the min.)
absoluteMax number true A reasonable maximum possible value for this metric. Note: values above this absolute maximum will be clamped to the max.
unitLabel string true The units the metric is measured in, displayed with the metric value.
children array false Optional array of child metrics that comprise this metric. Children metrics should conform to hGraph Metric Objects properties. Children are shown when a point is clicked and hGraph is in the "zoomed in" state.

License

hGraph is Apache 2.0 licensed.

For guidance integrating hGraph into your product or service, contact us at [email protected].

hgraph-react's People

Contributors

craigmcginley avatar dependabot[bot] avatar ericbenwa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hgraph-react's Issues

Feature Request: prop for pop-up card

Current designs call for a pop-up or overlay card, that can inspect contents of a data point on hGraph.

Screen Shot 2020-12-08 at 11 53 01 AM

It would be ideal to be able to feed in an external React component via a prop. Possible API might look like the following:

          <HGraph
            data={ data.currentData }
            width={ graphSize }
            height={ graphSize }
            healthyRangeFillColor={themePrimaryColor}
            showScore={ false }
            margin={{ top: 140, right: 72, bottom: 140, left: 72 }}      
            popUpPosition={['bottom', 'right']} // auto?
            popUpComponent={<SimplePopUp theme="dark" />}
          /> 

Feature Request: scoreFontWeight

Request from the design team to decrease the font weight of the hScore in the center. We currently have scoreFontSize and scoreFontColor, but no ability to control for font weight.

          <HGraph
            data={ data.currentData }
            width={ graphSize }
            height={ graphSize }
            score={ 42 }
            scoreFontSize={ graphSize < 300 ? 48 : 96 }
            scoreFontWeight={ 200 }
          /> 

Received NaN for the 'cx' attribute.

Hello,
We're trying to adjust the metrics of hGraph to do a categorical view of FHIR resource collections, in which case most all values will be 0 to N. So, we're trying to feed a dataset into hGraph that looks roughly like this:

let collectionBuckets = [
  {
    "id": "allergyIntoleranceCount",
    "label": "Allergy Intolerances",
    "healthMin": 0,
    "healthMax": 10,
    "absoluteMin": 0,
    "absoluteMax": 100,
    "value": 5,
    "weight": 10,
    "unitLabel": "records"
  },
  {
    "id": "conditionCount",
    "label": "Conditions",
    "healthMin": 0,
    "healthMax": 20,
    "absoluteMin": 0,
    "absoluteMax": 200,
    "value": 14,
    "weight": 10,
    "unitLabel": "records"
  },
  {
    "id": "diagnosticReportCount",
    "label": "Diagnostic Reports",
    "healthMin": 0,
    "healthMax": 20,
    "absoluteMin": 0,
    "absoluteMax": 200,
    "value": 6,
    "weight": 10,
    "unitLabel": "records"
  },
  {
    "id": "encounterCount",
    "label": "Encounters",
    "healthMin": 0,
    "healthMax": 100,
    "absoluteMin": 0,
    "absoluteMax": 1000,
    "value": 22,
    "weight": 10,
    "unitLabel": "records"
  }
];

When it renders, all the points are at the center origin, and aren't picking up the values.
Screen Shot 2020-12-02 at 8 51 26 AM

Digging into the console, we're getting a Received NaN for the 'cx' attribute. error message.
Screen Shot 2020-12-02 at 8 59 10 AM

React peerDependency @ ^16.13.0

Hi,
Next issue... hGraph is loading with the collection counts now, but it's react library is colliding with other libraries. Since React ~16.12, there has been a move towards pure components and the 'Rule of Hooks'. Could we move the react dependency to a peerDependency, and bump it up to @^16.13.0?

Screen Shot 2020-12-17 at 11 55 19 AM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.