Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing a responsiveOptions array to the update() method #1243

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
9 changes: 8 additions & 1 deletion src/scripts/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
* @param {Object} [data] Optional data you'd like to set for the chart before it will update. If not specified the update method will use the data that is already configured with the chart.
* @param {Object} [options] Optional options you'd like to add to the previous options for the chart before it will update. If not specified the update method will use the options that have been already configured with the chart.
* @param {Boolean} [override] If set to true, the passed options will be used to extend the options that have been configured already. Otherwise the chart default options will be used as the base
* @param {Array} [responsiveOptions] Optional array of responsive option arrays which are a media query and options object pair => [[mediaQueryString, optionsObject],[more...]]. Always overrides any already configured responsiveOptions.
* @memberof Chartist.Base
*/
function update(data, options, override) {
function update(data, options, override, responsiveOptions) {
if(data) {
this.data = data || {};
this.data.labels = this.data.labels || [];
Expand All @@ -35,9 +36,15 @@
});
}

if(responsiveOptions) {
this.responsiveOptions = responsiveOptions;
}

if(options) {
this.options = Chartist.extend({}, override ? this.options : this.defaultOptions, options);
}

if(options || responsiveOptions) {
// If chartist was not initialized yet, we just set the options and leave the rest to the initialization
// Otherwise we re-create the optionsProvider at this point
if(!this.initializeTimeoutId) {
Expand Down