panosoft / node-chartist

SVG Charts on the server.
The Unlicense
83 stars 20 forks source link

feature Allow Chartist options for chart #10

Closed shibanovp closed 8 years ago

shibanovp commented 8 years ago

@alexgig Chartist have some settings that should be set as a property e.g Chartist cannot be required https://github.com/gionkunz/chartist-js/issues/780

{
  axisX: {
    type: Chartist.FixedScaleAxis,
    divisor: 5,
  }

Please help, how it can be properly done? I'm started with lib/chart.js with idea that it can be used like


const Chartist = yield require('node-chartist/lib/chart').Chartist();

Is this approach the best? Should it be expanded to lib/index.js?

alexgig commented 8 years ago

Hello @paul-shibanov,

The option presets AUTOSCALEAXIS, FIXEDSCALEAXIS, etc. are not supported. Instead, the proper way to use these presets is to just manually include the options they set. The actual options for each can be found in the Chartist docs (https://gionkunz.github.io/chartist-js/api-documentation.html). Depending on which you chose, there are only 2-5 options to set.

Best regards, Alex

shibanovp commented 7 years ago

@alexgig I've been trying to use your advice and can't make it work. Thing is you have no ability to set projection to axis with options object. You must have Chartist to do that.

Also you can't set any interpolation with options object because you have to use Chartist API in them.

I have an idea how to solve this without breaking change https://github.com/panosoft/node-chartist/compare/master...paul-shibanov:feature/support-chartist-options?expand=1 Valid:

const co = require('co');
const generate = require('node-chartist');

co(function * () {
  const options = {width: 400, height: 200};
  const data = {
    labels: ['a','b','c','d','e'],
    series: [
      [1, 2, 3, 4, 5],
      [3, 4, 5, 6, 7]
    ]
  };
  const bar = yield generate('bar', options, data); //=> chart HTML
})

New approach with Chartist properties:

const co = require('co');
const generate = require('node-chartist');

co(function *() {
  const bar = yield generate('bar',
    (Chartist) => ({
      showLine: false,
      axisX: {
        type: Chartist.AutoScaleAxis
      },
      axisY: {
        type: Chartist.FixedScaleAxis
      },
    }),
    (Chartist) => ({
      series: {
        'series-1': {
          lineSmooth: Chartist.Interpolation.step()
        }
      }
    }));
});  

If this looks good can you reopen this PR to allow me create some tests and update the docs?

alexgig commented 7 years ago

Hey @paul-shibanov,

Sorry for the delayed response. This pr can't be reopened for some reason (github is saying the branch got force pushed or something). That aside, I think it'd be good to explore ways to allow things like Chartist.Interpolation.step() to be used in options as you illustrated.

I am going to open an issue to track the work. I hope to get some time to work on it this week.

Thanks for raising the issue.

Best regards, Alex

shibanovp commented 7 years ago

@alexgig Great! Please try again, I removed force push.

shibanovp commented 7 years ago

@alexgig In case you missed previous notification. I have some time to complete the PR.

alexgig commented 7 years ago

Hey @paul-shibanov,

Sorry I didn't get to this before the holidays. I have an idea on how I'd like to implement this and should be able to get it done this week. You can follow issue #12 to stay updated on progress.

Best, Alex

alexgig commented 7 years ago

Hey @paul-shibanov,

+ node-chartist@1.0.0 supports this feature. Happy charting!

Best, Alex