c3-rails 0.4.0 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8305c80daac3cd9c88037a2a924acccb660cf4b0
4
- data.tar.gz: 7a06208b8900531dc154d15365f6c45d30f8d350
3
+ metadata.gz: 2af42ee06a4a8faf8c82e37002f9b742b62b7936
4
+ data.tar.gz: 1778852ef17eea288816f5bc1dd356d5c8a4f588
5
5
  SHA512:
6
- metadata.gz: 566d0f80a45491e6d4b6ca4b7ac398bc275e7b985164074c98c2fdc5526f9de24d44a214f7c9dcb402b8e4374c3604b3fb768d580b49a0a661a138fa9ed8e5c5
7
- data.tar.gz: 2ef17b7e1430c5ffd374b465220128f2423c62a030f308713b405a6cefdccc41d6209413d9dc1c50c7de6a1379391afeea89f46d3b37702817c28acb08ab04e3
6
+ metadata.gz: 4dde6172793ab7cee798a676d5bcace2ab3f738c8c928c752fb6dc3d17091e1c883eb27658291cce1a308a2aec3124350a199e94e475e2586828b229bf4765a5
7
+ data.tar.gz: fc67f6469210f021304d442a3d6ad0f5414cb68ec234b8e4d6952b46756873d1d7d5b78eb74cb012fb28ef038b015b41c06aeb23ada3f0170690c2ab5179a964
data/README.md CHANGED
@@ -62,11 +62,12 @@ you can install by putting this line in the `Gemfile` instead:
62
62
  Then you'll be able to include files like
63
63
 
64
64
  ```
65
+ //= require c3/c3
65
66
  //= require c3/c3.min
66
- //= require c3/c3.old
67
67
  //= require c3/extensions/js/c3ext
68
68
 
69
69
  *= require c3/c3
70
+ *= require c3/c3.min
70
71
  *= require c3/htdocs/css/bootstrap.min
71
72
  ```
72
73
 
@@ -1,5 +1,5 @@
1
1
  module C3
2
2
  module Rails
3
- VERSION = "0.4.0"
3
+ VERSION = "0.4.3"
4
4
  end
5
5
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  /*global define, module, exports, require */
5
5
 
6
- var c3 = { version: "0.4.0" };
6
+ var c3 = { version: "0.4.3" };
7
7
 
8
8
  var c3_chart_fn, c3_chart_internal_fn;
9
9
 
@@ -484,7 +484,7 @@
484
484
  $$.subXAxis.tickValues([]);
485
485
  }
486
486
 
487
- if (withY && !options.flow) {
487
+ if (config.zoom_rescale && !options.flow) {
488
488
  xDomainForZoom = $$.x.orgDomain();
489
489
  }
490
490
 
@@ -552,7 +552,7 @@
552
552
  .style('opacity', targetsToShow.length ? 0 : 1);
553
553
 
554
554
  // grid
555
- $$.redrawGrid(duration, withY);
555
+ $$.redrawGrid(duration);
556
556
 
557
557
  // rect for regions
558
558
  $$.redrawRegion(duration);
@@ -590,9 +590,12 @@
590
590
  if ($$.updateZoom) { $$.updateZoom(); }
591
591
  }
592
592
 
593
+ // update circleY based on updated parameters
594
+ $$.updateCircleY();
595
+
593
596
  // generate circle x/y functions depending on updated params
594
- cx = ($$.config.axis_rotated ? $$.generateCircleY() : $$.circleX).bind($$);
595
- cy = ($$.config.axis_rotated ? $$.circleX : $$.generateCircleY()).bind($$);
597
+ cx = ($$.config.axis_rotated ? $$.circleY : $$.circleX).bind($$);
598
+ cy = ($$.config.axis_rotated ? $$.circleX : $$.circleY).bind($$);
596
599
 
597
600
  // transition should be derived from one transition
598
601
  d3.transition().duration(duration).each(function () {
@@ -661,6 +664,14 @@
661
664
  // Draw with new sizes & scales
662
665
  $$.redraw(options, transitions);
663
666
  };
667
+ c3_chart_internal_fn.redrawWithoutRescale = function () {
668
+ this.redraw({
669
+ withY: false,
670
+ withSubchart: false,
671
+ withEventRect: false,
672
+ withTransitionForAxis: false
673
+ });
674
+ };
664
675
 
665
676
  c3_chart_internal_fn.isTimeSeries = function () {
666
677
  return this.config.axis_x_type === 'timeseries';
@@ -1561,13 +1572,20 @@
1561
1572
  })
1562
1573
  };
1563
1574
  };
1575
+ c3_chart_internal_fn.updateXs = function () {
1576
+ var $$ = this;
1577
+ $$.xs = [];
1578
+ $$.data.targets[0].values.forEach(function (v) {
1579
+ $$.xs[v.index] = v.x;
1580
+ });
1581
+ };
1564
1582
  c3_chart_internal_fn.getPrevX = function (i) {
1565
- var $$ = this, value = $$.getValueOnIndex($$.data.targets[0].values, i - 1);
1566
- return value ? value.x : null;
1583
+ var x = this.xs[i - 1];
1584
+ return typeof x !== 'undefined' ? x : null;
1567
1585
  };
1568
1586
  c3_chart_internal_fn.getNextX = function (i) {
1569
- var $$ = this, value = $$.getValueOnIndex($$.data.targets[0].values, i + 1);
1570
- return value ? value.x : null;
1587
+ var x = this.xs[i + 1];
1588
+ return typeof x !== 'undefined' ? x : null;
1571
1589
  };
1572
1590
  c3_chart_internal_fn.getMaxDataCount = function () {
1573
1591
  var $$ = this;
@@ -1780,10 +1798,11 @@
1780
1798
  };
1781
1799
  c3_chart_internal_fn.dist = function (data, pos) {
1782
1800
  var $$ = this, config = $$.config,
1783
- yScale = $$.getAxisId(data.id) === 'y' ? $$.y : $$.y2,
1784
1801
  xIndex = config.axis_rotated ? 1 : 0,
1785
- yIndex = config.axis_rotated ? 0 : 1;
1786
- return Math.pow($$.x(data.x) - pos[xIndex], 2) + Math.pow(yScale(data.value) - pos[yIndex], 2);
1802
+ yIndex = config.axis_rotated ? 0 : 1,
1803
+ y = $$.circleY(data, data.index),
1804
+ x = $$.x(data.x);
1805
+ return Math.pow(x - pos[xIndex], 2) + Math.pow(y - pos[yIndex], 2);
1787
1806
  };
1788
1807
  c3_chart_internal_fn.convertValuesToStep = function (values) {
1789
1808
  var converted = [].concat(values), i;
@@ -2161,6 +2180,10 @@
2161
2180
  }
2162
2181
  else {
2163
2182
  if (($$.isCustomX() || $$.isTimeSeries()) && !$$.isCategorized()) {
2183
+
2184
+ // update index for x that is used by prevX and nextX
2185
+ $$.updateXs();
2186
+
2164
2187
  rectW = function (d) {
2165
2188
  var prevX = $$.getPrevX(d.index), nextX = $$.getNextX(d.index);
2166
2189
 
@@ -2935,16 +2958,16 @@
2935
2958
  c3_chart_internal_fn.circleX = function (d) {
2936
2959
  return d.x || d.x === 0 ? this.x(d.x) : null;
2937
2960
  };
2938
- c3_chart_internal_fn.generateCircleY = function () {
2961
+ c3_chart_internal_fn.updateCircleY = function () {
2939
2962
  var $$ = this, lineIndices, getPoints;
2940
2963
  if ($$.config.data_groups.length > 0) {
2941
2964
  lineIndices = $$.getShapeIndices($$.isLineType),
2942
2965
  getPoints = $$.generateGetLinePoints(lineIndices);
2943
- return function (d, i) {
2966
+ $$.circleY = function (d, i) {
2944
2967
  return getPoints(d, i)[0][1];
2945
2968
  };
2946
2969
  } else {
2947
- return function (d) {
2970
+ $$.circleY = function (d) {
2948
2971
  return $$.getYScale(d.id)(d.value);
2949
2972
  };
2950
2973
  }
@@ -3370,7 +3393,7 @@
3370
3393
  };
3371
3394
 
3372
3395
 
3373
- c3_chart_internal_fn.redrawGrid = function (duration, withY) {
3396
+ c3_chart_internal_fn.redrawGrid = function (duration) {
3374
3397
  var $$ = this, main = $$.main, config = $$.config,
3375
3398
  xgridLine, ygridLine, yv;
3376
3399
 
@@ -3402,43 +3425,41 @@
3402
3425
  .remove();
3403
3426
 
3404
3427
  // Y-Grid
3405
- if (withY && config.grid_y_show) {
3428
+ if (config.grid_y_show) {
3406
3429
  $$.updateYGrid();
3407
3430
  }
3408
- if (withY) {
3409
- $$.ygridLines = main.select('.' + CLASS.ygridLines).selectAll('.' + CLASS.ygridLine)
3410
- .data(config.grid_y_lines);
3411
- // enter
3412
- ygridLine = $$.ygridLines.enter().append('g')
3413
- .attr("class", function (d) { return CLASS.ygridLine + (d['class'] ? ' ' + d['class'] : ''); });
3414
- ygridLine.append('line')
3415
- .style("opacity", 0);
3416
- ygridLine.append('text')
3417
- .attr("text-anchor", "end")
3418
- .attr("transform", config.axis_rotated ? "rotate(-90)" : "")
3419
- .attr('dx', config.axis_rotated ? 0 : -$$.margin.top)
3420
- .attr('dy', -5)
3421
- .style("opacity", 0);
3422
- // update
3423
- yv = $$.yv.bind($$);
3424
- $$.ygridLines.select('line')
3425
- .transition().duration(duration)
3426
- .attr("x1", config.axis_rotated ? yv : 0)
3427
- .attr("x2", config.axis_rotated ? yv : $$.width)
3428
- .attr("y1", config.axis_rotated ? 0 : yv)
3429
- .attr("y2", config.axis_rotated ? $$.height : yv)
3430
- .style("opacity", 1);
3431
- $$.ygridLines.select('text')
3432
- .transition().duration(duration)
3433
- .attr("x", config.axis_rotated ? 0 : $$.width)
3434
- .attr("y", yv)
3435
- .text(function (d) { return d.text; })
3436
- .style("opacity", 1);
3437
- // exit
3438
- $$.ygridLines.exit().transition().duration(duration)
3439
- .style("opacity", 0)
3440
- .remove();
3441
- }
3431
+ $$.ygridLines = main.select('.' + CLASS.ygridLines).selectAll('.' + CLASS.ygridLine)
3432
+ .data(config.grid_y_lines);
3433
+ // enter
3434
+ ygridLine = $$.ygridLines.enter().append('g')
3435
+ .attr("class", function (d) { return CLASS.ygridLine + (d['class'] ? ' ' + d['class'] : ''); });
3436
+ ygridLine.append('line')
3437
+ .style("opacity", 0);
3438
+ ygridLine.append('text')
3439
+ .attr("text-anchor", "end")
3440
+ .attr("transform", config.axis_rotated ? "rotate(-90)" : "")
3441
+ .attr('dx', config.axis_rotated ? 0 : -$$.margin.top)
3442
+ .attr('dy', -5)
3443
+ .style("opacity", 0);
3444
+ // update
3445
+ yv = $$.yv.bind($$);
3446
+ $$.ygridLines.select('line')
3447
+ .transition().duration(duration)
3448
+ .attr("x1", config.axis_rotated ? yv : 0)
3449
+ .attr("x2", config.axis_rotated ? yv : $$.width)
3450
+ .attr("y1", config.axis_rotated ? 0 : yv)
3451
+ .attr("y2", config.axis_rotated ? $$.height : yv)
3452
+ .style("opacity", 1);
3453
+ $$.ygridLines.select('text')
3454
+ .transition().duration(duration)
3455
+ .attr("x", config.axis_rotated ? 0 : $$.width)
3456
+ .attr("y", yv)
3457
+ .text(function (d) { return d.text; })
3458
+ .style("opacity", 1);
3459
+ // exit
3460
+ $$.ygridLines.exit().transition().duration(duration)
3461
+ .style("opacity", 0)
3462
+ .remove();
3442
3463
  };
3443
3464
  c3_chart_internal_fn.addTransitionForGrid = function (transitions) {
3444
3465
  var $$ = this, config = $$.config, xv = $$.xv.bind($$);
@@ -3503,7 +3524,7 @@
3503
3524
  return params ? function (line) {
3504
3525
  var found = false;
3505
3526
  [].concat(params).forEach(function (param) {
3506
- if ((('value' in param && line.value === params.value) || ('class' in param && line['class'] === params['class']))) {
3527
+ if ((('value' in param && line.value === param.value) || ('class' in param && line['class'] === param['class']))) {
3507
3528
  found = true;
3508
3529
  }
3509
3530
  });
@@ -4328,7 +4349,7 @@
4328
4349
  return forHorizontal ? -(1 + left) : -(left - 1);
4329
4350
  };
4330
4351
  c3_chart_internal_fn.getAxisClipY = function (forHorizontal) {
4331
- return forHorizontal ? -20 : -4;
4352
+ return forHorizontal ? -20 : -this.margin.top;
4332
4353
  };
4333
4354
  c3_chart_internal_fn.getXAxisClipX = function () {
4334
4355
  var $$ = this;
@@ -4354,7 +4375,7 @@
4354
4375
  return forHorizontal ? $$.width + 2 + left + right : $$.margin.left + 20;
4355
4376
  };
4356
4377
  c3_chart_internal_fn.getAxisClipHeight = function (forHorizontal) {
4357
- return (forHorizontal ? this.margin.bottom : this.height) + 8;
4378
+ return (forHorizontal ? this.margin.bottom : (this.margin.top + this.height)) + 8;
4358
4379
  };
4359
4380
  c3_chart_internal_fn.getXAxisClipWidth = function () {
4360
4381
  var $$ = this;
@@ -4928,8 +4949,8 @@
4928
4949
 
4929
4950
  c3_chart_internal_fn.selectPoint = function (target, d, i) {
4930
4951
  var $$ = this, config = $$.config,
4931
- cx = (config.axis_rotated ? $$.generateCircleY() : $$.circleX).bind($$),
4932
- cy = (config.axis_rotated ? $$.circleX : $$.generateCircleY()).bind($$),
4952
+ cx = (config.axis_rotated ? $$.circleY : $$.circleX).bind($$),
4953
+ cy = (config.axis_rotated ? $$.circleX : $$.circleY).bind($$),
4933
4954
  r = $$.pointSelectR.bind($$);
4934
4955
  config.data_onselected.call($$.api, d, target.node());
4935
4956
  // add selected-circle on low layer g
@@ -5523,7 +5544,7 @@
5523
5544
  return CLASS.chartArc + this.classTarget(d.data.id);
5524
5545
  };
5525
5546
  c3_chart_internal_fn.getTargetSelectorSuffix = function (targetId) {
5526
- return targetId || targetId === 0 ? ('-' + targetId).replace(/[\s!@#$%^&*()_+,.<>'":;\[\]]/g, '-') : '';
5547
+ return targetId || targetId === 0 ? ('-' + targetId).replace(/[\s?!@#$%^&*()_=+,.<>'":;\[\]/|~`{}\\]/g, '-') : '';
5527
5548
  };
5528
5549
  c3_chart_internal_fn.selectorTarget = function (id, prefix) {
5529
5550
  return (prefix || '') + '.' + CLASS.target + this.getTargetSelectorSuffix(id);
@@ -5699,7 +5720,8 @@
5699
5720
  domain = domain.map(function (x) { return $$.parseDate(x); });
5700
5721
  }
5701
5722
  $$.brush.extent(domain);
5702
- $$.redraw({withUpdateXDomain: true});
5723
+ $$.redraw({withUpdateXDomain: true, withY: $$.config.zoom_rescale});
5724
+ $$.config.zoom_onzoom.call(this, $$.x.orgDomain());
5703
5725
  }
5704
5726
  return $$.brush.extent();
5705
5727
  };
@@ -6143,7 +6165,7 @@
6143
6165
  var $$ = this.internal, config = $$.config;
6144
6166
  if (! grids) { return config.grid_x_lines; }
6145
6167
  config.grid_x_lines = grids;
6146
- $$.redraw();
6168
+ $$.redrawWithoutRescale();
6147
6169
  return config.grid_x_lines;
6148
6170
  };
6149
6171
  c3_chart_fn.xgrids.add = function (grids) {
@@ -6159,7 +6181,7 @@
6159
6181
  var $$ = this.internal, config = $$.config;
6160
6182
  if (! grids) { return config.grid_y_lines; }
6161
6183
  config.grid_y_lines = grids;
6162
- $$.redraw();
6184
+ $$.redrawWithoutRescale();
6163
6185
  return config.grid_y_lines;
6164
6186
  };
6165
6187
  c3_chart_fn.ygrids.add = function (grids) {
@@ -6175,14 +6197,14 @@
6175
6197
  var $$ = this.internal, config = $$.config;
6176
6198
  if (!regions) { return config.regions; }
6177
6199
  config.regions = regions;
6178
- $$.redraw();
6200
+ $$.redrawWithoutRescale();
6179
6201
  return config.regions;
6180
6202
  };
6181
6203
  c3_chart_fn.regions.add = function (regions) {
6182
6204
  var $$ = this.internal, config = $$.config;
6183
6205
  if (!regions) { return config.regions; }
6184
6206
  config.regions = config.regions.concat(regions);
6185
- $$.redraw();
6207
+ $$.redrawWithoutRescale();
6186
6208
  return config.regions;
6187
6209
  };
6188
6210
  c3_chart_fn.regions.remove = function (options) {
@@ -6517,7 +6539,7 @@
6517
6539
  }
6518
6540
 
6519
6541
  if (!maxWidth || maxWidth <= 0) {
6520
- maxWidth = isVertical ? 95 : params.isCategory ? (tickOffset * 2 - 10) : 110;
6542
+ maxWidth = isVertical ? 95 : params.isCategory ? (Math.ceil(scale1(ticks[1]) - scale1(ticks[0])) - 10) : 110;
6521
6543
  }
6522
6544
 
6523
6545
  function split(splitted, text) {
@@ -6548,7 +6570,7 @@
6548
6570
  if (orient === 'left' || orient === 'right') {
6549
6571
  dy = -((counts[d.index] - 1) * (sizeFor1Char.h / 2) - (params.isCategory ? 2 : 3));
6550
6572
  } else {
6551
- dy = params.isCategory ? ".40em" : ".71em";
6573
+ dy = ".71em";
6552
6574
  }
6553
6575
  }
6554
6576
  return dy;
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: c3-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sunny Li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-16 00:00:00.000000000 Z
11
+ date: 2014-11-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This gem provides "c3 - A D3-based reusable chart library" for Rails
14
14
  email: