Commit 5f3b9e63 authored by Masayuki Tanaka's avatar Masayuki Tanaka

Fix conflict

parents cdac727c e8ac367d
...@@ -253,7 +253,8 @@ ...@@ -253,7 +253,8 @@
// bar // bar
var __bar_width = getConfig(['bar', 'width']), var __bar_width = getConfig(['bar', 'width']),
__bar_width_ratio = getConfig(['bar', 'width', 'ratio'], 0.6); __bar_width_ratio = getConfig(['bar', 'width', 'ratio'], 0.6),
__bar_zerobased = getConfig(['bar', 'zerobased'], true);
// pie // pie
var __pie_label_show = getConfig(['pie', 'label', 'show'], true), var __pie_label_show = getConfig(['pie', 'label', 'show'], true),
...@@ -700,7 +701,7 @@ ...@@ -700,7 +701,7 @@
subYMin = __axis_rotated ? 0 : height2; subYMin = __axis_rotated ? 0 : height2;
subYMax = __axis_rotated ? width2 : 1; subYMax = __axis_rotated ? width2 : 1;
// update scales // update scales
x = getX(xMin, xMax, forInit ? undefined : x.domain(), function () { return xAxis.tickOffset(); }); x = getX(xMin, xMax, forInit ? undefined : x.orgDomain(), function () { return xAxis.tickOffset(); });
y = getY(yMin, yMax, forInit ? undefined : y.domain()); y = getY(yMin, yMax, forInit ? undefined : y.domain());
y2 = getY(yMin, yMax, forInit ? undefined : y2.domain()); y2 = getY(yMin, yMax, forInit ? undefined : y2.domain());
subX = getX(xMin, xMax, orgXDomain, function (d) { return d % 1 ? 0 : subXAxis.tickOffset(); }); subX = getX(xMin, xMax, orgXDomain, function (d) { return d % 1 ? 0 : subXAxis.tickOffset(); });
...@@ -750,11 +751,7 @@ ...@@ -750,11 +751,7 @@
scale[key] = _scale[key]; scale[key] = _scale[key];
} }
scale.orgDomain = function () { scale.orgDomain = function () {
var domain = _scale.domain(); return _scale.domain();
if (orgXDomain && orgXDomain[0] === domain[0] && orgXDomain[1] < domain[1]) {
domain[1] = orgXDomain[1];
}
return domain;
}; };
// define custom domain() for categorized axis // define custom domain() for categorized axis
if (isCategorized) { if (isCategorized) {
...@@ -763,7 +760,6 @@ ...@@ -763,7 +760,6 @@
domain = this.orgDomain(); domain = this.orgDomain();
return [domain[0], domain[1] + 1]; return [domain[0], domain[1] + 1];
} }
orgXDomain = domain;
_scale.domain(domain); _scale.domain(domain);
return scale; return scale;
}; };
...@@ -975,12 +971,25 @@ ...@@ -975,12 +971,25 @@
return textAnchorForAxisLabel(__axis_rotated, getY2AxisLabelPosition()); return textAnchorForAxisLabel(__axis_rotated, getY2AxisLabelPosition());
} }
function getMaxTickWidth(id) { function getMaxTickWidth(id) {
var maxWidth = 0, axisClass = id === 'x' ? CLASS.axisX : id === 'y' ? CLASS.axisY : CLASS.axisY2; var maxWidth = 0, targetsToShow, scale, axis;
if (svg) { if (svg) {
svg.selectAll('.' + axisClass + ' .tick text').each(function () { targetsToShow = filterTargetsToShow(c3.data.targets);
var box = this.getBoundingClientRect(); if (id === 'y') {
if (maxWidth < box.width) { maxWidth = box.width; } scale = y.copy().domain(getYDomain(targetsToShow, 'y'));
}); axis = getYAxis(scale, yOrient, __axis_y_tick_format, __axis_y_ticks);
} else if (id === 'y2') {
scale = y2.copy().domain(getYDomain(targetsToShow, 'y2'));
axis = getYAxis(scale, y2Orient, __axis_y2_tick_format, __axis_y2_ticks);
} else {
scale = x.copy().domain(getXDomain(targetsToShow));
axis = getXAxis(scale, xOrient, getXAxisTickFormat(), __axis_x_tick_values ? __axis_x_tick_values : xAxis.tickValues());
}
main.append("g").call(axis).each(function () {
d3.select(this).selectAll('text').each(function () {
var box = this.getBoundingClientRect();
if (maxWidth < box.width) { maxWidth = box.width; }
});
}).remove();
} }
currentMaxTickWidth = maxWidth <= 0 ? currentMaxTickWidth : maxWidth; currentMaxTickWidth = maxWidth <= 0 ? currentMaxTickWidth : maxWidth;
return currentMaxTickWidth; return currentMaxTickWidth;
...@@ -1250,6 +1259,7 @@ ...@@ -1250,6 +1259,7 @@
domainLength, padding, padding_top, padding_bottom, domainLength, padding, padding_top, padding_bottom,
center = axisId === 'y2' ? __axis_y2_center : __axis_y_center, center = axisId === 'y2' ? __axis_y2_center : __axis_y_center,
yDomainAbs, lengths, diff, ratio, isAllPositive, isAllNegative, yDomainAbs, lengths, diff, ratio, isAllPositive, isAllNegative,
isZeroBased = (hasBarType(yTargets) && __bar_zerobased) || hasAreaType(yTargets),
showHorizontalDataLabel = hasDataLabel() && __axis_rotated, showHorizontalDataLabel = hasDataLabel() && __axis_rotated,
showVerticalDataLabel = hasDataLabel() && !__axis_rotated; showVerticalDataLabel = hasDataLabel() && !__axis_rotated;
if (yTargets.length === 0) { // use current domain if target of axisId is none if (yTargets.length === 0) { // use current domain if target of axisId is none
...@@ -1262,7 +1272,7 @@ ...@@ -1262,7 +1272,7 @@
isAllNegative = yDomainMin <= 0 && yDomainMax <= 0; isAllNegative = yDomainMin <= 0 && yDomainMax <= 0;
// Bar/Area chart should be 0-based if all positive|negative // Bar/Area chart should be 0-based if all positive|negative
if (hasBarType(yTargets) || hasAreaType(yTargets)) { if (isZeroBased) {
if (isAllPositive) { yDomainMin = 0; } if (isAllPositive) { yDomainMin = 0; }
if (isAllNegative) { yDomainMax = 0; } if (isAllNegative) { yDomainMax = 0; }
} }
...@@ -1296,7 +1306,7 @@ ...@@ -1296,7 +1306,7 @@
padding_bottom = getAxisPadding(__axis_y2_padding, 'bottom', padding, domainLength); padding_bottom = getAxisPadding(__axis_y2_padding, 'bottom', padding, domainLength);
} }
// Bar/Area chart should be 0-based if all positive|negative // Bar/Area chart should be 0-based if all positive|negative
if (hasBarType(yTargets) || hasAreaType(yTargets)) { if (isZeroBased) {
if (isAllPositive) { padding_bottom = yDomainMin; } if (isAllPositive) { padding_bottom = yDomainMin; }
if (isAllNegative) { padding_top = -yDomainMax; } if (isAllNegative) { padding_top = -yDomainMax; }
} }
...@@ -2292,6 +2302,7 @@ ...@@ -2292,6 +2302,7 @@
else { else {
if (ids.indexOf(id) < 0) { ids.push(id); } if (ids.indexOf(id) < 0) { ids.push(id); }
color = pattern[ids.indexOf(id) % pattern.length]; color = pattern[ids.indexOf(id) % pattern.length];
colors[id] = color;
} }
return callback instanceof Function ? callback(color, d) : color; return callback instanceof Function ? callback(color, d) : color;
}; };
...@@ -2946,7 +2957,7 @@ ...@@ -2946,7 +2957,7 @@
// MEMO: call here to update legend box and tranlate for all // MEMO: call here to update legend box and tranlate for all
// MEMO: translate will be upated by this, so transform not needed in updateLegend() // MEMO: translate will be upated by this, so transform not needed in updateLegend()
updateLegend(mapToIds(c3.data.targets), {withTransform: false, withTransitionForTransform: false}); updateLegend(mapToIds(c3.data.targets), {withTransform: false, withTransitionForTransform: false, withTransition: false});
/*-- Main Region --*/ /*-- Main Region --*/
...@@ -3571,21 +3582,6 @@ ...@@ -3571,21 +3582,6 @@
transitions.axisY2.call(y2Axis); transitions.axisY2.call(y2Axis);
transitions.axisSubX.call(subXAxis); transitions.axisSubX.call(subXAxis);
if (targetsToShow.length) {
// Update dimensions according to the width of ticks, etc
updateSizes();
updateScales();
updateSvgSize();
transformAll(true, transitions);
// x changes above, so need to update domain too
updateXDomain(targetsToShow, withUpdateXDomain, withUpdateOrgXDomain);
// Update axis again because the length can be updated because of update of max tick width and generate tickOffset
transitions.axisX.call(xAxis);
transitions.axisSubX.call(subXAxis);
transitions.axisY.call(yAxis);
transitions.axisY2.call(y2Axis);
}
// Update axis label // Update axis label
updateAxisLabels(withTransition); updateAxisLabels(withTransition);
...@@ -5116,7 +5112,7 @@ ...@@ -5116,7 +5112,7 @@
c3.groups = function (groups) { c3.groups = function (groups) {
if (isUndefined(groups)) { return __data_groups; } if (isUndefined(groups)) { return __data_groups; }
__data_groups = groups; __data_groups = groups;
redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); redraw();
return __data_groups; return __data_groups;
}; };
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -313,6 +313,12 @@ ...@@ -313,6 +313,12 @@
Change radius of data point Change radius of data point
</a> </a>
</div> </div>
<div class="col-md-4">
<h3>Bar</h3>
<a href="./samples/bar_zerobased.html">
Disable zero-based y domain
</a>
</div>
</div> </div>
</div> </div>
</div> </div>
...@@ -326,6 +332,9 @@ ...@@ -326,6 +332,9 @@
<a href="./samples/zoom.html"> <a href="./samples/zoom.html">
Enable zoom Enable zoom
</a> </a>
<a href="./samples/zoom.html">
Zoom on category axis
</a>
<a href="./samples/zoom_reduction.html"> <a href="./samples/zoom_reduction.html">
Zoom with reduction Zoom with reduction
</a> </a>
...@@ -363,7 +372,7 @@ ...@@ -363,7 +372,7 @@
</a> </a>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<h3>grid</h3> <h3>Grid</h3>
<a href="./samples/api_xgrid_lines.html"> <a href="./samples/api_xgrid_lines.html">
Update x grid lines Update x grid lines
</a> </a>
...@@ -392,6 +401,14 @@ ...@@ -392,6 +401,14 @@
</a> </a>
</div> </div>
</div> </div>
<div class="row">
<div class="col-md-4">
<h3>Data</h3>
<a href="./samples/api_data_colors.html">
Update data color
</a>
</div>
</div>
</div> </div>
</div> </div>
......
<html>
<head>
<link rel="stylesheet" type="text/css" href="/css/c3.css">
</head>
<body>
<div id="chart"></div>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="/js/c3.js"></script>
<script>
var chart = c3.generate({
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250],
['data2', 50, 20, 10, 40, 15, 25]
],
},
axis: {
x: {
type: 'category'
}
}
});
setTimeout(function () {
chart.data.colors({data1: '#000'});
}, 1000);
</script>
</body>
</html>
...@@ -8,7 +8,10 @@ ...@@ -8,7 +8,10 @@
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="/js/c3.js"></script> <script src="/js/c3.js"></script>
<script> <script>
var chart = c3.generate({
var axis_rotated = false, axis_x_type = "";
var generate = function () { return c3.generate({
bindto: '#chart', bindto: '#chart',
data: { data: {
columns: [ columns: [
...@@ -16,46 +19,106 @@ ...@@ -16,46 +19,106 @@
] ]
}, },
axis: { axis: {
// rotated: true, rotated: axis_rotated,
x: {
type: axis_x_type
}
}, },
grid: { grid: {
x: { x: {
// lines: [{value: 3, text:'Label 3'}, {value: 4.5, text: 'Label 4.5'}] // lines: [{value: 3, text:'Label 3'}, {value: 4.5, text: 'Label 4.5'}]
} }
} }
}); }); }, chart = generate();
setTimeout(function () { var queue = [
function () {
chart.xgrids([{value: 1, text:'Label 1'}, {value: 4, text: 'Label 4'}]); chart.xgrids([{value: 1, text:'Label 1'}, {value: 4, text: 'Label 4'}]);
}, 1000); },
function () {
setTimeout(function () {
chart.xgrids([{value: 2, text:'Label 2'}]); chart.xgrids([{value: 2, text:'Label 2'}]);
}, 2000); },
function () {
setTimeout(function () {
chart.xgrids.add([{value: 3, text:'Label 3', class:'hoge'}]); chart.xgrids.add([{value: 3, text:'Label 3', class:'hoge'}]);
}, 3000); },
function () {
setTimeout(function () {
chart.xgrids.remove({value:2}); chart.xgrids.remove({value:2});
}, 4000); },
function () {
setTimeout(function () {
chart.xgrids.remove({class:'hoge'}); chart.xgrids.remove({class:'hoge'});
}, 5000); },
function () {
setTimeout(function () {
chart.xgrids.remove([{value: 1}, {value: 4}]); chart.xgrids.remove([{value: 1}, {value: 4}]);
}, 6000); },
function () {
setTimeout(function () {
chart.xgrids([{value: 1, text:'Label 1'}, {value: 4, text: 'Label 4'}]); chart.xgrids([{value: 1, text:'Label 1'}, {value: 4, text: 'Label 4'}]);
}, 7000); },
function () {
setTimeout(function () { chart.xgrids.remove();
},
function () {
axis_rotated = true;
chart = generate();
},
function () {
chart.xgrids([{value: 1, text:'Label 1'}, {value: 4, text: 'Label 4'}]);
},
function () {
chart.xgrids([{value: 2, text:'Label 2'}]);
},
function () {
chart.xgrids.add([{value: 3, text:'Label 3', class:'hoge'}]);
},
function () {
chart.xgrids.remove({value:2});
},
function () {
chart.xgrids.remove({class:'hoge'});
},
function () {
chart.xgrids.remove([{value: 1}, {value: 4}]);
},
function () {
chart.xgrids([{value: 1, text:'Label 1'}, {value: 4, text: 'Label 4'}]);
},
function () {
chart.xgrids.remove(); chart.xgrids.remove();
}, 8000); },
function () {
axis_rotated = false;
axis_x_type = 'category';
chart = generate();
},
function () {
chart.xgrids([{value: 1, text:'Label 1'}, {value: 4, text: 'Label 4'}]);
},
function () {
chart.xgrids([{value: 2, text:'Label 2'}]);
},
function () {
chart.xgrids.add([{value: 3, text:'Label 3', class:'hoge'}]);
},
function () {
chart.xgrids.remove({value:2});
},
function () {
chart.xgrids.remove({class:'hoge'});
},
function () {
chart.xgrids.remove([{value: 1}, {value: 4}]);
},
function () {
chart.xgrids([{value: 1, text:'Label 1'}, {value: 4, text: 'Label 4'}]);
},
function () {
chart.xgrids.remove();
},
];
var i = 0;
queue.forEach(function (f) {
setTimeout(f, 1000 * i++);
});
</script> </script>
</body> </body>
......
<html>
<head>
<link href="/css/c3.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="chart"></div>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="/js/c3.js"></script>
<script>
var chart = c3.generate({
data: {
columns: [
['data1', 1030, 1200, 1100, 1400, 1150, 1250],
['data2', 2130, 2100, 2140, 2200, 2150, 1850]
],
type: 'bar',
},
bar: {
zerobased: false
}
});
</script>
</body>
</html>
...@@ -11,8 +11,10 @@ ...@@ -11,8 +11,10 @@
var chart = c3.generate({ var chart = c3.generate({
data: { data: {
columns: [ columns: [
['data1', 30, 200, 100, 400, 150, 250], ['data1', 1030, 1200, 1100, 1400, 1150, 1250],
['data2', 130, 100, 140, 200, 150, 50] ['data2', 2130, 2100, 2140, 2200, 2150, 1850]
// ['data1', 30, 200, 100, 400, 150, 250],
// ['data2', 130, 100, 140, 200, 150, 50]
], ],
type: 'bar', type: 'bar',
onclick: function (d, element) { console.log("onclick", d, element); }, onclick: function (d, element) { console.log("onclick", d, element); },
...@@ -27,7 +29,8 @@ ...@@ -27,7 +29,8 @@
bar: { bar: {
width: { width: {
ratio: 0.3 ratio: 0.3
} },
zerobased: false
} }
}); });
</script> </script>
......
...@@ -3,26 +3,35 @@ ...@@ -3,26 +3,35 @@
<link rel="stylesheet" type="text/css" href="/css/c3.css"> <link rel="stylesheet" type="text/css" href="/css/c3.css">
</head> </head>
<body> <body>
<!-- <div id="chart"></div>--> <div id="chart1"></div>
<div id="chart2"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="/js/c3.js"></script> <script src="/js/c3.js"></script>
<script> <script>
var chart = c3.generate({
var chart1 = c3.generate({
data: { data: {
columns: [ columns: [
['sample', 30, 200, 100, null, 150, 250] ['sample', 30, 200, 100, null, 150, 250]
], ],
}, },
// size: {
// width: 640,
// height: 320
// }
}); });
setTimeout(function () { var chart2 = c3.generate({
document.body.appendChild(chart.element); data: {
}, 1000); columns: [
['sample', 30, 200, 100, null, 150, 250]
],
type: 'bar'
}
});
document.getElementById('chart1').appendChild(chart1.element);
$('#chart2').append(chart2.element);
</script> </script>
</body> </body>
</html> </html>
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<div id="chart3"></div> <div id="chart3"></div>
<div id="chart4"></div> <div id="chart4"></div>
<div id="chart5"></div> <div id="chart5"></div>
<div id="chart6"></div>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="/js/c3.js"></script> <script src="/js/c3.js"></script>
...@@ -85,6 +86,26 @@ ...@@ -85,6 +86,26 @@
} }
}); });
c3.generate({
bindto: '#chart6',
data: {
columns: bigData
},
axis: {
x: {
type: 'category'
}
},
grid: {
x: {
show: true
},
y: {
show: true
}
}
});
</script> </script>
</body> </body>
</html> </html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="/css/c3.css">
</head>
<body>
<div id="chart"></div>
<button onclick="load()">Load</button>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="/js/c3.js"></script>
<script>
var chart = c3.generate({
bindto: '#chart',
data: {
columns: [
generateData(100)
],
},
axis: {
x: {
type: 'category'
}
},
zoom: { enabled: true },
subchart: { show: true }
});
function load() {
chart.load({
columns: [
generateData(Math.random() * 1000)
],
});
}
function generateData(n) {
var column = ['sample'];
for (var i = 0; i < n; i++) {
column.push(Math.random() * 500);
}
return column;
}
</script>
</body>
</html>
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