Code Monkey home page Code Monkey logo

react-scatter-board's Introduction

react-scatter-board

A React implementation of THREE.js 2d/3d scatter plot. This library was created using the create-react-library CLI.

NPM JavaScript Style Guide

Install

Python

pip install --user --upgrade git+git://github.com/maayanlab/react-scatter-board

Jupyter

from react_scatter_board.jupyter_compat import ScatterBoard
ScatterBoard(
  id='scatterboard-3d',
  is3d=True,
  data=[
    dict(x=0, y=0, z=0, label='a', shape='s', color='r'),
    dict(x=1, y=1, z=-1, label='b', shape='t', color='g'),
    dict(x=-1, y=-1, z=-1, label='c', shape='c', color='b'),
    dict(x=0, y=0, z=1, label='d', shape='c', color='r'),
    dict(x=0, y=1, z=0, label='e', shape='t', color='g'),
    dict(x=0, y=0, z=-1, label='f', shape='t', color='b'),
  ],
  shapeKey='shape',
  colorKey='color',
  labelKeys=['label'],
  searchKeys=['label', 'shape', 'color'],
  width=600,
  height=400,
)

Dash

from react_scatter_board import DashScatterBoard

app = dash.Dash(__name__)
app.layout = DashScatterBoard(
  id='scatterboard-2d',
  is3d=False,
  data=[
    dict(x=0, y=0, label='a', shape='s', color='r'),
    dict(x=1, y=1, label='b', shape='t', color='g'),
    dict(x=-1, y=-1, label='c', shape='c', color='b'),
    dict(x=-1, y=0, label='d', shape='c', color='r'),
    dict(x=0, y=1, label='e', shape='t', color='g'),
    dict(x=1, y=0, label='f', shape='t', color='b'),
  ],
  shapeKey='shape',
  colorKey='color',
  labelKeys=['label'],
  searchKeys=['label', 'shape', 'color'],
  width=600,
  height=400,
)

NodeJS

npm install --save maayanlab/react-scatter-board

Usage

import React, { Component } from "react";
import { ScatterBoard, Lazy } from "react-scatter-board";
import "./App.css";

export default class App extends Component {
  render() {
    return (
      <Lazy loading={<div>Loading...</div>}>{() =>
        fetch('http://localhost:8080/GSE48968_tSNE_3.json').then(
          response => response.json()
        ).then(data => (
          <ScatterBoard
            data={data}
            shapeKey="strain"
            colorKey="description"
            labelKeys={["sample_id"]}
            is3d={true}
          />
        ))
      }</Lazy>
    );
  }
}

Examples

A demo website with examples: React Scatter Board.

Development

Local development is broken into two parts (ideally using two tabs).

First, run rollup to watch your src/ module and automatically recompile it into dist/ whenever you make changes.

npm start # runs rollup with watch flag

The second part will be running the example/ create-react-app that's linked to the local version of your module.

# (in another tab)
cd example
npm start # runs create-react-app dev server

Now, anytime you make a change to your library in src/ or to the example app's example/src, create-react-app will live-reload your local dev server so you can iterate on your component in real-time.

Deployment to GitHub Pages

npm run deploy

This creates a production build of the example create-react-app that showcases your library and then runs gh-pages to deploy the resulting bundle.

Copyright

MaayanLab

react-scatter-board's People

Contributors

avimaayan avatar u8sand avatar wangz10 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-scatter-board's Issues

Opt for `data` prop instead of `url`

Data will be more flexible than url, which is trivial to resolve and possibly more application dependent.

Of course url can probably be kept for convenience.

Lasso Select Feature

Would be useful to be able to select points by lasso and see legend specifically within that selection and potentially extract that set of sample ids

Allow plot to be downloadable as PNG format

I put the small demo code below, and I attached the actual outlook of react scatter plot that might look like, which has a blue "download" button that we can clicked.

IMG_0470

<!DOCTYPE html>
<html>
<body>

<canvas id="myCanvas" width="200" height="100" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML canvas tag.</canvas>

<a download="new-image.png" id="download">Download</a>

<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.arc(95,50,40,0,2*Math.PI);
ctx.stroke();

var canvas = document.getElementById('myCanvas');
var button = document.getElementById('download');
button.setAttribute( 'href', canvas.toDataURL('image/png', 1) )
</script> 

</body>
</html>


[DASH]: Invisible second record

Un-confirmed for other branches but when using Dash, the second record always appears invisible for some reason (the label will be there, you can highlight it, but the point is invisible)

Plotted shapes do not match shapes in legend

Actual plotted shapes (circles, squares, crosses, diamonds) do not match any of the shapes in the legend. It seems like maybe each time Shape By is changed, the plotted shapes reset, but the legend shapes are assigned in succession without resetting.

Screen Shot 2021-06-15 at 9 22 50 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.