Giter Site home page Giter Site logo

ember-cli-chartist's Introduction

Chartist.js for Ember-CLI Projects

Ember Observer Score

This is an ember-cli wrapper for Chartist. It allows you to render Chartist charts in your templates using components.

Important note

  • You should probably not use this addon as Chartist is not maintained.
  • Per the previous this package is also in maintenance mode only
  • Consider easing your upgrade burden by copying the component code to your application (along with the license) as this is MIT licensed.

Compatibility

  • Ember.js v3.20 or above
  • Ember CLI v3.20 or above
  • ember-auto-import v2 required
  • Node.js v12 or above

Setup

In an existing ember-cli project. Install with:

ember install ember-cli-chartist

In the template where you want the chart to appear:

<ChartistChart @type="line" @data={{model.chartData}} />
  • data is an optional attribute. Its value should be an object. Check the Chartist docs for expected data structure.
  • type is a required attribute. It can be any of the recognized chat types.

Where does the data come from?

The data can be specified in an Ember route or controller. In the example above it's coming from the model which is defined in the route.

/app/routes/application.js

import Route from '@ember/routing/route';

export default class ApplicationRoute extends Route {
  model() {
    return {
      chartData: {
        labels: ['Day1', 'Day2', 'Day3'],
        series: [
          [5, 4, 8],
          [10, 2, 7],
          [8, 3, 6],
        ],
      },
    };
  }
}

Chart types

There are three types of charts; line, bar, and pie. The default is line. You can change the chart type using the type attribute.

/app/templates/application.hbs

<ChartistChart @type="bar" @data={{model.chartData}} />

Responsive scaling

Chartist charts scale up and down in size. They do so at specified ratios. You can change the ratio using the ratio attribute.

/app/templates/application.hbs

<ChartistChart @ratio="ct-golden-section" @data={{model.chartData}} />

See Chartist docs for the full list of ratios and info on how to create your own.

Chart configuration

Chartist charts have a whole bunch of cool configuration options. You can pass those to the chartist-chart components with the options attribute. You'll need to create the options object in a similar way as you do for the data attribute object.

/app/templates/application.hbs

<ChartistChart @options={{chartOptions}} @data={{model.chartData}} />

/app/controllers/application.js

import Controller from '@ember/controller';

export default ApplicationController extends Controller {
  chartOptions = {
    showArea: true,
    lineSmooth: false,

    axisX: {
      showGrid: false
    }
  };
};

See the Chartist docs for all available config options. There's bunch of good-uns!

Responsive config

You can also configure your charts based on media queries. The same configuration options are available, but you provide them via the responsiveOptions attribute. They can be used in tandem with standard options.

<ChartistChart @responsiveOptions={{chartResOptions}} @data={{model.chartData}} />

/app/controllers/application.js

import Controller from '@ember/controller';

export default ApplicationController extends Controller {
  chartResOptions = [
    ['screen and (min-width: 640px)', {
      showArea: true,
      lineSmooth: false,

      axisX: {
        showLabel: false
      }
    }]
  ];
};

Other configuration

There are other ways to configure chartist-chart components that are specific to the addon.

updateOnData: By default, when the data associated with a chartist-chart is changed, the chart will be updated to reflect the data. That can be turned off by setting updateOnData to false. Note: If you use this option, you will have to manually draw and redraw the chart using Chartist methods.

<ChartistChart @updateOnData={{false}} />

Custom CSS

If you want to use custom CSS you can tell the addon to not include the compiled version.

In your app's ember-cli-build.js:

let app = new EmberApp({
  'ember-cli-chartist': {
    useCustomCSS: true,
  },
});

If you use custom CSS, you'll likely want to import the Chartist Scss into your app's scss, you will need to install ember-cli-sass. You can then import the Chartist scss with:

In app.scss

@import 'chartist/chartist.scss';

you can also import the Chartist settings scss:

@import 'chartist/chartist-settings.scss';

For more on custom styles see the Chartist docs

Extending chartist-chart

Care has been taken to provide as many knobs and parameters as you'd need to NOT extend the <ChartistChart component. Pass in data you need. The component does yield its template above the chart.

Should you find yourself needing to extend the base class please open an issue.

Using Plugins

  1. Add the plugin of your choice to your dependencies, e.g. yarn add -D chartist-plugin-fill-donut
  2. In ember-cli-build.js import your plugin, e.g. app.import('node_modules/chartist-plugin-fill-donut/dist/chartist-plugin-fill-donut.js');
  3. In your chartOptions object add the plugin, e.g.
chartOptions = {
  plugins: [
    Chartist.plugins.fillDonut({
      // config of plugin
    }),
  ],
};

Live examples

There is an example app included in this repo in /tests/dummy/. It contains examples of most of the functionality described above. To view those examples you'll need to clone this repo and start the Ember cli server.

git clone https://github.com/jherdman/ember-cli-chartist.git
cd ember-cli-chartist
ember serve

The example app will be running at http://localhost:4200

How do I Test My Chart?

Asserting on characteristics of your chart is kind of hard as it's an SVG rendering. Tools like Percy may be of help with ensuring your chart looks the way it should. We do have an issue open and are interested in pull requests to help with this matter.

Consider, however, that your chart may be difficult to read for people that are visually impaired. Consider implementing an accessible data table โ€” these are vastly easier to make assertions on. Note that we do not provide tooling for this as it's out of scope for this library, and is probably too close to your business domain to meaningfully abstract.

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

ember-cli-chartist's People

Contributors

bachmann1234 avatar brlodi avatar darrenn avatar dependabot[bot] avatar ember-tomster avatar globegitter avatar jacobq avatar jherdman avatar knownasilya avatar miguelcobain avatar odoe avatar samselikoff avatar trianglegrrl avatar tylergaw 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

Watchers

 avatar  avatar

ember-cli-chartist's Issues

Docs seem incorrect

This line "You can see which version of Chartist is used by examining blueprints/ember-cli-chartist/index.js." no longer seems right.

Looking at the history this was once true but is no longer.

Prepare for 1.1.0

TODO

  • Draft release notes
  • Double check code against a prod version of an app
  • Ensure Ember CLI is up to date (#49)
  • Update build on Travis to use Chrome (#50)
  • Ensure Chartist is up to date (#51)
  • Update version number (#53)
  • Publish the release on Github
  • Publish the release on NPM
  • Investigate if it's possible to give me powers to publish to NPM so @tylergaw doesn't need to be pestered each time :)

sassOptions.includePaths not being recognized

[I have this fixed already, but I'm adding this issue for posterity. I can see this happening to other addon devs]

In an example app using the addon, when attempting to import scss files from chartist in app.scss I'm getting the following error:

Users/tyler/workspace/bucket/ember-cli-chartist-example/tmp/tree_merger-tmp_dest_dir-GVrWQhZ4.tmp/app/styles/app.scss:1: file to import not found or unreadable: "chartist"
Current dir: /Users/tyler/workspace/bucket/ember-cli-chartist-example/tmp/tree_merger-tmp_dest_dir-GVrWQhZ4.tmp/app/styles/ [string exception]

In app.scss:

@import "chartist";

This should work because in the chartist addon we're adding add the chartist scss directory to sassOptions.includePaths:

In index.js

...
app.options.sassOptions = app.options.sassOptions || {};
app.options.sassOptions.includePaths = app.options.sassOptions.includePaths || [];

app.options.sassOptions.includePaths.push(path_join(modulePath,
  chartistPath, 'scss'));

app.options.sassOptions.includePaths.push(path_join(modulePath,
  chartistPath, 'scss/settings'));
...

The first two lines create the sassOptions and includePaths obj/arr in a non-destructive way in case sassOptions are set somewhere else in an app. I got this from ember-cli-bootstrap-sass

Accessibility

Hi there,
Thanks for this awesome addon.

I was wondering if there is any plan to add accessibility to charts, like Screen readers be able to reach elements within the graph?
Thanks

Do Custom CSS instructions need updating?

Ember 3.1.

There is no Brockfile.js but I figured out it's actually ember-cli-build.js.

@import 'chartist' in styles/app.scss results in: "File to import not found ...".

Work around: copy the *.scss files from here into styles/ dir and import.

I'm probably missing something basic, but the instructions as written do not work. And even worse, my solution seems awfully workaroundy.

Chartist v1

Hi ๐Ÿ‘‹. Iโ€™m Dan from the Chartist team.

Thank you for your work on ember-cli-chartist!

Recently weโ€™ve released Chartist v1.0.0, fully rewritten to TypeScript and updated to the modern tech. What do you think about adding Chartist v1 support to ember-cli-chartist?

Latest Ember CLI breaks addon

Upgrading from Ember CLI 0.2.7 to...1.13.1 causes Ember Chartist to barf out an error....

Path or pattern "bower_components/chartist/dist/chartist.js" did not match any files
Error: Path or pattern "bower_components/chartist/dist/chartist.js" did not match any files
    at Object.multiGlob (/my-code/test-project/node_modules/ember-cli/node_modules/broccoli-kitchen-sink-helpers/index.js:203:13)
    at Class.module.exports.CachingWriter.extend.addFiles (/my-code/test-project/node_modules/ember-cli/node_modules/broccoli-sourcemap-concat/concat-with-maps.js:74:13)
    at Class.module.exports.CachingWriter.extend.updateCache (/my-code/test-project/node_modules/ember-cli/node_modules/broccoli-sourcemap-concat/concat-with-maps.js:52:12)
    at /my-code/test-project/node_modules/ember-cli/node_modules/broccoli-sourcemap-concat/node_modules/broccoli-caching-writer/index.js:92:34
    at lib$rsvp$$internal$$tryCatch (/my-code/test-project/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:489:16)
    at lib$rsvp$$internal$$invokeCallback (/my-code/test-project/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:501:17)
    at lib$rsvp$$internal$$publish (/my-code/test-project/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:472:11)
    at lib$rsvp$asap$$flush (/my-code/test-project/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:1290:9)
    at process._tickCallback (node.js:355:11)

Removing the addon restores normal functionality to the ember project.

Get ember-cli-chartist working with Ember CLI 0.2.x

If you're a developer who needs to run ember-cli-chartist with Ember CLI 0.2.x, put the following in your config/environment.js file:

ENV.sassOptions = {
  includePaths: [
    'node_modules/ember-cli-chartist/vendor/chartist/scss'
  ]
};

Of course, if this array already exists (for example, to get ember-cli-bootstrap-sass working), that string should be added to the includePaths array.

Update to 0.9.1

Hey there is a 0.9.1 version. Is it possible to update? tried to use lastest but it throws somethig like:
Uncaught Error: Exceeded maximum number of iterations while optimizing scale step!
Thanks!

Revert to Chartist 0.5.0

Until this issue https://github.com/gionkunz/chartist-js/issues/161 is fixed I think this should revert to the previous version. It's causing frequent js errors in a project I'm working on.

0.6.0 introduced the meta information for points which is very helpful, but gonna have to not use that for now.

I think I'll release this as a beta for now.

NOTE: I forgot that 0.5.0 contained a different error that was fixed in 0.6.0. I'm reverting this to a particular build that contains that fix but is before 0.6.0 release.

Do not throw an error if no data is present on creation

I initially thought that the component should pretty much blow up if the data property was not supplied. In the checkForReqs we're explicitly throwing an error if it is null. We need to not to that.

One, because it's mean. Missing data on a component should kill the entire app. Two, we need to allow for async data. You can make it work now by setting data to an empty object and then calling the render method when the data is ready, but that's not so good.

Chart should automatically update when data changes

I left this out initially because I didn't want the addon to assume too much about how it was going to be used. It's clear now though that this is a common enough use case that it should be in the addon. In #9 @samselikoff confirmed that this behavior is expected. @samselikoff also pointed out that we should allow the auto updating to be turned off.

We can use Chartists update method This will cause a full redraw of the chart, but I think @gionkuns might be working to change that behavior? I'm not sure that will have any effect on this though.

[Feature request] Remove dependence on bower

Since Bower is "going the way of the dodo" in favor of moving toward just npm/yarn, it'd be nice if this addon could put its chartist dependency into package.json instead of bower.json.

See also:

Add support for responsive options

When creating a new chart you can pass it a responsiveOptions array. It's described as:

Specify an array of responsive option arrays which are a media query and options object pair => [[mediaQueryString, optionsObject],[more...]]

This doesn't go in the options object, it should be passed as another option after that.

This will be an avaialbe attribute responsiveOptions on the Handlebars helper.

Memory leaks, chartist.js teardown functions

I believe as it currently stands, this addon creates memory leaks in any consuming Ember apps.

Using Chrome Dev Tools to create memory profiles of ember-cli-chartist, I found multiple detached SVGLineElements, detached HTMLSpanElements, etc. The memory usage is relatively small from the 2 simple charts in the "dummy" app, but could grow much larger depending on the size/complexity of the charts rendered. As an Ember developer, you should be aware that memory leaks can crash any SPA.

The chartist.js code has 2 teardown functions, detach() and off(), but your Ember wrapper doesn't make use of them on willDestroyElement() or didDestroyElement().

Using the chartist teardown functions could/should solve these memory leaks.

Fix Tests

Many of the tests are now failing. Why is that?

Data not updating on chart

Is there a trick to getting the chart to update when the data has changed? I have a simple

{{chartist-chart type='pie' data=pieData}}

in my template, but the chart isn't updating when pieData changes.

Thanks!

Error with chart component

First of all thanks for this plugin - really useful.

I am using ember-cli 0.2.0-beta.1 with the POD structure and trying to make my own chart-component. So I have app/components/topic-funds-over-time/component.js as well as the template.hbs in the same folder.

My code is just:

import ChartistChart from '../chartist-chart';

export default ChartistChart.extend({
  type: 'bar',
  welcome: function() {
    console.log('Hello component');
    var data = this.get('testData');
    this.set('data', data);
  }.on('init'),
  testData: function() {
    return {
      chartData: {
        labels: ['Day1', 'Day2', 'Day3'],
        series: [
          [5, 4, 8],
          [10, 2, 7],
          [8, 3, 6]
        ]
      }
    };
  }.property()

and I am getting the follwing error:

Uncaught TypeError: Cannot read property 'update' of undefined chartist-chart.js:60 (anonymous function)

On master branch this is the following line: https://github.com/tylergaw/ember-cli-chartist/blob/master/app/components/chartist-chart.js#L65

Any idea what the issue could be?

Btw, displaying the pre-defined charts such as {{chartist-chart data=model.chartData}} works fine.

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.