Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3b33e89

Browse files
committed
Create reportspec.md
1 parent 5586407 commit 3b33e89

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed

specs/reportspec.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
## Spec for Report class
2+
3+
#### Basic idea and usage
4+
5+
After importing plotly, a Report object is created behind-the-scenes.
6+
There is only one report object per Python session.
7+
Grids and plots returned from plot.ly are automatically appended to the report object during the Python session,
8+
so that when you create a report:
9+
10+
```python
11+
import plotly
12+
rp = plotly.report
13+
```
14+
15+
It is pre-loaded with a list of plots, grids, and widget boxes that you've created during your session. Something like
16+
17+
```python
18+
rp.save()
19+
```
20+
21+
Would then compile and save the report to a local html file.
22+
23+
#### Item class
24+
25+
Reports would be structured as a list of Item objects.
26+
Text, Plot, or Grid objects would subclass from an Item class.
27+
28+
Item objects would have these methods and attributes:
29+
30+
* inline -- True or False. Defaults to false. >=2 sequential Items in report with inline=True will display inline.
31+
* to_html() -- Returns the Item's representation as an html string, including container div.
32+
* serialize() -- Returns the Item's representation as a dict.
33+
34+
#### Text class
35+
36+
Methods / attributes:
37+
38+
* markdown -- True or False. Defaults to False. Used by to_html() to convert content to html.
39+
* content -- plain text, html, or markdown string of content.
40+
* type (optional) -- for the html or markdown noob, adds css class to parent div for styling and parent html tags on to_html().
41+
* possible types: caption, latex, paragraph, title, subtitle.
42+
43+
Usage examples:
44+
45+
```python
46+
t1 = Text( 'Hello, world', type='title' ) # plain text with type
47+
t2 = Text( '# Hello, world', markdown=True ) # markdown
48+
t3 = Text( '<table>...</table>' ) # html
49+
```
50+
51+
#### Grid class
52+
53+
Methods / attributes:
54+
55+
* max_rows -- maximum number of rows to display
56+
57+
Usage examples:
58+
59+
```python
60+
g1 = Grid( 234 ) # fid of user's grid
61+
g2 = Grid( 'https://plot.ly/~jackp/1724', inline=True ) URL of user's grid
62+
g3 = Grid( ('msunds',34), inline=True ) tuple for another user's grid, placed next to g2
63+
```
64+
65+
#### Plot class
66+
67+
Methods / attributes:
68+
69+
* None?
70+
71+
Usage examples:
72+
73+
```python
74+
p1 = Plot( 234 ) # fid of user's plot
75+
p2 = Plot( 'https://plot.ly/~jackp/1724', inline=True ) URL of user's plot
76+
p3 = Plot( ('msunds',34), inline=True ) tuple for another user's plot, placed next to p2
77+
```
78+
79+
## Serialization structure
80+
81+
In order to save reports, some serialization structure will be needed. Here's a suggestion:
82+
83+
```python
84+
{
85+
name: 'my report',
86+
items: [
87+
{ class: 'text', content: '## Subsection', markdown=True },
88+
{ class: 'grid', inline: True, fid: 123, username: 'alex' },
89+
{ class: 'plot', inline: True, fid: 234, username: 'alex' },
90+
{ class: 'text', content: 'Hello, hello', type='caption' },
91+
]
92+
}
93+
```
94+
95+
## Report class methods
96+
97+
#### Subclass from Python list
98+
Subclass from lists so user can get all the list behavior they would expect from a list-like object? pop(), splicing, copying...
99+
100+
#### rp.print()
101+
Prints the current report structure.
102+
What's the most helpful way to give the user a quick view of their report structure and item order?
103+
Points to consider:
104+
* How do we show items share the same vertical level (ie a grid (html table) and plot side-by-side)
105+
* Do we limit text to ~50 chars with ellipses?
106+
* Show indices for help with splicing out items?
107+
108+
```python
109+
[0] Text: '# Report Title' (BLOCK1)
110+
[1] Plot: https://plot.ly/~jackp/1 (BLOCK2)
111+
[2] Grid: https://plot.ly/~jackp/2 (BLOCK2)
112+
[3] Text: 'Lorem ipsum dolor sit amet, cons...' (BLOCK3)
113+
```
114+
Where BLOCK-N specifies vertical placement.
115+
116+
#### rp.append()
117+
118+
Accepts any Item object or list of Item objects:
119+
120+
```python
121+
>>> t = Text( '## Subsection title' );
122+
>>> rp.append( t )
123+
1 Text object added to report.
124+
```
125+
126+
#### rp.clear()
127+
128+
Clears all items from report
129+
130+
#### rp.save()
131+
132+
Writes report to flat html file.
133+
134+
optional kwargs:
135+
136+
```python
137+
rp.save( plot_format = 'pdf') # converts all plots to pdf or png
138+
rp.save( path = 'Desktop' ) # absolute or relative path for saving
139+
```
140+

0 commit comments

Comments
 (0)