diff --git a/app/src/modules/gql/metamaterial-gql.js b/app/src/modules/gql/metamaterial-gql.js new file mode 100644 index 00000000..ecd196c4 --- /dev/null +++ b/app/src/modules/gql/metamaterial-gql.js @@ -0,0 +1,33 @@ +import gql from 'graphql-tag' + +export const METAMATERIAL_QUERY = gql` + query PixelData($input: pixelDataQueryInput!) { + pixelData(input: $input) { + totalItems + data { + symmetry + unit_cell_x_pixels + C11 + C12 + C22 + C16 + C26 + C66 + CM0 + CM0_C11 + CM0_C12 + CM0_C22 + CM0_C16 + CM0_C26 + CM0_C66 + CM1 + CM1_C11 + CM1_C12 + CM1_C22 + CM1_C16 + CM1_C26 + CM1_C66 + geometry_full + } + } +}` diff --git a/app/src/modules/metamine/metamaterial-vega-spec.js b/app/src/modules/metamine/metamaterial-vega-spec.js index 4c795d08..61c4de26 100644 --- a/app/src/modules/metamine/metamaterial-vega-spec.js +++ b/app/src/modules/metamine/metamaterial-vega-spec.js @@ -42,14 +42,14 @@ const baseSpec = { padding: 10 } }, - color: { - field: 'symmetry', - type: 'nominal', - title: 'Symmetry', - legend: { - orient: 'top' - } - }, + // color: { + // field: 'symmetry', + // type: 'nominal', + // title: 'Symmetry', + // legend: { + // orient: 'top' + // } + // }, tooltip: [ { field: 'symmetry', @@ -158,11 +158,11 @@ const baseSpec = { }, title: 'C11' }, - color: { - field: 'symmetry', - type: 'nominal', - title: 'Symmetry' - }, + // color: { + // field: 'symmetry', + // type: 'nominal', + // title: 'Symmetry' + // }, opacity: { condition: { test: { @@ -213,11 +213,11 @@ const baseSpec = { }, title: 'C12' }, - color: { - field: 'symmetry', - type: 'nominal', - title: 'Symmetry' - }, + // color: { + // field: 'symmetry', + // type: 'nominal', + // title: 'Symmetry' + // }, opacity: { condition: { test: { @@ -268,11 +268,11 @@ const baseSpec = { }, title: 'C22' }, - color: { - field: 'symmetry', - type: 'nominal', - title: 'Symmetry' - }, + // color: { + // field: 'symmetry', + // type: 'nominal', + // title: 'Symmetry' + // }, opacity: { condition: { test: { @@ -323,11 +323,11 @@ const baseSpec = { }, title: 'C16' }, - color: { - field: 'symmetry', - type: 'nominal', - title: 'Symmetry' - }, + // color: { + // field: 'symmetry', + // type: 'nominal', + // title: 'Symmetry' + // }, opacity: { condition: { test: { @@ -378,11 +378,11 @@ const baseSpec = { }, title: 'C26' }, - color: { - field: 'symmetry', - type: 'nominal', - title: 'Symmetry' - }, + // color: { + // field: 'symmetry', + // type: 'nominal', + // title: 'Symmetry' + // }, opacity: { condition: { test: { @@ -433,13 +433,13 @@ const baseSpec = { }, title: 'C66' }, - color: { - field: 'symmetry', - type: 'nominal', - title: 'Symmetry', - scale: { scheme: 'category10' } + // color: { + // field: 'symmetry', + // type: 'nominal', + // title: 'Symmetry', + // scale: { scheme: 'category10' } - }, + // }, opacity: { condition: { test: { @@ -600,7 +600,7 @@ function createPatch (xAxis, yAxis) { } }, { - path: '/scales/1', + path: '/scales/0', op: 'replace', value: { domain: { @@ -623,7 +623,7 @@ function createPatch (xAxis, yAxis) { } }, { - path: '/scales/2', + path: '/scales/1', op: 'replace', value: { domain: { diff --git a/app/src/pages/metamine/visualization/metamaterial-plot.html b/app/src/pages/metamine/visualization/metamaterial-plot.html index e79bf035..573ce816 100644 --- a/app/src/pages/metamine/visualization/metamaterial-plot.html +++ b/app/src/pages/metamine/visualization/metamaterial-plot.html @@ -1,7 +1,7 @@
-

Metamaterial Properties: Interactive Plot

+

2D Pixelated Static Metamaterial Properties: Interactive Plot

Select properties from the dropdown menus below to graph on the x and y axes.

@@ -10,16 +10,16 @@

Metamaterial Properties: Interactive Plot

Scroll to zoom, click and drag to pan, and double-click to reset.

-
+
Error while rendering Vega-Lite specification: {{error.message}}.
-
+
@@ -51,7 +51,27 @@

Metamaterial Properties: Interactive Plot

+
+ + +
+
+ +
diff --git a/app/src/pages/metamine/visualization/metamaterial-plot.js b/app/src/pages/metamine/visualization/metamaterial-plot.js index b0817d08..117b2ab4 100644 --- a/app/src/pages/metamine/visualization/metamaterial-plot.js +++ b/app/src/pages/metamine/visualization/metamaterial-plot.js @@ -1,9 +1,9 @@ import VegaLite from '@/components/explorer/VegaLiteWrapper.vue' import spinner from '@/components/Spinner' import { buildCsvSpec } from '@/modules/vega-chart' -import Papa from '@/modules/papaparse.min.js' import embed from 'vega-embed' import { baseSpec, createPatch } from '@/modules/metamine/metamaterial-vega-spec' +import { METAMATERIAL_QUERY } from '@/modules/gql/metamaterial-gql' export default { name: 'Mockup', @@ -12,14 +12,14 @@ export default { spinner }, data: () => ({ + loading: false, spec: null, baseSpec: baseSpec, - loading: false, error: { status: false, message: null }, - results: null, + pixelDim: 'TEN', xAxis: 'C11', yAxis: 'C12', - patchSpec: {}, + pixelData: {}, // Dictionary so we can add more attributes in the future // that might have different attr names than labels attributes: [ @@ -29,6 +29,10 @@ export default { { attr: 'C16', label: 'C16' }, { attr: 'C26', label: 'C26' }, { attr: 'C66', label: 'C66' } + ], + pixelDimOpts: [ + { attr: 'TEN', label: '10 by 10' }, + { attr: 'FIFTY', label: '50 by 50' } ] }), computed: { @@ -41,34 +45,8 @@ export default { } }, methods: { - async loadVisualization () { - try { - this.spec = buildCsvSpec(this.baseSpec, this.results) - } catch (e) { - this.error = { status: true, message: e.message } - } finally { - this.loading = false - } - }, - // TODO: remove this method. Should happen server side! - async CSVToJSON (delimiter = ',') { - const thisVue = this - const requestOptions = { - headers: { - accept: 'application/sparql-results+json' - } - } - // TODO: Change to Apollo GraphQL - return await fetch('../metamaterials_combined_1000.csv', requestOptions) - .then(response => response.text()) - .then(data => { - Papa.parse(data, { - header: true, - complete: function (result) { - thisVue.results = result.data - } - }) - }) + buildSpec () { + this.spec = buildCsvSpec(this.baseSpec, this.pixelData.data) }, // Handle screen resizing alignVegaTooltips () { @@ -83,22 +61,39 @@ export default { .then(() => this.alignVegaTooltips()) } catch (e) { this.error = { status: true, message: e.message } + } finally { + this.loading = false } } }, - created () { - this.loading = true - this.CSVToJSON() - .then(() => this.loadVisualization()) - .then(async () => await this.patchVegaSpec()) - }, - watch: { - async xAxis () { - await this.patchVegaSpec() + watch: + { + async xAxis () { + this.loading = true + // Pause to allow event to register + setTimeout(async () => await this.patchVegaSpec(), 100) + }, + async yAxis () { + this.loading = true + // Pause to allow event to register + setTimeout(async () => await this.patchVegaSpec(), 100) + } }, - async yAxis () { - await this.patchVegaSpec() + apollo: { + pixelData: { + query: METAMATERIAL_QUERY, + variables () { + return { + input: { unitCell: this.pixelDim } + } + }, + fetchPolicy: 'cache-and-network', + result () { + if (this.pixelData) { + this.buildSpec() + this.patchVegaSpec() + } + } } - } }