diff --git a/sample.html b/sample.html new file mode 100644 index 0000000..40c848c --- /dev/null +++ b/sample.html @@ -0,0 +1,134 @@ + + + + + + + + + + + +

+Inline Sparkline: 1,4,4,7,5,9,10. +

+

+Sparkline with dynamic data: Loading.. +

+

+Bar chart with dynamic data: Loading.. +

+

+Bar chart with inline data: 1,3,4,5,3,5 +

+ +
+

Default sparklines

+

+Line chart: Loading.. +

+

+Bar chart: Loading.. +

+

+Tristate chart: Loading.. +

+

+Bullet chart: Loading.. +

+

+Discrete chart: Loading.. +

+

+Pie chart: Loading.. +

+

+Box chart: Loading.. +

+ +
+

Fixed-dimension sparklines

+ +

+Line chart: Loading.. +

+

+Bar chart: Loading.. +

+

+Tristate chart: Loading.. +

+

+Bullet chart: Loading.. +

+

+Discrete chart: Loading.. +

+

+Pie chart: Loading.. +

+

+Box chart: Loading.. +

+ + diff --git a/src/chart-bar.js b/src/chart-bar.js index de0e376..72de525 100644 --- a/src/chart-bar.js +++ b/src/chart-bar.js @@ -43,7 +43,9 @@ this.barWidth = barWidth; this.barSpacing = barSpacing; this.totalBarWidth = barWidth + barSpacing; - this.width = width = (values.length * barWidth) + ((values.length - 1) * barSpacing); + var rawWidth = (values.length * barWidth) + ((values.length - 1) * barSpacing); + this.xScale = Math.min(1, rawWidth ? width / rawWidth : 1); + this.width = rawWidth * this.xScale; this.initTarget(); @@ -103,7 +105,7 @@ this.zeroAxis = zeroAxis = options.get('zeroAxis', true); if (min <= 0 && max >= 0 && zeroAxis) { xaxisOffset = 0; - } else if (zeroAxis == false) { + } else if (zeroAxis === false) { xaxisOffset = min; } else if (min > 0) { xaxisOffset = min; @@ -145,6 +147,7 @@ }, getRegion: function (el, x, y) { + x /= this.xScale; var result = Math.floor(x / this.totalBarWidth); return (result < 0 || result >= this.values.length) ? undefined : result; }, @@ -245,7 +248,7 @@ if (highlight) { color = this.calcHighlightColor(color, options); } - result.push(target.drawRect(x, y, this.barWidth - 1, height - 1, color, color)); + result.push(target.drawRect(x * this.xScale, y, (this.barWidth - 1) * this.xScale, height - 1, color, color)); } if (result.length === 1) { return result[0]; diff --git a/src/chart-line.js b/src/chart-line.js index bb1c7ef..e144208 100644 --- a/src/chart-line.js +++ b/src/chart-line.js @@ -121,7 +121,6 @@ this.xvalues = xvalues; this.yvalues = yvalues; this.yminmax = yminmax; - }, processRangeOptions: function () { diff --git a/src/chart-tristate.js b/src/chart-tristate.js index 6b2771b..6a1f66b 100644 --- a/src/chart-tristate.js +++ b/src/chart-tristate.js @@ -14,7 +14,9 @@ this.barSpacing = barSpacing; this.totalBarWidth = barWidth + barSpacing; this.values = $.map(values, Number); - this.width = width = (values.length * barWidth) + ((values.length - 1) * barSpacing); + var rawWidth = (values.length * barWidth) + ((values.length - 1) * barSpacing); + this.xScale = Math.min(1, rawWidth ? width / rawWidth : 1); + this.width = rawWidth * this.xScale; if ($.isArray(options.get('colorMap'))) { this.colorMapByIndex = options.get('colorMap'); @@ -92,7 +94,7 @@ if (highlight) { color = this.calcHighlightColor(color, options); } - return target.drawRect(x, y, this.barWidth - 1, height - 1, color, color); + return target.drawRect(x * this.xScale, y, (this.barWidth - 1) * this.xScale, height - 1, color, color); } });