From e06e7cb53526f2effa3c01c546fcbfed8aaebe17 Mon Sep 17 00:00:00 2001 From: orioncohen Date: Thu, 7 Oct 2021 09:00:25 -0700 Subject: [PATCH 01/21] new page on website to demo phonon visualization --- src/app.tsx | 8 ++++ .../PhononVisualization.tsx | 37 +++++++++++++++++++ src/pages/PhononVisualization/index.tsx | 1 + 3 files changed, 46 insertions(+) create mode 100644 src/pages/PhononVisualization/PhononVisualization.tsx create mode 100644 src/pages/PhononVisualization/index.tsx diff --git a/src/app.tsx b/src/app.tsx index cfdb25b9..0e8c07ae 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -21,6 +21,7 @@ import { Sandbox } from './pages/Sandbox'; import { SynthesisExplorer } from './pages/SynthesisExplorer'; import { MPContribsSearch } from './pages/MPContribsSearch'; import { CatalystExplorer } from './pages/CatalystExplorer'; +import { PhononVisualization } from './pages/PhononVisualization'; import { Navbar } from './components/navigation/Navbar'; import periodicTableImage from './assets/images/periodictable.png'; @@ -64,6 +65,10 @@ ReactDOM.render( icon: 'icon-fontastic-synthesis', href: '/catalysts' }, + { + label: 'Phonon Visualization', + href: '/phonon' + }, { icon: 'icon-fontastic-synthesis', isRight: true, @@ -124,6 +129,9 @@ ReactDOM.render( + + + diff --git a/src/pages/PhononVisualization/PhononVisualization.tsx b/src/pages/PhononVisualization/PhononVisualization.tsx new file mode 100644 index 00000000..28d39a75 --- /dev/null +++ b/src/pages/PhononVisualization/PhononVisualization.tsx @@ -0,0 +1,37 @@ +import React, { useEffect, useState } from 'react'; +import { scene, scene2 } from '../../components/crystal-toolkit/scene/mike'; +import { s2, s3, s4, s5, shperes } from '../../components/crystal-toolkit/scene/simple-scene'; +import { CameraContextProvider } from '../../components/crystal-toolkit/CameraContextProvider'; +import { AnimationStyle, Renderer } from '../../components/crystal-toolkit/scene/constants'; +import { CrystalToolkitScene } from '../../components/crystal-toolkit/CrystalToolkitScene/CrystalToolkitScene'; +import { ExportType } from '../../components/crystal-toolkit/scene/constants'; +import { Download } from '../../components/crystal-toolkit/Download'; +import { ScenePosition } from '../../components/crystal-toolkit/scene/inset-helper'; +import { CameraState } from '../../components/crystal-toolkit/CameraContextProvider/camera-reducer'; +import * as THREE from 'three'; +import { Camera } from 'three'; +import { useRef } from 'react'; + +export const PhononVisualization: React.FC = () => { + const [dataInput, setDataInput] = useState(); + const [structureContainerWidth, setStructureContainerWidth] = useState('100%'); + const structureContainer = useRef(null); + + const [value, setValue] = useState('test'); + + return ( +
+ +
+ ); +}; diff --git a/src/pages/PhononVisualization/index.tsx b/src/pages/PhononVisualization/index.tsx new file mode 100644 index 00000000..746b2a1a --- /dev/null +++ b/src/pages/PhononVisualization/index.tsx @@ -0,0 +1 @@ +export { PhononVisualization } from './PhononVisualization'; From c7b6ffbb9d6ce88d775d841b9b2aad6824643205 Mon Sep 17 00:00:00 2001 From: orioncohen Date: Mon, 6 Dec 2021 09:27:19 -0800 Subject: [PATCH 02/21] create crystal test scene and include in PhononVisualization page --- .../crystal-toolkit/scene/crystal-scene.json | 231 +++++++++ .../crystal-toolkit/scene/simple-scene.ts | 488 +++++++++--------- .../PhononVisualization.tsx | 11 +- 3 files changed, 488 insertions(+), 242 deletions(-) create mode 100644 src/components/crystal-toolkit/scene/crystal-scene.json diff --git a/src/components/crystal-toolkit/scene/crystal-scene.json b/src/components/crystal-toolkit/scene/crystal-scene.json new file mode 100644 index 00000000..2cbf3c3e --- /dev/null +++ b/src/components/crystal-toolkit/scene/crystal-scene.json @@ -0,0 +1,231 @@ +{ + "name": "Structure", + "contents": [ + { + "name": "atoms", + "contents": [ + { + "positions": [[-1.5733063740697162e-8, 1.8166976957501553, 5.996085336983941]], + "color": "#bfc2c7", + "radius": 0.5, + "type": "spheres", + "tooltip": "Ti (-0.000, 1.817, 5.996)", + "clickable": true + }, + { + "positions": [[1.57330635, 2.72504653, 0.0]], + "color": "#909090", + "radius": 0.5, + "type": "spheres", + "tooltip": "C (1.573, 2.725, 0.000)", + "clickable": true + }, + { + "positions": [[3.1466127, 0.0, 14.21716731]], + "color": "#909090", + "radius": 0.5, + "type": "spheres", + "tooltip": "C (3.147, 0.000, 14.217)", + "clickable": true + }, + { + "positions": [[-1.57330635, 2.72504653, 7.108583655]], + "color": "#909090", + "radius": 0.5, + "type": "spheres", + "tooltip": "C (-1.573, 2.725, 7.109)", + "clickable": true + }, + { + "positions": [[3.1466127, 0.0, 7.108583655]], + "color": "#909090", + "radius": 0.5, + "type": "spheres", + "tooltip": "C (3.147, 0.000, 7.109)", + "clickable": true + }, + { + "positions": [[1.5733063657330637, 0.9083488342498449, 13.104668991983942]], + "color": "#bfc2c7", + "radius": 0.5, + "type": "spheres", + "tooltip": "Ti (1.573, 0.908, 13.105)", + "clickable": true + }, + { + "positions": [[0.0, 0.0, 14.21716731]], + "color": "#909090", + "radius": 0.5, + "type": "spheres", + "tooltip": "C (0.000, 0.000, 14.217)", + "clickable": true + }, + { + "positions": [[-1.57330635, 2.72504653, 14.21716731]], + "color": "#909090", + "radius": 0.5, + "type": "spheres", + "tooltip": "C (-1.573, 2.725, 14.217)", + "clickable": true + }, + { + "positions": [[-1.5733063740697162e-8, 1.8166976957501553, 10.6628754825]], + "color": "#a67573", + "radius": 0.5, + "type": "spheres", + "tooltip": "In (-0.000, 1.817, 10.663)", + "clickable": true + }, + { + "positions": [[0.0, 0.0, 7.108583655]], + "color": "#909090", + "radius": 0.5, + "type": "spheres", + "tooltip": "C (0.000, 0.000, 7.109)", + "clickable": true + }, + { + "positions": [[-1.57330635, 2.72504653, 0.0]], + "color": "#909090", + "radius": 0.5, + "type": "spheres", + "tooltip": "C (-1.573, 2.725, 0.000)", + "clickable": true + }, + { + "positions": [[3.1466127, 0.0, 0.0]], + "color": "#909090", + "radius": 0.5, + "type": "spheres", + "tooltip": "C (3.147, 0.000, 0.000)", + "clickable": true + }, + { + "positions": [[1.5733063657330637, 0.9083488342498449, 8.221081973016059]], + "color": "#bfc2c7", + "radius": 0.5, + "type": "spheres", + "tooltip": "Ti (1.573, 0.908, 8.221)", + "clickable": true + }, + { + "positions": [[1.57330635, 2.72504653, 7.108583655]], + "color": "#909090", + "radius": 0.5, + "type": "spheres", + "tooltip": "C (1.573, 2.725, 7.109)", + "clickable": true + }, + { + "positions": [[1.57330635, 2.72504653, 14.21716731]], + "color": "#909090", + "radius": 0.5, + "type": "spheres", + "tooltip": "C (1.573, 2.725, 14.217)", + "clickable": true + }, + { + "positions": [[0.0, 0.0, 0.0]], + "color": "#909090", + "radius": 0.5, + "type": "spheres", + "tooltip": "C (0.000, 0.000, 0.000)", + "clickable": true + }, + { + "positions": [[1.5733063657330637, 0.9083488342498449, 3.5542918275]], + "color": "#a67573", + "radius": 0.5, + "type": "spheres", + "tooltip": "In (1.573, 0.908, 3.554)", + "clickable": true + }, + { + "positions": [[-1.5733063740697162e-8, 1.8166976957501553, 1.1124983180160586]], + "color": "#bfc2c7", + "radius": 0.5, + "type": "spheres", + "tooltip": "Ti (-0.000, 1.817, 1.112)", + "clickable": true + } + ], + "origin": [-0.786653175, -1.362523265, -7.108583655], + "visible": true, + "tiling": [2, 1, 0], + "lattice": [ + [3.1466127, 0.0, 0.0], + [-1.57330635, 2.72504653, 0.0], + [0.0, 0.0, 14.21716731] + ] + }, + { + "name": "bonds", + "contents": [], + "origin": [-0.786653175, -1.362523265, -7.108583655], + "visible": true + }, + { + "name": "polyhedra", + "contents": [], + "origin": [-0.786653175, -1.362523265, -7.108583655], + "visible": true + }, + { + "name": "magmoms", + "contents": [], + "origin": [-0.786653175, -1.362523265, -7.108583655], + "visible": true + }, + { + "name": "unit_cell", + "contents": [ + { + "name": "a=3.1466127, b=3.1466126964746337, c=14.21716731, alpha=90.0, beta=90.0, gamma=120.0000000370615", + "contents": [ + { + "positions": [ + [0, 0, 0], + [3.1466127, 0.0, 0.0], + [0, 0, 0], + [-1.57330635, 2.72504653, 0.0], + [0, 0, 0], + [0.0, 0.0, 14.21716731], + [3.1466127, 0.0, 0.0], + [1.57330635, 2.72504653, 0.0], + [3.1466127, 0.0, 0.0], + [3.1466127, 0.0, 14.21716731], + [-1.57330635, 2.72504653, 0.0], + [1.57330635, 2.72504653, 0.0], + [-1.57330635, 2.72504653, 0.0], + [-1.57330635, 2.72504653, 14.21716731], + [0.0, 0.0, 14.21716731], + [3.1466127, 0.0, 14.21716731], + [0.0, 0.0, 14.21716731], + [-1.57330635, 2.72504653, 14.21716731], + [1.57330635, 2.72504653, 0.0], + [1.57330635, 2.72504653, 14.21716731], + [3.1466127, 0.0, 14.21716731], + [1.57330635, 2.72504653, 14.21716731], + [-1.57330635, 2.72504653, 14.21716731], + [1.57330635, 2.72504653, 14.21716731] + ], + "type": "lines", + "clickable": false + } + ], + "visible": true + } + ], + "origin": [-0.786653175, -1.362523265, -7.108583655], + "visible": true, + "tiling": [2, 1, 0], + "lattice": [ + [3.1466127, 0.0, 0.0], + [-1.57330635, 2.72504653, 0.0], + [0.0, 0.0, 14.21716731] + ] + } + ], + "origin": [-0.786653175, -1.362523265, -7.108583655], + "visible": true +} diff --git a/src/components/crystal-toolkit/scene/simple-scene.ts b/src/components/crystal-toolkit/scene/simple-scene.ts index 3e13f9b2..8316581a 100644 --- a/src/components/crystal-toolkit/scene/simple-scene.ts +++ b/src/components/crystal-toolkit/scene/simple-scene.ts @@ -30,27 +30,27 @@ export const s4 = { positions: [ [1.6081450794147842, 0.9284629773820368, 2.6153700106355755], [-1.9414784057759444e-8, 1.8569259826179634, 5.235351240635575], - [-1.9414784057759444e-8, 1.8569259826179634, -0.004611219364424821], + [-1.9414784057759444e-8, 1.8569259826179634, -0.004611219364424821] ], color: '#9ee373', radius: 0.8, type: 'ellipsoids', scale: [0.4, 1.2, 1.9], - clickable: true, + clickable: true }, { positions: [ [1.6081450794147842, 0.9284629773820368, 4.589578371864425], - [-1.9414784057759444e-8, 1.8569259826179634, 1.9695971418644245], + [-1.9414784057759444e-8, 1.8569259826179634, 1.9695971418644245] ], color: '#b0b9e6', radius: 0.5, type: 'spheres', - clickable: true, - }, + clickable: true + } ], origin: [-0.80407253, -1.39269448, -2.61998123], - visible: true, + visible: true }, { name: 'bonds', @@ -59,68 +59,67 @@ export const s4 = { positionPairs: [ [ [1.6081450794147842, 0.9284629773820368, 2.6153700106355755], - [0.8040725300000001, 1.39269448, 2.29248357625], + [0.8040725300000001, 1.39269448, 2.29248357625] ], [ [1.6081450794147842, 0.9284629773820368, 2.6153700106355755], - [1.6081450794147842, 0.9284629773820368, 3.6024741912500002], + [1.6081450794147842, 0.9284629773820368, 3.6024741912500002] ], [ [-1.9414784057759444e-8, 1.8569259826179634, 5.235351240635575], - [0.8040725300000001, 1.39269448, 4.91246480625], + [0.8040725300000001, 1.39269448, 4.91246480625] ], [ [-1.9414784057759444e-8, 1.8569259826179634, -0.004611219364424821], - [-1.9414784057759444e-8, 1.8569259826179634, 0.9824929612499999], - ], + [-1.9414784057759444e-8, 1.8569259826179634, 0.9824929612499999] + ] ], color: '#9ee373', radius: 0.1, type: 'cylinders', - clickable: false, + clickable: false }, { positionPairs: [ [ [1.6081450794147842, 0.9284629773820368, 4.589578371864425], - [0.8040725300000001, 1.39269448, 4.91246480625], + [0.8040725300000001, 1.39269448, 4.91246480625] ], [ [1.6081450794147842, 0.9284629773820368, 4.589578371864425], - [1.6081450794147842, 0.9284629773820368, 3.6024741912500002], + [1.6081450794147842, 0.9284629773820368, 3.6024741912500002] ], [ [-1.9414784057759444e-8, 1.8569259826179634, 1.9695971418644245], - [0.8040725300000001, 1.39269448, 2.29248357625], + [0.8040725300000001, 1.39269448, 2.29248357625] ], [ [-1.9414784057759444e-8, 1.8569259826179634, 1.9695971418644245], - [-1.9414784057759444e-8, 1.8569259826179634, 0.9824929612499999], - ], + [-1.9414784057759444e-8, 1.8569259826179634, 0.9824929612499999] + ] ], animate: [[[1, 1, 1], [2, 2, 2], 0]], keyframes: [0, 1], color: '#b0b9e6', radius: 0.1, type: 'cylinders', - clickable: false, - }, + clickable: false + } ], origin: [-0.80407253, -1.39269448, -2.61998123], - visible: true, + visible: true }, { name: 'polyhedra', contents: [], origin: [-0.80407253, -1.39269448, -2.61998123], - visible: true, + visible: true }, { name: 'unit_cell', contents: [ { - name: - 'a=3.21629013, b=3.2162901337807175, c=5.23996246, alpha=90.0, beta=90.0, gamma=120.00000006396569', + name: 'a=3.21629013, b=3.2162901337807175, c=5.23996246, alpha=90.0, beta=90.0, gamma=120.00000006396569', contents: [ { positions: [ @@ -147,17 +146,17 @@ export const s4 = { [3.21629013, 0, 5.23996246], [1.60814506, 2.78538896, 5.23996246], [-1.60814507, 2.78538896, 5.23996246], - [1.60814506, 2.78538896, 5.23996246], + [1.60814506, 2.78538896, 5.23996246] ], type: 'lines', - clickable: false, - }, + clickable: false + } ], - visible: false, - }, + visible: false + } ], origin: [-0.80407253, -1.39269448, -2.61998123], - visible: true, + visible: true }, { name: 'axes', @@ -166,57 +165,57 @@ export const s4 = { positionPairs: [ [ [-0.80407253, -1.39269448, -2.61998123], - [0.19592747, -1.39269448, -2.61998123], - ], + [0.19592747, -1.39269448, -2.61998123] + ] ], color: 'red', radius: 0.07, headLength: 0.24, headWidth: 0.14, type: 'arrows', - clickable: false, + clickable: false }, { positionPairs: [ [ [-0.80407253, -1.39269448, -2.61998123], - [-1.304072530966841, -0.5266690767737673, -2.61998123], - ], + [-1.304072530966841, -0.5266690767737673, -2.61998123] + ] ], color: 'green', radius: 0.07, headLength: 0.24, headWidth: 0.14, type: 'arrows', - clickable: false, + clickable: false }, { positionPairs: [ [ [-0.80407253, -1.39269448, -2.61998123], - [-0.80407253, -1.39269448, -1.61998123], - ], + [-0.80407253, -1.39269448, -1.61998123] + ] ], color: 'blue', radius: 0.07, headLength: 0.24, headWidth: 0.14, type: 'arrows', - clickable: false, + clickable: false }, { positions: [[-0.80407253, -1.39269448, -2.61998123]], color: 'white', radius: 0.0175, type: 'spheres', - clickable: false, - }, + clickable: false + } ], - visible: false, - }, + visible: false + } ], origin: [-0.80407253, -1.39269448, -2.61998123], - visible: true, + visible: true }; export const s2 = { @@ -235,7 +234,7 @@ export const s2 = { [4.2, 4.2, 4.2], [0, 0, 0], [0, 0, 4.2], - [4.2, 0, 0], + [4.2, 0, 0] ], color: '#f9dc3c', radius: 0.5, @@ -250,9 +249,9 @@ export const s2 = { [4, 4, 4], [1, 1, 1], [1, 1, 4], - [4, 1, 1], + [4, 1, 1] ], - keyframes: [0, 1], + keyframes: [0, 1] }, { positions: [[2.1, 2.1, 2.1]], @@ -262,11 +261,11 @@ export const s2 = { tooltip: 'label', clickable: true, animate: [1, 1, 1], - keyframes: [0, 1], - }, + keyframes: [0, 1] + } ], origin: [-2.1, -2.1, -2.1], - visible: true, + visible: true }, { name: 'bonds', @@ -275,36 +274,36 @@ export const s2 = { positionPairs: [ [ [4.2, 4.2, 0], - [3.1500000000000004, 3.1500000000000004, 1.05], + [3.1500000000000004, 3.1500000000000004, 1.05] ], [ [0, 4.2, 4.2], - [1.05, 3.1500000000000004, 3.1500000000000004], + [1.05, 3.1500000000000004, 3.1500000000000004] ], [ [0, 4.2, 0], - [1.05, 3.1500000000000004, 1.05], + [1.05, 3.1500000000000004, 1.05] ], [ [4.2, 0, 4.2], - [3.1500000000000004, 1.05, 3.1500000000000004], + [3.1500000000000004, 1.05, 3.1500000000000004] ], [ [4.2, 4.2, 4.2], - [3.1500000000000004, 3.1500000000000004, 3.1500000000000004], + [3.1500000000000004, 3.1500000000000004, 3.1500000000000004] ], [ [0, 0, 0], - [1.05, 1.05, 1.05], + [1.05, 1.05, 1.05] ], [ [0, 0, 4.2], - [1.05, 1.05, 3.1500000000000004], + [1.05, 1.05, 3.1500000000000004] ], [ [4.2, 0, 0], - [3.1500000000000004, 1.05, 1.05], - ], + [3.1500000000000004, 1.05, 1.05] + ] ], animate: [ [[4, 4, 1], [1, 1, 1], 0], @@ -314,49 +313,49 @@ export const s2 = { [[4, 4, 4], [1, 1, 1], 4], [[1, 1, 1], [1, 1, 1], 5], [[1, 1, 4], [1, 1, 1], 6], - [[4, 1, 1], [1, 1, 1], 7], + [[4, 1, 1], [1, 1, 1], 7] ], keyframes: [0, 1], color: '#f9dc3c', tooltip: 'label', radius: 0.1, type: 'cylinders', - clickable: true, + clickable: true }, { positionPairs: [ [ [2.1, 2.1, 2.1], // starts from center sphere - [1.05, 1.05, 1.05], // end in yellow + [1.05, 1.05, 1.05] // end in yellow ], [ [2.1, 2.1, 2.1], - [3.1500000000000004, 1.05, 1.05], + [3.1500000000000004, 1.05, 1.05] ], [ [2.1, 2.1, 2.1], - [3.1500000000000004, 3.1500000000000004, 3.1500000000000004], + [3.1500000000000004, 3.1500000000000004, 3.1500000000000004] ], [ [2.1, 2.1, 2.1], - [3.1500000000000004, 1.05, 3.1500000000000004], + [3.1500000000000004, 1.05, 3.1500000000000004] ], [ [2.1, 2.1, 2.1], - [1.05, 3.1500000000000004, 1.05], + [1.05, 3.1500000000000004, 1.05] ], [ [2.1, 2.1, 2.1], - [3.1500000000000004, 3.1500000000000004, 1.05], + [3.1500000000000004, 3.1500000000000004, 1.05] ], [ [2.1, 2.1, 2.1], - [1.05, 1.05, 3.1500000000000004], + [1.05, 1.05, 3.1500000000000004] ], [ [2.1, 2.1, 2.1], - [1.05, 3.1500000000000004, 3.1500000000000004], - ], + [1.05, 3.1500000000000004, 3.1500000000000004] + ] ], animate: [ [[1, 1, 1], [0, 0, 0], 0], @@ -366,18 +365,18 @@ export const s2 = { [[1, 1, 1], [0, 0, 0], 4], [[1, 1, 1], [0, 0, 0], 5], [[1, 1, 1], [0, 0, 0], 6], - [[1, 1, 1], [0, 0, 0], 7], + [[1, 1, 1], [0, 0, 0], 7] ], keyframes: [0, 1], color: '#a121f6', radius: 0.1, type: 'cylinders', tooltip: 'label', - clickable: true, - }, + clickable: true + } ], origin: [-2.1, -2.1, -2.1], - visible: true, + visible: true }, { name: 'cubes', @@ -385,16 +384,16 @@ export const s2 = { { positions: [ [4, 4, 4], - [10, 10, 10], + [10, 10, 10] ], width: 2, color: '#ababaa', type: 'cubes', animate: [10, 10, 10], tooltip: 'label', - keyframes: [0, 1], - }, - ], + keyframes: [0, 1] + } + ] }, { name: 'polyhedra', @@ -409,7 +408,7 @@ export const s2 = { [0, 4.2, 0], [4.2, 4.2, 0], [0, 0, 4.2], - [0, 4.2, 4.2], + [0, 4.2, 4.2] ], animate: [ [[3.1, 3.1, 3.1], 0], @@ -420,16 +419,16 @@ export const s2 = { [[1, 4, 1], 6], [[4, 4, 1], 7], [[1, 1, 4], 8], - [[1, 4, 4], 9], + [[1, 4, 4], 9] ], keyframes: [0, 1], color: '#a121f6', - type: 'convex', - }, + type: 'convex' + } ], origin: [-2.1, -2.1, -2.1], tooltip: 'label', - visible: true, + visible: true }, { name: 'unit_cell', @@ -462,7 +461,7 @@ export const s2 = { [4.2, 0, 4.2], [4.2, 4.2, 4.2], [0, 4.2, 4.2], - [4.2, 4.2, 4.2], + [4.2, 4.2, 4.2] ], animate: [ [0, 0, 0], @@ -488,17 +487,17 @@ export const s2 = { [4.2, 0, 4.2], [4.2, 4.2, 4.2], [0, 4.2, 4.2], - [4.2, 4.2, 4.2], + [4.2, 4.2, 4.2] ], keyframes: [0, 1], - type: 'lines', - }, + type: 'lines' + } ], - visible: false, - }, + visible: false + } ], origin: [-2.1, -2.1, -2.1], - visible: false, + visible: false }, { name: 'axes', @@ -507,57 +506,57 @@ export const s2 = { positionPairs: [ [ [-2.1, -2.1, -2.1], - [-1.4, -1.4, -3.1], - ], + [-1.4, -1.4, -3.1] + ] ], color: 'red', radius: 0.07, // / 0.37302772291498865) * 2, headLength: 0.24, headWidth: 0.14, type: 'arrows', - clickable: false, + clickable: false }, { positionPairs: [ [ [-2.1, -2.1, -2.1], - [-0.1, -2.5, -1.1], - ], + [-0.1, -2.5, -1.1] + ] ], color: 'green', radius: 0.07, // / 0.37302772291498865) * 2, headLength: 0.24, // / 0.37302772291498865, headWidth: 0.14, // 0.37302772291498865, type: 'arrows', - clickable: false, + clickable: false }, { positionPairs: [ [ [-2.1, -2.1, -2.1], - [-1.1, -1.1, -1.1], - ], + [-1.1, -1.1, -1.1] + ] ], color: 'blue', radius: 0.07, // 0.37302772291498865) * 2, headLength: 0.24, // / 0.37302772291498865) * 2, headWidth: 0.14, // / 0.37302772291498865) * 2, type: 'arrows', - clickable: false, + clickable: false }, { positions: [[-2.1, -2.1, -2.1]], color: 'black', radius: 0.0175, type: 'spheres', - clickable: false, - }, + clickable: false + } ], - visible: false, - }, + visible: false + } ], origin: [-2.1, -2.1, -2.1], - visible: true, + visible: true }; export const s3 = { @@ -570,36 +569,36 @@ export const s3 = { positionPairs: [ [ [4.2, 4.2, 0], - [3.1500000000000004, 3.1500000000000004, 1.05], + [3.1500000000000004, 3.1500000000000004, 1.05] ], [ [0, 4.2, 4.2], - [1.05, 3.1500000000000004, 3.1500000000000004], + [1.05, 3.1500000000000004, 3.1500000000000004] ], [ [0, 4.2, 0], - [1.05, 3.1500000000000004, 1.05], + [1.05, 3.1500000000000004, 1.05] ], [ [4.2, 0, 4.2], - [3.1500000000000004, 1.05, 3.1500000000000004], + [3.1500000000000004, 1.05, 3.1500000000000004] ], [ [4.2, 4.2, 4.2], - [3.1500000000000004, 3.1500000000000004, 3.1500000000000004], + [3.1500000000000004, 3.1500000000000004, 3.1500000000000004] ], [ [0, 0, 0], - [1.05, 1.05, 1.05], + [1.05, 1.05, 1.05] ], [ [0, 0, 4.2], - [1.05, 1.05, 3.1500000000000004], + [1.05, 1.05, 3.1500000000000004] ], [ [4.2, 0, 0], - [3.1500000000000004, 1.05, 1.05], - ], + [3.1500000000000004, 1.05, 1.05] + ] ], animate: [ [[4, 4, 1], [1, 1, 1], 0], @@ -609,49 +608,49 @@ export const s3 = { [[4, 4, 4], [1, 1, 1], 4], [[1, 1, 1], [1, 1, 1], 5], [[1, 1, 4], [1, 1, 1], 6], - [[4, 1, 1], [1, 1, 1], 7], + [[4, 1, 1], [1, 1, 1], 7] ], keyframes: [0, 1], color: '#f9dc3c', tooltip: 'label', radius: 0.1, type: 'cylinders', - clickable: true, + clickable: true }, { positionPairs: [ [ [2.1, 2.1, 2.1], // starts from center sphere - [1.05, 1.05, 1.05], // end in yellow + [1.05, 1.05, 1.05] // end in yellow ], [ [2.1, 2.1, 2.1], - [3.1500000000000004, 1.05, 1.05], + [3.1500000000000004, 1.05, 1.05] ], [ [2.1, 2.1, 2.1], - [3.1500000000000004, 3.1500000000000004, 3.1500000000000004], + [3.1500000000000004, 3.1500000000000004, 3.1500000000000004] ], [ [2.1, 2.1, 2.1], - [3.1500000000000004, 1.05, 3.1500000000000004], + [3.1500000000000004, 1.05, 3.1500000000000004] ], [ [2.1, 2.1, 2.1], - [1.05, 3.1500000000000004, 1.05], + [1.05, 3.1500000000000004, 1.05] ], [ [2.1, 2.1, 2.1], - [3.1500000000000004, 3.1500000000000004, 1.05], + [3.1500000000000004, 3.1500000000000004, 1.05] ], [ [2.1, 2.1, 2.1], - [1.05, 1.05, 3.1500000000000004], + [1.05, 1.05, 3.1500000000000004] ], [ [2.1, 2.1, 2.1], - [1.05, 3.1500000000000004, 3.1500000000000004], - ], + [1.05, 3.1500000000000004, 3.1500000000000004] + ] ], animate: [ [[1, 1, 1], [0, 0, 0], 0], @@ -661,18 +660,18 @@ export const s3 = { [[1, 1, 1], [0, 0, 0], 4], [[1, 1, 1], [0, 0, 0], 5], [[1, 1, 1], [0, 0, 0], 6], - [[1, 1, 1], [0, 0, 0], 7], + [[1, 1, 1], [0, 0, 0], 7] ], keyframes: [0, 1], color: '#a121f6', radius: 0.1, type: 'cylinders', tooltip: 'label', - clickable: true, - }, + clickable: true + } ], origin: [-2.1, -2.1, -2.1], - visible: true, + visible: true }, { name: 'cubes', @@ -680,16 +679,16 @@ export const s3 = { { positions: [ [4, 4, 4], - [10, 10, 10], + [10, 10, 10] ], width: 2, color: '#ababaa', type: 'cubes', animate: [10, 10, 10], tooltip: 'label', - keyframes: [0, 1], - }, - ], + keyframes: [0, 1] + } + ] }, { name: 'polyhedra', @@ -704,7 +703,7 @@ export const s3 = { [0, 4.2, 0], [4.2, 4.2, 0], [0, 0, 4.2], - [0, 4.2, 4.2], + [0, 4.2, 4.2] ], animate: [ [[3.1, 3.1, 3.1], 0], @@ -715,16 +714,16 @@ export const s3 = { [[1, 4, 1], 6], [[4, 4, 1], 7], [[1, 1, 4], 8], - [[1, 4, 4], 9], + [[1, 4, 4], 9] ], keyframes: [0, 1], color: '#a121f6', - type: 'convex', - }, + type: 'convex' + } ], origin: [-2.1, -2.1, -2.1], tooltip: 'label', - visible: true, + visible: true }, { name: 'unit_cell', @@ -757,7 +756,7 @@ export const s3 = { [4.2, 0, 4.2], [4.2, 4.2, 4.2], [0, 4.2, 4.2], - [4.2, 4.2, 4.2], + [4.2, 4.2, 4.2] ], animate: [ [0, 0, 0], @@ -783,17 +782,17 @@ export const s3 = { [4.2, 0, 4.2], [4.2, 4.2, 4.2], [0, 4.2, 4.2], - [4.2, 4.2, 4.2], + [4.2, 4.2, 4.2] ], keyframes: [0, 1], - type: 'lines', - }, + type: 'lines' + } ], - visible: false, - }, + visible: false + } ], origin: [-2.1, -2.1, -2.1], - visible: false, + visible: false }, { name: 'axes', @@ -802,57 +801,57 @@ export const s3 = { positionPairs: [ [ [-2.1, -2.1, -2.1], - [-1.4, -1.4, -3.1], - ], + [-1.4, -1.4, -3.1] + ] ], color: 'red', radius: 0.07, // / 0.37302772291498865) * 2, headLength: 0.24, headWidth: 0.14, type: 'arrows', - clickable: false, + clickable: false }, { positionPairs: [ [ [-2.1, -2.1, -2.1], - [-0.1, -2.5, -1.1], - ], + [-0.1, -2.5, -1.1] + ] ], color: 'green', radius: 0.07, // / 0.37302772291498865) * 2, headLength: 0.24, // / 0.37302772291498865, headWidth: 0.14, // 0.37302772291498865, type: 'arrows', - clickable: false, + clickable: false }, { positionPairs: [ [ [-2.1, -2.1, -2.1], - [-1.1, -1.1, -1.1], - ], + [-1.1, -1.1, -1.1] + ] ], color: 'blue', radius: 0.07, // 0.37302772291498865) * 2, headLength: 0.24, // / 0.37302772291498865) * 2, headWidth: 0.14, // / 0.37302772291498865) * 2, type: 'arrows', - clickable: false, + clickable: false }, { positions: [[-2.1, -2.1, -2.1]], color: 'black', radius: 0.0175, type: 'spheres', - clickable: false, - }, + clickable: false + } ], - visible: false, - }, + visible: false + } ], origin: [-2.1, -2.1, -2.1], - visible: true, + visible: true }; export const scene = { @@ -865,56 +864,56 @@ export const scene = { positionPairs: [ [ [-2.13336842, -1.2940969500000001, -7.74158491], - [-1.618063699237322, -1.2962610988334031, -6.884580615250245], - ], + [-1.618063699237322, -1.2962610988334031, -6.884580615250245] + ] ], color: 'red', radius: 0.7, headLength: 2.3, headWidth: 1.4, type: 'arrows', - clickable: true, + clickable: true }, { positionPairs: [ [ [-2.13336842, -1.2940969500000001, -7.74158491], - [-1.8972015468796977, -0.8360916583284603, -6.884580615470827], - ], + [-1.8972015468796977, -0.8360916583284603, -6.884580615470827] + ] ], color: 'green', radius: 0.7, headLength: 2.3, headWidth: 1.4, type: 'arrows', - clickable: true, + clickable: true }, { positionPairs: [ [ [-2.13336842, -1.2940969500000001, -7.74158491], - [-2.1369361013796637, -1.296261098833144, -6.741593615983197], - ], + [-2.1369361013796637, -1.296261098833144, -6.741593615983197] + ] ], color: 'blue', radius: 0.7, headLength: 2.3, headWidth: 1.4, type: 'arrows', - clickable: true, + clickable: true }, { positions: [[-2.13336842, -1.2940969500000001, -7.74158491]], color: 'white', radius: 0.175, type: 'spheres', - clickable: true, - }, + clickable: true + } ], - origin: [0, 0, 0], - }, + origin: [0, 0, 0] + } ], - origin: [2.13336842, 1.2940969500000001, 7.74158491], + origin: [2.13336842, 1.2940969500000001, 7.74158491] }; export const shperes = { @@ -930,53 +929,53 @@ export const shperes = { positionPairs: [ [ [-2.1, -2.1, -2.1], - [-1.4, -1.4, -3.1], - ], + [-1.4, -1.4, -3.1] + ] ], color: 'red', radius: 0.07, // / 0.37302772291498865) * 2, headLength: 0.24, headWidth: 0.14, type: 'arrows', - clickable: false, + clickable: false }, { positionPairs: [ [ [-2.1, -2.1, -2.1], - [-0.1, -2.5, -1.1], - ], + [-0.1, -2.5, -1.1] + ] ], color: 'green', radius: 0.07, // / 0.37302772291498865) * 2, headLength: 0.24, // / 0.37302772291498865, headWidth: 0.14, // 0.37302772291498865, type: 'arrows', - clickable: false, + clickable: false }, { positionPairs: [ [ [-2.1, -2.1, -2.1], - [-1.1, -1.1, -1.1], - ], + [-1.1, -1.1, -1.1] + ] ], color: 'blue', radius: 0.07, // 0.37302772291498865) * 2, headLength: 0.24, // / 0.37302772291498865) * 2, headWidth: 0.14, // / 0.37302772291498865) * 2, type: 'arrows', - clickable: false, + clickable: false }, { positions: [[-2.1, -2.1, -2.1]], color: 'black', radius: 0.0175, type: 'spheres', - clickable: false, - }, + clickable: false + } ], - visible: false, + visible: false }, { positions: [ @@ -987,33 +986,39 @@ export const shperes = { [2.13336842, 1.2940969500000001, 7.74158491], [-2.15372178, -1.3064432600000002, -2.0367080900000003], [0.7860537699999997, -1.31878957, 2.8524384099999995], - [-0.7860537700000001, 1.3187895699999999, -2.8524384100000004], + [-0.7860537700000001, 1.3187895699999999, -2.8524384100000004] ], clickable: true, color: '#ffaaaa', radius: [0.5], - type: 'spheres', + type: 'spheres' }, { positions: [ [1.1352943356867837, 0.688667561081374, 4.1197692008924705], - [-1.1352941382531998, -0.6886632575514795, -4.119769120104752], + [-1.1352941382531998, -0.6886632575514795, -4.119769120104752] ], color: '#111111', radius: [0.5], - type: 'spheres', + type: 'spheres' }, { positions: [[1.3132662690651387e-7, 0.000002162567968477802, -0.000004955452009625105]], color: '#00ffdd', radius: [0.65], - type: 'spheres', - }, + type: 'spheres' + } ], - origin: [0, 0, 0], - }, + origin: [0, 0, 0] + } ], origin: [-2.1, -2.1, -2.1], + latticeVectors: [ + [1, 0, 0], + [0, 1, 0], + [0, 0, 1] + ], + tiling: [1, 0, 0] }; export const buggyScene = { @@ -1027,17 +1032,17 @@ export const buggyScene = { [-0.7860537700000001, 1.3187895699999999, -2.8524384100000004], [-1.7860537700000001, 1.3187895699999999, -2.8524384100000004], [-2.7860537700000001, 1.3187895699999999, -2.8524384100000004], - [-3.7860537700000001, 1.3187895699999999, -2.8524384100000004], + [-3.7860537700000001, 1.3187895699999999, -2.8524384100000004] ], color: '#ffaaaa', radius: [0.5], - type: 'spheres', - }, + type: 'spheres' + } ], - origin: [0, 0, 0], - }, + origin: [0, 0, 0] + } ], - origin: [2.13336842, 1.2940969500000001, 7.74158491], + origin: [2.13336842, 1.2940969500000001, 7.74158491] }; export const s5 = { @@ -1050,28 +1055,28 @@ export const s5 = { positions: [ [1.6081450794147842, 0.9284629773820368, 2.6153700106355755], [-1.9414784057759444e-8, 1.8569259826179634, 5.235351240635575], - [-1.9414784057759444e-8, 1.8569259826179634, -0.004611219364424821], + [-1.9414784057759444e-8, 1.8569259826179634, -0.004611219364424821] ], color: '#9ee373', radius: 0.5, type: 'spheres', tooltip: 'heell', - clickable: true, + clickable: true }, { positions: [ [1.6081450794147842, 0.9284629773820368, 4.589578371864425], - [-1.9414784057759444e-8, 1.8569259826179634, 1.9695971418644245], + [-1.9414784057759444e-8, 1.8569259826179634, 1.9695971418644245] ], color: '#b0b9e6', radius: 0.5, type: 'spheres', tooltip: 'heell2', - clickable: true, - }, + clickable: true + } ], origin: [-0.80407253, -1.39269448, -2.61998123], - visible: true, + visible: true }, { name: 'bonds', @@ -1080,20 +1085,20 @@ export const s5 = { positionPairs: [ [ [1.6081450794147842, 0.9284629773820368, 2.6153700106355755], - [0.8040725300000001, 1.39269448, 2.29248357625], + [0.8040725300000001, 1.39269448, 2.29248357625] ], [ [1.6081450794147842, 0.9284629773820368, 2.6153700106355755], - [1.6081450794147842, 0.9284629773820368, 3.6024741912500002], + [1.6081450794147842, 0.9284629773820368, 3.6024741912500002] ], [ [-1.9414784057759444e-8, 1.8569259826179634, 5.235351240635575], - [0.8040725300000001, 1.39269448, 4.91246480625], + [0.8040725300000001, 1.39269448, 4.91246480625] ], [ [-1.9414784057759444e-8, 1.8569259826179634, -0.004611219364424821], - [-1.9414784057759444e-8, 1.8569259826179634, 0.9824929612499999], - ], + [-1.9414784057759444e-8, 1.8569259826179634, 0.9824929612499999] + ] ], color: '#9ee373', radius: 0.1, @@ -1101,50 +1106,49 @@ export const s5 = { radiusBottom: 0.4, type: 'cylinders', tooltip: 'heell4', - clickable: false, + clickable: false }, { positionPairs: [ [ [1.6081450794147842, 0.9284629773820368, 4.589578371864425], - [0.8040725300000001, 1.39269448, 4.91246480625], + [0.8040725300000001, 1.39269448, 4.91246480625] ], [ [1.6081450794147842, 0.9284629773820368, 4.589578371864425], - [1.6081450794147842, 0.9284629773820368, 3.6024741912500002], + [1.6081450794147842, 0.9284629773820368, 3.6024741912500002] ], [ [-1.9414784057759444e-8, 1.8569259826179634, 1.9695971418644245], - [0.8040725300000001, 1.39269448, 2.29248357625], + [0.8040725300000001, 1.39269448, 2.29248357625] ], [ [-1.9414784057759444e-8, 1.8569259826179634, 1.9695971418644245], - [-1.9414784057759444e-8, 1.8569259826179634, 0.9824929612499999], - ], + [-1.9414784057759444e-8, 1.8569259826179634, 0.9824929612499999] + ] ], color: '#b0b9e6', radius: 0.1, radiusTop: [0.13, 0.01, 0.05, 0.1, 0.25], radiusBottom: [0.4, 0.3, 0.25, 0.5, 0.01], type: 'cylinders', - clickable: false, - }, + clickable: false + } ], origin: [-0.80407253, -1.39269448, -2.61998123], - visible: true, + visible: true }, { name: 'polyhedra', contents: [], origin: [-0.80407253, -1.39269448, -2.61998123], - visible: true, + visible: true }, { name: 'unit_cell', contents: [ { - name: - 'a=3.21629013, b=3.2162901337807175, c=5.23996246, alpha=90.0, beta=90.0, gamma=120.00000006396569', + name: 'a=3.21629013, b=3.2162901337807175, c=5.23996246, alpha=90.0, beta=90.0, gamma=120.00000006396569', contents: [ { positions: [ @@ -1171,17 +1175,17 @@ export const s5 = { [3.21629013, 0, 5.23996246], [1.60814506, 2.78538896, 5.23996246], [-1.60814507, 2.78538896, 5.23996246], - [1.60814506, 2.78538896, 5.23996246], + [1.60814506, 2.78538896, 5.23996246] ], type: 'lines', - clickable: false, - }, + clickable: false + } ], - visible: true, - }, + visible: true + } ], origin: [-0.80407253, -1.39269448, -2.61998123], - visible: true, + visible: true }, { name: 'axes', @@ -1190,55 +1194,59 @@ export const s5 = { positionPairs: [ [ [-0.80407253, -1.39269448, -2.61998123], - [0.19592747, -1.39269448, -2.61998123], - ], + [0.19592747, -1.39269448, -2.61998123] + ] ], color: 'red', radius: 0.07, headLength: 0.24, headWidth: 0.14, type: 'arrows', - clickable: false, + clickable: false }, { positionPairs: [ [ [-0.80407253, -1.39269448, -2.61998123], - [-1.304072530966841, -0.5266690767737673, -2.61998123], - ], + [-1.304072530966841, -0.5266690767737673, -2.61998123] + ] ], color: 'green', radius: 0.07, headLength: 0.24, headWidth: 0.14, type: 'arrows', - clickable: false, + clickable: false }, { positionPairs: [ [ [-0.80407253, -1.39269448, -2.61998123], - [-0.80407253, -1.39269448, -1.61998123], - ], + [-0.80407253, -1.39269448, -1.61998123] + ] ], color: 'blue', radius: 0.07, headLength: 0.24, headWidth: 0.14, type: 'arrows', - clickable: false, + clickable: false }, { positions: [[-0.80407253, -1.39269448, -2.61998123]], color: 'white', radius: 0.0175, type: 'spheres', - clickable: false, - }, + clickable: false + } ], - visible: false, - }, + visible: false + } ], origin: [-0.80407253, -1.39269448, -2.61998123], - visible: true, + visible: true }; + +// a test structure +import crystal from './crystal-scene.json'; +export const crystalScene = crystal; diff --git a/src/pages/PhononVisualization/PhononVisualization.tsx b/src/pages/PhononVisualization/PhononVisualization.tsx index 28d39a75..2bc71df7 100644 --- a/src/pages/PhononVisualization/PhononVisualization.tsx +++ b/src/pages/PhononVisualization/PhononVisualization.tsx @@ -1,6 +1,13 @@ import React, { useEffect, useState } from 'react'; import { scene, scene2 } from '../../components/crystal-toolkit/scene/mike'; -import { s2, s3, s4, s5, shperes } from '../../components/crystal-toolkit/scene/simple-scene'; +import { + s2, + s3, + s4, + s5, + shperes, + crystalScene +} from '../../components/crystal-toolkit/scene/simple-scene'; import { CameraContextProvider } from '../../components/crystal-toolkit/CameraContextProvider'; import { AnimationStyle, Renderer } from '../../components/crystal-toolkit/scene/constants'; import { CrystalToolkitScene } from '../../components/crystal-toolkit/CrystalToolkitScene/CrystalToolkitScene'; @@ -27,7 +34,7 @@ export const PhononVisualization: React.FC = () => { extractAxis: false, zoomToFit2D: true }} - data={s3} + data={crystalScene} sceneSize="100%" debug={false} toggleVisibility={{}} From e556147739427314ac059537e7dde620fa3afbed Mon Sep 17 00:00:00 2001 From: orioncohen Date: Mon, 6 Dec 2021 09:28:14 -0800 Subject: [PATCH 03/21] adwrite new inner loop in Scene.ts to include tiling --- src/components/crystal-toolkit/scene/Scene.ts | 66 ++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/src/components/crystal-toolkit/scene/Scene.ts b/src/components/crystal-toolkit/scene/Scene.ts index 20e5eab4..b1e2b21c 100644 --- a/src/components/crystal-toolkit/scene/Scene.ts +++ b/src/components/crystal-toolkit/scene/Scene.ts @@ -486,7 +486,71 @@ export default class Scene { }); }; - traverse_scene(sceneJson, rootObject, ''); + const _get_tiles = (tiling: number[]) => { + // enumerate all tiles needed for a given tiling size + let tiles: number[][] = []; + for (let x: number = 0; x <= tiling[0]; x++) { + for (let y: number = 0; y <= tiling[1]; y++) { + for (let z: number = 0; z <= tiling[2]; z++) { + tiles.push([x, y, z]); + } + } + } + return tiles; + }; + + // a alternative inner loop that includes tiling + const traverse_scene_w_tiling = ( + o: SceneJsonObject, + parent: THREE.Object3D, + currentId: string + ) => { + o.contents!.forEach((childObject, idx) => { + // determine proper tiling if it exists + let tiling = childObject.tiling ? childObject.tiling : [0, 0, 0]; + let tiles = _get_tiles(tiling); + let lattice = childObject.lattice + ? childObject.lattice + : [ + [0, 0, 0], + [0, 0, 0], + [0, 0, 0] + ]; + // loop over all tiles and render each tile + for (const tile of tiles) { + const threeObject = new THREE.Object3D(); + threeObject.name = childObject.name!; + this.computeIdToThree[`${currentId}--${threeObject.name}`] = threeObject; + childObject.id = `${currentId}--${threeObject.name}`; + threeObject.visible = childObject.visible === undefined ? true : !!childObject.visible; + let scaled_lattice = lattice.map((vector: number[], index: number) => { + return vector.map((x: number) => x * tile[index]); + }); + // transform tile according to lattice vectors + for (const vec of scaled_lattice) { + const tiling_translation = new THREE.Matrix4(); + tiling_translation.makeTranslation(...(vec as ThreePosition)); + threeObject.applyMatrix4(tiling_translation); + } + if (childObject.origin) { + const origin_translation = new THREE.Matrix4(); + // note(chab) have a typedefinition for the JSON + origin_translation.makeTranslation(...(childObject.origin as ThreePosition)); + threeObject.applyMatrix4(origin_translation); + } + if (!this.settings.extractAxis || threeObject.name !== 'axes') { + parent.add(threeObject); + } + traverse_scene(childObject, threeObject, `${currentId}--${threeObject.name}`); + if (threeObject.name === 'axes') { + this.axis = threeObject.clone(); + this.axisJson = { ...childObject }; + } + } + }); + }; + + traverse_scene_w_tiling(sceneJson, rootObject, ''); // can cause memory leak //console.log('rootObject', rootObject, rootObject); this.scene.add(rootObject); From a93b5d214d36cb24e81bda40859ab44c6421edc3 Mon Sep 17 00:00:00 2001 From: orioncohen Date: Mon, 6 Dec 2021 09:34:35 -0800 Subject: [PATCH 04/21] restore original commas in simple-scene.ts --- src/components/crystal-toolkit/scene/simple-scene.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/components/crystal-toolkit/scene/simple-scene.ts b/src/components/crystal-toolkit/scene/simple-scene.ts index 8316581a..d4e0496f 100644 --- a/src/components/crystal-toolkit/scene/simple-scene.ts +++ b/src/components/crystal-toolkit/scene/simple-scene.ts @@ -1012,13 +1012,7 @@ export const shperes = { origin: [0, 0, 0] } ], - origin: [-2.1, -2.1, -2.1], - latticeVectors: [ - [1, 0, 0], - [0, 1, 0], - [0, 0, 1] - ], - tiling: [1, 0, 0] + origin: [-2.1, -2.1, -2.1] }; export const buggyScene = { From 178b602a8dc0cc01e81521c99e8f7bec7927e957 Mon Sep 17 00:00:00 2001 From: orioncohen Date: Mon, 6 Dec 2021 09:36:59 -0800 Subject: [PATCH 05/21] add commas fix From a15d1c3345235f3a06b317027a73082cb890b38f Mon Sep 17 00:00:00 2001 From: orioncohen Date: Mon, 23 May 2022 15:28:30 -0700 Subject: [PATCH 06/21] previously the defaults in SimpleSlider were hardcoded, I fixed SimpleSlider to optionally use the props. --- .../scene/animation-slider.tsx | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/components/crystal-toolkit/scene/animation-slider.tsx b/src/components/crystal-toolkit/scene/animation-slider.tsx index de97d984..4c8b7e31 100644 --- a/src/components/crystal-toolkit/scene/animation-slider.tsx +++ b/src/components/crystal-toolkit/scene/animation-slider.tsx @@ -6,10 +6,10 @@ const sliderStyle: any = { position: 'relative', margin: 'auto', width: '80%', - touchAction: 'none', + touchAction: 'none' }; -const domain: any = [0, 100]; +const defaultDomain: any = [0, 100]; const defaultValues: any = [0]; class SimpleSlider extends Component { @@ -19,7 +19,7 @@ class SimpleSlider extends Component { state = { values: defaultValues.slice(), - update: defaultValues.slice(), + update: defaultValues.slice() }; onUpdate = (update) => { @@ -28,12 +28,13 @@ class SimpleSlider extends Component { }; onChange = (values) => { + this.props.onChange(values[0]); this.setState({ values }); }; render() { const { - state: { values, update }, + state: { values, update } } = this; return ( @@ -41,11 +42,11 @@ class SimpleSlider extends Component { {({ getRailProps }) => } @@ -55,7 +56,7 @@ class SimpleSlider extends Component { ))} @@ -95,7 +96,7 @@ const railOuterStyle = { height: 42, transform: 'translate(0%, -50%)', borderRadius: 7, - cursor: 'pointer', + cursor: 'pointer' // border: '1px solid white', }; @@ -106,7 +107,7 @@ const railInnerStyle: any = { transform: 'translate(0%, -50%)', borderRadius: 7, pointerEvents: 'none', - backgroundColor: 'rgb(155,155,155)', + backgroundColor: 'rgb(155,155,155)' }; export function SliderRail({ getRailProps }) { @@ -119,7 +120,7 @@ export function SliderRail({ getRailProps }) { } SliderRail.propTypes = { - getRailProps: PropTypes.func.isRequired, + getRailProps: PropTypes.func.isRequired }; // ******************************************************* @@ -129,7 +130,7 @@ export function Handle({ domain: [min, max], handle: { id, value, percent }, disabled, - getHandleProps, + getHandleProps }) { return ( @@ -144,7 +145,7 @@ export function Handle({ height: 42, cursor: 'pointer', // border: '1px solid white', - backgroundColor: 'none', + backgroundColor: 'none' }} {...getHandleProps(id)} /> @@ -162,7 +163,7 @@ export function Handle({ height: 24, borderRadius: '50%', boxShadow: '1px 1px 1px 1px rgba(0, 0, 0, 0.3)', - backgroundColor: disabled ? '#666' : '#ffc400', + backgroundColor: disabled ? '#666' : '#ffc400' }} /> @@ -174,14 +175,14 @@ Handle.propTypes = { handle: PropTypes.shape({ id: PropTypes.string.isRequired, value: PropTypes.number.isRequired, - percent: PropTypes.number.isRequired, + percent: PropTypes.number.isRequired }).isRequired, getHandleProps: PropTypes.func.isRequired, - disabled: PropTypes.bool, + disabled: PropTypes.bool }; Handle.defaultProps = { - disabled: false, + disabled: false }; // ******************************************************* @@ -192,7 +193,7 @@ export function KeyboardHandle({ domain: [min, max], handle: { id, value, percent }, disabled, - getHandleProps, + getHandleProps }) { return (