Skip to content

Commit

Permalink
Many report fixes, tweaks and upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
fbdesignpro committed Nov 27, 2020
1 parent 509bdf7 commit e73f9d3
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 37 deletions.
20 changes: 13 additions & 7 deletions sweetviz/dataframe_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,9 @@ def show_html(self, filepath='SWEETVIZ_REPORT.html', open_browser=True, layout='
# https://bugs.python.org/issue5993
webbrowser.open('file://' + os.path.realpath(filepath))
else:
print(f"Report {filepath} was generated!")
print(f"Report {filepath} was generated.")

def show_notebook(self, w=None, h=None, scale=None, layout='widescreen', filepath='SWEETVIZ_REPORT.html', file_open_browser=True):
def show_notebook(self, w=None, h=None, scale=None, layout='widescreen', filepath=None):
w = self.use_config_if_none(w, "notebook_width")
h = self.use_config_if_none(h, "notebook_height")
scale = float(self.use_config_if_none(scale, "notebook_scale"))
Expand All @@ -510,13 +510,19 @@ def show_notebook(self, w=None, h=None, scale=None, layout='widescreen', filepat

width=w
height=h
if str(height).lower() == "full":
height = self.page_height

# Output to iFrame
import html
self._page_html = html.escape(self._page_html)
from IPython.display import IFrame
iframe = f' <iframe width="{width}" height="{height}" srcdoc="{self._page_html}" frameborder="0" allowfullscreen></iframe>'
from IPython.core.display import display
# display(IFrame(src=self._page_html, width=w, height=h))
iframe = f'<iframe width="{width}" height="{height}" srcdoc="{self._page_html}" frameborder="0" allowfullscreen></iframe>'
# from IPython.core.display import display
# from IPython.core.display import HTML
from IPython.core.display import HTML
display(HTML(iframe))

if filepath is not None:
f = open(filepath, 'w', encoding="utf-8")
f.write(self._page_html)
f.close()
print(f"Report '{filepath}' was saved to storage.")
49 changes: 42 additions & 7 deletions sweetviz/graph_associations.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,39 @@
CORRELATION_ERROR = 83572398457329.0
CORRELATION_IDENTICAL = 1357239845732.0

def wrap_custom(source_text, separator_chars, width=70, keep_separators = True):
current_length = 0
latest_separator = -1
current_chunk_start = 0
output = ""
char_index = 0
while char_index < len(source_text):
if source_text[char_index] in separator_chars:
latest_separator = char_index
output += source_text[char_index]
current_length += 1
if current_length == width:
if latest_separator >= current_chunk_start:
# Valid earlier separator, cut there
cutting_length = char_index - latest_separator
if not keep_separators:
cutting_length += 1
if cutting_length:
output = output[:-cutting_length]
output += "\n"
current_chunk_start = latest_separator + 1
char_index = current_chunk_start
else:
# No separator found, hard cut
output += "\n"
current_chunk_start = char_index + 1
latest_separator = current_chunk_start - 1
char_index += 1
current_length = 0
else:
char_index += 1
return output

class GraphAssoc(sweetviz.graph.Graph):
def __init__(self, dataframe_report, which_graph: str, association_data):
self.set_style(["graph_base.mplstyle"])
Expand Down Expand Up @@ -259,15 +292,17 @@ def value_to_size(val):
# return int(size_scale)
# return val_position * int(size_scale)

def do_wrapping(label):
return '\n'.join(wrap(label, 15))

def do_wrapping(label, length):
return wrap_custom(label, ["_", "-"], length)
# return '\n'.join(wrap(label, 15))
wrap_x = 12 # at top/bottom
wrap_y = 13
if 'x_order' in kwargs:
x_names = [t for t in kwargs['x_order']]
else:
x_names = [t for t in sorted(set([v for v in x]))]
# Wrap to help avoid overflow
x_names = [do_wrapping(label) for label in x_names]
x_names = [do_wrapping(label, wrap_x) for label in x_names]

x_to_num = {p[1]:p[0] for p in enumerate(x_names)}

Expand All @@ -276,7 +311,7 @@ def do_wrapping(label):
else:
y_names = [t for t in sorted(set([v for v in y]))]
# Wrap to help avoid overflow
y_names = [do_wrapping(label) for label in y_names]
y_names = [do_wrapping(label, wrap_y) for label in y_names]

y_to_num = {p[1]:p[0] for p in enumerate(y_names)}

Expand Down Expand Up @@ -312,8 +347,8 @@ def do_wrapping(label):

index = 0
for cur_x, cur_y in zip(x,y):
wrapped_x_name = do_wrapping(cur_x)
wrapped_y_name = do_wrapping(cur_y)
wrapped_x_name = do_wrapping(cur_x, wrap_x)
wrapped_y_name = do_wrapping(cur_y, wrap_y)
before_coordinate = np.array(ax.transData.transform((x_to_num[wrapped_x_name]-0.5, y_to_num[wrapped_y_name] -0.5)))
after_coordinate = np.array(ax.transData.transform((x_to_num[wrapped_x_name]+0.5, y_to_num[wrapped_y_name] +0.5)))
before_pixels = np.round(before_coordinate, 0)
Expand Down
6 changes: 5 additions & 1 deletion sweetviz/sv_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ def generate_html_dataframe_page(dataframe_report):
# Add in total page size (160 is hardcoded from the top of page-all-summaries in CSS)
# This could be programmatically set
dataframe_report.page_height = 160 + (dataframe_report.num_summaries * (config["Layout"].getint("summary_height_per_element")))
padding = 100 # max(50, (dataframe_report.num_summaries * (config["Layout"].getint("summary_vertical_padding"))))
if dataframe_report.page_layout == "widescreen":
padding_type = "full_page_padding_widescreen"
else:
padding_type = "full_page_padding_vertical"
padding = config["Layout"].getint(padding_type)
dataframe_report.page_height += padding
# scaling = dict()
# scaling["main_column"] = scale
Expand Down
5 changes: 4 additions & 1 deletion sweetviz/sweetviz_defaults.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ association_min_to_bold = 0.1
html_layout = widescreen
html_scale = 1.0
notebook_layout = vertical
notebook_scale = 1.0
notebook_scale = 0.9
notebook_width = 100%
notebook_height = 700

Expand Down Expand Up @@ -61,6 +61,9 @@ detail_max_text_rows = 60
[Layout]
show_logo = 1

full_page_padding_widescreen = 160
full_page_padding_vertical = 300

;230px->48 = 4.8
;37px->6 = 6.2
;216px->44 = 4.9
Expand Down
3 changes: 2 additions & 1 deletion sweetviz/templates/dataframe_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEACABoBQAAFgAAACgAAAAQAAAAIAAAAAEACAAAAAAAAAEAAAAAAAAAAAAAAAEAAAAAAAAAAAAAPD4/AC0vMADd3+AAWFpbAFlaWwC8vb0AOjw9AERHRwCSlJ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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAS1gjNy91XV0MDUItMl1dXSFwGxsbHy5dZEBuPGpdXV0sUx5oNRsbFngiXTkkMl1dXV1dXTtZGzBrXV1dT0RdXV1dXV0dcBsFC11yXTRcQ11dXV1dThsBBzFdFANdGG1dXV1dJRsbeBBdNgBbXQlXXV1dWhsbUzh0XTxjBF1xAkhdKAEbDlVgXSp3XV4PXSlfXVIbHydoK11GVF1QCF0SIF0wGz1dGRdNURxhXWZKU0ldVhsHPl1Fc2UbP10TClJdXV0zG3dHXV1MGhtsXV1dXV1daW8bGzpiJjMbEV1dXV1dXV0nFRsbGwEbG0FdXV1dXV1dXV0GdgcbWTpnXV1dXQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" type="image/x-icon" />
{% if not dataframe.test_mode: %}
<script> {% include 'js/jquery-3.4.1.min.js' %} </script>
{% if dataframe.page_layout == 'widescreen': %}
Expand Down Expand Up @@ -66,7 +67,7 @@
<div class="pos-logo im-logo"></div>
<div class="pos-credits text-credits">
<span class="text-version">{{ version }}<br>
<a href="https://github.com/fbdesignpro/sweetviz">Click here for docs & updates</a></span><br>
<a href="https://github.com/fbdesignpro/sweetviz">Get updates, docs & report issues here</a></span><br>
Created & maintained by <a href="https://www.fbdesignpro.com">Francois Bertrand</a> <br>
Graphic design by <a href="https://www.fbdesignpro.com" data-reach="Jeff is working on his contact info :)">Jean-Francois Hains</a>
</div>
Expand Down
12 changes: 6 additions & 6 deletions sweetviz/templates/feature_detail_numeric.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
<!-- ASSOCIATIONS -->
{% if numerical is not none %}
<div class="pos-detail-cat-assoc-1" id="cat-assoc-CN-f{{ feature_dict.order_index }}">
<span class="bg-extra-column"></span>
<span class="bg-extra-column" {{ 'style="height: 588px"' if feature_dict.order_index == -1 and dataframe.page_layout == "vertical" }} <!-- expand if target in vertical layout -->
></span>
<div class="container-detail-assoc">
<div class="text-large-bold">NUMERICAL ASSOCIATIONS</div>
<div class="text-small-bold color-light" style="line-height: 10px">
Expand All @@ -41,8 +42,7 @@
{% for item in numerical %}
<div class="{{ 'assoc-row-target' if item[2] else 'assoc-row' }} {{ loop.cycle('', 'row-colored') }}" {{ 'style="font-weight: bold;"' if (item[1] > general.association_min_to_bold) or (item[1] < -general.association_min_to_bold) }}>
<div class="pos-assoc-row__label text-label">{{ item[0] }}</div>
<div class="pos-assoc-row__source text-label
{{ "color-red" if item[1] < 0.0 else "color-source" }}">{{ item[1]|fmt_assoc }}</div>
<div class="pos-assoc-row__source text-label {{ "color-red" if item[1] < 0.0 else "color-source" }}">{{ item[1]|fmt_assoc }}</div>
</div>
{% endfor %}
<br>
Expand All @@ -68,7 +68,7 @@
<hr>
{% for item in feature_dict.detail.frequent_values[:layout.num_detail_max_listed_values] %}
<div class="assoc-row {{ loop.cycle('', 'row-colored') }}">
<div class="pos-assoc-row__label text-label pos-detail-num-label">{{ item[0] }}</div>
<div class="pos-num-detail-row__label text-label pos-detail-num-label">{{ item[0] }}</div>
<div class="pos-detail-num-source-pair color-source text-value">
<div class="pos-detail-num-pair-pos__num dim">{{ item[1].number|fmt_int_limit }}</div>
<div class="pos-detail-num-pair-pos__perc">{{ item[1].perc|fmt_percent1d }}</div>
Expand All @@ -92,7 +92,7 @@
<hr>
{% for item in feature_dict.detail.min_values[:layout.num_detail_max_listed_values] %}
<div class="assoc-row {{ loop.cycle('', 'row-colored') }}">
<div class="pos-assoc-row__label text-label pos-detail-num-label">{{ item[0] }}</div>
<div class="pos-num-detail-row__label text-label pos-detail-num-label">{{ item[0] }}</div>
<div class="pos-detail-num-source-pair color-source text-value">
<div class="pos-detail-num-pair-pos__num dim">{{ item[1].number|fmt_int_limit }}</div>
<div class="pos-detail-num-pair-pos__perc">{{ item[1].perc|fmt_percent1d }}</div>
Expand All @@ -116,7 +116,7 @@
<hr>
{% for item in feature_dict.detail.max_values[:layout.num_detail_max_listed_values] %}
<div class="assoc-row {{ loop.cycle('', 'row-colored') }}">
<div class="pos-assoc-row__label text-label pos-detail-num-label">{{ item[0] }}</div>
<div class="pos-num-detail-row__label text-label pos-detail-num-label">{{ item[0] }}</div>
<div class="pos-detail-num-source-pair color-source text-value">
<div class="pos-detail-num-pair-pos__num dim">{{ item[1].number|fmt_int_limit }}</div>
<div class="pos-detail-num-pair-pos__perc">{{ item[1].perc|fmt_percent1d }}</div>
Expand Down
29 changes: 23 additions & 6 deletions sweetviz/templates/js/sweetviz.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ function hideAllDetails()
$(".container-feature-detail").hide();
$(".container-df-associations").hide();
$("span.bg-tab-summary-rollover").hide();
$("#button-summary-associations-source, #button-summary-associations-compare").removeClass("button-assoc-selected");
$("#button-summary-associations-source, #button-summary-associations-compare").addClass("button-assoc");
}


Expand Down Expand Up @@ -73,6 +75,10 @@ function(event) {
// EVENT: SUMMARY CLICK
// $(".container-feature-summary, .container-feature-summary-target").click(function(event) {
$(".selector").click(function(event) {
// No matter what, we should deselect the associations buttons
$("#button-summary-associations-source, #button-summary-associations-compare").removeClass("button-assoc-selected");
$("#button-summary-associations-source, #button-summary-associations-compare").addClass("button-assoc");

// alert($(this).parent().attr('id'));
let this_to_snap=$(this).parent().attr('id');

Expand Down Expand Up @@ -136,9 +142,11 @@ function fix_scroll() {
$(window).on('scroll',fix_scroll);
*/

// ---------------------------------------------------------------------------------------------------------------------------
// SPECIFIC BUTTONS
// ---------------------------------------------------------------------------------------------------------------------------
// SUMMARY: ASSOCIATIONS
// SUMMARY: ASSOCIATIONS -> HOVER
// --------------------------------------------------------
$("#button-summary-associations-source, #button-summary-associations-compare").hover(
// ENTER function
function()
Expand All @@ -160,33 +168,42 @@ $("#button-summary-associations-source, #button-summary-associations-compare").h
hideAllDetails();
}
});
// ASSOCIATIONS CLICK

// SUMMARY: ASSOCIATIONS -> CLICK
// --------------------------------------------------------
$("#button-summary-associations-source, #button-summary-associations-compare").click(function(event) {
// Quick hack: just remove the selected state to both buttons and restore if needed
$("#button-summary-associations-source, #button-summary-associations-compare").removeClass("button-assoc-selected");
$("#button-summary-associations-source, #button-summary-associations-compare").addClass("button-assoc");
let this_to_snap=this.id;
if(g_snapped == this_to_snap)
{
// "Unselect"
// DESELECT/HIDE ASSOC
// --------------------------------------------------------
g_snapped = "";
}
else if(g_snapped=="")
{
// "Select"
// SELECT/SHOW ASSOC (Hide other one if already shown)
// --------------------------------------------------------
//$(".container-feature-detail").hide();
//alert("#" + this.id+" GS:"+g_snapped);
//$("#df-assoc").show();
g_snapped = this.id;
$(this).addClass("button-assoc-selected");
}
else
{
// "Select" while another was previously selected
// SWAP to OTHER ASSOC: DESELECT old, select new
// --------------------------------------------------------
$("#" + $("#"+g_snapped).children().data("rollover-span")).removeClass("bg-tab-summary-rollover-locked");
$("#" + $("#"+g_snapped).children().data("rollover-span")).addClass("bg-tab-summary-rollover");
hideAllDetails();
$(this).addClass("button-assoc-selected");
g_snapped = this.id;
$("#" + $(this).data("detail-div")).show();
}
// $(this).addClass("assoc_active");

});


Expand Down
4 changes: 1 addition & 3 deletions sweetviz/templates/js/sweetviz_vertical.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ $("#button-summary-associations-source, #button-summary-associations-compare").c
}
else if(g_snapped == "")
{
// SELECT/SHOW ASSOC (Hide other one if already shown)
// SELECT/SHOW ASSOC
// --------------------------------------------------------
g_snapped = actual_div;
$(actual_div).show();
Expand All @@ -220,8 +220,6 @@ $("#button-summary-associations-source, #button-summary-associations-compare").c
{
// SWAP to OTHER ASSOC: DESELECT old, select new
// --------------------------------------------------------
$(g_snapped).removeClass("button-assoc-selected");
$(g_snapped).addClass("button-assoc");
$(g_snapped).hide();
g_snapped = actual_div;
$(this).addClass("button-assoc-selected");
Expand Down
17 changes: 12 additions & 5 deletions sweetviz/templates/sweetviz.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e73f9d3

Please sign in to comment.