Skip to content

Commit

Permalink
Fix reading element values when display is 'auto'
Browse files Browse the repository at this point in the history
Chart.js 3 removed el._model in favor of getProps(), making harder to
abstract reading values in positioners. Also, using string arrays to
read values (i.e. var {a,b,c} = el.getProps(["a","b","c"])) would make
positioners inefficient in the normal case (i.e. not the final values)
and the code a bit ugly, so let's use a Proxy instead.
  • Loading branch information
simonbrunel committed May 15, 2021
1 parent 02adbb8 commit f0b8ca1
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
extends: chartjs

parserOptions:
ecmaVersion: 8
sourceType: module
ecmaVersion: 2015

env:
browser: true
node: true
es6: true
5 changes: 0 additions & 5 deletions docs/.vuepress/.eslintrc.js

This file was deleted.

6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@typescript-eslint/parser": "^4.22.0",
"@vuepress/plugin-google-analytics": "^1.8.2",
"archiver": "^5.3.0",
"chart.js": "^3.1.0",
"chart.js": "^3.2.1",
"chartjs-test-utils": "^0.2.2",
"eslint": "^7.24.0",
"eslint-config-chartjs": "^0.3.0",
Expand Down
5 changes: 0 additions & 5 deletions scripts/.eslintrc.yml

This file was deleted.

2 changes: 1 addition & 1 deletion src/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins: [es]

extends: [
plugin:es/restrict-to-es5
plugin:es/restrict-to-es2015
]

rules:
Expand Down
11 changes: 9 additions & 2 deletions src/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,23 @@ function collide(labels, collider) {
}

function compute(labels) {
var i, ilen, label, state, geometry, center;
var i, ilen, label, state, geometry, center, proxy;

// Initialize labels for overlap detection
for (i = 0, ilen = labels.length; i < ilen; ++i) {
label = labels[i];
state = label.$layout;

if (state._visible) {
// Chart.js 3 removed el._model in favor of getProps(), making harder to
// abstract reading values in positioners. Also, using string arrays to
// read values (i.e. var {a,b,c} = el.getProps(["a","b","c"])) would make
// positioners inefficient in the normal case (i.e. not the final values)
// and the code a bit ugly, so let's use a Proxy instead.
proxy = new Proxy(label._el, {get: (el, p) => el.getProps([p], true)[p]});

geometry = label.geometry();
center = coordinates(label._el, label.model(), geometry);
center = coordinates(proxy, label.model(), geometry);
state._box.update(center, geometry, label.rotation());
}
}
Expand Down
3 changes: 0 additions & 3 deletions test/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
env:
jasmine: true
es6: true
parserOptions:
ecmaVersion: 8

globals:
__karma__: true
Expand Down

0 comments on commit f0b8ca1

Please sign in to comment.