Skip to content

Commit 99cb36a

Browse files
authored
Merge pull request #2 from coreui/dev-canvas-id-gen
extract _setCanvasId
2 parents c6aa831 + cd3d682 commit 99cb36a

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
"jsx-quotes": "error",
142142
"key-spacing": "off",
143143
"keyword-spacing": "error",
144-
"linebreak-style": ["error", "unix"],
144+
"linebreak-style": 0,
145145
"line-comment-position": "off",
146146
"lines-around-comment": "off",
147147
"lines-around-directive": "error",

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.css text eol=lf
2+
*.js text eol=lf

js/custom-tooltips.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77

88
function CustomTooltips(tooltipModel) {
99
// Add unique id if not exist
10-
if (!this._chart.canvas.id) {
11-
const _hex = 16
12-
const _multiply = 0x10000
13-
const _idMaker = () => ((1 + Math.random()) * _multiply | 0).toString(_hex)
14-
const _canvasId = `_canvas${_idMaker() + _idMaker()}`
15-
this._chart.canvas.id = this._chart.canvas.id || _canvasId
10+
const _setCanvasId = () => {
11+
const _idMaker = () => {
12+
const _hex = 16
13+
const _multiplier = 0x10000
14+
return ((1 + Math.random()) * _multiplier | 0).toString(_hex)
15+
}
16+
const _canvasId = `_canvas-${_idMaker() + _idMaker()}`
17+
this._chart.canvas.id = _canvasId
18+
return _canvasId
1619
}
1720

1821
const ClassName = {
@@ -32,7 +35,7 @@ function CustomTooltips(tooltipModel) {
3235
const Selector = {
3336
DIV : 'div',
3437
SPAN : 'span',
35-
TOOLTIP : `${this._chart.canvas.id}-tooltip`
38+
TOOLTIP : `${this._chart.canvas.id || _setCanvasId()}-tooltip`
3639
}
3740

3841
let tooltip = document.getElementById(Selector.TOOLTIP)

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,20 @@
4343
"watch-js": "nodemon --ignore dist/ -e js -x npm run js"
4444
},
4545
"devDependencies": {
46-
"@babel/cli": "7.0.0-beta.42",
47-
"@babel/core": "7.0.0-beta.42",
48-
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.42",
49-
"@babel/preset-env": "7.0.0-beta.42",
50-
"babel-eslint": "^8.2.2",
51-
"babel-plugin-istanbul": "^4.1.5",
46+
"@babel/cli": "7.0.0-beta.46",
47+
"@babel/core": "7.0.0-beta.46",
48+
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.46",
49+
"@babel/preset-env": "7.0.0-beta.46",
50+
"babel-eslint": "^8.2.3",
51+
"babel-plugin-istanbul": "^4.1.6",
5252
"babel-plugin-transform-es2015-modules-strip": "^0.1.1",
5353
"babel-plugin-transform-object-rest-spread": "^6.26.0",
5454
"cross-env": "^5.1.4",
55-
"eslint": "^4.16.0",
56-
"eslint-plugin-compat": "^2.1.0",
57-
"nodemon": "^1.12.1",
55+
"eslint": "^4.19.1",
56+
"eslint-plugin-compat": "^2.2.0",
57+
"nodemon": "^1.17.3",
5858
"npm-run-all": "^4.1.2",
59-
"uglify-js": "^3.3.8"
59+
"uglify-js": "^3.3.22"
6060
},
6161
"peerDependencies": {
6262
"chart.js": "^2.7.2"

0 commit comments

Comments
 (0)