Skip to content

Instantly share code, notes, and snippets.

@erikfried
Created October 3, 2012 19:45
Show Gist options
  • Save erikfried/3829366 to your computer and use it in GitHub Desktop.
Save erikfried/3829366 to your computer and use it in GitHub Desktop.
Some YUI3 components, e g AutoComplete or Charts, have a lot of config to set up general look-and-feel, that you typically wish to reuse throughout the application. I have not found out a satisfying way to reuse such config. For instance, extending the C
YUI().use('charts', function (Y) {
//Some config that i want to reuse for more or less all charts in my application
var defaultConfig = function () {
return {
categoryType: "time",
axes: {
category: {
labelFormat: "%e %b"
}
},
styles: {
axes: {
category: {
label: {
rotation: -45
}
}
}
}
//...And it goes on with ~ hundred lines of config
}
};
// Just some dummy data for the chart
var myDataValues = [
{category:"5/1/2010", values:2000},
{category:"5/2/2010", values:50},
{category:"5/3/2010", values:400},
{category:"5/4/2010", values:200},
{category:"5/5/2010", values:5000}
];
//Merge the general "look-and-feel" kind of properties with the instance unique ones, with the latter taking precendence
var finalConfig = Y.mix(defaultConfig(), {
dataProvider: myDataValues,
render: "#mychart"
}, true, null, 0, true);
// Instantiate and render the chart
var mychart = new Y.Chart(finalConfig);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment