Skip to content

Commit

Permalink
feat: added all the other properties plots to the stats page
Browse files Browse the repository at this point in the history
  • Loading branch information
sriramkanakam87 committed Dec 9, 2024
1 parent 40f85d7 commit 15f44e3
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 19 deletions.
4 changes: 0 additions & 4 deletions app/Livewire/AnnotationScorePlot.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ class AnnotationScorePlot extends Component
// Making our data properties public so they're accessible in the view
public $chartData_overall = [];

public $chartData_collections = [];

public $selectedCollections = [];

public function mount()
{
$jsonPath = public_path('reports/density_charts.json');
Expand Down
6 changes: 0 additions & 6 deletions app/Livewire/DensityPlot.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ class DensityPlot extends Component
// Making our data properties public so they're accessible in the view
public $chartData_overall = [];

public $chartData_collections = [];

public $selectedCollections = [];

public function mount()
{
$jsonPath = public_path('reports/density_charts.json');
Expand All @@ -31,9 +27,7 @@ public function mount()

// Store in the public property
$this->chartData_overall = $decodedData;
// $this->chartData_overall = $decodedData['properties']['np_likeness']['overall']['density_data'];
$this->chartData_collections = $decodedData['properties']['np_likeness']['collections'];
// $this->chartData = $decodedData['properties']['np_likeness']['overall'];

} catch (\Exception $e) {
\Log::error('Failed to load density chart data: '.$e->getMessage());
Expand Down
23 changes: 23 additions & 0 deletions app/Livewire/PropertiesPlot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Livewire;

use Livewire\Component;

class PropertiesPlot extends Component
{
public $property;

public $name;

public function mount($property, $name)
{
$this->property = $property;
$this->name = $name;
}

public function render()
{
return view('livewire.properties-plot');
}
}
30 changes: 29 additions & 1 deletion app/Livewire/Stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,36 @@

class Stats extends Component
{
public $properties_json_data = [];

public function mount()
{
$jsonPath = public_path('reports/density_charts.json');

try {
if (! file_exists($jsonPath)) {
throw new \Exception('Density chart data file not found');
}

$jsonContent = file_get_contents($jsonPath);
$decodedData = json_decode($jsonContent, true);

if (json_last_error() !== JSON_ERROR_NONE) {
throw new \Exception('Error decoding JSON data: '.json_last_error_msg());
}

// Store in the public property
$this->properties_json_data = $decodedData['properties'];

} catch (\Exception $e) {
\Log::error('Failed to load density chart data: '.$e->getMessage());
}
}

public function render()
{
return view('livewire.stats');
return view('livewire.stats', [
'properties_json_data' => $this->properties_json_data,
]);
}
}
2 changes: 1 addition & 1 deletion public/reports/density_charts.json

Large diffs are not rendered by default.

150 changes: 150 additions & 0 deletions resources/views/livewire/properties-plot.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<div class="w-full">
<div>
<h2 class="text-2xl font-bold tracking-tight text-gray-900 sm:text-3xl mb-3">
{{ ucfirst(str_replace('_', ' ', $name)) }} (Density Plot)
</h2>
<div class="flex flex-col">
<div style="height: 400px;" class="w-full">
<canvas id="plot-{{ $name }}"></canvas>
</div>
<div id="legend-{{ $name }}" class="chart-legend-container w-full mt-2">
</div>
</div>
</div>

<script>
document.addEventListener('DOMContentLoaded', function() {
const plotCanvas = document.getElementById('plot-{{ $name }}');
// Data from Livewire/PHP
const plotData = @js($property);
const datasets = [{
label: 'COCONUT',
data: plotData.overall.density_data.map(point => ({
x: point.x,
y: point.y
})),
borderColor: 'black',
borderWidth: 2,
pointRadius: 0,
tension: 0.4,
fill: false
}];
Object.entries(plotData.collections).forEach(([name, collection], index) => {
datasets.push({
label: name,
data: collection.density_data.map(point => ({
x: point.x,
y: point.y
})),
borderColor: `hsl(${index * 30}, 70%, 50%)`,
borderWidth: 2,
pointRadius: 0,
tension: 0.4,
fill: false,
hidden: true
});
});
const chart = new Chart(plotCanvas, {
type: 'line',
data: {
datasets: datasets
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
x: {
type: 'linear',
title: {
display: true,
text: '{{ ucfirst(str_replace('_', ' ', $name)) }}'
},
ticks: {
stepSize: 1
},
},
y: {
type: 'linear',
title: {
display: true,
text: 'Density'
}
}
},
plugins: {
htmlLegend: {
containerID: 'legend-{{ $name }}'
},
legend: {
display: false
}
}
},
// plugins: [{
// id: 'htmlLegend',
// beforeInit(chart) {
// const container = document.getElementById('legend-{{ $name }}');
// if (!container) return;
// // Clear existing legend
// container.innerHTML = '';
// const ul = document.createElement('ul');
// ul.style.listStyle = 'none';
// ul.style.padding = 0;
// ul.style.display = 'flex';
// ul.style.flexWrap = 'wrap';
// ul.style.gap = '8px';
// chart.data.datasets.forEach((dataset, i) => {
// const li = document.createElement('li');
// li.style.marginBottom = '4px';
// li.style.opacity = dataset.hidden ? '0.3' : '1';
// li.style.display = 'flex';
// li.style.alignItems = 'center';
// li.style.minWidth = '120px';
// const button = document.createElement('button');
// button.style.border = 'none';
// button.style.background = dataset.borderColor;
// button.style.width = '12px';
// button.style.height = '12px';
// button.style.marginRight = '6px';
// button.style.cursor = 'pointer';
// const label = document.createTextNode(dataset.label);
// li.onclick = () => {
// dataset.hidden = !dataset.hidden;
// chart.update();
// li.style.opacity = dataset.hidden ? '0.3' : '1';
// };
// li.style.cursor = 'pointer';
// li.appendChild(button);
// li.appendChild(label);
// ul.appendChild(li);
// });
// container.appendChild(ul);
// }
// }]
});
});
</script>

<!-- <style>
.chart-legend-container {
padding: 8px;
border-top: 1px solid #eee;
}
.chart-legend-container ul {
margin: 0;
padding: 0;
}
</style> -->
</div>
25 changes: 18 additions & 7 deletions resources/views/livewire/stats.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
COCONUT Analytics: Natural Product Chemical Space Exploration
</h1>
<p class="relative mt-6 text-lg leading-7 text-gray-600 sm:max-w-md lg:max-w-none">
Natural product chemistry is intrinsically complex, with molecules exhibiting diverse structural features and bioactivities. This analytics dashboard provides comprehensive insights into the COCONUT (COlleCtion of Open NatUral producTs) database, enabling researchers to explore chemical space distributions, structural patterns, and property relationships across various natural product families.
Natural product chemistry is intrinsically complex, with molecules exhibiting diverse structural features and bioactivities. This analytics dashboard provides comprehensive insights into the COCONUT (COlleCtion of Open NatUral producTs) database, enabling researchers to explore chemical space distributions, structural patterns, and property relationships across various natural product families.
</p>
</div>
<div class="mt-14 flex justify-end gap-8 sm:-mt-44 sm:justify-start sm:pl-20 lg:mt-0 lg:pl-0">
Expand All @@ -71,7 +71,7 @@ class="aspect-[2/3] w-full rounded-xl bg-gray-900/5 object-cover shadow-lg" />
class="pointer-events-none absolute inset-0 rounded-xl ring-1 ring-inset ring-gray-900/10">
</div>
</div>

</div>
<div class="w-44 flex-none space-y-8 pt-32 sm:pt-0">
<div class="relative">
Expand All @@ -88,11 +88,22 @@ class="pointer-events-none absolute inset-0 rounded-xl ring-1 ring-inset ring-gr
</div>
</div>

<div class="mx-auto max-w-6xl pb-32 px-8 w-full">
<div class="mx-auto max-w-6xl pb-32 px-8 w-full">
<livewire:density-plot />
</div>
<div class="mx-auto max-w-6xl pb-32 px-8 w-full">
</div>
<div class="mx-auto max-w-6xl pb-32 px-8 w-full">
<livewire:annotation-score-plot />
</div>
</div>
<div class="ml-10 mr-10 grid grid-cols-1 md:grid-cols-2 gap-4 p-4">
@foreach ($properties_json_data as $name => $property)
@if ($name != 'np_likeness')
@livewire('properties-plot', [
'property' => $property,
'name' => $name
])
@endif
@endforeach
</div>

</div>
</div>
</div>

0 comments on commit 15f44e3

Please sign in to comment.