Thanks to visit codestin.com
Credit goes to github.com

Skip to content

extract _setCanvasId #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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