Comparing version 1.1.1 to 1.2.1
@@ -0,1 +1,10 @@ | ||
;(function(root, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
define([], factory); | ||
} else if (typeof exports === 'object') { | ||
module.exports = factory(); | ||
} else { | ||
root.Dailychart = factory(); | ||
} | ||
}(this, function() { | ||
'use strict'; | ||
@@ -15,10 +24,31 @@ | ||
this.element = el; | ||
if (!el) { | ||
throw 'Dailychart.js: el is not defined'; | ||
} else { | ||
this.element = el; | ||
} | ||
this.width = this.options.width || el.offsetWidth; | ||
this.height = this.options.height || el.offsetHeight; | ||
this.values = el.getAttribute('data-dailychart-values').split(',').map(Number); | ||
this.length = +el.getAttribute('data-dailychart-length'); | ||
this.previous = +el.getAttribute('data-dailychart-close'); | ||
if (!el.getAttribute('data-dailychart-values') || el.getAttribute('data-dailychart-values').length === 0) { | ||
return; // nothing to draw | ||
} else { | ||
this.values = el.getAttribute('data-dailychart-values').split(',').map(Number); | ||
} | ||
if (this.values.length < 2) return; // at least two points needs to draw a line | ||
if (!el.getAttribute('data-dailychart-length') || el.getAttribute('data-dailychart-length').length === 0) { | ||
this.length = this.values.length; | ||
} else { | ||
this.length = +el.getAttribute('data-dailychart-length'); | ||
} | ||
if (!el.getAttribute('data-dailychart-close') || el.getAttribute('data-dailychart-close').length === 0) { | ||
this.previous = this.values[0]; | ||
} else { | ||
this.previous = +el.getAttribute('data-dailychart-close'); | ||
} | ||
this._normalize(); | ||
@@ -61,3 +91,3 @@ this._translate(); | ||
value: function _path() { | ||
var inc = this.width / this.length; | ||
var inc = this.width / (this.length - 1); | ||
var i = 0, | ||
@@ -238,2 +268,4 @@ d = []; | ||
Dailychart.version = '1.1.1'; | ||
Dailychart.version = '1.2.0'; | ||
return Dailychart; | ||
})); |
@@ -1,1 +0,1 @@ | ||
"use strict";var _createClass=function(){function s(t,e){for(var i=0;i<e.length;i++){var s=e[i];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}return function(t,e,i){return e&&s(t.prototype,e),i&&s(t,i),t}}();function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var SVG_NS="http://www.w3.org/2000/svg",Dailychart=function(){function i(t,e){_classCallCheck(this,i),this.options=i.extend({},this.defaultOptions,e),this.element=t,this.width=this.options.width||t.offsetWidth,this.height=this.options.height||t.offsetHeight,this.values=t.getAttribute("data-dailychart-values").split(",").map(Number),this.length=+t.getAttribute("data-dailychart-length"),this.previous=+t.getAttribute("data-dailychart-close"),this._normalize(),this._translate(),this._draw()}return _createClass(i,[{key:"_normalize",value:function(){var e=this,t=Math.max.apply(null,this.values.concat([this.previous])),i=Math.min.apply(null,this.values.concat([this.previous])),s=(this.height-2*this.options.lineWidth)/(t-i);this.values=this.values.map(function(t){return(t-i)*s+e.options.lineWidth}),this.previous=(this.previous-i)*s+this.options.lineWidth}},{key:"_translate",value:function(){var e=this;this.values=this.values.map(function(t){return e.height-t}),this.previous=this.height-this.previous}},{key:"_id",value:function(){return Math.random().toString(36).substr(2,9)}},{key:"_path",value:function(){for(var t=this.width/this.length,e=0,i=[];e<this.values.length;e++)i.push(0===e?"M":"L"),i.push(e*t),i.push(this.values[e]);return i.join(" ")}},{key:"_close",value:function(t,e){return"positive"===e&&(t+=" V "+this.height+" H 0 Z"),"negative"===e&&(t+=" V 0 H 0 Z"),t}},{key:"_draw",value:function(){var t=this.options,e=t.lineWidth,i=t.colorPositive,s=t.colorNegative,n=t.fillPositive,h=t.fillNegative,r=this._id(),a="dailychart-"+r+"-positive",l="dailychart-"+r+"-negative",o=this._path(),u=this._close(o,"positive"),p=this._close(o,"negative"),c=this._svgElement(),v=this._lineElement(this.previous),d=this._pathElement(o,e,i,"",a),f=this._pathElement(u,0,"",n,a),m=this._clipElement(a),g=this._rectElement(0,0,this.width,this.previous),_=this._pathElement(o,e,s,"",l),y=this._pathElement(p,0,"",h,l),b=this._clipElement(l),A=this._rectElement(0,this.previous,this.width,this.height-this.previous);m.appendChild(g),b.appendChild(A),c.appendChild(m),c.appendChild(b),c.appendChild(v),c.appendChild(f),c.appendChild(y),c.appendChild(d),c.appendChild(_),this.element.appendChild(c)}},{key:"_svgElement",value:function(){var t=document.createElementNS(SVG_NS,"svg");return t.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns",SVG_NS),t.setAttribute("width",this.width),t.setAttribute("height",this.height),t}},{key:"_lineElement",value:function(t){var e=document.createElementNS(SVG_NS,"line");return e.setAttribute("x1",0),e.setAttribute("y1",t),e.setAttribute("x2",this.width),e.setAttribute("y2",t),e.setAttribute("stroke",this.options.closeColor),e.setAttribute("stroke-width",this.options.closeWidth),e.style.shapeRendering="crispEdges",e}},{key:"_pathElement",value:function(t,e,i,s,n){var h=document.createElementNS(SVG_NS,"path");return h.setAttribute("d",t),h.setAttribute("fill",""===s?"none":s),h.setAttribute("stroke-width",e),h.setAttribute("stroke-linejoin","bevel"),h.setAttribute("stroke",""===i?"none":i),h.setAttribute("clip-path","url(#"+n+")"),h}},{key:"_rectElement",value:function(t,e,i,s){var n=document.createElementNS(SVG_NS,"rect");return n.setAttribute("x",t),n.setAttribute("y",e),n.setAttribute("width",i),n.setAttribute("height",s),n}},{key:"_clipElement",value:function(t){var e=document.createElementNS(SVG_NS,"clipPath");return e.setAttribute("id",t),e}}],[{key:"extend",value:function(t){for(var e=arguments.length,i=Array(1<e?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];var n=i,h=Array.isArray(n),r=0;for(n=h?n:n[Symbol.iterator]();;){var a;if(h){if(r>=n.length)break;a=n[r++]}else{if((r=n.next()).done)break;a=r.value}var l=a;for(var o in l){var u=l[o];t[o]=u}}return t}}]),i}();Dailychart.prototype.defaultOptions={width:void 0,height:void 0,lineWidth:1,colorPositive:"#33AE45",colorNegative:"#EB5757",fillPositive:"",fillNegative:"",closeWidth:1,closeColor:"#e0e0e0"},Dailychart.version="1.1.1"; | ||
!function(t,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():t.Dailychart=e()}(this,function(){"use strict";var t=function(){function s(t,e){for(var i=0;i<e.length;i++){var s=e[i];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}return function(t,e,i){return e&&s(t.prototype,e),i&&s(t,i),t}}();var r="http://www.w3.org/2000/svg",e=function(){function i(t,e){if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,i),this.options=i.extend({},this.defaultOptions,e),!t)throw"Dailychart.js: el is not defined";this.element=t,this.width=this.options.width||t.offsetWidth,this.height=this.options.height||t.offsetHeight,t.getAttribute("data-dailychart-values")&&0!==t.getAttribute("data-dailychart-values").length&&(this.values=t.getAttribute("data-dailychart-values").split(",").map(Number),this.values.length<2||(t.getAttribute("data-dailychart-length")&&0!==t.getAttribute("data-dailychart-length").length?this.length=+t.getAttribute("data-dailychart-length"):this.length=this.values.length,t.getAttribute("data-dailychart-close")&&0!==t.getAttribute("data-dailychart-close").length?this.previous=+t.getAttribute("data-dailychart-close"):this.previous=this.values[0],this._normalize(),this._translate(),this._draw()))}return t(i,[{key:"_normalize",value:function(){var e=this,t=Math.max.apply(null,this.values.concat([this.previous])),i=Math.min.apply(null,this.values.concat([this.previous])),s=(this.height-2*this.options.lineWidth)/(t-i);this.values=this.values.map(function(t){return(t-i)*s+e.options.lineWidth}),this.previous=(this.previous-i)*s+this.options.lineWidth}},{key:"_translate",value:function(){var e=this;this.values=this.values.map(function(t){return e.height-t}),this.previous=this.height-this.previous}},{key:"_id",value:function(){return Math.random().toString(36).substr(2,9)}},{key:"_path",value:function(){for(var t=this.width/(this.length-1),e=0,i=[];e<this.values.length;e++)i.push(0===e?"M":"L"),i.push(e*t),i.push(this.values[e]);return i.join(" ")}},{key:"_close",value:function(t,e){return"positive"===e&&(t+=" V "+this.height+" H 0 Z"),"negative"===e&&(t+=" V 0 H 0 Z"),t}},{key:"_draw",value:function(){var t=this.options,e=t.lineWidth,i=t.colorPositive,s=t.colorNegative,n=t.fillPositive,h=t.fillNegative,r=this._id(),a="dailychart-"+r+"-positive",l="dailychart-"+r+"-negative",o=this._path(),u=this._close(o,"positive"),d=this._close(o,"negative"),p=this._svgElement(),c=this._lineElement(this.previous),v=this._pathElement(o,e,i,"",a),f=this._pathElement(u,0,"",n,a),g=this._clipElement(a),m=this._rectElement(0,0,this.width,this.previous),y=this._pathElement(o,e,s,"",l),b=this._pathElement(d,0,"",h,l),A=this._clipElement(l),_=this._rectElement(0,this.previous,this.width,this.height-this.previous);g.appendChild(m),A.appendChild(_),p.appendChild(g),p.appendChild(A),p.appendChild(c),p.appendChild(f),p.appendChild(b),p.appendChild(v),p.appendChild(y),this.element.appendChild(p)}},{key:"_svgElement",value:function(){var t=document.createElementNS(r,"svg");return t.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns",r),t.setAttribute("width",this.width),t.setAttribute("height",this.height),t}},{key:"_lineElement",value:function(t){var e=document.createElementNS(r,"line");return e.setAttribute("x1",0),e.setAttribute("y1",t),e.setAttribute("x2",this.width),e.setAttribute("y2",t),e.setAttribute("stroke",this.options.closeColor),e.setAttribute("stroke-width",this.options.closeWidth),e.style.shapeRendering="crispEdges",e}},{key:"_pathElement",value:function(t,e,i,s,n){var h=document.createElementNS(r,"path");return h.setAttribute("d",t),h.setAttribute("fill",""===s?"none":s),h.setAttribute("stroke-width",e),h.setAttribute("stroke-linejoin","bevel"),h.setAttribute("stroke",""===i?"none":i),h.setAttribute("clip-path","url(#"+n+")"),h}},{key:"_rectElement",value:function(t,e,i,s){var n=document.createElementNS(r,"rect");return n.setAttribute("x",t),n.setAttribute("y",e),n.setAttribute("width",i),n.setAttribute("height",s),n}},{key:"_clipElement",value:function(t){var e=document.createElementNS(r,"clipPath");return e.setAttribute("id",t),e}}],[{key:"extend",value:function(t){for(var e=arguments.length,i=Array(1<e?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];var n=i,h=Array.isArray(n),r=0;for(n=h?n:n[Symbol.iterator]();;){var a;if(h){if(r>=n.length)break;a=n[r++]}else{if((r=n.next()).done)break;a=r.value}var l=a;for(var o in l){var u=l[o];t[o]=u}}return t}}]),i}();return e.prototype.defaultOptions={width:void 0,height:void 0,lineWidth:1,colorPositive:"#33AE45",colorNegative:"#EB5757",fillPositive:"",fillNegative:"",closeWidth:1,closeColor:"#e0e0e0"},e.version="1.2.0",e}); |
@@ -5,2 +5,3 @@ const gulp = require('gulp'); | ||
const rename = require('gulp-rename'); | ||
const umd = require('gulp-umd'); | ||
@@ -10,2 +11,3 @@ gulp.task('js', () => { | ||
.pipe(babel()) | ||
.pipe(umd()) | ||
.pipe(gulp.dest('dist')) | ||
@@ -12,0 +14,0 @@ .pipe(uglify()) |
{ | ||
"name": "dailychart", | ||
"version": "1.1.1", | ||
"version": "1.2.1", | ||
"description": "Tiny SVG charting library to display daily graph of a stock market security", | ||
@@ -28,4 +28,5 @@ "homepage": "https://github.com/kbychkov/dailychart", | ||
"gulp-rename": "^1.2.3", | ||
"gulp-uglify": "^3.0.0" | ||
"gulp-uglify": "^3.0.0", | ||
"gulp-umd": "^2.0.0" | ||
} | ||
} |
@@ -9,6 +9,18 @@ # Dailychart.js | ||
Download the standalone Dailychart.js and include it like this: | ||
Download from NPM | ||
```bash | ||
npm install dailychart | ||
``` | ||
Include the library | ||
```js | ||
var Dailychart = require('dailychart'); | ||
``` | ||
of include the file | ||
```html | ||
<script scr='./path/to/dailychart.js'></script> | ||
<script src='./path/to/dailychart.js'></script> | ||
``` | ||
@@ -64,4 +76,8 @@ | ||
### 1.2.0 | ||
- Added UMD wrapper | ||
### 1.1.0 | ||
- Added new options: `fillPositive`, `fillNegative` |
@@ -7,10 +7,31 @@ const SVG_NS = 'http://www.w3.org/2000/svg'; | ||
this.element = el; | ||
if (!el) { | ||
throw 'Dailychart.js: el is not defined'; | ||
} else { | ||
this.element = el; | ||
} | ||
this.width = this.options.width || el.offsetWidth; | ||
this.height = this.options.height || el.offsetHeight; | ||
this.values = el.getAttribute('data-dailychart-values').split(',').map(Number); | ||
this.length = +el.getAttribute('data-dailychart-length'); | ||
this.previous = +el.getAttribute('data-dailychart-close'); | ||
if (!el.getAttribute('data-dailychart-values') || el.getAttribute('data-dailychart-values').length === 0) { | ||
return; // nothing to draw | ||
} else { | ||
this.values = el.getAttribute('data-dailychart-values').split(',').map(Number); | ||
} | ||
if (this.values.length < 2) return; // at least two points needs to draw a line | ||
if (!el.getAttribute('data-dailychart-length') || el.getAttribute('data-dailychart-length').length === 0) { | ||
this.length = this.values.length; | ||
} else { | ||
this.length = +el.getAttribute('data-dailychart-length'); | ||
} | ||
if (!el.getAttribute('data-dailychart-close') || el.getAttribute('data-dailychart-close').length === 0) { | ||
this.previous = this.values[0]; | ||
} else { | ||
this.previous = +el.getAttribute('data-dailychart-close'); | ||
} | ||
this._normalize(); | ||
@@ -50,3 +71,3 @@ this._translate(); | ||
_path() { | ||
const inc = this.width / this.length; | ||
const inc = this.width / (this.length - 1); | ||
let i = 0, d = []; | ||
@@ -182,2 +203,2 @@ | ||
Dailychart.version = '1.1.1'; | ||
Dailychart.version = '1.2.1'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30032
397
82
8