Skip to content

Commit 0c08d5e

Browse files
authored
Merge pull request #113 from Exabyte-io/feat/SOF-6399-2
SOF-6399-2: prettier reformat
2 parents b021796 + cc5d342 commit 0c08d5e

File tree

16 files changed

+1423
-1373
lines changed

16 files changed

+1423
-1373
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/coverage/**

.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"singleQuote": false,
3+
"printWidth": 100,
4+
"trailingComma": "all",
5+
"tabWidth": 4
6+
}

package-lock.json

Lines changed: 34 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"@babel/preset-env": "7.16.4",
3636
"@babel/preset-react": "7.16.7",
3737
"@babel/runtime-corejs2": "7.16.7",
38-
"@exabyte-io/eslint-config": "^2022.11.16-0",
3938
"@exabyte-io/periodic-table.js": "2022.5.5-2",
4039
"@material-ui/core": "^4.12.3",
4140
"@material-ui/icons": "^4.11.2",
@@ -61,15 +60,18 @@
6160
"react-dom": "^16.14.0"
6261
},
6362
"devDependencies": {
63+
"@exabyte-io/eslint-config": "^2022.11.17-0",
6464
"@exabyte-io/made.js": "2022.5.5-3",
6565
"babel-jest": "^28.1.0",
6666
"cross-env": "^7.0.3",
6767
"enzyme": "^3.11.0",
6868
"eslint": "7.32.0",
6969
"eslint-config-airbnb": "19.0.2",
70+
"eslint-config-prettier": "^8.5.0",
7071
"eslint-plugin-import": "2.25.3",
7172
"eslint-plugin-jsdoc": "37.1.0",
7273
"eslint-plugin-jsx-a11y": "6.5.1",
74+
"eslint-plugin-prettier": "^4.2.1",
7375
"eslint-plugin-simple-import-sort": "7.0.0",
7476
"expect": "27.4.2",
7577
"gl": "4.9.2",

src/mixins/atoms.js

Lines changed: 94 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -6,111 +6,112 @@ import { ATOM_GROUP_NAME } from "../enums";
66
* Mixin containing the logic for dealing with atoms.
77
* Draws atoms as spheres and handles actions performed on them.
88
*/
9-
export const AtomsMixin = (superclass) => class extends superclass {
10-
constructor(config) {
11-
super(config);
9+
export const AtomsMixin = (superclass) =>
10+
class extends superclass {
11+
constructor(config) {
12+
super(config);
1213

13-
// to draw atoms as spheres
14-
this.initSphereParameters();
14+
// to draw atoms as spheres
15+
this.initSphereParameters();
1516

16-
this.drawAtomsAsSpheres = this.drawAtomsAsSpheres.bind(this);
17-
this.getAtomColorByElement = this.getAtomColorByElement.bind(this);
17+
this.drawAtomsAsSpheres = this.drawAtomsAsSpheres.bind(this);
18+
this.getAtomColorByElement = this.getAtomColorByElement.bind(this);
1819

19-
this.setStructure(this._structure);
20-
}
20+
this.setStructure(this._structure);
21+
}
2122

22-
get structure() {
23-
return this._structure;
24-
}
23+
get structure() {
24+
return this._structure;
25+
}
2526

26-
/**
27+
/**
2728
* Helper function to set the structural information.
2829
* @param {Made.Material} s - Structural information as Made.Material.
2930
*/
30-
setStructure(s) {
31-
this._structure = s.clone(); // clone original structure to assert that any updates are propagated to parents
32-
this._basis = s.Basis;
33-
this._basis.originalUnits = this._basis.units;
34-
this._basis.toCartesian();
35-
}
36-
37-
get basis() {
38-
return this._basis;
39-
}
40-
41-
initSphereParameters() {
42-
// radius, segment, ring
43-
const sphereGeometry = new THREE.SphereGeometry(
44-
1,
45-
this.settings.sphereQuality,
46-
this.settings.sphereQuality,
47-
);
48-
const sphereMaterial = new THREE.MeshLambertMaterial();
49-
this.sphereMesh = new THREE.Mesh(sphereGeometry, sphereMaterial);
50-
}
51-
52-
/**
31+
setStructure(s) {
32+
this._structure = s.clone(); // clone original structure to assert that any updates are propagated to parents
33+
this._basis = s.Basis;
34+
this._basis.originalUnits = this._basis.units;
35+
this._basis.toCartesian();
36+
}
37+
38+
get basis() {
39+
return this._basis;
40+
}
41+
42+
initSphereParameters() {
43+
// radius, segment, ring
44+
const sphereGeometry = new THREE.SphereGeometry(
45+
1,
46+
this.settings.sphereQuality,
47+
this.settings.sphereQuality,
48+
);
49+
const sphereMaterial = new THREE.MeshLambertMaterial();
50+
this.sphereMesh = new THREE.Mesh(sphereGeometry, sphereMaterial);
51+
}
52+
53+
/**
5354
* Prepares a sphere mesh object
5455
* @param {String} color
5556
* @param {Number} radius
5657
* @param {Array} coordinate
5758
* @return {THREE.Object3D}
5859
*/
59-
getSphereMeshObject({
60-
color = this.settings.defaultColor,
61-
radius = this.settings.sphereRadius,
62-
coordinate = [],
63-
}) {
64-
// clone original mesh to optimize the speed
65-
const sphereMesh = this.sphereMesh.clone();
66-
// set material color after cloning to optimize the speed and avoid re-creating material object
67-
sphereMesh.material = sphereMesh.material.clone();
68-
sphereMesh.material.setValues({ color });
69-
70-
// eslint-disable-next-line no-multi-assign
71-
sphereMesh.scale.x = sphereMesh.scale.y = sphereMesh.scale.z = radius;
72-
sphereMesh.position.set(...coordinate);
73-
74-
return sphereMesh;
75-
}
76-
77-
_getDefaultSettingsForElement(
78-
element = this.settings.defaultElement,
79-
scale = this.settings.atomRadiiScale,
80-
) {
81-
return {
82-
color: this.getAtomColorByElement(element),
83-
radius: this.getAtomRadiusByElement(element, scale),
84-
};
85-
}
86-
87-
createAtomsGroup(basis, atomRadiiScale) {
88-
const atomsGroup = new THREE.Group();
89-
atomsGroup.name = ATOM_GROUP_NAME;
90-
basis.coordinates.forEach((atomicCoordinate, atomicIndex) => {
91-
const element = basis.getElementByIndex(atomicIndex);
92-
const sphereMesh = this.getSphereMeshObject({
93-
...this._getDefaultSettingsForElement(element, atomRadiiScale),
94-
coordinate: atomicCoordinate.value,
60+
getSphereMeshObject({
61+
color = this.settings.defaultColor,
62+
radius = this.settings.sphereRadius,
63+
coordinate = [],
64+
}) {
65+
// clone original mesh to optimize the speed
66+
const sphereMesh = this.sphereMesh.clone();
67+
// set material color after cloning to optimize the speed and avoid re-creating material object
68+
sphereMesh.material = sphereMesh.material.clone();
69+
sphereMesh.material.setValues({ color });
70+
71+
// eslint-disable-next-line no-multi-assign
72+
sphereMesh.scale.x = sphereMesh.scale.y = sphereMesh.scale.z = radius;
73+
sphereMesh.position.set(...coordinate);
74+
75+
return sphereMesh;
76+
}
77+
78+
_getDefaultSettingsForElement(
79+
element = this.settings.defaultElement,
80+
scale = this.settings.atomRadiiScale,
81+
) {
82+
return {
83+
color: this.getAtomColorByElement(element),
84+
radius: this.getAtomRadiusByElement(element, scale),
85+
};
86+
}
87+
88+
createAtomsGroup(basis, atomRadiiScale) {
89+
const atomsGroup = new THREE.Group();
90+
atomsGroup.name = ATOM_GROUP_NAME;
91+
basis.coordinates.forEach((atomicCoordinate, atomicIndex) => {
92+
const element = basis.getElementByIndex(atomicIndex);
93+
const sphereMesh = this.getSphereMeshObject({
94+
...this._getDefaultSettingsForElement(element, atomRadiiScale),
95+
coordinate: atomicCoordinate.value,
96+
});
97+
sphereMesh.name = `${element}-${atomicIndex}`;
98+
atomsGroup.add(sphereMesh);
9599
});
96-
sphereMesh.name = `${element}-${atomicIndex}`;
97-
atomsGroup.add(sphereMesh);
98-
});
99-
return atomsGroup;
100-
}
101-
102-
drawAtomsAsSpheres(atomRadiiScale) {
103-
const basis = this.areNonPeriodicBoundariesPresent
104-
? this.basisWithElementsInsideNonPeriodicBoundaries
105-
: this.basis;
106-
this.repeatAtomsAtRepetitionCoordinates(this.createAtomsGroup(basis, atomRadiiScale));
107-
}
108-
109-
getAtomColorByElement(element, pallette = this.settings.elementColors) {
110-
return pallette[element] || this.settings.defaultColor;
111-
}
112-
113-
getAtomRadiusByElement(element, scale = 1.0, radiimap = this.settings.vdwRadii) {
114-
return (radiimap[element] || this.settings.sphereRadius) * scale;
115-
}
116-
};
100+
return atomsGroup;
101+
}
102+
103+
drawAtomsAsSpheres(atomRadiiScale) {
104+
const basis = this.areNonPeriodicBoundariesPresent
105+
? this.basisWithElementsInsideNonPeriodicBoundaries
106+
: this.basis;
107+
this.repeatAtomsAtRepetitionCoordinates(this.createAtomsGroup(basis, atomRadiiScale));
108+
}
109+
110+
getAtomColorByElement(element, pallette = this.settings.elementColors) {
111+
return pallette[element] || this.settings.defaultColor;
112+
}
113+
114+
getAtomRadiusByElement(element, scale = 1.0, radiimap = this.settings.vdwRadii) {
115+
return (radiimap[element] || this.settings.sphereRadius) * scale;
116+
}
117+
};

0 commit comments

Comments
 (0)