Skip to content

Commit

Permalink
Fix smells + coverage (#43)
Browse files Browse the repository at this point in the history
* Fix smells + coverage

* coverage

* add fixtures

* Exclude tests from duplications
  • Loading branch information
kurkle committed Dec 7, 2021
1 parent 865e5d9 commit 133b605
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 3 deletions.
4 changes: 3 additions & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ sonar.organization=kurkle
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8

sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.javascript.lcov.reportPaths=coverage/chrome/lcov.info,coverage/firefox/lcov.info

sonar.coverage.exclusions=**/test/**, **/types/**, **/*.config.js, **/*.conf.js

sonar.cpd.exclusions=**/test/**
24 changes: 22 additions & 2 deletions src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export default class MatrixController extends DatasetController {
const options = me.resolveDataElementOptions(i, mode);
const {width, height, anchorX, anchorY} = options;
const properties = {
x: anchorX === 'left' ? x : x - width / (anchorX === 'right' ? 1 : 2),
y: anchorY === 'top' ? y : y - height / (anchorY === 'bottom' ? 1 : 2),
x: resolveX(anchorX, x, width),
y: resolveY(anchorY, y, height),
width,
height,
options
Expand All @@ -51,6 +51,26 @@ export default class MatrixController extends DatasetController {
}
}

function resolveX(anchorX, x, width) {
if (anchorX === 'left' || anchorX === 'start') {
return x;
}
if (anchorX === 'right' || anchorX === 'end') {
return x - width;
}
return x - width / 2;
}

function resolveY(anchorY, y, height) {
if (anchorY === 'top' || anchorY === 'start') {
return y;
}
if (anchorY === 'bottom' || anchorY === 'end') {
return y - height;
}
return y - height / 2;
}

MatrixController.id = 'matrix';

MatrixController.version = version;
Expand Down
38 changes: 38 additions & 0 deletions test/fixtures/anchor/center-center.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module.exports = {
config: {
type: 'matrix',
data: {
datasets: [{
data: [
{x: 1, y: 1, v: 1},
],
backgroundColor: 'red',
borderColor: 'black',
borderWidth: 2,
width: 50,
height: 50
}]
},
options: {
plugins: {
legend: false
},
scales: {
x: {
type: 'linear',
display: false
},
y: {
type: 'linear',
display: false
}
}
}
},
options: {
canvas: {
height: 256,
width: 256
}
}
};
Binary file added test/fixtures/anchor/center-center.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions test/fixtures/anchor/left-bottom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module.exports = {
config: {
type: 'matrix',
data: {
datasets: [{
anchorX: 'left',
anchorY: 'bottom',
data: [
{x: 1, y: 1, v: 1},
],
backgroundColor: 'red',
borderColor: 'black',
borderWidth: 2,
width: 50,
height: 50
}]
},
options: {
plugins: {
legend: false
},
scales: {
x: {
type: 'linear',
display: false
},
y: {
type: 'linear',
display: false
}
}
}
},
options: {
canvas: {
height: 256,
width: 256
}
}
};
Binary file added test/fixtures/anchor/left-bottom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions test/fixtures/anchor/left-top.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module.exports = {
config: {
type: 'matrix',
data: {
datasets: [{
anchorX: 'left',
anchorY: 'top',
data: [
{x: 1, y: 1, v: 1},
],
backgroundColor: 'red',
borderColor: 'black',
borderWidth: 2,
width: 50,
height: 50
}]
},
options: {
plugins: {
legend: false
},
scales: {
x: {
type: 'linear',
display: false
},
y: {
type: 'linear',
display: false
}
}
}
},
options: {
canvas: {
height: 256,
width: 256
}
}
};
Binary file added test/fixtures/anchor/left-top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions test/fixtures/anchor/right-bottom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module.exports = {
config: {
type: 'matrix',
data: {
datasets: [{
anchorX: 'right',
anchorY: 'bottom',
data: [
{x: 1, y: 1, v: 1},
],
backgroundColor: 'red',
borderColor: 'black',
borderWidth: 2,
width: 50,
height: 50
}]
},
options: {
plugins: {
legend: false
},
scales: {
x: {
type: 'linear',
display: false
},
y: {
type: 'linear',
display: false
}
}
}
},
options: {
canvas: {
height: 256,
width: 256
}
}
};
Binary file added test/fixtures/anchor/right-bottom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions test/fixtures/anchor/right-top.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module.exports = {
config: {
type: 'matrix',
data: {
datasets: [{
anchorX: 'right',
anchorY: 'top',
data: [
{x: 1, y: 1, v: 1},
],
backgroundColor: 'red',
borderColor: 'black',
borderWidth: 2,
width: 50,
height: 50
}]
},
options: {
plugins: {
legend: false
},
scales: {
x: {
type: 'linear',
display: false
},
y: {
type: 'linear',
display: false
}
}
}
},
options: {
canvas: {
height: 256,
width: 256
}
}
};
Binary file added test/fixtures/anchor/right-top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/specs/scales.spec.js → test/specs/fixtures.spec.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
describe('auto', jasmine.fixtures('anchor'));
describe('auto', jasmine.fixtures('scales'));

0 comments on commit 133b605

Please sign in to comment.