8000 enforce sequential order · plotly/plotly.r-docs@0431e09 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0431e09

Browse files
author
Joseph Damiba
committed
enforce sequential order
1 parent 60a33da commit 0431e09

File tree

74 files changed

+399
-287
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+399
-287
lines changed

check-or-enforce-order.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import frontmatter as fm
2+
from pathlib import Path, PosixPath
3+
import sys
4+
5+
# path here is intended to include only posts from a single language
6+
# _posts/r, _posts/plotly_js, _posts/python-v3, _posts/python in 'documentation'
7+
# build/html in 'plotly.py-docs'
8+
try:
9+
folder_path = str(sys.argv[1])
10+
except:
11+
raise Exception("You need to specify a path!")
12+
13+
# check to see if enforce flag was given at command line
14+
enforce = False
15+
if len(sys.argv) == 3:
16+
if sys.argv[2] == 'enforce':
17+
enforce = True
18+
19+
categories = ["file_settings", "basic", "financial", "statistical", "scientific", "maps", "3d_charts", "multiple_axes"]
20+
21+
def get_post(path):
22+
return fm.load(str(path))
23+
24+
def get_front_matter(post):
25+
if "jupyter" in post.metadata:
26+
return post["jupyter"]["plotly"]
27+
else:
28+
return post.metadata
29+
30+
# this function will mutate the front-matter to enforce a sequential order
31+
def enforceOrder(list_to_be_ordered):
32+
print(list_to_be_ordered)
33+
for index, post in enumerate(list_to_be_ordered):
34+
post_to_be_altered = fm.load(str(post))
35+
if folder_path == "python": # accounts for the fact that this is also run in the plotly.py-docs repo
36+
post_to_be_altered.metadata["jupyter"]["plotly"]['order'] = (index+2 if index>=4 else index+1)
37+
fm.dump(post_to_be_altered, str(post))
38+
else:
39+
post_to_be_altered.metadata['order'] = index+1
40+
fm.dump(post_to_be_altered, str(post))
41+
42+
def is_consecutive(list_to_be_checked):
43+
print(sorted(list_to_be_checked))
44+
return sorted(list_to_be_checked) == list(range(1, len(list_to_be_checked)+1))
45+
46+
def validate_front_matter(front_matter):
47+
if len(front_matter.keys()) > 0:
48+
if "display_as" in front_matter and "order" in front_matter:
49+
if front_matter['display_as'] in categories:
50+
return True
51+
else:
52+
return False
53+
else:
54+
return False
55+
56+
def get_paths_and_orders_by_category():
57+
posts_by_category = {category: dict(orders=[], paths=[]) for category in categories}
58+
suffixes = ["md", "html"]
59+
if folder_path == "r":
60+
suffixes = ["Rmd"]
61+
for suffix in suffixes:
62+
for path in Path(folder_path).glob("**/*."+suffix):
63+
if ".ipynb_checkpoints" not in str(path):
64+
post = get_post(path)
65+
front_matter = get_front_matter(post)
66+
if "display_as" in front_matter:
67+
post_category = front_matter['display_as']
68+
if post_category in posts_by_category and validate_front_matter(front_matter):
69+
posts_by_category[post_category]["paths"].append(path)
70+
posts_by_category[post_category]["orders"].append(front_matter['order'])
71+
return posts_by_category
72+
73+
def check_order():
74+
posts_by_category = get_paths_and_orders_by_category()
75+
for category in categories:
76+
print(category)
77+
orders = posts_by_category[category]["orders"]
78+
paths = posts_by_category[category]["paths"]
79+
sorted_paths = [path for order, path in sorted(zip(orders, paths))]
80+
if not is_consecutive(posts_by_category[category]["orders"]):
81+
print("Order is not sequential! **CHECK NOT PASSED** in '{}' display_as!".format(category))
82+
if enforce is True:
83+
print("ENFORCING CORRECT ORDER! for {}\n".format(category))
84+
enforceOrder(sorted_paths)
85+
else:
86+
arg = folder_path
87+
if folder_path == "build/html":
88+
arg = "python"
89+
if folder_path == "build":
90+
arg = "r"
91+
raise Exception("Order is not sequential! **CHECK NOT PASSED** in '{}' display_as! Run 'python check-or-enforce-order.py {} enforce' to resolve!".format(category, arg))
92+
else:
93+
print("*Check Passed!*\n")
94+
95+
print("**********************************************")
96+
print("Order of '{}' Before Enforcing!".format(folder_path))
97+
print("**********************************************\n")
98+
99+
check_order()
100+
101+
if enforce is True:
102+
print("*******************************************")
103+
print("Order of '{}' After Enforcing!".format(folder_path))
104+
print("*******************************************\n")
105+
check_order()

r/2015-07-30-2D-Histogram.Rmd

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
---
2-
name: 2D Histograms
3-
permalink: r/2D-Histogram/
4-
description: How to make a 2D histogram in R. A 2D histogram is a visualization of a bivariate distribution.
5-
layout: base
6-
thumbnail: thumbnail/histogram2d.jpg
7-
language: r
8-
page_type: example_index
2+
description: How to make a 2D histogram in R. A 2D histogram is a visualization of
3+
a bivariate distribution.
94
display_as: statistical
5+
language: r
6+
layout: base
7+
name: 2D Histograms
108
order: 1
119
output:
1210
html_document:
1311
keep_md: true
12+
page_type: example_index
13+
permalink: r/2D-Histogram/
14+
thumbnail: thumbnail/histogram2d.jpg
1415
---
1516

1617
```{r, echo = FALSE, message=FALSE}
@@ -42,4 +43,4 @@ If `z` is not provided, the only way to control coloring is through the [colorsc
4243
fig <- fig %>% add_histogram2d(colorscale = "Blues")
4344
4445
fig
45-
```
46+
```

r/2015-07-30-LaTeX.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ display_as: file_settings
44
language: r
55
layout: base
66
name: LaTeX Typesetting in R Graphs
7-
order: 12
7+
order: 11
88
output:
99
html_document:
1010
keep_md: true

r/2015-07-30-bar-charts.Rmd

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
---
2-
name: Bar Charts
3-
permalink: r/bar-charts/
4-
description: How to make a bar chart in R. Examples of grouped, stacked, overlaid, and colored bar charts.
5-
layout: base
6-
thumbnail: thumbnail/bar.jpg
7-
language: r
8-
page_type: example_index
2+
description: How to make a bar chart in R. Examples of grouped, stacked, overlaid,
3+
and colored bar charts.
94
display_as: basic
5+
language: r
6+
layout: base
7+
name: Bar Charts
108
order: 3
119
output:
1210
html_document:
1311
keep_md: true
12+
page_type: example_index
13+
permalink: r/bar-charts/
14+
thumbnail: thumbnail/bar.jpg
1415
---
1516

1617
```{r, echo = FALSE, message=FALSE}
@@ -342,5 +343,4 @@ See examples of horizontal bar charts [here](https://plotly.com/r/horizontal-bar
342343

343344
#Reference
344345

345-
See [https://plotly.com/r/reference/#bar](https://plotly.com/r/reference/#bar) for more information and chart attribute options!
346-
346+
See [https://plotly.com/r/reference/#bar](https://plotly.com/r/reference/#bar) for more information and chart attribute options!

r/2015-07-30-box-plots.Rmd

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
---
2-
name: Box Plots
3-
permalink: r/box-plots/
4-
description: How to make an interactive box plot in R. Examples of box plots in R that are grouped, colored, and display the underlying data distribution.
5-
layout: base
6-
thumbnail: thumbnail/box.jpg
7-
language: r
8-
page_type: example_index
2+
description: How to make an interactive box plot in R. Examples of box plots in R
3+
that are grouped, colored, and display the underlying data distribution.
94
display_as: statistical
5+
language: r
6+
layout: base
7+
name: Box Plots
108
order: 2
119
output:
1210
html_document:
1311
keep_md: true
12+
page_type: example_index
13+
permalink: r/box-plots/
14+
thumbnail: thumbnail/box.jpg
1415
---
1516

1617
```{r, echo = FALSE, message=FALSE}
@@ -148,4 +149,4 @@ fig
148149

149150
### Reference
150151

151-
See [https://plotly.com/r/reference/#box](https://plotly.com/r/reference/#box) for more information and chart attribute options!
152+
See [https://plotly.com/r/reference/#box](https://plotly.com/r/reference/#box) for more information and chart attribute options!

r/2015-07-30-bubble-charts.Rmd

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
---
2-
name: Bubble Charts
3-
permalink: r/bubble-charts/
4-
description: How to make a bubble chart in R. A bubble chart is a scatter plot whose markers have variable color and size.
5-
layout: base
6-
thumbnail: thumbnail/bubble.jpg
7-
language: r
2+
description: How to make a bubble chart in R. A bubble chart is a scatter plot whose
3+
markers have variable color and size.
84
display_as: basic
9-
order: 6
5+
language: r
6+
layout: base
7+
name: Bubble Charts
8+
order: 5
109
output:
1110
html_document:
1211
keep_md: true
12+
permalink: r/bubble-charts/
13+
thumbnail: thumbnail/bubble.jpg
1314
---
1415

1516
```{r, echo = FALSE, message=FALSE}
@@ -256,4 +257,4 @@ fig
256257

257258
#Reference
258259

259-
See [https://plotly.com/r/reference/#scatter](https://plotly.com/r/reference/#scatter) for more information and chart attribute options!
260+
See [https://plotly.com/r/reference/#scatter](https://plotly.com/r/reference/#scatter) for more information and chart attribute options!

r/2015-07-30-bubble-maps.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ display_as: maps
44
language: r
55
layout: base
66
name: Bubble Maps
7-
order: 12
7+
order: 11
88
output:
99
html_document:
1010
keep_md: true

r/2015-07-30-dumbbell-plots.Rmd

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
---
2-
name: Dumbbell Plots
3-
permalink: r/dumbbell-plots/
4-
description: How to make a dumbbell plot in R. Dumbbell plots show changes between two points in time or between two conditions.
5-
layout: base
6-
thumbnail: thumbnail/dumbbell-plot.jpg
7-
language: r
2+
description: How to make a dumbbell plot in R. Dumbbell plots show changes between
3+
two points in time or between two conditions.
84
display_as: basic
9-
order: 15
5+
language: r
6+
layout: base
7+
name: Dumbbell Plots
8+
order: 14
109
output:
1110
html_document:
1211
keep_md: true
12+
permalink: r/dumbbell-plots/
13+
thumbnail: thumbnail/dumbbell-plot.jpg
1314
---
1415

1516
```{r, echo = FALSE, message=FALSE}
@@ -38,4 +39,4 @@ fig
3839

3940
#Reference
4041

41-
See [https://plotly.com/r/reference/#scatter](https://plotly.com/r/reference/#scatter) for more information and chart attribute options!
42+
See [https://plotly.com/r/reference/#scatter](https://plotly.com/r/reference/#scatter) for more information and chart attribute options!

r/2015-07-30-filled-area-plots.Rmd

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
---
2-
name: Filled Area Plots
3-
permalink: r/filled-area-plots/
4-
description: How to make a filled area plot in R. An area chart displays a solid color between the traces of a graph.
5-
layout: base
6-
thumbnail: thumbnail/area.jpg
7-
language: r
2+
description: How to make a filled area plot in R. An area chart displays a solid color
3+
between the traces of a graph.
84
display_as: basic
9-
order: 8
5+
language: r
6+
layout: base
7+
name: Filled Area Plots
8+
order: 7
109
output:
1110
html_document:
1211
keep_md: true
12+
permalink: r/filled-area-plots/
13+
thumbnail: thumbnail/area.jpg
1314
---
1415

1516
```{r, echo = FALSE, message=FALSE}
@@ -242,4 +243,4 @@ fig
242243

243244
#Reference
244245

245-
See [https://plotly.com/r/reference/#area](https://plotly.com/r/reference/#area) for more information and chart attribute options!
246+
See [https://plotly.com/r/reference/#area](https://plotly.com/r/reference/#area) for more information and chart attribute options!

r/2015-07-30-graphing-multiple-chart-types.Rmd

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
---
2-
name: Graphing Multiple Chart Types
3-
permalink: r/graphing-multiple-chart-types/
4-
description: How to design figures with multiple chart types in R. An example of a line chart with a line of best fit and an uncertainty band.
5-
layout: base
6-
thumbnail: thumbnail/mixed.jpg
7-
language: r
2+
description: How to design figures with multiple chart types in R. An example of a
3+
line chart with a line of best fit and an uncertainty band.
84
display_as: basic
9-
order: 11
5+
language: r
6+
layout: base
7+
name: Graphing Multiple Chart Types
8+
order: 10
109
output:
1110
html_document:
1211
keep_md: true
12+
permalink: r/graphing-multiple-chart-types/
13+
thumbnail: thumbnail/mixed.jpg
1314
---
1415

1516
```{r, echo = FALSE, message=FALSE}
@@ -87,4 +88,4 @@ fig
8788

8889
#Reference
8990

90-
See [https://plotly.com/r/reference/](https://plotly.com/r/reference/) for more information and chart attribute options!
91+
See [https://plotly.com/r/reference/](https://plotly.com/r/reference/) for more information and chart attribute options!

r/2015-07-30-histograms.Rmd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
---
2-
name: Histograms
3-
permalink: r/histograms/
42
description: How to make a histogram in R.
5-
layout: base
6-
thumbnail: thumbnail/histogram.jpg
7-
language: r
8-
page_type: example_index
93
display_as: statistical
4+
language: r
5+
layout: base
6+
name: Histograms
107
order: 3
118
output:
129
html_document:
1310
keep_md: true
11+
page_type: example_index
12+
permalink: r/histograms/
13+
thumbnail: thumbnail/histogram.jpg
1414
---
1515

1616
```{r, echo = FALSE, message=FALSE}
@@ -134,4 +134,4 @@ fig
134134
```
135135
### Reference
136136

137-
See [https://plotly.com/r/reference/#histogram](https://plotly.com/r/reference/#histogram) for more information and chart attribute options!
137+
See [https://plotly.com/r/reference/#histogram](https://plotly.com/r/reference/#histogram) for more information and chart attribute options!

r/2015-07-30-legend.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,4 @@ fig
285285

286286
Reference
287287

288-
See [https://plotly.com/r/reference/#layout-legend](https://plotly.com/r/reference/#layout-legend) for more information and chart attribute options!
288+
See [https://plotly.com/r/reference/#layout-legend](https://plotly.com/r/reference/#layout-legend) for more information and chart attribute options!

0 commit comments

Comments
 (0)
0