chartist-rails 0.9.4 → 0.9.5

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: 39bc9e3c657dc9ad2000b172c9e731e3dc8c244e
4
- data.tar.gz: 47072fd165949cbb572999e912a9f14c1c0638ce
3
+ metadata.gz: 9da48d66cb4101e6a0b4989cdb25078d08ac5ff3
4
+ data.tar.gz: 9bdef3c4828e1a2d2be2f090ae79f268f7af5e3a
5
5
  SHA512:
6
- metadata.gz: 3cca900193de406b03f4266ed766f9ccee4eb1d2493807a12389cf0e79c9265fefbbf8b29ef2813ceece229f405d6a7454c2ac95a1232c95930e4e7931b6d81c
7
- data.tar.gz: 956e00fe09f8f1c9a90ecbfaef29ef5df1c4b8456419d7f9f011b3786df40c38526a63723629da564fb882c9a49a51bdcc3bc287a975fb026c5575b1b317072f
6
+ metadata.gz: 951ca14c5626948a3be16b37867894882d67307c1493bffb840be7ff9776fabe2b54bd7d24b878e194e2c4715e2e15b4f587b8512d6b074c3cdce8202d442993
7
+ data.tar.gz: bfc52094a576adc8b2600552801c647fb9d8373639c69732eb114733fc757a98ae928a52171e123433de060c5e8c0c249078f1b7bb30c6a0e8f7d0220086893d
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Chartist::Rails
2
2
 
3
- This gem is a wrapper for the [Charist.js](https://github.com/gionkunz/chartist-js) library (v0.9.4).
3
+ This gem is a wrapper for the [Charist.js](https://github.com/gionkunz/chartist-js) library (v0.9.5).
4
4
  The state of this gem is that it is fully functional, but you can not change the settings yet.
5
5
  I am currently working on a generator so that you can customize the settings file to your liking.
6
6
 
@@ -26,7 +26,7 @@ Or if you're using pure javascript, add this to your `app/assets/javascripts/app
26
26
  //= require chartist
27
27
  ```
28
28
 
29
- Then add this to your `app/assets/stylesheets/applcation.css`:
29
+ Then add this to your `app/assets/stylesheets/application.css`:
30
30
 
31
31
  ```
32
32
  *= require chartist.min
Binary file
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["AnthonyBobsin"]
10
10
  spec.email = ["bobsinj@gmail.com"]
11
11
  spec.summary = %q{Vendors the Chartist.js library for use with the Rail's assets pipeline.}
12
- spec.description = %q{Current using Chartist version 0.9.4}
12
+ spec.description = %q{Current using Chartist version 0.9.5}
13
13
  spec.homepage = "https://github.com/AnthonyBobsin/chartist-rails"
14
14
  spec.license = "MIT"
15
15
 
@@ -1,5 +1,5 @@
1
1
  module Chartist
2
2
  module Rails
3
- VERSION = "0.9.4"
3
+ VERSION = "0.9.5"
4
4
  end
5
5
  end
@@ -14,7 +14,7 @@
14
14
  }
15
15
  }(this, function () {
16
16
 
17
- /* Chartist.js 0.9.4
17
+ /* Chartist.js 0.9.5
18
18
  * Copyright © 2015 Gion Kunz
19
19
  * Free to use under the WTFPL license.
20
20
  * http://www.wtfpl.net/
@@ -25,7 +25,7 @@
25
25
  * @module Chartist.Core
26
26
  */
27
27
  var Chartist = {
28
- version: '0.9.4'
28
+ version: '0.9.5'
29
29
  };
30
30
 
31
31
  (function (window, document, Chartist) {
@@ -92,21 +92,6 @@ var Chartist = {
92
92
  return str.replace(new RegExp(subStr, 'g'), newSubStr);
93
93
  };
94
94
 
95
- /**
96
- * Converts a string to a number while removing the unit if present. If a number is passed then this will be returned unmodified.
97
- *
98
- * @memberof Chartist.Core
99
- * @param {String|Number} value
100
- * @return {Number} Returns the string as number or NaN if the passed length could not be converted to pixel
101
- */
102
- Chartist.stripUnit = function(value) {
103
- if(typeof value === 'string') {
104
- value = value.replace(/[^0-9\+-\.]/g, '');
105
- }
106
-
107
- return +value;
108
- };
109
-
110
95
  /**
111
96
  * Converts a number to a string with a unit. If a string is passed then this will be returned unmodified.
112
97
  *
@@ -123,6 +108,24 @@ var Chartist = {
123
108
  return value;
124
109
  };
125
110
 
111
+ /**
112
+ * Converts a number or string to a quantity object.
113
+ *
114
+ * @memberof Chartist.Core
115
+ * @param {String|Number} input
116
+ * @return {Object} Returns an object containing the value as number and the unit as string.
117
+ */
118
+ Chartist.quantity = function(input) {
119
+ if (typeof input === 'string') {
120
+ var match = (/^(\d+)\s*(.*)$/g).exec(input);
121
+ return {
122
+ value : +match[1],
123
+ unit: match[2] || undefined
124
+ };
125
+ }
126
+ return { value: input };
127
+ };
128
+
126
129
  /**
127
130
  * This is a wrapper around document.querySelector that will return the query if it's already of type Node
128
131
  *
@@ -463,7 +466,7 @@ var Chartist = {
463
466
  * @return {Number} The height of the area in the chart for the data series
464
467
  */
465
468
  Chartist.getAvailableHeight = function (svg, options) {
466
- return Math.max((Chartist.stripUnit(options.height) || svg.height()) - (options.chartPadding.top + options.chartPadding.bottom) - options.axisX.offset, 0);
469
+ return Math.max((Chartist.quantity(options.height).value || svg.height()) - (options.chartPadding.top + options.chartPadding.bottom) - options.axisX.offset, 0);
467
470
  };
468
471
 
469
472
  /**
@@ -718,7 +721,7 @@ var Chartist = {
718
721
  * @param {Number} centerY X-axis coordinates of center point of circle segment
719
722
  * @param {Number} radius Radius of circle segment
720
723
  * @param {Number} angleInDegrees Angle of circle segment in degrees
721
- * @return {Number} Coordinates of point on circumference
724
+ * @return {{x:Number, y:Number}} Coordinates of point on circumference
722
725
  */
723
726
  Chartist.polarToCartesian = function (centerX, centerY, radius, angleInDegrees) {
724
727
  var angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0;
@@ -743,8 +746,8 @@ var Chartist = {
743
746
  var yAxisOffset = hasAxis ? options.axisY.offset : 0;
744
747
  var xAxisOffset = hasAxis ? options.axisX.offset : 0;
745
748
  // If width or height results in invalid value (including 0) we fallback to the unitless settings or even 0
746
- var width = svg.width() || Chartist.stripUnit(options.width) || 0;
747
- var height = svg.height() || Chartist.stripUnit(options.height) || 0;
749
+ var width = svg.width() || Chartist.quantity(options.width).value || 0;
750
+ var height = svg.height() || Chartist.quantity(options.height).value || 0;
748
751
  var normalizedPadding = Chartist.normalizePadding(options.chartPadding, fallbackPadding);
749
752
 
750
753
  // If settings were to small to cope with offset (legacy) and padding, we'll adjust
@@ -967,30 +970,45 @@ var Chartist = {
967
970
  /**
968
971
  * This interpolation function does not smooth the path and the result is only containing lines and no curves.
969
972
  *
973
+ * @example
974
+ * var chart = new Chartist.Line('.ct-chart', {
975
+ * labels: [1, 2, 3, 4, 5],
976
+ * series: [[1, 2, 8, 1, 7]]
977
+ * }, {
978
+ * lineSmooth: Chartist.Interpolation.none({
979
+ * fillHoles: false
980
+ * })
981
+ * });
982
+ *
983
+ *
970
984
  * @memberof Chartist.Interpolation
971
985
  * @return {Function}
972
986
  */
973
- Chartist.Interpolation.none = function() {
987
+ Chartist.Interpolation.none = function(options) {
988
+ var defaultOptions = {
989
+ fillHoles: false
990
+ };
991
+ options = Chartist.extend({}, defaultOptions, options);
974
992
  return function none(pathCoordinates, valueData) {
975
993
  var path = new Chartist.Svg.Path();
976
- // We need to assume that the first value is a "hole"
977
994
  var hole = true;
978
995
 
979
- for(var i = 1; i < pathCoordinates.length; i += 2) {
980
- var data = valueData[(i - 1) / 2];
996
+ for(var i = 0; i < pathCoordinates.length; i += 2) {
997
+ var currX = pathCoordinates[i];
998
+ var currY = pathCoordinates[i + 1];
999
+ var currData = valueData[i / 2];
1000
+
1001
+ if(currData.value !== undefined) {
981
1002
 
982
- // If the current value is undefined we should treat it as a hole start
983
- if(data.value === undefined) {
984
- hole = true;
985
- } else {
986
- // If this value is valid we need to check if we're coming out of a hole
987
1003
  if(hole) {
988
- // If we are coming out of a hole we should first make a move and also reset the hole flag
989
- path.move(pathCoordinates[i - 1], pathCoordinates[i], false, data);
990
- hole = false;
1004
+ path.move(currX, currY, false, currData);
991
1005
  } else {
992
- path.line(pathCoordinates[i - 1], pathCoordinates[i], false, data);
1006
+ path.line(currX, currY, false, currData);
993
1007
  }
1008
+
1009
+ hole = false;
1010
+ } else if(!options.fillHoles) {
1011
+ hole = true;
994
1012
  }
995
1013
  }
996
1014
 
@@ -1011,7 +1029,8 @@ var Chartist = {
1011
1029
  * series: [[1, 2, 8, 1, 7]]
1012
1030
  * }, {
1013
1031
  * lineSmooth: Chartist.Interpolation.simple({
1014
- * divisor: 2
1032
+ * divisor: 2,
1033
+ * fillHoles: false
1015
1034
  * })
1016
1035
  * });
1017
1036
  *
@@ -1022,7 +1041,8 @@ var Chartist = {
1022
1041
  */
1023
1042
  Chartist.Interpolation.simple = function(options) {
1024
1043
  var defaultOptions = {
1025
- divisor: 2
1044
+ divisor: 2,
1045
+ fillHoles: false
1026
1046
  };
1027
1047
  options = Chartist.extend({}, defaultOptions, options);
1028
1048
 
@@ -1030,26 +1050,19 @@ var Chartist = {
1030
1050
 
1031
1051
  return function simple(pathCoordinates, valueData) {
1032
1052
  var path = new Chartist.Svg.Path();
1033
- var hole = true;
1053
+ var prevX, prevY, prevData;
1034
1054
 
1035
- for(var i = 2; i < pathCoordinates.length; i += 2) {
1036
- var prevX = pathCoordinates[i - 2];
1037
- var prevY = pathCoordinates[i - 1];
1055
+ for(var i = 0; i < pathCoordinates.length; i += 2) {
1038
1056
  var currX = pathCoordinates[i];
1039
1057
  var currY = pathCoordinates[i + 1];
1040
1058
  var length = (currX - prevX) * d;
1041
- var prevData = valueData[(i / 2) - 1];
1042
1059
  var currData = valueData[i / 2];
1043
1060
 
1044
- if(prevData.value === undefined) {
1045
- hole = true;
1046
- } else {
1061
+ if(currData.value !== undefined) {
1047
1062
 
1048
- if(hole) {
1049
- path.move(prevX, prevY, false, prevData);
1050
- }
1051
-
1052
- if(currData.value !== undefined) {
1063
+ if(prevData === undefined) {
1064
+ path.move(currX, currY, false, currData);
1065
+ } else {
1053
1066
  path.curve(
1054
1067
  prevX + length,
1055
1068
  prevY,
@@ -1060,9 +1073,13 @@ var Chartist = {
1060
1073
  false,
1061
1074
  currData
1062
1075
  );
1063
-
1064
- hole = false;
1065
1076
  }
1077
+
1078
+ prevX = currX;
1079
+ prevY = currY;
1080
+ prevData = currData;
1081
+ } else if(!options.fillHoles) {
1082
+ prevX = currX = prevData = undefined;
1066
1083
  }
1067
1084
  }
1068
1085
 
@@ -1083,7 +1100,8 @@ var Chartist = {
1083
1100
  * series: [[1, 2, 8, 1, 7]]
1084
1101
  * }, {
1085
1102
  * lineSmooth: Chartist.Interpolation.cardinal({
1086
- * tension: 1
1103
+ * tension: 1,
1104
+ * fillHoles: false
1087
1105
  * })
1088
1106
  * });
1089
1107
  *
@@ -1093,7 +1111,8 @@ var Chartist = {
1093
1111
  */
1094
1112
  Chartist.Interpolation.cardinal = function(options) {
1095
1113
  var defaultOptions = {
1096
- tension: 1
1114
+ tension: 1,
1115
+ fillHoles: false
1097
1116
  };
1098
1117
 
1099
1118
  options = Chartist.extend({}, defaultOptions, options);
@@ -1111,7 +1130,9 @@ var Chartist = {
1111
1130
  for(var i = 0; i < pathCoordinates.length; i += 2) {
1112
1131
  // If this value is a "hole" we set the hole flag
1113
1132
  if(valueData[i / 2].value === undefined) {
1114
- hole = true;
1133
+ if(!options.fillHoles) {
1134
+ hole = true;
1135
+ }
1115
1136
  } else {
1116
1137
  // If it's a valid value we need to check if we're coming out of a hole and create a new empty segment
1117
1138
  if(hole) {
@@ -1213,7 +1234,8 @@ var Chartist = {
1213
1234
  * series: [[1, 2, 8, 1, 7]]
1214
1235
  * }, {
1215
1236
  * lineSmooth: Chartist.Interpolation.step({
1216
- * postpone: true
1237
+ * postpone: true,
1238
+ * fillHoles: false
1217
1239
  * })
1218
1240
  * });
1219
1241
  *
@@ -1223,34 +1245,27 @@ var Chartist = {
1223
1245
  */
1224
1246
  Chartist.Interpolation.step = function(options) {
1225
1247
  var defaultOptions = {
1226
- postpone: true
1248
+ postpone: true,
1249
+ fillHoles: false
1227
1250
  };
1228
1251
 
1229
1252
  options = Chartist.extend({}, defaultOptions, options);
1230
1253
 
1231
1254
  return function step(pathCoordinates, valueData) {
1232
1255
  var path = new Chartist.Svg.Path();
1233
- var hole = true;
1234
1256
 
1235
- for (var i = 2; i < pathCoordinates.length; i += 2) {
1236
- var prevX = pathCoordinates[i - 2];
1237
- var prevY = pathCoordinates[i - 1];
1257
+ var prevX, prevY, prevData;
1258
+
1259
+ for (var i = 0; i < pathCoordinates.length; i += 2) {
1238
1260
  var currX = pathCoordinates[i];
1239
1261
  var currY = pathCoordinates[i + 1];
1240
- var prevData = valueData[(i / 2) - 1];
1241
1262
  var currData = valueData[i / 2];
1242
1263
 
1243
- // If last point is a "hole"
1244
- if(prevData.value === undefined) {
1245
- hole = true;
1246
- } else {
1247
- // If last point is not a "hole" but we just came back out of a "hole" we need to move first
1248
- if(hole) {
1249
- path.move(prevX, prevY, false, prevData);
1250
- }
1251
-
1252
- // If the current point is also not a hole we can draw the step lines
1253
- if(currData.value !== undefined) {
1264
+ // If the current point is also not a hole we can draw the step lines
1265
+ if(currData.value !== undefined) {
1266
+ if(prevData === undefined) {
1267
+ path.move(currX, currY, false, currData);
1268
+ } else {
1254
1269
  if(options.postpone) {
1255
1270
  // If postponed we should draw the step line with the value of the previous value
1256
1271
  path.line(currX, prevY, false, prevData);
@@ -1260,9 +1275,13 @@ var Chartist = {
1260
1275
  }
1261
1276
  // Line to the actual point (this should only be a Y-Axis movement
1262
1277
  path.line(currX, currY, false, currData);
1263
- // Reset the "hole" flag as previous and current point have valid values
1264
- hole = false;
1265
1278
  }
1279
+
1280
+ prevX = currX;
1281
+ prevY = currY;
1282
+ prevData = currData;
1283
+ } else if(!options.fillHoles) {
1284
+ prevX = prevY = prevData = undefined;
1266
1285
  }
1267
1286
  }
1268
1287
 
@@ -2084,7 +2103,7 @@ var Chartist = {
2084
2103
 
2085
2104
  // In guided mode we also set begin to indefinite so we can trigger the start manually and put the begin
2086
2105
  // which needs to be in ms aside
2087
- timeout = Chartist.stripUnit(animationDefinition.begin || 0);
2106
+ timeout = Chartist.quantity(animationDefinition.begin || 0).value;
2088
2107
  animationDefinition.begin = 'indefinite';
2089
2108
  }
2090
2109
 
@@ -2844,6 +2863,9 @@ var Chartist = {
2844
2863
  this.ticks = options.ticks || Chartist.times(this.divisor).map(function(value, index) {
2845
2864
  return highLow.low + (highLow.high - highLow.low) / this.divisor * index;
2846
2865
  }.bind(this));
2866
+ this.ticks.sort(function(a, b) {
2867
+ return a - b;
2868
+ });
2847
2869
  this.range = {
2848
2870
  min: highLow.low,
2849
2871
  max: highLow.high
@@ -3399,8 +3421,11 @@ var Chartist = {
3399
3421
  },
3400
3422
  // Specify the distance in pixel of bars in a group
3401
3423
  seriesBarDistance: 15,
3402
- // If set to true this property will cause the series bars to be stacked and form a total for each series point. This will also influence the y-axis and the overall bounds of the chart. In stacked mode the seriesBarDistance property will have no effect.
3424
+ // If set to true this property will cause the series bars to be stacked. Check the `stackMode` option for further stacking options.
3403
3425
  stackBars: false,
3426
+ // If set to 'overlap' this property will force the stacked bars to draw from the zero line.
3427
+ // If set to 'accumulate' this property will form a total for each series point. This will also influence the y-axis and the overall bounds of the chart. In stacked mode the seriesBarDistance property will have no effect.
3428
+ stackMode: 'accumulate',
3404
3429
  // Inverts the axes of the bar chart in order to draw a horizontal bar chart. Be aware that you also need to invert your axis settings as the Y Axis will now display the labels and the X Axis the values.
3405
3430
  horizontalBars: false,
3406
3431
  // If set to true then each bar will represent a series and the data array is expected to be a one dimensional array of data values rather than a series array of series. This is useful if the bar chart should represent a profile rather than some data over time.
@@ -3643,9 +3668,20 @@ var Chartist = {
3643
3668
  var positions = {};
3644
3669
  positions[labelAxis.units.pos + '1'] = projected[labelAxis.units.pos];
3645
3670
  positions[labelAxis.units.pos + '2'] = projected[labelAxis.units.pos];
3646
- // If bars are stacked we use the stackedBarValues reference and otherwise base all bars off the zero line
3647
- positions[labelAxis.counterUnits.pos + '1'] = options.stackBars ? previousStack : zeroPoint;
3648
- positions[labelAxis.counterUnits.pos + '2'] = options.stackBars ? stackedBarValues[valueIndex] : projected[labelAxis.counterUnits.pos];
3671
+
3672
+ if(options.stackBars && (options.stackMode === 'accumulate' || !options.stackMode)) {
3673
+ // Stack mode: accumulate (default)
3674
+ // If bars are stacked we use the stackedBarValues reference and otherwise base all bars off the zero line
3675
+ // We want backwards compatibility, so the expected fallback without the 'stackMode' option
3676
+ // to be the original behaviour (accumulate)
3677
+ positions[labelAxis.counterUnits.pos + '1'] = previousStack;
3678
+ positions[labelAxis.counterUnits.pos + '2'] = stackedBarValues[valueIndex];
3679
+ } else {
3680
+ // Draw from the zero line normally
3681
+ // This is also the same code for Stack mode: overlap
3682
+ positions[labelAxis.counterUnits.pos + '1'] = zeroPoint;
3683
+ positions[labelAxis.counterUnits.pos + '2'] = projected[labelAxis.counterUnits.pos];
3684
+ }
3649
3685
 
3650
3686
  // Limit x and y so that they are within the chart rect
3651
3687
  positions.x1 = Math.min(Math.max(positions.x1, chartRect.x1), chartRect.x2);
@@ -3777,6 +3813,7 @@ var Chartist = {
3777
3813
  // If specified the donut CSS classes will be used and strokes will be drawn instead of pie slices.
3778
3814
  donut: false,
3779
3815
  // Specify the donut stroke width, currently done in javascript for convenience. May move to CSS styles in the future.
3816
+ // This option can be set as number or string to specify a relative width (i.e. 100 or '30%').
3780
3817
  donutWidth: 60,
3781
3818
  // If a label should be shown or not
3782
3819
  showLabel: true,
@@ -3840,10 +3877,15 @@ var Chartist = {
3840
3877
  return previousValue + currentValue;
3841
3878
  }, 0);
3842
3879
 
3880
+ var donutWidth = Chartist.quantity(options.donutWidth);
3881
+ if (donutWidth.unit === '%') {
3882
+ donutWidth.value *= radius / 100;
3883
+ }
3884
+
3843
3885
  // If this is a donut chart we need to adjust our radius to enable strokes to be drawn inside
3844
3886
  // Unfortunately this is not possible with the current SVG Spec
3845
3887
  // See this proposal for more details: http://lists.w3.org/Archives/Public/www-svg/2003Oct/0000.html
3846
- radius -= options.donut ? options.donutWidth / 2 : 0;
3888
+ radius -= options.donut ? donutWidth.value / 2 : 0;
3847
3889
 
3848
3890
  // If labelPosition is set to `outside` or a donut chart is drawn then the label position is at the radius,
3849
3891
  // if regular pie chart it's half of the radius
@@ -3928,7 +3970,7 @@ var Chartist = {
3928
3970
  // If this is a donut, we add the stroke-width as style attribute
3929
3971
  if(options.donut) {
3930
3972
  pathElement.attr({
3931
- 'style': 'stroke-width: ' + (+options.donutWidth) + 'px'
3973
+ 'style': 'stroke-width: ' + donutWidth.value + 'px'
3932
3974
  });
3933
3975
  }
3934
3976