Skip to content

Commit

Permalink
Merge pull request #2 from coreui/dev-canvas-id-gen
Browse files Browse the repository at this point in the history
extract _setCanvasId
  • Loading branch information
xidedix authored Apr 23, 2018
2 parents c6aa831 + cd3d682 commit 99cb36a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
"jsx-quotes": "error",
"key-spacing": "off",
"keyword-spacing": "error",
"linebreak-style": ["error", "unix"],
"linebreak-style": 0,
"line-comment-position": "off",
"lines-around-comment": "off",
"lines-around-directive": "error",
Expand Down
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.css text eol=lf
*.js text eol=lf
17 changes: 10 additions & 7 deletions js/custom-tooltips.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@

function CustomTooltips(tooltipModel) {
// Add unique id if not exist
if (!this._chart.canvas.id) {
const _hex = 16
const _multiply = 0x10000
const _idMaker = () => ((1 + Math.random()) * _multiply | 0).toString(_hex)
const _canvasId = `_canvas${_idMaker() + _idMaker()}`
this._chart.canvas.id = this._chart.canvas.id || _canvasId
const _setCanvasId = () => {
const _idMaker = () => {
const _hex = 16
const _multiplier = 0x10000
return ((1 + Math.random()) * _multiplier | 0).toString(_hex)
}
const _canvasId = `_canvas-${_idMaker() + _idMaker()}`
this._chart.canvas.id = _canvasId
return _canvasId
}

const ClassName = {
Expand All @@ -32,7 +35,7 @@ function CustomTooltips(tooltipModel) {
const Selector = {
DIV : 'div',
SPAN : 'span',
TOOLTIP : `${this._chart.canvas.id}-tooltip`
TOOLTIP : `${this._chart.canvas.id || _setCanvasId()}-tooltip`
}

let tooltip = document.getElementById(Selector.TOOLTIP)
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@
"watch-js": "nodemon --ignore dist/ -e js -x npm run js"
},
"devDependencies": {
"@babel/cli": "7.0.0-beta.42",
"@babel/core": "7.0.0-beta.42",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.42",
"@babel/preset-env": "7.0.0-beta.42",
"babel-eslint": "^8.2.2",
"babel-plugin-istanbul": "^4.1.5",
"@babel/cli": "7.0.0-beta.46",
"@babel/core": "7.0.0-beta.46",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.46",
"@babel/preset-env": "7.0.0-beta.46",
"babel-eslint": "^8.2.3",
"babel-plugin-istanbul": "^4.1.6",
"babel-plugin-transform-es2015-modules-strip": "^0.1.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"cross-env": "^5.1.4",
"eslint": "^4.16.0",
"eslint-plugin-compat": "^2.1.0",
"nodemon": "^1.12.1",
"eslint": "^4.19.1",
"eslint-plugin-compat": "^2.2.0",
"nodemon": "^1.17.3",
"npm-run-all": "^4.1.2",
"uglify-js": "^3.3.8"
"uglify-js": "^3.3.22"
},
"peerDependencies": {
"chart.js": "^2.7.2"
Expand Down

0 comments on commit 99cb36a

Please sign in to comment.