Skip to content

Commit 49b7975

Browse files
kt3kkelthuzad
andauthored
fix: fix #1691 (#2761)
Co-authored-by: Jakob Kneissl <j_the_k@web.de>
1 parent ed0e523 commit 49b7975

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

spec/data-spec.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,25 +102,28 @@ describe('c3 chart data', function () {
102102
"112": ["600"],
103103
"223": [{"224": "100"}],
104104
"334": [[],[{"335": "300"}]],
105-
"556": {"557" : {"558" : ["1000"]}}
105+
"556": {"557" : {"558" : ["1000"]}},
106+
"778.889" : "700"
106107
}, {
107108
"date": "2014-06-04",
108109
"443": "1000",
109110
"112": ["700"],
110111
"223": [{"224": "200"}],
111-
"556": {"557" : {"558" : ["2000"]}}
112+
"556": {"557" : {"558" : ["2000"]}},
113+
"778.889" : "300"
112114
}, {
113115
"date": "2014-06-05",
114116
"995": {"996": "1000"},
115117
"112": ["800"],
116118
"223": [{"224": "300"}],
117119
"443": "5000",
118120
"334": [[],[{"335": "500"}]],
119-
"556": {"557" : {"558" : ["3000"]}}
121+
"556": {"557" : {"558" : ["3000"]}},
122+
"778.889" : "800"
120123
}],
121124
keys: {
122125
x: 'date',
123-
value: [ "443","995.996","112[0]","223[0].224","334[1][0].335","556.557.558[0]"]
126+
value: [ "443","995.996","112[0]","223[0].224","334[1][0].335","556.557.558[0]","778.889"]
124127
}
125128
},
126129
axis: {
@@ -139,7 +142,8 @@ describe('c3 chart data', function () {
139142
112: [354, 347, 340],
140143
223: [391, 383, 376],
141144
334: [376, 398, 362],
142-
556: [326, 253, 181]
145+
556: [326, 253, 181],
146+
"778.889": [347, 376, 340]
143147
};
144148

145149
d3.selectAll('.c3-circles-443 .c3-circle').each(function (d, i) {
@@ -177,6 +181,12 @@ describe('c3 chart data', function () {
177181
expect(+circle.attr('cx')).toBeCloseTo(expectedCx[i], 0);
178182
expect(+circle.attr('cy')).toBeCloseTo(expectedCy[556][i], 0);
179183
});
184+
185+
d3.selectAll('.c3-circles-778-889 .c3-circle').each(function (d, i) {
186+
var circle = d3.select(this);
187+
expect(+circle.attr('cx')).toBeCloseTo(expectedCx[i], 0);
188+
expect(+circle.attr('cy')).toBeCloseTo(expectedCy["778.889"][i], 0);
189+
});
180190
});
181191
});
182192
});

src/data.convert.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,20 @@ ChartInternal.prototype.convertJsonToData = function (json, keys) {
6363
}
6464
return data;
6565
};
66+
/**
67+
* Finds value from the given nested object by the given path.
68+
* If it's not found, then this returns undefined.
69+
* @param {Object} object the object
70+
* @param {string} path the path
71+
*/
6672
ChartInternal.prototype.findValueInJson = function (object, path) {
73+
if (path in object) {
74+
// If object has a key that contains . or [], return the key's value
75+
// instead of searching for an inner object.
76+
// See https://github.com/c3js/c3/issues/1691 for details.
77+
return object[path];
78+
}
79+
6780
path = path.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to properties (replace [] with .)
6881
path = path.replace(/^\./, ''); // strip a leading dot
6982
var pathArray = path.split('.');

0 commit comments

Comments
 (0)