Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-liquidchart

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-liquidchart

A Reusable liquid chart made with d3 and react

  • 0.1.13
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

React-liquidchart

A Nice looking liquid chart done with d3 and react, based off http://bl.ocks.org/brattonc/5e5ce9beee483220e2f6

I will put up an example page when I am finished with all the graph types that I want to do and use - about 4 -5 more.

Install from NPM

npm install react-liquidchart

Usage

import React, { Component } from 'react';
import { render } from 'react-dom';
import { Chart, Liquid, Gradient } from 'react-liquidchart';

class ChartLiquid extends Component {
  constructor() {
    super();
    this.onClick = this.onClick.bind(this);
    this.state = ({
      value: (Math.random() * 100),
    });
  }

  onClick() {
    this.setState({
      value: (Math.random() * 100),
    });
  }

  render() {
    return (
      <div
        style={{
          width: '100%',
          height: '500px',
        }}
      >
        <Chart
          responsive
          gradient="liquid"
        >
          <Liquid
            animate
            animateWaves
            onClick={this.onClick}
            amplitude={4}
            value={this.state.value}

          />
          <Gradient />
        </Chart>
      </div>
    );
  }
}
render(<ChartLiquid />, document.getElementById('app'));

Simpler version but with no gradient control

import React, { Component } from 'react';
import { render } from 'react-dom';
import LiquidChart from 'react-liquidchart';

class ChartLiquid extends Component {
  constructor() {
    super();
    this.onClick = this.onClick.bind(this);
    this.state = ({
      value: (Math.random() * 100),
    });
  }

  onClick() {
    this.setState({
      value: (Math.random() * 100),
    });
  }

  render() {
    return (
      <div
        style={{
          width: '100%',
          height: '500px',
        }}
      >
        <LiquidChart
          responsive
          gradient="liquid"
          animate
          ease='easeBackIn'
          animateWaves
          animationWavesTime={4000}
          onClick={this.onClick}
          amplitude={4}
          value={this.state.value}
        />
      </div>
    );
  }
}
render(<ChartLiquid />, document.getElementById('app'));

Components

This chart is broken down into components.

Chart

This is the container that renders the SVG element and the children. It can keep the chart responsive so you dont have to worry about the width and heigth if you have a responsive layout.

Chart PropTypes

NameTypeDefaultDescription
responsivebooleantrueRerenders the chart on screen resize
widthnumbernonesets the width of the component, if responsive is true then it will take fill out into the parent container
heightnumbernonesets the height of the component, the same applies here to the responsive prop.
gradientstringnullIf you want a more watery liquid you can add a lineargradient but you have to set this value to a string variable and also add the component

Liquid

This is the main element that renders all the visable elements in the chart along with one defs for the clipPath.

Liquid PropTypes

NameTypeDefaultDescription
Valuenumber65The value
animateboolfalseIf true then the chart is animated
animateWavesboolfalseif true then the waves will loop between the liquid radius and 0 forever.
animationWavesTimenumber2000The speed of the wave animation
animationTimenumber2000milliseconds for animation length
easestring'easeCubicInOut'The name of the d3 easing function, other values like, easeBack, easeBackInOut, easeSinInOut, easeExpInOut. See d3 easing page for more ideas.
outerRadiusnumber0.9This is the outerRadius of the chart where 1 would be 100% of the radius and 0 would be 0% of the radius..
innerRadiusnumber0.8The innerwidth of the outerpath surronding the liquid, again 0.8 would be 80% of the radius.
marginnumber0.025The margin between the outer path and the liquid, here 0.025 would be 2.5%
amplitudenumber2The Amplitude X * sine(frequency) part of the formula
frequencynumber4Still have to fix this one, this is actually the inverse of frequency it's sine(x/freq) so the higher the number the smoother the wave.
waveScaleLimitbooltrueThis is in the original, this will create a scale that limits the wave height close to 0 or 100
outerArcStyleshape{ fill: 'rgb(23,139,202)'}The style of the outerarc fill and stroke
liquidshape{ fill: 'rgb(23, 139, 202)'}The style of the liquid, fill and stroke
liquidNumbershape{fill: 'rgb(164, 219, 248)'}The style of the number that is in the liquid, fill and stroke
numbershape{fill: 'rgb(4, 86, 129)'}The style of the number that is not in the liquid, fill and stroke

Gradient

This component is nothing more than an ultra thin wrapper around a linearGradient defs.

It takes in stop to create the gradient effect.

But by default it uses shades of the liquid.fill color to create a ultra simple gradient.

Gradient PropTypes

NameTypeDefaultDescription
x1number0The X start coordinate
x2number0The X end coordinate
y1number100The Y start coordinate, remember it starts on the bottom :)
y2number0The Y end coordinate
Example
 // Create a Gradient effect coing from bottom left to top right
 <Gradient
   x1={0}
   y1={100}
   x2={100}
   y2={0}
 >
  <stop stopColor={someColor1} offset="0%" />
  <stop stopColor={someColor2} offset="25%" />
  <stop stopColor={someColor3} offset="50%" />
  <stop stopColor={someColor4} offset="75%" />
  <stop stopColor={someColor5} offset="100%" />
 </Gradient>

LiquidChart PropTypes

All of the above propTypes apply, except you cant insert the stop children into the gradient so it just uses the liquid.fill color to create the gradient.

TODO

  1. Write some tests
  2. Create a Text Component
Licence

This software was available initially under the BSD-2-Clause and it still is. Please see the original and put a github like on it at https://gist.github.com/brattonc/5e5ce9beee483220e2f6

arnthor3@gmail.com

Keywords

FAQs

Package last updated on 15 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc