@@ -1544,9 +1544,9 @@ class Document(models.Model):
1544
1544
1545
1545
1546
1546
# ------------------------------------------------------------------------------
1547
- class PlotlyPlot (object ):
1547
+ class GenExpPlot (object ):
1548
1548
"""
1549
- Class for Plotly barplots.
1549
+ Class for Plotly barplots and violins .
1550
1550
traces = [
1551
1551
0 : {
1552
1552
group1: [ values ],
@@ -1559,14 +1559,17 @@ class PlotlyPlot(object):
1559
1559
"""
1560
1560
def __init__ (self ):
1561
1561
self .traces = list ()
1562
+ self .traces_set = set ()
1562
1563
self .groups = list ()
1564
+ self .groups_set = set ()
1563
1565
self .title = str ()
1564
1566
self .ylab = str ()
1565
1567
self .trace_names = list ()
1566
1568
1567
1569
def add_group (self , group ):
1568
- if group not in self .groups :
1570
+ if group not in self .groups_set :
1569
1571
self .groups .append (group )
1572
+ self .groups_set .add (group )
1570
1573
1571
1574
for trace in self .traces :
1572
1575
if group not in trace :
@@ -1610,7 +1613,7 @@ def is_empty(self):
1610
1613
1611
1614
1612
1615
# ------------------------------------------------------------------------------
1613
- class BarPlot (PlotlyPlot ):
1616
+ class BarPlot (GenExpPlot ):
1614
1617
"""
1615
1618
Class for Plotly bar plots.
1616
1619
Each bar (group) consists of only one value.
@@ -1648,7 +1651,7 @@ def plot(self):
1648
1651
1649
1652
1650
1653
# ------------------------------------------------------------------------------
1651
- class ViolinPlot (PlotlyPlot ):
1654
+ class ViolinPlot (GenExpPlot ):
1652
1655
"""
1653
1656
Class for Plotly violinplots.
1654
1657
Each violin (group) is made of multiple values.
@@ -1711,6 +1714,79 @@ def plot(self):
1711
1714
return theplot
1712
1715
1713
1716
1717
+ class ScatterPlot (object ):
1718
+ '''
1719
+ Class for Plotly scatterplots
1720
+ '''
1721
+ def __init__ (self ):
1722
+ self .traces = dict ()
1723
+
1724
+ def add_trace (self , name ):
1725
+ if name not in self .traces :
1726
+ self .traces [name ] = PlotlyTrace (name )
1727
+ self .traces [name ].order = len (self .traces )
1728
+
1729
+ def add_x (self , trace_name , x ):
1730
+ if trace_name in self .traces :
1731
+ self .traces [trace_name ].x .append (x )
1732
+ else :
1733
+ raise (KeyError ("Trace %s not found in ScatterPlot!" % trace_name ))
1734
+
1735
+ def add_y (self , trace_name , y ):
1736
+ if trace_name in self .traces :
1737
+ self .traces [trace_name ].y .append (y )
1738
+
1739
+ def add_name (self , trace_name , name ):
1740
+ if trace_name in self .traces :
1741
+ self .traces [trace_name ].names .append (name )
1742
+
1743
+ def plot (self ):
1744
+ theplot = dict ()
1745
+ theplot ['data' ] = list ()
1746
+ theplot ['layout' ] = dict ()
1747
+ for trace_name in sorted (self .traces .keys (), key = lambda n : self .traces [n ].order ):
1748
+ trace = self .traces [trace_name ]
1749
+ trace_data = dict ()
1750
+ if str (trace_name ).isdigit ():
1751
+ trace_data ['name' ] = 'c' + str (trace .name )
1752
+ else :
1753
+ trace_data ['name' ] = str (trace .name )
1754
+ trace_data ['x' ] = trace .x
1755
+ trace_data ['y' ] = trace .y
1756
+ trace_data ['type' ] = trace .type
1757
+ trace_data ['mode' ] = trace .mode
1758
+ if trace .color :
1759
+ trace_data ['marker' ] = { 'color' : list (trace .color ) }
1760
+ if trace .names :
1761
+ trace_data ['text' ] = trace .names
1762
+ theplot ['data' ].append (trace_data )
1763
+ return theplot
1764
+
1765
+ def add_color_to_trace (self , trace_name , colors ):
1766
+ if trace_name in self .traces :
1767
+ self .traces [trace_name ].color = colors
1768
+ else :
1769
+ raise (KeyError ("Trace %s not found in ScatterPlot!" % trace_name ))
1770
+
1771
+
1772
+
1773
+ class PlotlyTrace (object ):
1774
+ '''
1775
+ Class for plotly traces
1776
+ '''
1777
+ def __init__ (self , name ):
1778
+ self .name = name
1779
+ self .order = int ()
1780
+ self .x = list ()
1781
+ self .y = list ()
1782
+ self .names = list ()
1783
+ self .mode = 'markers'
1784
+ self .type = 'scatter'
1785
+ self .color = list ()
1786
+
1787
+
1788
+
1789
+
1714
1790
1715
1791
1716
1792
# EXCEPTIONS
@@ -2002,6 +2078,13 @@ def __unicode__(self):
2002
2078
name_str += self .units
2003
2079
return name_str
2004
2080
2081
+
2082
+ class CellPlotPosition (models .Model ):
2083
+ experiment = models .ForeignKey (Experiment , on_delete = models .CASCADE )
2084
+ sample = models .ForeignKey (Sample , on_delete = models .CASCADE )
2085
+ dataset = models .ForeignKey (Dataset , on_delete = models .CASCADE )
2086
+ x_position = models .FloatField ()
2087
+ y_position = models .FloatField ()
2005
2088
2006
2089
2007
2090
# ------------------------------------------------------------------------------
0 commit comments