GithubHelp home page GithubHelp logo

elemental-design / vx-primitives Goto Github PK

View Code? Open in Web Editor NEW

This project forked from airbnb/visx

3.0 2.0 0.0 10.01 MB

Fork of vx with cross-platform support for React Native, Sketch, etc.

Home Page: https://github.com/elemental-design/vx-primitives/tree/develop

License: MIT License

JavaScript 0.08% CSS 1.78% HTML 0.25% TypeScript 97.89%

vx-primitives's Introduction

Coverage Status

vx

vx is a collection of reusable low-level visualization components. vx combines the power of d3 to generate your visualization with the benefits of react for updating the DOM.


Docs Gallery Blog Slack #vx Changelog Getting started tutorial

Usage

Remix on Glitch

Let's make a simple bar graph.

First we'll install the relevant packages:

$ npm install --save @vx/mock-data @vx/group @vx/shape @vx/scale

import React from 'react';
import { letterFrequency } from '@vx/mock-data';
import { Group } from '@vx/group';
import { Bar } from '@vx/shape';
import { scaleLinear, scaleBand } from '@vx/scale';

// We'll use some mock data from `@vx/mock-data` for this.
const data = letterFrequency;

// Define the graph dimensions and margins
const width = 500;
const height = 500;
const margin = { top: 20, bottom: 20, left: 20, right: 20 };

// Then we'll create some bounds
const xMax = width - margin.left - margin.right;
const yMax = height - margin.top - margin.bottom;

// We'll make some helpers to get at the data we want
const x = d => d.letter;
const y = d => +d.frequency * 100;

// And then scale the graph by our data
const xScale = scaleBand({
  range: [0, xMax],
  round: true,
  domain: data.map(x),
  padding: 0.4,
});
const yScale = scaleLinear({
  range: [yMax, 0],
  round: true,
  domain: [0, Math.max(...data.map(y))],
});

// Compose together the scale and accessor functions to get point functions
const compose = (scale, accessor) => data => scale(accessor(data));
const xPoint = compose(xScale, x);
const yPoint = compose(yScale, y);

// Finally we'll embed it all in an SVG
function BarGraph(props) {
  return (
    <svg width={width} height={height}>
      {data.map((d, i) => {
        const barHeight = yMax - yPoint(d);
        return (
          <Group key={`bar-${i}`}>
            <Bar
              x={xPoint(d)}
              y={yMax - barHeight}
              height={barHeight}
              width={xScale.bandwidth()}
              fill="#fc2e1c"
            />
          </Group>
        );
      })}
    </svg>
  );
}

// ... somewhere else, render it ...
// <BarGraph />

For more examples using vx, check out the gallery.

Motivation

Goal

The goal is to create a library of components you can use to make both your own reusable chart library or your slick custom one-off chart. vx is largely unopinionated and is meant to be built upon. Keep your bundle sizes down and use only the packages you need.

How?

Under the hood, vx is using d3 for the calculations and math. If you're creating your own awesome chart library on top of vx, it's easy to create a component api that hides d3 entirely. Meaning your team could create charts as easily as using reusable react components.

But why?

Mixing two mental models for updating the DOM is never a good time. Copy and pasting d3 code into componentDidMount() is just that. This collection of components lets you easily build your own reusable visualization charts or library without having to learn d3. No more selections or enter()/exit()/update().

Status

Beta We're still in pre v1. Need to add interactions. No breaking changes planned right now read more. Check out the road to v1.

If you're a curious coder, feel free to install and play around with the packages. I recommend using --save-exact when you npm install.

Roadmap

Lots coming soon, check out the roadmap.

In the wild

FAQ

  1. What does vx stand for?

    vx stands for visualization components.

  2. Do you plan on supporting animation/transitions?

    A common criticism of vx is it doesn't have animation baked in, but this was a concious choice. It's a powerful feature to not bake it in.

    Imagine your app already bundles react-motion, adding a hypothetical @vx/animation is bloat. Since vx is react, it already supports all react animation libs.

    Charting libraries are like style guides. Each org or app will eventually want full control over their own implementation.

    vx makes this easier for everyone. No need to reinvent the wheel each time.

    more info: airbnb#6

    examples:

  3. Do I have to use every package to make a chart?

    nope! pick and choose the packages you need.

  4. Can I use this to create my own library of charts for my team?

    Please do.

  5. Does vx work with preact?

    yup! need to alias react + react-dom and use preact-compat. Here's a quick demo: https://vx-preact.now.sh/. more info

  6. I like using d3.

    Me too.

Development

Please see CONTRIBUTING.md

✌️

MIT@hshoff

FOSSA Status

vx-primitives's People

Contributors

crcarlo avatar dennisja avatar diagramatics avatar ffloriel avatar flaque avatar geekplux avatar gillesdemey avatar hshoff avatar jaywelsh avatar jens-ox avatar jordanoverbye avatar kandros avatar kristw avatar lambstack avatar lorenries avatar lucafalasco avatar marcofugaro avatar maryschmidt avatar mmarkelov avatar nschnierer avatar pringels avatar ptmx avatar robinsoncol avatar sdd avatar spiderbites avatar sto3psl avatar techniq avatar trainorpj avatar williaster avatar yuchi avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

vx-primitives's Issues

Publish fork to npm

TODO: Publish the fork to npm to allow React Sketch.app and React Native users to use it today.

API parity with vx

Components

  • @vx/shape
  • @vx/group
  • @vx/gradient
  • @vx/mock-data
  • @vx/scale
  • TODO: Add the rest of the components

Project Discussion

Umbrella issue to discuss the project.

I've renamed the project to vx-primitives and registered an npm org for publishing this over at @vx-primitives/*. I feel that this effort should eventually move upstream to vx, but publishing to vx-primitives in the meantime should be a nice way to let people use the project in native/primitives apps for now.

Stable branch is master, but I think feat/primitives should remain as the PR branch. master should be merged into feat/primitives periodically, stripping out README changes and rollback package.json npm namespace from @vx-primitives/* to @vx/.

Workflow should be opening feature PRs, either from branches (for collaborators), or forks (for (future-)contributors) to merge into master.

@browniefed

[GUIDE] Updating master from upstream

Force push upstream/master to origin/master – This removes all fork changes in master, so make sure they're backed up in separate branches/PRs

git remote add upstream https://github.com/hshoff/vx.git
git checkout upstream/master
git push origin HEAD:master --force

Applying patches

git checkout master
git merge patch/package-json
git push origin master

Master README instructions

npm i @vx/primitives@npm:@vx-primitives/primitives
npm i @vx/shape@npm:@vx-primitives/shape
npm i @vx/gradient@npm:@vx-primitives/gradient
npm i @vx/group@npm:@vx-primitives/group

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.