GithubHelp home page GithubHelp logo

doytsujin / giraffe Goto Github PK

View Code? Open in Web Editor NEW

This project forked from influxdata/giraffe

0.0 1.0 0.0 2.14 MB

A foundation for visualizations in the InfluxDB UI

Home Page: https://influxdata.github.io/giraffe/

License: MIT License

TypeScript 98.96% JavaScript 0.73% Shell 0.31%

giraffe's Introduction

Giraffe

A React-based visualization library powering the data visualizations in InfluxDB 2.0 UI.

This library is currently in pre-beta

๐Ÿฆ’ Features

There exist plenty of terrific visualization libraries in the JavaScript ecosystem. Giraffe aims to distinguish itself with several features:

  • Supports Flux
  • Easy reactivity and extensibility via React
  • Support for mapping groupings of columns to a single visual aesthetic
  • A high-level Grammar of Graphics style API that can specify a wide variety of visualizations with a few simple concepts
  • A columnar interface for input data that enables efficient interop with Web Workers and Apache Arrow
  • Self-contained configs in the style of Vega-Lite

Getting Started

Installation

Install Giraffe with your package manager

yarn add @influxdata/giraffe or npm install @influxdata/giraffe

Example

  1. In your React code, import the Plot component and the newTable utility function
  import {Plot, newTable} from '@influxdata/giraffe'
  
  1. Build the config object.
    a. Required properties:

    • table is data built using the newTable utilty function (also built from Flux results, see Flux example)
    • layers is an array of objects that describe how to render the data.

    b. Optional properties include customizations for

    • gridlines: color and opacity
    • axes: appearance, color, opacity, and scaling
    • ticks: generation, formatting and labeling, font, and color
    • legend (tooltip): labeling and styling

    For details on all configuration properties, go to the configuration guide.

    Here is an example of building the config object while skipping optional properties:

  // Example table and layer

  const table = newTable(5)
    .addColumn('_time', 'time', [1589838401244, 1589838461244, 1589838521244, 1589838581244, 1589838641244])
    .addColumn('_value', 'number', [2.58, 7.11, 4.79, 8.89, 2.23])

  const lineLayer = {
    type: "line",
    x: "_time",
    y: "_value",
  }

  const config = {
    table: table,
    layers: [lineLayer],
  }
  
  1. Render your component by passing the config object as the config prop to the <Plot> component. Be sure that the parent component around <Plot> has both a height and a width measured in positive values. If either is not a positive value, the graph will not be visible.

    For example, to make a <Plot> that adjusts to screen height and width, in your React rendering code return this element:

  // return this element in your React rendering code:

  <div
    style={{
      width: "calc(70vw - 20px)",
      height: "calc(70vh - 20px)",
      margin: "40px",
    }}
  >
    <Plot config={config} />
  </div>
  

Example Using Flux

When generating the table through a Flux result:

  • call the fromFlux utility function on the csv that is generated by Flux
  • get the table in the returned object from calling fromFlux

Here is an example of turning a result in comma separate values (CSV) from Flux into a table and rendering it without optional properties:

  import {Plot, fromFlux} from '@influxdata/giraffe'

  // ...

  const fluxResultCSV = `#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,double,string,string,string,string
#group,false,false,true,true,false,false,true,true,true,true
#default,_result,,,,,,,,,
,result,table,_start,_stop,_time,_value,_field,_measurement,example,location
,,0,2020-03-25T20:58:15.731129Z,2020-04-24T20:58:15.731129Z,2020-04-03T18:31:33.95Z,29.9,value,temperature,index.html,browser
,,0,2020-03-25T20:58:15.731129Z,2020-04-24T20:58:15.731129Z,2020-04-03T18:55:23.863Z,28.7,value,temperature,index.html,browser
,,0,2020-03-25T20:58:15.731129Z,2020-04-24T20:58:15.731129Z,2020-04-03T19:50:52.357Z,15,value,temperature,index.html,browser
,,0,2020-03-25T20:58:15.731129Z,2020-04-24T20:58:15.731129Z,2020-04-03T19:53:37.198Z,24.8,value,temperature,index.html,browser
,,0,2020-03-25T20:58:15.731129Z,2020-04-24T20:58:15.731129Z,2020-04-03T19:53:53.033Z,23,value,temperature,index.html,browser
,,0,2020-03-25T20:58:15.731129Z,2020-04-24T20:58:15.731129Z,2020-04-03T20:19:21.88Z,20.1,value,temperature,index.html,browser
,,0,2020-03-25T20:58:15.731129Z,2020-04-24T20:58:15.731129Z,2020-04-10T22:20:40.776Z,28.7,value,temperature,index.html,browser
`

  const dataFromFlux = fromFlux(fluxResultCSV)

  const lineLayer = {
    type: "line",
    x: "_time",
    y: "_value",
  }

  const config = {
    table: dataFromFlux.table,
    layers: [lineLayer],
  }

  // ...

  // return this element in your React rendering code:

  <div
    style={{
      width: "calc(70vw - 20px)",
      height: "calc(70vh - 20px)",
      margin: "40px",
    }}
  >
    <Plot config={config} />
  </div>
  

Development

To contribute to Giraffe, see the contributing guide.

Looking for details on the configuration? See the configuration guide.

giraffe's People

Contributors

121watts avatar alexpaxton avatar asalem1 avatar chnn avatar ebb-tide avatar goller avatar hoorayimhelping avatar karel-rehor avatar tcl735 avatar timhallinflux avatar

Watchers

 avatar

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.