mirror of https://github.com/masayuki0812/c3.git
Quite good looking graph derived from d3.js
http://c3js.org
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
3.7 KiB
89 lines
3.7 KiB
c3_chart_internal_fn.getScale = function (min, max, forTimeseries) { |
|
return (forTimeseries ? this.d3.time.scale() : this.d3.scale.linear()).range([min, max]); |
|
}; |
|
c3_chart_internal_fn.getX = function (min, max, domain, offset) { |
|
var $$ = this, |
|
scale = $$.getScale(min, max, $$.isTimeSeries()), |
|
_scale = domain ? scale.domain(domain) : scale, key; |
|
// Define customized scale if categorized axis |
|
if ($$.isCategorized()) { |
|
offset = offset || function () { return 0; }; |
|
scale = function (d, raw) { |
|
var v = _scale(d) + offset(d); |
|
return raw ? v : Math.ceil(v); |
|
}; |
|
} else { |
|
scale = function (d, raw) { |
|
var v = _scale(d); |
|
return raw ? v : Math.ceil(v); |
|
}; |
|
} |
|
// define functions |
|
for (key in _scale) { |
|
scale[key] = _scale[key]; |
|
} |
|
scale.orgDomain = function () { |
|
return _scale.domain(); |
|
}; |
|
// define custom domain() for categorized axis |
|
if ($$.isCategorized()) { |
|
scale.domain = function (domain) { |
|
if (!arguments.length) { |
|
domain = this.orgDomain(); |
|
return [domain[0], domain[1] + 1]; |
|
} |
|
_scale.domain(domain); |
|
return scale; |
|
}; |
|
} |
|
return scale; |
|
}; |
|
c3_chart_internal_fn.getY = function (min, max, domain) { |
|
var scale = this.getScale(min, max, this.isTimeSeriesY()); |
|
if (domain) { scale.domain(domain); } |
|
return scale; |
|
}; |
|
c3_chart_internal_fn.getYScale = function (id) { |
|
return this.getAxisId(id) === 'y2' ? this.y2 : this.y; |
|
}; |
|
c3_chart_internal_fn.getSubYScale = function (id) { |
|
return this.getAxisId(id) === 'y2' ? this.subY2 : this.subY; |
|
}; |
|
c3_chart_internal_fn.updateScales = function () { |
|
var $$ = this, config = $$.config, |
|
forInit = !$$.x; |
|
// update edges |
|
$$.xMin = config.axis_rotated ? 1 : 0; |
|
$$.xMax = config.axis_rotated ? $$.height : $$.width; |
|
$$.yMin = config.axis_rotated ? 0 : $$.height; |
|
$$.yMax = config.axis_rotated ? $$.width : 1; |
|
$$.subXMin = $$.xMin; |
|
$$.subXMax = $$.xMax; |
|
$$.subYMin = config.axis_rotated ? 0 : $$.height2; |
|
$$.subYMax = config.axis_rotated ? $$.width2 : 1; |
|
// update scales |
|
$$.x = $$.getX($$.xMin, $$.xMax, forInit ? undefined : $$.x.orgDomain(), function () { return $$.xAxis.tickOffset(); }); |
|
$$.y = $$.getY($$.yMin, $$.yMax, forInit ? config.axis_y_default : $$.y.domain()); |
|
$$.y2 = $$.getY($$.yMin, $$.yMax, forInit ? config.axis_y2_default : $$.y2.domain()); |
|
$$.subX = $$.getX($$.xMin, $$.xMax, $$.orgXDomain, function (d) { return d % 1 ? 0 : $$.subXAxis.tickOffset(); }); |
|
$$.subY = $$.getY($$.subYMin, $$.subYMax, forInit ? config.axis_y_default : $$.subY.domain()); |
|
$$.subY2 = $$.getY($$.subYMin, $$.subYMax, forInit ? config.axis_y2_default : $$.subY2.domain()); |
|
// update axes |
|
$$.xAxisTickFormat = $$.getXAxisTickFormat(); |
|
$$.xAxisTickValues = $$.getXAxisTickValues(); |
|
$$.yAxisTickValues = $$.getYAxisTickValues(); |
|
$$.y2AxisTickValues = $$.getY2AxisTickValues(); |
|
|
|
$$.xAxis = $$.getXAxis($$.x, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues, config.axis_x_tick_outer); |
|
$$.subXAxis = $$.getXAxis($$.subX, $$.subXOrient, $$.xAxisTickFormat, $$.xAxisTickValues, config.axis_x_tick_outer); |
|
$$.yAxis = $$.getYAxis($$.y, $$.yOrient, config.axis_y_tick_format, $$.yAxisTickValues, config.axis_y_tick_outer); |
|
$$.y2Axis = $$.getYAxis($$.y2, $$.y2Orient, config.axis_y2_tick_format, $$.y2AxisTickValues, config.axis_y2_tick_outer); |
|
|
|
// Set initialized scales to brush and zoom |
|
if (!forInit) { |
|
if ($$.brush) { $$.brush.scale($$.subX); } |
|
if (config.zoom_enabled) { $$.zoom.scale($$.x); } |
|
} |
|
// update for arc |
|
if ($$.updateArc) { $$.updateArc(); } |
|
};
|
|
|