hansmaad / chartist-plugin-zoom

Zoom Plugin for Chartist.js
Do What The F*ck You Want To Public License
17 stars 15 forks source link

[Feature request] Expose some minimal API #19

Open SleepProgger opened 5 years ago

SleepProgger commented 5 years ago

It would be nice to have some minimal API which supported direct access to zoom/reset and some convenience functions. Something like this would prob. work well enough (not the nicest approach, but wouldn't break any existing usage).

  Chartist.plugins.zoom = function (options) {
    options = Chartist.extend({}, defaultOptions, options);
    var plugin = function zoom(chart) {
      ...
      var reset = function () {
    ...
      };
      ...
      function zoomIn(rect) {
        ...
      }
      ...
      plugin.zoomIn = zoomIn;
      plugin.reset = reset;
      plugin.translate = ...;
      ...
    };
    return plugin;
  };
} (window, document, Chartist));

My current (crudish) proposal for the API would look like something like this:

The api prob. needs some more thought but something similar would be really nice to have i think If this (or an similar API) is implemented there should prob also be a way to disable the current mouse/touch events so user can write their own UI if they want.

I am going to toy around a bit over the weekend but would need some more days to finalize something nice.

hansmaad commented 5 years ago

Sounds great. Before making bigger changes, I'd really like to have some basic tests. Unfortunatly, I've no experience with the current grunt setup. I just copied it from the chartist plugin template. So replacing the current build setup with something simpler and something I understand is the first step :)