Code Monkey home page Code Monkey logo

d3-bootstrap's Introduction

⚠️ This repository is no longer maintained ⚠️

Please see sebt3/d3-bootstrap, an implementation that supports D3 v4.

d3-bootstrap

Twitter's Bootstrap is an awesome CSS framework with some really nice JavaScript tools. The problem with these tools, though, is that they rely heavily on jQuery, while d3 provides (approximately) 99% of the functionality they require.

At first I considered a shim for $ that would expose a more jQuery-like facade on top of d3, but that quickly got messy. Instead, I decided to start rewriting each of Bootstrap's tools from scratch and in a more d3-friendly style. For example, Bootstrap's tooltips:

$("a.tt").tooltip({
  placement: "right"
});

become:

d3.selectAll("a.tt")
  .call(bootstrap.tooltip()
    .placement("right"));

Plugins

So far we've got:

  1. Tooltips (bootstrap)
  2. Popovers (bootstrap)
  3. Alerts (bootstrap)

Usage

There are a couple of ways to use the plugins. The easiest is to just include d3-bootstrap.js (or the minified version, d3-bootstrap.min.js). If you want individual tools you'll need:

  1. d3-compat.js (or d3-compat.min.js), which provides some baseline jQuery-like compatibility such as "mouseenter" and "mouseleave" event support; and
  2. One or more bootstrap-{tool}.js scripts, e.g. bootstrap-tooltip.js.

d3-bootstrap's People

Contributors

jfirebaugh avatar paul-english avatar shawnbot avatar tmcw avatar

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

d3-bootstrap's Issues

Getting Object #<Object> has no method 'tooltip' error

I am trying to use d3-popover on a map I am rendering using d3. Here are my script includes:

<script src="js/d3.v3.min.js"></script> <script src="js/d3-compat.js"></script> <script src="js/bootstrap-popover.js"></script>

At the appropriate time I invoke:
d3.selectAll(".desired")
.call( d3.tooltip().placement("right") );

At this point, the chrome console displays a typeerror with the message: "Object # has no method 'popover'"

I could not find any help on the internet. I also thought it was an issue with d3.v3 since your examples use d3.v2, but even when using v2 I get the typeerror.

Any ideas?

Thank you.

Where to store per-element state? (bootstrap-typeahead)

Hi Shawn, and CC @mbostock,

As you may know, @tmcw and I are using d3-bootstrap components in iD. Right now we have a home-grown typeahead component, and I was looking into generalizing it for inclusion in d3-bootstrap. However, it's not clear to me how to translate some of the bootstrap idioms to d3, and I wanted to see if you had any thoughts.

bootstrap-typeahead uses $.fn.data to store a per-element Typeahead instance which implements the necessary state and behavior. For typeahead, this includes most importantly a reference (this.$menu) to the ul element that displays the typeahead results. Imagine implementing for d3-bootstrap-typeahead a typeahead.close(selection) function -- it needs to hide the menu element corresponding to each element in the selection.

In d3, per-element state is normally either part of the datum or manifested in the local variables of a element-specific closure. Neither of those are suitable in this case: for reusable components like typeahead, the data need to be reserved for user purposes. And closures provide no way of obtaining the state given only a selection or element.

Alternatives:

  • Store data in DOM element properties. This appears to be what existing boostrap-d3 components do. Simple, but introduces risks of name collision, and leads one towards an un-d3-ish classical Typeahead prototype.
  • Materialize all state in the DOM such that it can be recalculated later. For instance, finding the typeahead menu based on DOM traversal or sub-selection. Awkward and error-prone in some cases.
  • Create a per-element data side-channel akin to $.fn.data. This also boils down to DOM element properties, but perhaps in a more maintainable way.

That's a very brief summary of the issues so let me know if it is unclear. Otherwise, any thoughts?

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.