times / axisJS

Open source framework for creating simple interactive graphs
MIT License
74 stars 12 forks source link

Figure out how to move formatter callbacks around #110

Closed aendra-rininsland closed 8 years ago

aendra-rininsland commented 9 years ago

Presently they're all in a block sort of like this:

importData.config.axis.x.tick.format = function(b) {if('series'===config.chartGlobalType&&'category'!==config.axis.x.type){var b=d3.format(config.axis.x.commas?',':config.axis.x.accuracy);return config.axis.x.prefix+b(a).toString()+config.axis.x.suffix}return a};
importData.config.axis.y.tick.format = function(b) {if('series'===config.chartGlobalType&&'category'!==config.axis.y.type){var b=d3.format(config.axis.y.commas?',':config.axis.y.accuracy);return config.axis.y.prefix+b(a).toString()+config.axis.y.suffix}return a};
importData.config.axis.y2.tick.format = function(b) {if('series'===config.chartGlobalType&&'category'!==config.axis.y2.type){var b=d3.format(config.axis.y2.commas?',':config.axis.y2.accuracy);return config.axis.y2.prefix+b(a).toString()+config.axis.y2.suffix}return a};
importData.config.donut.label.format = function(b,c) {return(100*c).toFixed(importData.config.chartAccuracy)+'%';};
importData.config.pie.label.format = function(b,c) {return(100*c).toFixed(importData.config.chartAccuracy)+'%';};
importData.config.gauge.label.format = function(b,c) {return(100*c).toFixed(importData.config.chartAccuracy)+'%';};

This is super brittle, ugly as sin, and currently not working for WordPress.

There has to be a better way.

aendra-rininsland commented 8 years ago

This is fixed in c3.service.js on ln. 386:

      restoreCallbacks: function(config){
        function evalFormatters(key, value) {
          if (key === 'format' && typeof value === 'string') {
            return eval('(' + value + ')'); // jshint ignore:line
          } else {
            return value;
          }
        }

        traverse(config, evalFormatters);
        return config;
      }