From 3a7b9059eb40f90e47b05eaf39027f72fa864c94 Mon Sep 17 00:00:00 2001 From: eireland Date: Thu, 26 Oct 2023 13:26:10 -0700 Subject: [PATCH 1/9] Adds default height and width on open in CODAP --- src/scripts/connect.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/scripts/connect.js b/src/scripts/connect.js index 8f1613e..21b58b1 100644 --- a/src/scripts/connect.js +++ b/src/scripts/connect.js @@ -2,6 +2,8 @@ import { codapInterface } from "./codapInterface"; const dataSetName = "NASS Quickstats Data"; const dataSetTitle = "NASS Quickstats Data"; +const appDefaultWidth = 380; +const appDefaultHeight = 520; export const connect = { initialize: async function () { @@ -143,6 +145,10 @@ export const connect = { iFrameDescriptor: { version: '0.0.1', name: 'nass-plugin', - title: 'NASS Quickstats Data' + title: 'NASS Quickstats Data', + dimensions: { + width: appDefaultWidth, + height: appDefaultHeight + }, }, } From 197674702527b0fc4593db73045dd04cb2423695 Mon Sep 17 00:00:00 2001 From: eireland Date: Thu, 26 Oct 2023 13:30:28 -0700 Subject: [PATCH 2/9] Changes max-height to fit-content to see all the options in the dropdown --- src/components/dropdown.scss | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/dropdown.scss b/src/components/dropdown.scss index f045ff7..9a87999 100644 --- a/src/components/dropdown.scss +++ b/src/components/dropdown.scss @@ -7,7 +7,7 @@ .dropdownBody { padding-left: 0; padding-right: 0; - max-height: 1000px; + max-height: fit-content; transition: max-height; transition-duration: .5s; transition-timing-function: ease-in; @@ -56,8 +56,6 @@ } } - - .userSelection { font-family: 'Montserrat', sans-serif; font-size: 12px; @@ -81,4 +79,4 @@ display: flex; flex-direction: column; padding: 12px 0px; -} \ No newline at end of file +} From c1bb3aaef285ed43d0253b84c5905e8ff70de7fc Mon Sep 17 00:00:00 2001 From: eireland Date: Thu, 30 Nov 2023 13:42:50 -0800 Subject: [PATCH 3/9] Adds state to queryHeaders for Organization Type queries --- src/constants/queryHeaders.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/constants/queryHeaders.ts b/src/constants/queryHeaders.ts index 6c5f3d7..a0f1b2b 100644 --- a/src/constants/queryHeaders.ts +++ b/src/constants/queryHeaders.ts @@ -119,10 +119,10 @@ export const queryData: Array = [ "FARM OPERATIONS, ORGANIZATION, TAX PURPOSES, PARTNERSHIP - NUMBER OF OPERATIONS" ], domain_desc: "Total", - geographicAreas: ["County"], + geographicAreas: ["State", "County"], years: { "County": ["1997", "2002", "2007", "2012", "2017"], - "State": [] + "State": ["1997", "2002", "2007", "2012", "2017"] } }, { From 34902291d73c0c903a3bde31cbd406975851137e Mon Sep 17 00:00:00 2001 From: eireland Date: Fri, 1 Dec 2023 07:49:25 -0800 Subject: [PATCH 4/9] Adds unit to the attribute headers passed to CODAP --- src/scripts/api.ts | 32 ++++++++++++++++++++++++++------ src/scripts/connect.js | 3 ++- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/scripts/api.ts b/src/scripts/api.ts index 077aea6..48cb644 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -98,7 +98,7 @@ export const createRequest = ({attribute, geographicLevel, years, states, cropUn export const getAllAttrs = (selectedOptions: IStateOptions) => { const {geographicLevel, states, cropUnits, years, ...subOptions} = selectedOptions; - const allAttrs: Array = ["Year"]; + const allAttrs: Array> = [{"name": "Year"}]; for (const key in subOptions) { const selections = subOptions[key as keyof typeof subOptions]; @@ -111,21 +111,27 @@ export const getAllAttrs = (selectedOptions: IStateOptions) => { if (attribute === "Economic Class") { for (const econAttr of economicClassAttirbutes) { const codapColumnName = attrToCODAPColumnName[econAttr].attributeNameInCodapTable; - allAttrs.push(codapColumnName); + const codapColumnUnit = attrToCODAPColumnName[econAttr].unitInCodapTable; + allAttrs.push({"name": codapColumnName, "unit": codapColumnUnit}); } } else if (attribute === "Acres Operated") { for (const acresAttr of acresOperatedAttributes) { const codapColumnName = attrToCODAPColumnName[acresAttr].attributeNameInCodapTable; - allAttrs.push(codapColumnName); + const codapColumnUnit = attrToCODAPColumnName[acresAttr].unitInCodapTable; + allAttrs.push({"name": codapColumnName, "unit": codapColumnUnit}); } } else if (Array.isArray(short_desc)) { for (const desc of short_desc) { const codapColumnName = attrToCODAPColumnName[desc].attributeNameInCodapTable; - allAttrs.push(codapColumnName); + const codapColumnUnit = attrToCODAPColumnName[desc].unitInCodapTable; + allAttrs.push({"name": codapColumnName, "unit": codapColumnUnit}); } } else if (typeof short_desc === "object" && cropUnits) { const attr = short_desc[cropUnits as keyof ICropDataItem][0]; - allAttrs.push(attrToCODAPColumnName[attr].attributeNameInCodapTable); + allAttrs.push({"name": attrToCODAPColumnName[attr].attributeNameInCodapTable}); + const codapColumnName = attrToCODAPColumnName[attr].attributeNameInCodapTable; + const codapColumnUnit = attrToCODAPColumnName[attr].unitInCodapTable; + allAttrs.push({"name": codapColumnName, "unit": codapColumnUnit}); } } } @@ -134,17 +140,29 @@ export const getAllAttrs = (selectedOptions: IStateOptions) => { export const createTableFromSelections = async (selectedOptions: IStateOptions, setReqCount: ISetReqCount) => { const {geographicLevel} = selectedOptions; + console.log("UNIT selectedOptions", selectedOptions); try { const allAttrs = getAllAttrs(selectedOptions); + console.log("UNIT allAttrs", allAttrs); const items = await getItems(selectedOptions, setReqCount); + console.log("UNIT items", items); await connect.getNewDataContext(); + console.log("UNIT in getNewDataContext"); + await connect.createStateCollection(geographicLevel === "State"); + console.log("UNIT in createStateCollection"); + if (geographicLevel === "County") { await connect.createCountyCollection(); } await connect.createSubCollection(geographicLevel, allAttrs); + console.log("UNIT in createSubCollection"); + await connect.createItems(items); + console.log("UNIT in createItems"); + await connect.makeCaseTableAppear(); + console.log("UNIT in success"); return "success"; } catch (error) { // eslint-disable-next-line no-console @@ -193,6 +211,7 @@ const getItems = async (selectedOptions: IStateOptions, setReqCount: ISetReqCoun items.forEach((item: any) => { // find all the data items that match this item's location and year const matchingData = data.filter((dataObj: any) => { + console.log("UNIT dataObj in getItems", dataObj); if (isMultiStateRegion) { const {region_desc, year} = dataObj; const regionThatIncludesState = multiRegions.find((r) => r.States.includes(item.State)); @@ -212,10 +231,11 @@ const getItems = async (selectedOptions: IStateOptions, setReqCount: ISetReqCoun return isSameGeoLevel && Number(item.Year) === year; } }); + console.log("UNIT matchingData in getItems", matchingData); if (isMultiStateRegion) { if (item.State !== "Alaska") { - const { Value } = matchingData[0]; + const { Value } = matchingData.length > 0 && matchingData[0]; const codapColumnName = attrToCODAPColumnName[matchingData[0].short_desc].attributeNameInCodapTable; item[codapColumnName] = Value; } diff --git a/src/scripts/connect.js b/src/scripts/connect.js index 21b58b1..6194fa2 100644 --- a/src/scripts/connect.js +++ b/src/scripts/connect.js @@ -12,7 +12,8 @@ export const connect = { makeCODAPAttributeDef: function (attr) { return { - name: attr, + name: attr.name, + unit: attr.unit, type: "numeric" } }, From 20f9e144ed87ac11ea2f24cc88db8b29bd2ac015 Mon Sep 17 00:00:00 2001 From: eireland Date: Fri, 1 Dec 2023 12:37:51 -0800 Subject: [PATCH 5/9] WIP getting state boundaries to show --- src/scripts/api.ts | 22 ++++++++++++++++------ src/scripts/connect.js | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/scripts/api.ts b/src/scripts/api.ts index 077aea6..b0e968e 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -98,7 +98,8 @@ export const createRequest = ({attribute, geographicLevel, years, states, cropUn export const getAllAttrs = (selectedOptions: IStateOptions) => { const {geographicLevel, states, cropUnits, years, ...subOptions} = selectedOptions; - const allAttrs: Array = ["Year"]; + const allAttrs: Array = ["Year", geographicLevel, "Boundary"]; + console.log("UNIT geographicLevel", geographicLevel); for (const key in subOptions) { const selections = subOptions[key as keyof typeof subOptions]; @@ -134,18 +135,27 @@ export const getAllAttrs = (selectedOptions: IStateOptions) => { export const createTableFromSelections = async (selectedOptions: IStateOptions, setReqCount: ISetReqCount) => { const {geographicLevel} = selectedOptions; + console.log("UNIT createTableFromSelections geographicLevel", geographicLevel); + try { const allAttrs = getAllAttrs(selectedOptions); const items = await getItems(selectedOptions, setReqCount); await connect.getNewDataContext(); await connect.createStateCollection(geographicLevel === "State"); if (geographicLevel === "County") { - await connect.createCountyCollection(); + // await connect.createStateCollection(true); + // await connect.createCountyCollection(); + await connect.createSubCollection(geographicLevel, allAttrs); + await connect.createItems(items); + await connect.makeCaseTableAppear(); + return "success"; + } else { + // await connect.createSubCollection(geographicLevel, allAttrs); + await connect.createCollection(allAttrs); + await connect.createItems(items); + await connect.makeCaseTableAppear(); + return "success"; } - await connect.createSubCollection(geographicLevel, allAttrs); - await connect.createItems(items); - await connect.makeCaseTableAppear(); - return "success"; } catch (error) { // eslint-disable-next-line no-console console.log("Error creating CODAP Table from API data:", error); diff --git a/src/scripts/connect.js b/src/scripts/connect.js index 21b58b1..99bcedb 100644 --- a/src/scripts/connect.js +++ b/src/scripts/connect.js @@ -10,7 +10,28 @@ export const connect = { return await codapInterface.init(this.iFrameDescriptor, null); }, - makeCODAPAttributeDef: function (attr) { + makeCODAPAttributeDef: function (attr, geoLevel) { + console.log("UNIT attr", attr, geoLevel); + if (attr === "Boundary") { + if (geoLevel === "County") { + return ( + { + "name": attr, + "formula": `lookupBoundary(US_county_boundaries, County, State)`, + "formulaDependents": "State" + } + ) + } + if (geoLevel === "State") { + return ( + { + "name": attr, + "formula": `lookupBoundary(US_state_boundaries, State)`, + "formulaDependents": "State" + } + ) + } + } return { name: attr, type: "numeric" @@ -96,13 +117,25 @@ export const connect = { }, createSubCollection: async function(geoLevel, attrs) { - const plural = geoLevel === "State" ? "States" : "Counties"; + const plural = (geoLevel === "State") && "States"; const message = { "action": "create", "resource": `dataContext[${dataSetName}].collection`, "values": { "name": "Data", "parent": plural, + "attributes": attrs.map((attr) => this.makeCODAPAttributeDef(attr, geoLevel)) + } + }; + await codapInterface.sendRequest(message); + }, + + createCollection: async function(attrs) { + const message = { + "action": "create", + "resource": `dataContext[${dataSetName}].collection`, + "values": { + "name": "Data", "attributes": attrs.map((attr) => this.makeCODAPAttributeDef(attr)) } }; From 7e85c72a289e6e1bf65c5f7999809b0897805ba4 Mon Sep 17 00:00:00 2001 From: eireland Date: Fri, 1 Dec 2023 14:47:45 -0800 Subject: [PATCH 6/9] Removes console.logs --- src/scripts/api.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/scripts/api.ts b/src/scripts/api.ts index 48cb644..5f9ef78 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -140,29 +140,21 @@ export const getAllAttrs = (selectedOptions: IStateOptions) => { export const createTableFromSelections = async (selectedOptions: IStateOptions, setReqCount: ISetReqCount) => { const {geographicLevel} = selectedOptions; - console.log("UNIT selectedOptions", selectedOptions); try { const allAttrs = getAllAttrs(selectedOptions); - console.log("UNIT allAttrs", allAttrs); const items = await getItems(selectedOptions, setReqCount); - console.log("UNIT items", items); await connect.getNewDataContext(); - console.log("UNIT in getNewDataContext"); await connect.createStateCollection(geographicLevel === "State"); - console.log("UNIT in createStateCollection"); if (geographicLevel === "County") { await connect.createCountyCollection(); } await connect.createSubCollection(geographicLevel, allAttrs); - console.log("UNIT in createSubCollection"); await connect.createItems(items); - console.log("UNIT in createItems"); await connect.makeCaseTableAppear(); - console.log("UNIT in success"); return "success"; } catch (error) { // eslint-disable-next-line no-console @@ -211,7 +203,6 @@ const getItems = async (selectedOptions: IStateOptions, setReqCount: ISetReqCoun items.forEach((item: any) => { // find all the data items that match this item's location and year const matchingData = data.filter((dataObj: any) => { - console.log("UNIT dataObj in getItems", dataObj); if (isMultiStateRegion) { const {region_desc, year} = dataObj; const regionThatIncludesState = multiRegions.find((r) => r.States.includes(item.State)); @@ -231,7 +222,6 @@ const getItems = async (selectedOptions: IStateOptions, setReqCount: ISetReqCoun return isSameGeoLevel && Number(item.Year) === year; } }); - console.log("UNIT matchingData in getItems", matchingData); if (isMultiStateRegion) { if (item.State !== "Alaska") { From 0c8ea1ab8aa9361f653f01ae7aa0ec40d02f643e Mon Sep 17 00:00:00 2001 From: eireland Date: Fri, 1 Dec 2023 16:39:10 -0800 Subject: [PATCH 7/9] Flattens the table by one level so attribute legends can be added to maps --- src/scripts/api.ts | 7 +------ src/scripts/connect.js | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/scripts/api.ts b/src/scripts/api.ts index b0e968e..ff5625e 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -99,7 +99,6 @@ export const createRequest = ({attribute, geographicLevel, years, states, cropUn export const getAllAttrs = (selectedOptions: IStateOptions) => { const {geographicLevel, states, cropUnits, years, ...subOptions} = selectedOptions; const allAttrs: Array = ["Year", geographicLevel, "Boundary"]; - console.log("UNIT geographicLevel", geographicLevel); for (const key in subOptions) { const selections = subOptions[key as keyof typeof subOptions]; @@ -135,22 +134,18 @@ export const getAllAttrs = (selectedOptions: IStateOptions) => { export const createTableFromSelections = async (selectedOptions: IStateOptions, setReqCount: ISetReqCount) => { const {geographicLevel} = selectedOptions; - console.log("UNIT createTableFromSelections geographicLevel", geographicLevel); try { const allAttrs = getAllAttrs(selectedOptions); const items = await getItems(selectedOptions, setReqCount); await connect.getNewDataContext(); - await connect.createStateCollection(geographicLevel === "State"); if (geographicLevel === "County") { - // await connect.createStateCollection(true); - // await connect.createCountyCollection(); + await connect.createStateCollection(true); await connect.createSubCollection(geographicLevel, allAttrs); await connect.createItems(items); await connect.makeCaseTableAppear(); return "success"; } else { - // await connect.createSubCollection(geographicLevel, allAttrs); await connect.createCollection(allAttrs); await connect.createItems(items); await connect.makeCaseTableAppear(); diff --git a/src/scripts/connect.js b/src/scripts/connect.js index 99bcedb..e4f51c7 100644 --- a/src/scripts/connect.js +++ b/src/scripts/connect.js @@ -11,30 +11,32 @@ export const connect = { }, makeCODAPAttributeDef: function (attr, geoLevel) { - console.log("UNIT attr", attr, geoLevel); if (attr === "Boundary") { if (geoLevel === "County") { return ( { - "name": attr, - "formula": `lookupBoundary(US_county_boundaries, County, State)`, - "formulaDependents": "State" + name: attr, + type: "boundary", + formula: `lookupBoundary(US_county_boundaries, County, State)`, + formulaDependents: "State" } ) - } - if (geoLevel === "State") { + } else { return ( { - "name": attr, - "formula": `lookupBoundary(US_state_boundaries, State)`, - "formulaDependents": "State" + name: attr, + type: "boundary", + formula: `lookupBoundary(US_state_boundaries, State)`, + formulaDependents: "State" } ) } } return { name: attr, - type: "numeric" + type: attr === "Boundary" ? "boundary" + : attr === "State" || attr === "County" + ? " string" : "numeric" } }, @@ -117,13 +119,12 @@ export const connect = { }, createSubCollection: async function(geoLevel, attrs) { - const plural = (geoLevel === "State") && "States"; const message = { "action": "create", "resource": `dataContext[${dataSetName}].collection`, "values": { "name": "Data", - "parent": plural, + "parent": "States", "attributes": attrs.map((attr) => this.makeCODAPAttributeDef(attr, geoLevel)) } }; @@ -136,6 +137,7 @@ export const connect = { "resource": `dataContext[${dataSetName}].collection`, "values": { "name": "Data", + "parent": "_root_", "attributes": attrs.map((attr) => this.makeCODAPAttributeDef(attr)) } }; From dbae954e9410eeb622af4384944af9b42a68fea0 Mon Sep 17 00:00:00 2001 From: eireland Date: Mon, 4 Dec 2023 10:46:10 -0700 Subject: [PATCH 8/9] Fixes bug introduced with merge conflict --- src/scripts/api.ts | 2 +- src/scripts/connect.js | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/scripts/api.ts b/src/scripts/api.ts index 8f7b75a..cb59592 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -152,7 +152,7 @@ export const createTableFromSelections = async (selectedOptions: IStateOptions, await connect.makeCaseTableAppear(); return "success"; } else { - await connect.createCollection(allAttrs); + await connect.createCollection(allAttrs, geographicLevel); await connect.createItems(items); await connect.makeCaseTableAppear(); return "success"; diff --git a/src/scripts/connect.js b/src/scripts/connect.js index e4f51c7..4efc323 100644 --- a/src/scripts/connect.js +++ b/src/scripts/connect.js @@ -11,11 +11,11 @@ export const connect = { }, makeCODAPAttributeDef: function (attr, geoLevel) { - if (attr === "Boundary") { + if (attr.name === "Boundary") { if (geoLevel === "County") { return ( { - name: attr, + name: attr.name, type: "boundary", formula: `lookupBoundary(US_county_boundaries, County, State)`, formulaDependents: "State" @@ -24,7 +24,7 @@ export const connect = { } else { return ( { - name: attr, + name: attr.name, type: "boundary", formula: `lookupBoundary(US_state_boundaries, State)`, formulaDependents: "State" @@ -33,10 +33,10 @@ export const connect = { } } return { - name: attr, - type: attr === "Boundary" ? "boundary" - : attr === "State" || attr === "County" - ? " string" : "numeric" + name: attr.name, + type: attr.name === "Boundary" ? "boundary" + : attr.name === "State" || attr.name === "County" + ? "string" : "numeric" } }, @@ -131,14 +131,14 @@ export const connect = { await codapInterface.sendRequest(message); }, - createCollection: async function(attrs) { + createCollection: async function(attrs, geoLevel) { const message = { "action": "create", "resource": `dataContext[${dataSetName}].collection`, "values": { "name": "Data", "parent": "_root_", - "attributes": attrs.map((attr) => this.makeCODAPAttributeDef(attr)) + "attributes": attrs.map((attr) => this.makeCODAPAttributeDef(attr, geoLevel)) } }; await codapInterface.sendRequest(message); From 00d4545be6d6997d811af756a6ba5ad107b35f30 Mon Sep 17 00:00:00 2001 From: eireland Date: Mon, 4 Dec 2023 19:02:00 -0700 Subject: [PATCH 9/9] Adds back units that get missed on merging main to the table flattening --- src/scripts/connect.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/scripts/connect.js b/src/scripts/connect.js index 4efc323..f7bc515 100644 --- a/src/scripts/connect.js +++ b/src/scripts/connect.js @@ -34,6 +34,7 @@ export const connect = { } return { name: attr.name, + unit: attr.unit, type: attr.name === "Boundary" ? "boundary" : attr.name === "State" || attr.name === "County" ? "string" : "numeric"