Update c3.js and c3.min.js

parent a72262cb
......@@ -219,9 +219,14 @@
};
var __filename; // used in Node.js to get css file using path
var c3_chart_fn, c3_chart_internal_fn;
var c3 = { version: "0.4.9" };
var c3_chart_fn, c3_chart_internal_fn;
var c3init = function(module){
__filename = module.uri;
return c3;
}
function Chart(config) {
var $$ = this.internal = new ChartInternal(this);
......@@ -264,9 +269,52 @@
c3_chart_internal_fn = c3.chart.internal.fn;
var nodeCss;
var styleCache = {};
// Seek a specific value in the stylesheets of a document
function getStyleValue(selector, property) {
function getStyleValue($$, selector, property) {
function cache(value){
if(!styleCache[selector]){
styleCache[selector] = {};
}
styleCache[selector][property] = value.trim();
return styleCache[selector][property];
}
if(styleCache[selector] && styleCache[selector][property]){
return styleCache[selector][property];
}
var css, rule, sheet, value;
if(isNode()){
if(!nodeCss){
var style = require('fs').readFileSync(__filename.replace('c3.js', 'c3.css'), 'utf-8');
nodeCss = [require('css').parse(style), require('css').parse($$.ed3Config.style)];
}
var obj, rule, sel, decl;
for(var i = 0; i<nodeCss.length; i++){
obj = nodeCss[i];
for(var j = 0; j<obj.stylesheet.rules.length; j++){
rule = obj.stylesheet.rules[j];
if(!rule.selectors) continue;
for(var k = 0; k<rule.selectors.length; k++){
sel = rule.selectors[k];
for(var l = 0; l<rule.declarations.length; l++){
decl = rule.declarations[l];
if(decl.property === property){
return cache(decl.value);
}
}
}
}
}
console.log('Style not found: ', selector, '->', property);
return undefined;
}
for (var styleId = 0; styleId < document.styleSheets.length; styleId++) {
sheet = document.styleSheets[styleId];
for (var ruleId = 0; ruleId < sheet.cssRules.length; ruleId++) {
......@@ -276,7 +324,7 @@
if (css.indexOf(property) !== -1) {
try {
value = css.split(property)[1].split(':')[1].split(';')[0];
return value.trim();
return cache(value);
} catch (e) {
// Error will be caught in case of incorrect CSS
return undefined;
......@@ -3610,7 +3658,7 @@
];
};
c3_chart_internal_fn.getTextRect = function (text, cls) {
var fontSize = parseFloat(getStyleValue(cls, 'font-size'));
var fontSize = parseFloat(getStyleValue(this, cls, 'font-size'));
return {
height: fontSize,
......@@ -4236,7 +4284,7 @@
var hasFocused = $$.legend.selectAll('.' + CLASS.legendItemFocused).size();
var texts, rects, tiles, background;
var nodeOffset = isNode() ? 3 : 1;
var nodeOffset = 1;
options = options || {};
withTransition = getOption(options, "withTransition", true);
......@@ -8183,7 +8231,7 @@
tspan.enter().append('tspan');
tspan.exit().remove();
var fontSize = parseFloat(getStyleValue('.c3-axis-y .tick', 'font-size'));
var fontSize = parseFloat(getStyleValue($$, '.c3-axis-y .tick', 'font-size'));
tspan.text(function (d) {
if (d.splitted.length) {
......@@ -8316,7 +8364,7 @@
};
if (typeof define === 'function' && define.amd) {
define("c3", ["d3"], c3);
define("c3", ["module", "d3"], c3init);
} else if ('undefined' !== typeof exports && 'undefined' !== typeof module) {
module.exports = c3;
} else {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment