| Index: packages/charted/lib/charts/cartesian_renderers/bar_chart_renderer.dart
|
| diff --git a/packages/charted/lib/charts/cartesian_renderers/bar_chart_renderer.dart b/packages/charted/lib/charts/cartesian_renderers/bar_chart_renderer.dart
|
| index cc55c2d741f2dae06fc1ed0f60ad7f8a51387b4f..74e93cab0b0f37638dd650ceb19422559a6fa9b5 100644
|
| --- a/packages/charted/lib/charts/cartesian_renderers/bar_chart_renderer.dart
|
| +++ b/packages/charted/lib/charts/cartesian_renderers/bar_chart_renderer.dart
|
| @@ -11,7 +11,7 @@ part of charted.charts;
|
| class BarChartRenderer extends CartesianRendererBase {
|
| static const RADIUS = 2;
|
|
|
| - final Iterable<int> dimensionsUsingBand = const[0];
|
| + final Iterable<int> dimensionsUsingBand = const [0];
|
| final bool alwaysAnimate;
|
|
|
| @override
|
| @@ -38,12 +38,12 @@ class BarChartRenderer extends CartesianRendererBase {
|
| dimensionScale = area.dimensionScales.first;
|
|
|
| var rows = new List()
|
| - ..addAll(area.data.rows.map((e) =>
|
| - new List.generate(
|
| - measuresCount, (i) => e[series.measures.elementAt(i)])));
|
| + ..addAll(area.data.rows.map((e) => new List.generate(
|
| + measuresCount, (i) => e[series.measures.elementAt(i)])));
|
|
|
| - var dimensionVals = area.data.rows.map(
|
| - (row) => row.elementAt(area.config.dimensions.first)).toList();
|
| + var dimensionVals = area.data.rows
|
| + .map((row) => row.elementAt(area.config.dimensions.first))
|
| + .toList();
|
|
|
| var bars = new OrdinalScale()
|
| ..domain = new Range(series.measures.length).toList()
|
| @@ -56,32 +56,37 @@ class BarChartRenderer extends CartesianRendererBase {
|
|
|
| groups.enter.append('g')
|
| ..classed('bar-rdr-rowgroup')
|
| - ..attrWithCallback('transform', (d, i, c) => verticalBars ?
|
| - 'translate(${dimensionScale.scale(dimensionVals[i])}, 0)' :
|
| - 'translate(0, ${dimensionScale.scale(dimensionVals[i])})');
|
| + ..attrWithCallback(
|
| + 'transform',
|
| + (d, i, c) => verticalBars
|
| + ? 'translate(${dimensionScale.scale(dimensionVals[i])}, 0)'
|
| + : 'translate(0, ${dimensionScale.scale(dimensionVals[i])})');
|
| groups.attrWithCallback('data-row', (d, i, e) => i);
|
| groups.exit.remove();
|
|
|
| if (animateBarGroups) {
|
| groups.transition()
|
| - ..attrWithCallback('transform', (d, i, c) => verticalBars ?
|
| - 'translate(${dimensionScale.scale(dimensionVals[i])}, 0)' :
|
| - 'translate(0, ${dimensionScale.scale(dimensionVals[i])})')
|
| + ..attrWithCallback(
|
| + 'transform',
|
| + (d, i, c) => verticalBars
|
| + ? 'translate(${dimensionScale.scale(dimensionVals[i])}, 0)'
|
| + : 'translate(0, ${dimensionScale.scale(dimensionVals[i])})')
|
| ..duration(theme.transitionDurationMilliseconds);
|
| }
|
|
|
| // TODO: Test interactions between stroke width and bar width.
|
|
|
| var barWidth = bars.rangeBand.abs() -
|
| - theme.defaultSeparatorWidth - theme.defaultStrokeWidth,
|
| + theme.defaultSeparatorWidth -
|
| + theme.defaultStrokeWidth,
|
| strokeWidth = theme.defaultStrokeWidth,
|
| strokeWidthOffset = strokeWidth ~/ 2;
|
|
|
| // Create and update the bars
|
| // Avoids animation on first render unless alwaysAnimate is set to true.
|
|
|
| - var bar = groups.selectAll('.bar-rdr-bar').dataWithCallback(
|
| - (d, i, c) => rows[i]),
|
| + var bar =
|
| + groups.selectAll('.bar-rdr-bar').dataWithCallback((d, i, c) => rows[i]),
|
| scaled0 = measureScale.scale(0).round();
|
|
|
| var getBarLength = (d) {
|
| @@ -105,42 +110,43 @@ class BarChartRenderer extends CartesianRendererBase {
|
| return fn(
|
| bars.scale(i).toInt() + strokeWidthOffset,
|
| animate ? rect.height : getBarPos(d),
|
| - barWidth, animate ? 0 : getBarLength(d), RADIUS);
|
| + barWidth,
|
| + animate ? 0 : getBarLength(d),
|
| + RADIUS);
|
| } else {
|
| - var fn = d > 0 ? rightRoundedRect : leftRoundedRect;
|
| - return fn(
|
| - getBarPos(d), bars.scale(i).toInt() + strokeWidthOffset,
|
| + var fn = d > 0 ? rightRoundedRect : leftRoundedRect;
|
| + return fn(getBarPos(d), bars.scale(i).toInt() + strokeWidthOffset,
|
| animate ? 0 : getBarLength(d), barWidth, RADIUS);
|
| }
|
| };
|
|
|
| bar.enter.appendWithCallback((d, i, e) {
|
| - var rect = Namespace.createChildElement('path', e),
|
| - measure = series.measures.elementAt(i),
|
| - row = int.parse(e.dataset['row']),
|
| - color = colorForValue(measure, row),
|
| - filter = filterForValue(measure, row),
|
| - style = stylesForValue(measure, row);
|
| -
|
| - if (!isNullOrEmpty(style)) {
|
| - rect.classes.addAll(style);
|
| - }
|
| - rect.classes.add('bar-rdr-bar');
|
| + var rect = Namespace.createChildElement('path', e),
|
| + measure = series.measures.elementAt(i),
|
| + row = int.parse(e.dataset['row']),
|
| + color = colorForValue(measure, row),
|
| + filter = filterForValue(measure, row),
|
| + style = stylesForValue(measure, row);
|
| +
|
| + if (!isNullOrEmpty(style)) {
|
| + rect.classes.addAll(style);
|
| + }
|
| + rect.classes.add('bar-rdr-bar');
|
|
|
| - rect.attributes
|
| - ..['d'] = buildPath(d, i, animateBarGroups)
|
| - ..['stroke-width'] = '${strokeWidth}px'
|
| - ..['fill'] = color
|
| - ..['stroke'] = color;
|
| + rect.attributes
|
| + ..['d'] = buildPath(d, i, animateBarGroups)
|
| + ..['stroke-width'] = '${strokeWidth}px'
|
| + ..['fill'] = color
|
| + ..['stroke'] = color;
|
|
|
| - if (!isNullOrEmpty(filter)) {
|
| - rect.attributes['filter'] = filter;
|
| - }
|
| - if (!animateBarGroups) {
|
| - rect.attributes['data-column'] = '$measure';
|
| - }
|
| - return rect;
|
| - })
|
| + if (!isNullOrEmpty(filter)) {
|
| + rect.attributes['filter'] = filter;
|
| + }
|
| + if (!animateBarGroups) {
|
| + rect.attributes['data-column'] = '$measure';
|
| + }
|
| + return rect;
|
| + })
|
| ..on('click', (d, i, e) => _event(mouseClickController, d, i, e))
|
| ..on('mouseover', (d, i, e) => _event(mouseOverController, d, i, e))
|
| ..on('mouseout', (d, i, e) => _event(mouseOutController, d, i, e));
|
| @@ -167,8 +173,7 @@ class BarChartRenderer extends CartesianRendererBase {
|
| });
|
|
|
| bar.transition()
|
| - ..attrWithCallback('d',
|
| - (d, i, e) => buildPath(d, i, false));
|
| + ..attrWithCallback('d', (d, i, e) => buildPath(d, i, false));
|
| }
|
|
|
| bar.exit.remove();
|
| @@ -184,8 +189,9 @@ class BarChartRenderer extends CartesianRendererBase {
|
| double get bandInnerPadding {
|
| assert(series != null && area != null);
|
| var measuresCount = series.measures.length;
|
| - return measuresCount > 2 ? 1 - (measuresCount / (measuresCount + 1)) :
|
| - area.theme.getDimensionAxisTheme().axisBandInnerPadding;
|
| + return measuresCount > 2
|
| + ? 1 - (measuresCount / (measuresCount + 1))
|
| + : area.theme.getDimensionAxisTheme().axisBandInnerPadding;
|
| }
|
|
|
| @override
|
| @@ -199,12 +205,12 @@ class BarChartRenderer extends CartesianRendererBase {
|
| var groups = host.querySelectorAll('.bar-rdr-rowgroup');
|
| if (groups == null || groups.isEmpty) return;
|
|
|
| - for(int i = 0, len = groups.length; i < len; ++i) {
|
| + for (int i = 0, len = groups.length; i < len; ++i) {
|
| var group = groups.elementAt(i),
|
| bars = group.querySelectorAll('.bar-rdr-bar'),
|
| row = int.parse(group.dataset['row']);
|
|
|
| - for(int j = 0, barsCount = bars.length; j < barsCount; ++j) {
|
| + for (int j = 0, barsCount = bars.length; j < barsCount; ++j) {
|
| var bar = bars.elementAt(j),
|
| column = int.parse(bar.dataset['column']),
|
| color = colorForValue(column, row),
|
| @@ -228,8 +234,7 @@ class BarChartRenderer extends CartesianRendererBase {
|
| if (controller == null) return;
|
| var rowStr = e.parent.dataset['row'];
|
| var row = rowStr != null ? int.parse(rowStr) : null;
|
| - controller.add(
|
| - new DefaultChartEventImpl(scope.event, area,
|
| - series, row, series.measures.elementAt(index), data));
|
| + controller.add(new DefaultChartEventImpl(scope.event, area, series, row,
|
| + series.measures.elementAt(index), data));
|
| }
|
| }
|
|
|