GithubHelp home page GithubHelp logo

netflix / ember-nf-graph Goto Github PK

View Code? Open in Web Editor NEW
241.0 408.0 46.0 7.95 MB

Composable graphing component library for EmberJS.

License: Apache License 2.0

JavaScript 65.22% CSS 1.04% HTML 33.74%

ember-nf-graph's Introduction

Build Status npm version

ember-nf-graph

A Component-based DSL for creating graphs in your Ember app. The goal of the library is to create a set of components that allows application or component authors to build graphs in a compositional way. This includes components for templated axes, graph lines, areas, stacked areas, bar graphs, and much more. Check the documentation for more information.

A basic graph example is as follows:

export default Ember.Route.extend({
  model() {
    return {
      myLineData: [
        { x: 0, y: 12 },
        { x: 1, y: 32 },
        { x: 2, y: 42 },
        // ...
      ],
      myAreaData: [
        { x: 0, y: 43 },
        { x: 1, y: 54 },
        { x: 2, y: 13 },
        // ...
      ]
    };
  }
});
{{#nf-graph width=500 height=300 as |nf|}}
  {{#nf.graph as |graph|}}
    <!-- add a line -->
    {{graph.line data=model.myLineData}}

    <!-- add an area -->
    {{graph.area data=model.myAreaData}}

    <!-- mix in any SVG element you want -->
    <circle cx="40" cy="40" r="10"></circle>
  {{/nf.graph}}

	<!-- axis ticks are templateable as well -->
  {{#nf.y-axis as |tick|}}
    <text>{{tick.value}}</text>
  {{/nf.y-axis}}


  {{#nf.x-axis as |tick|}}
    <text>{{tick.value}}</text>
  {{/nf.x-axis}}
{{/nf-graph}}

Installation

This set of Ember components requires Ember-CLI 0.2.0 or higher and Ember 1.10.0 or higher.

To install, simply run ember install ember-nf-graph, or npm install -D ember-nf-graph

Documentation

  • Online at: netflix.github.io/ember-nf-graph/docs (generated by YUIDocs)
  • In package: Documentation for these components is included in the package, and can be found under node_modules/ember-nf-graph/docs/index.html just open in any browser.

Contributing

  • git clone this repository
  • npm install

Running

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://www.ember-cli.com/.

Generating Documentation

This project uses YUIDoc to generate documentation. Once YUIDoc is installed run:

yuidoc -c yuidoc.json

The documentation is located in docs/.

ember-nf-graph's People

Stargazers

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

Watchers

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

ember-nf-graph's Issues

Update from old-fashion style builds

Now that Ember-CLI supports building SASS properly (for a LONG time now, actually), we should move the CSS building into the proper place, rather than having a separate build.

[Bug] D3.js not found

Steps to reproduce

ember new nfgraph-test; cd nfgraph-test
ember install ember-nf-graph
ember s

screen shot 2015-04-17 at 3 36 10 pm

package.json

 "ember-nf-graph": "1.0.0-beta.8",

Tick labels don't work on Glimmer

On ember 1.13.2, when I do

{{#nf-y-axis as |tick|}}
  <text>{{tick.value}}%</text>
{{/nf-y-axis}}

I get the tick lines, but no labels.

Additionally, the guides don't show the tick block-param , though the code seems to expect that.

Remove nf-scroll-area

It's cruft and not part of nf-graph. It's left-overs from the split with nf-table

autoscaling width

If I set {{#nf-graph width="100%"}} this works okay but when trying to combine that with an {{nf-bars}} things go awry and the bars end up stacked on top of each other.

contentClipPathId doesn't work on apps with <base> tag

When the page has a <base href="/something/"> tag, SVG IRIs that are just fragments don't work. The only such IRI in this project is

'clip-path': Ember.computed('graph.contentClipPathId', function(){
  var clipPathId = this.get('graph.contentClipPathId');
  return  `url('#${clipPathId}')`;
}),

which emits something like

<g clip-path="url(#ember718-content-mask)">

Unfortunately, the only workaround is to use the absolute URL of the page. Thus, I suggest something like

'clip-path': Ember.computed('graph.contentClipPathId', function(){
  var clipPathId = this.get('graph.contentClipPathId');
  const currentURL = document.location.href.replace(/#.+$/, '');
  return  `url('${currentURL}#${clipPathId}')`;
}),

which would in turn emit something like

<g clip-path="url(https://myapp.example.com/some/route#ember718-content-mask)">

/cc @jayphelps, who has some experience with these issues.

maxProperty doesn't have a good way to use "default"

๐Ÿ˜„ If I don't pass a yMax, I get a nice default behavior:

{{ember-nf-graph}}

๐Ÿ˜„ If I do pass a yMax, I can get a nice override:

{{ember-nf-graph yMax=100 class='percent-graph'}}

๐Ÿ˜ข But there's no way for me to use yMax=someBoundProperty that might be undefined or might be an integer. If it's undefined, then yMax gets set to undefined, not to the default behavior.

I think an easy solution would be to change the logic in the maxProperty to use the override only if it's not null:

// was:
if(arguments.length > 1) {
  this[__Max_] = value;
} else {

// suggested:
if (value != null) {
  this[__Max_] = value;
} else {

Demo

It might be handy to have a demo showing the graphs that come out of the box with this.

Incompatible rxjs versions

Installing browser packages via Bower...
  cached git://github.com/mbostock/d3.git#3.5.5
  cached git://github.com/blesh/RxEmber.git#0.2.3
  cached git://github.com/Reactive-Extensions/RxJS.git#2.4.7
  cached git://github.com/Reactive-Extensions/RxJS.git#2.3.25
  new version for git://github.com/Reactive-Extensions/RxJS.git#~2.4.6
  resolved git://github.com/Reactive-Extensions/RxJS.git#2.4.10
  conflict Unable to find suitable version for rxjs
    1) rxjs ~2.3.22
    2) rxjs ~2.4.6
[?] Answer: 

Which is due to us saying we need ~2.4.6 but RxEmber needs ~2.3.22

app/ components need to use the new cp syntax

Apparently when I did #63, I missed the entire app/ directory......

New syntax with polyfill looks like this:

import computed from 'ember-new-computed';

export default Ember.Component.extend({
  fullName: computed('firstName', 'lastName', {
    get() {
      return this.get('firstName') + ' ' + this.get('lastName');
    },
    set(key, newName) {
      var parts = newName.split(' ');
      this.setProperties({ firstName: parts[0], lastName: parts[1] });
      return newName;
    }
  });
});

Getter-only should still use this syntax, just not include a set()

Bars displaying only in one column but tracked x and y values actually move

Hi, I have the following input data for a bars graph but for some reason the bars only display in one column:

menuItemStockCount: [
    { x: 0, y: 200 },
    { x: 1, y: 154 },
    { x: 2, y: 130 },
    { x: 3, y: 300 }
  ]

My code in my .hbs file to display the graph is:

{{#nf-graph width=500 
           height=300 
           paddingRight=10 
           paddingTop=10 
            xScaleType="ordinal" 
            yMinMode="fixed" 
            yMin=0
            showLanes=true
            showFrets=true
            }}
  {{#nf-graph-content}}

    {{nf-bars data=model.menuItemStockCount
                trackingMode="snap-last"
        trackedData=tracked}}    

  {{/nf-graph-content}}

  {{#nf-y-axis as |tick|}}
    <text>{{tick.value}}</text>
  {{/nf-y-axis}}

  {{#nf-x-axis as |tick|}}
    <text>{{tick.value}}</text>
  {{/nf-x-axis}}

 {{/nf-graph}}

 <text>{{tracked.x}} {{tracked.y}}</text>

Am I just doing something wrong?

reduce CSS specificity

Example, styling an nf-area:

.my-area > .area {
   fill: blue;
}

this should not be a requirement. A simple class or two should be able to override the default behavior.
Example:

.my-area {
  fill: blue
}

/* or */

.my-area .area {
  fill: blue
}

The first is ideal, but because of the nested nature of some of these components, some specificity will likely be required, as the class is applied to the component container.

Remove RxJS as a dependency

Needing to pull in RxJS via RxEmber (or ember-cli-rx) seems very unnecessary and boatful. The current places it's used seem very easy to do without Rx and would save consumers significant file size.

Create global files

Create a set of files for "global" install. (for use with things like JSBin or non-Ember-CLI applications).

This is a lower priority, but would be nice to have for playground apps.

Examples are missing in FF 28

When the examples page is viewed in FF 28 on mac all the graphs are blank. Safari and Chrome both show this content.

Use ember-cli-rx instead of rx-ember

Bower is painful to deal with. The only reason we are using bower right now is because of an old issue with previous versions of Ember-CLI not allowing addons to use addons. That's fixed, so we should just be using ember-cli-rx.

Remove clippath

Its not being used, and it causes issues with SVG image export

Enable nf-bars-group to support stacked bar charts

It would be great if we could pass an option to nf-bars-group that would change the behavior of nf-bars to stack the different bars within a gorup on top of each other.

{{#nf-bars-group stacked=true}}
  {{nf-bars data=someData yprop="firstprop" ... }}
  {{nf-bars data=someData yprop="otherprop" ... }}
{{/nf-bars-group}}

nf-graph should not disable user-select/drag for every element within

Right now everything inside .nf-graph is made non-selectable/draggable. This prevents someone from easily copying numbers, labels, etc which I don't think was the intent.

.nf-graph * {
  user-select: none;
  user-drag: none;
}

* {
-moz-user-select: none;
-webkit-user-select: none;
user-select: none;
-moz-user-drag: none;
-webkit-user-drag: none;
user-drag: none;
}

Instead, we should explicitly opt out things that should be selectable, Things like lines, paths, etc; if this is even necessary?

wrong property names for x and y

The documentation for nf-line (and others) says the x and y properties contains the paths to access on each data object. But doing

{{nf-line data=model x="foo" y="bar"}}

didn't work. It seems the properties are actually named xprop and yprop, and doing

{{nf-line data=model xprop="foo" yprop="bar"}}

instead worked for me.

Remove nf-scroll-area

MutationObserver is currently being used in nf-scroll-area which prevents it from being used in IE 10 and below as well as phantomjs 1.x; which means testing is a pain, need to add polyfills just for testing which introduces possible bugs if the polyfill doesn't behave exactly the same.

{{nf-scroll-area}} needs to be removed from this library.

Mouse Tracking doesn't work on Glimmer

On Ember 1.13.2 and latest Chrome, I have the following:

{{#nf-graph selected=selectedLine}}
  {{#nf-graph-content}}
    {{nf-vertical-line x=selectedLine.hoverData.x}}
    {{nf-horizontal-line y=selectedLine.hoverData.y}}

    {{nf-line data=data trackingMode="hover" selectable=true selected=true}}
   {{/nf-graph-content}}
{{/nf-graph}}

I've logged the hoverData objects; they all come up with x: null, y: null.

nf-vertical-line doesn't handle null input, produces invalid SVG

nf-vertical-line (and nf-horizontal-line) doesn't handle the case where it's x property is set to null or something non-number. This is a common case since nf-vertical-line is often bound to hoverData on another element, and hoverData is often null or undefined when the mouse is not hovering. It will produce invalid SVG resulting in this error:

Error: Invalid value for attribute y1="NaN"

Docs organization: Modules showing strange classes associated to them

If you look at the documentation and switch to the modules tab, it's really weirdly organized. Probably from a lack of understanding around how YUIDocs organizes modules vs classes.

Input here is welcome, but I'll probably just end up going around and making each module file an actual "module" and skipping the namespace bit. This might have implications for any global file build I do, though, which will likely just be namespaced.

Bar chart xScaleType="ordinal" hides x-axis labels

Adding xScaleType="ordinal" to get a properly formatted bar chart hides the x-axis labels.

screen shot 2015-08-25 at 1 15 51 pm

Removing xScaleType="ordinal" shows labels but formatting is jacked.

screen shot 2015-08-25 at 1 14 49 pm

I'm assuming it has something to do with the way ticks are calculated in the nf-x-axis component. Going to look into it more in depth tomorrow.

For reference, this is the template code I'm using:

     {{#nf-graph
        xScaleType="ordinal"
        yMinMode="fixed"
        yMin=0
        width=336
        height=206
        showFrets=false
        showLanes=true
        paddingTop=10
        paddingLeft=-18
        paddingRight=0}}

        {{#nf-x-axis tickCount=7 as |tick|}}
          <text>{{tick.value}}</text>
        {{/nf-x-axis}}

        {{#nf-y-axis as |tick|}}
          <text>{{tick.value}}</text>
        {{/nf-y-axis}}

        {{#nf-graph-content}}

          {{nf-bars
            data=averageVisitorsPerDayOfWeek
            barWidth=18
            barClass="barz"}}

        {{/nf-graph-content}}
      {{/nf-graph}}

Use block params

Magically making things like tick available inside of templates is no bueno.

Recipes - Add examples for how to use these components.

A top priority for since this component library is really a DSL of sorts, is putting out some sort of "recipe" list or pages that show various ways to use the components to create various effects.

A few ideas for this are:

  • Basic line graph
  • Creating area graphs and stacked area graphs
  • "Hover data" on mouse moves - displaying data nearest the mouse on the graph
  • Shared line/area selection - sharing selected data between multiple graphs
  • Brush selection - adding brush selection to a graph or graphs with nf-brush-selection
  • Using nf-bars
  • Mixing nf-bars and line or area graphs
  • Creating custom graph components
  • Using "primitive" components (nf-svg-rect for example)
  • Customizing axis ticks with tickFilter, etc

attn @jeff3dx and @jayphelps - I could really use your help here.

TESTSSSSS

This library was developed in a hurry and is definitely battle-tested, but it's woefully under-tested.

All major components need more unit tests around them. And Travis needs to be set up. This is a requirement to get out of beta.

Docs links broken

The documentation links from the README appear to be broken (404 error).

2015-04-17_08-49-59

Rename blueprint

blueprints/ember-cli-ember-dvc should be named blueprints/ember-cli-nf-graph so it executes on ember install:install

nf-area-stack should sum y values for each area

Currently, nf-area-stack requires each area underneath it to have data y values that are exactly where they should be plotted. We have an internal requirement that the nf-area-stack should add the values of the each area under the current area. This is the way this should have behaved to begin with, but we can leave the original behavior.

Proposed Fix:

  • add a property named something like sum to nf-area-stack that is a boolean.
  • if sum is not set, show a deprication message warning that the default behavior will be changing in the next version to be sum=true, but is currently sum=false.. in other words, if you're already using the default incorrect behavior, it won't break.

To reiterate, and hopefully add clarity:

new sum property value:

  • true: will add the y values of areas "under" the current area to a total for plotting purposes.
  • false: (the current default bahavior) values are exactly where they should be to create a stacked area.
  • (no value): Defaults to false, but gives a warning message that it will default to true in the next version.

So given the following data y values:

dy1 = [1,2,3,4,5];
dy2 = [2,3,4,5,6];

If sum is false or not set, it will plot as:

dy1PlotAt = [1,2,3,4,5];
dy2PlotAt = [2,3,4,5,6];

if sum is true, it will plot as:

dy1PlotAt = [1,2,3,4,5];
dy2PlotAt = [3,5,7,9,11]; //sums of dy1 and dy2

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.