Skip to content

Commit

Permalink
Knowledge graph (datacommonsorg#4700)
Browse files Browse the repository at this point in the history
## Description

This PR implements the redesign of the knowledge graph (browser landing)
page.

It consists of both a conversion of the page itself to a React app with
components (along with the movement of the source data that populates
the page into json, similar to comparable pages), and a reworking of the
page itself into the new layout.

It includes a general component (the intro) that will be used in other
similar redesigns, as well as components specific to the knowledge graph
page.

---------

Co-authored-by: Pablo Noel <[email protected]>
  • Loading branch information
nick-next and pablonoel authored Nov 13, 2024
1 parent bbd38ec commit 2adf62c
Show file tree
Hide file tree
Showing 15 changed files with 539 additions and 113 deletions.
102 changes: 8 additions & 94 deletions server/templates/browser/landing.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{#
Copyright 2020 Google LLC
Copyright 2024 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -19,102 +19,16 @@
{% set main_id = 'browser_landing' %}
{% set page_id = 'page-browser_landing' %}
{% set title = 'Knowledge Graph' %}
{% set is_show_header_search_bar = true %}

{% block head %}
<link rel="stylesheet" href={{url_for('static', filename='css/browser.min.css', t=config['VERSION'])}} >
<link rel="stylesheet" href={{url_for('static', filename='css/browser_landing.min.css', t=config['VERSION'])}} >
<script src={{url_for('static', filename='browser_landing.js', t=config['VERSION'])}} async></script>
{% endblock %}

{% block content %}
<div class="container">
<h1 class="mb-4">Knowledge Graph</h1>
<p>
The Data Commons Knowledge Graph is constructed by synthesizing a single
database from many different data sources.
This knowledge graph can be used both to explore what data is available and
to understand the graph structure.
</p>
{# TODO: Use a config to drive these lists #}
<ul>
<li class="type-list">
<strong>Cities</strong>:
<a href="/browser/geoId/4261000">Pittsburgh, PA</a>,
<a href="/browser/geoId/0649670">Mountain View, CA</a>,
<a href="/browser/geoId/4805000">Austin, TX</a>,
<a href="/browser/geoId/0606000">Berkeley, CA</a>,
<a href="/browser/City"> More ...</a>
</li>
<li class="type-list">
<strong>Counties</strong>:
<a href="/browser/geoId/06085">Santa Clara</a>,
<a href="/browser/geoId/12086">Miami-Dade</a>,
<a href="/browser/County">More ...</a>
</li>
<li class="type-list">
<strong>States</strong>:
<a href="/browser/geoId/12">Florida</a>,
<a href="/browser/geoId/06">California</a>,
<a href="/browser/geoId/56">Wyoming</a>,
<a href="/browser/geoId/36">New York</a>,
<a href="/browser/State">More ...</a>
</li>
<li class="type-list">
<strong>Countries</strong>:
<a href="/browser/country/USA">United States</a>,
<a href="/browser/country/CAN">Canada</a>,
<a href="/browser/Country">More ...</a>
</li>
<li class="type-list">
<strong>Congressional Districts</strong>:
<a href="/browser/geoId/0618">CA-18</a>,
<a href="/browser/geoId/3601">NY-01</a>,
<a href="/browser/CongressionalDistrict">More ...</a>
</li>
<li class="type-list">
<strong>Elections</strong>:
<a href="/browser/election/2016_P_US00">2016 US Presidential Election</a>,
<a href="/browser/election/1990_S_MI00">1990 US Senate Elections for Michigan</a>,
<a href="/browser/Election">More ...</a>
</li>
<li class="type-list">
<strong>Census Estimates </strong>:
<a href="/browser/geoId/06085?statVar=Count_Person_AsianAlone">Asian Population in Santa Clara</a>,
<a href="/browser/geoId/2255000?statVar=Count_Person_EducationalAttainmentMastersDegree">Master Degree Holders in New Orleans</a>
</li>
<li class="type-list">
<strong>Labor Statistics </strong>:
<a href="/browser/geoId/2507000?statVar=UnemploymentRate_Person">Unemployment in Boston </a>
</li>
<li class="type-list">
<strong>Crime Data</strong>:
<a href="/browser/geoId/1304000?statVar=Count_CriminalActivities_Robbery">Violent Robbery in Atlanta, Georgia</a>,
<a href="/browser/geoId/13?statVar=Count_CriminalActivities_LarcenyTheft">Larceny-Theft in Georgia</a>
</li>
<li class="type-list">
<strong>Health Data</strong>:
<a href="/browser/geoId/1304000?statVar=Percent_Person_WithDiabetes">Prevalence of Diabetes in Atlanta</a>
</li>
<li class="type-list">
<strong>DEA ARCOS</strong>:
<a href="/browser/geoId/54099?statVar=RetailDrugDistribution_DrugDistribution_Amphetamine">Amphetamine distribution in Wayne County, WV</a>
</li>
<li class="type-list">
<strong>Botanical Specimens</strong>:
<a href="/browser/dc/bsmvthtq89217">Austrobaileya scandens</a>,
<a href="/browser/BiologicalSpecimen">More ...</a>
</li>
<li class="type-list">
<strong>ENCODE (Encyclopedia Of DNA Elements)</strong>:
<a href="/browser/Lab">Labs</a>,
<a href="/browser/EncodeBiosampleType">Biosamples</a>,
<a href="/browser/EncodeExperiment">Experiments</a>,
<a href="/browser/EncodeBedFile">More ...</a>
</li>
<li class="type-list">
<strong>Public Schools and School Districts</strong>:
<a href="/browser/nces/062961004587">Henry M. Gunn High</a>,
<a href="/browser/nces/360007702877">Stuyvesant High School</a>,
<a href="/browser/geoId/sch3620580">New York City Department of Education</a>
</li>
</ul>
</div>

<div id="app-container">
</div>

{% endblock %}
1 change: 1 addition & 0 deletions server/templates/static/build.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
#}

{%- extends BASE_HTML -%}

{% set main_id = 'build' %}
Expand Down
2 changes: 1 addition & 1 deletion server/tests/routes/browser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TestStaticPage(unittest.TestCase):
def test_browser_static(self):
response = app.test_client().get('/browser/')
assert response.status_code == 200
assert b"The Data Commons Knowledge Graph is constructed by" in response.data
assert b'<div id="app-container">' in response.data

@patch('server.routes.shared_api.place.names')
def test_browser_node(self, mock_names):
Expand Down
22 changes: 14 additions & 8 deletions server/webdriver/shared_tests/browser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,25 @@ def test_page_landing(self):
# Assert page title is correct
WebDriverWait(self.driver,
self.TIMEOUT_SEC).until(EC.title_contains(title_text))
self.assertEqual(title_text, self.driver.title)
self.assertIn(title_text, self.driver.title)

# Wait for title to be present
title_present = EC.text_to_be_present_in_element((By.TAG_NAME, 'h1'),
'Knowledge Graph')
WebDriverWait(self.driver, self.TIMEOUT_SEC).until(title_present)
h1_locator = (By.CSS_SELECTOR, '#intro-text h1')
WebDriverWait(self.driver, self.TIMEOUT_SEC).until(
EC.text_to_be_present_in_element(h1_locator, 'Knowledge Graph'))
h1_element = self.driver.find_element(*h1_locator)
self.assertEqual("Knowledge Graph", h1_element.text)

# Assert intro is correct
intro = self.driver.find_element(By.XPATH,
'//*[@id="browser_landing"]/div/p[1]')
intro_locator = (By.CSS_SELECTOR, '#intro-text .container header p')
WebDriverWait(self.driver, self.TIMEOUT_SEC).until(
EC.presence_of_element_located(intro_locator))
intro_element = self.driver.find_element(*intro_locator)
expected_intro_start = 'The Data Commons Knowledge Graph is constructed'
self.assertTrue(
intro.text.startswith(
'The Data Commons Knowledge Graph is constructed'))
intro_element.text.startswith(expected_intro_start),
f"Intro text does not start with expected text. Found: {intro_element.text}"
)

def test_page_serve_ca_population(self):
"""Test the browser page for California population can be loaded successfully."""
Expand Down
41 changes: 41 additions & 0 deletions static/css/browser_landing.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* Styles for the browser landing (knowledge graph page) */

@use "./variables" as var;
@import "base";
@import "./content/browser_items";
@import "./content/intro_text";

#browser_landing {
&.main-content {
margin: 0;
}
.container {
padding: calc(#{var.$spacing} * 8) 0;
&.big {
padding: calc(#{var.$spacing} * 12) 0;
@include media-breakpoint-down(lg) {
padding: calc(#{var.$spacing} * 8) calc(#{var.$spacing} * 3);
}
}
@include media-breakpoint-down(lg) {
max-width: 100%!important;
padding: var.$container-horizontal-padding calc(#{var.$spacing} * 3);
}
}
}
72 changes: 72 additions & 0 deletions static/css/content/browser_items.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.a
*/

/* Styles for the browser items component located on the browser landing (knowledge graph) page */

.browser-items {
.item {
padding-bottom: calc(#{var.$spacing} * 10);
margin-bottom: calc(#{var.$spacing} * 10);
border-bottom: 1px solid rgba(220,220,220,0.3);
&:last-of-type {
border-bottom: none;
}
@include media-breakpoint-down(md) {
padding-bottom: calc(#{var.$spacing} * 6);
margin-bottom: calc(#{var.$spacing} * 6);
}
@include media-breakpoint-down(sm) {
padding-bottom: calc(#{var.$spacing} * 4);
margin-bottom: calc(#{var.$spacing} * 4);
}
.header {
h3 {
@include var.title_md;
margin-bottom: calc(#{var.$spacing} * 3);
}
}
ul {
margin: 0;
margin-left: 200px;
padding: 0;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: calc(#{var.$spacing} * 2) calc(#{var.$spacing} * 3);
@include media-breakpoint-down(md) {
grid-template-columns: 1fr 1fr;
}
@include media-breakpoint-down(sm) {
grid-template-columns: 1fr;
gap: calc(#{var.$spacing} * 2) calc(#{var.$spacing} * 3);
margin-left: 10%;
}
li {
@include var.text_lg;
font-weight: 200;
margin:0;
padding: 0;
list-style: none;
display: block;
.more {
display: flex;
align-content: center;
gap: var.$spacing;
color: var(--gm-3-ref-neutral-neutral-40);
}
}
}
}
}
18 changes: 10 additions & 8 deletions static/css/content/intro_text.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.a
*/

.intro-text {

/* Styles for a general intro text component (used on pages such as browser landing and explorer landing) */

.intro-text {
.container {
display: grid;
grid-template-columns: 6fr 4fr;
gap: calc(#{var.$spacing} * 2) calc(#{var.$spacing} * 6);
@include media-breakpoint-down(md) {
@include media-breakpoint-down(md) {
grid-template-columns: 1fr;
}
@include media-breakpoint-down(sm) {
@include media-breakpoint-down(sm) {
display: block;
}
}
h1 {
@include var.title_lg;
}
h1 {
@include var.title_lg;
margin-bottom: calc(#{var.$spacing} * 3);
}
}
}
4 changes: 3 additions & 1 deletion static/css/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ $color-gray_pill_bckg:#E2E2EC;
bottom: 0;
left: 0;
-webkit-mask-image: -webkit-radial-gradient(white, black);
mask-image: -webkit-radial-gradient(white, black);
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
backface-visibility: hidden;
}
}

Expand All @@ -182,4 +184,4 @@ $color-gray_pill_bckg:#E2E2EC;
border: 0;
border-bottom: 1px solid #C7C7C7;
max-width: 1280px;
}
}
50 changes: 50 additions & 0 deletions static/js/apps/browser_landing/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Main component for the browser landing (knowledge graph) page
*/

import React, { ReactElement } from "react";

import { IntroText } from "../../components/content/intro_text";
import { KnowledgeGraphBrowser } from "../../components/knowledge_graph/knowledge_graph_browser";
import { KnowledgeGraphCategory } from "../../shared/types/knowledge_graph";
import knowledgeGraphData from "./knowledge_graph.json";

const knowledgeGraph: KnowledgeGraphCategory[] = knowledgeGraphData;

/**
* Application container
*/
export function App(): ReactElement {
return (
<>
<IntroText>
<header>
<h1>Knowledge Graph</h1>
<p>
The Data Commons Knowledge Graph is constructed by synthesizing a
single database from many different data sources. This knowledge
graph can be used both to explore what data is available and to
understand the graph structure.
</p>
</header>
</IntroText>
<KnowledgeGraphBrowser knowledgeGraph={knowledgeGraph} />
</>
);
}
Loading

0 comments on commit 2adf62c

Please sign in to comment.