<commit_before># parent class of all splice objects in splice_objs.py

# imports
import json
import itertools
import plotly.graph_objs as go
from splicers import * # FIX THIS!
from colors import *

class Splice(object):
    
    def __init__(self, df, plot_func, x, y, slice_by=None, idx=None, hover_text=None, 
                 color=None, group_legend=True, **kwargs):
        
        # instantiate parameters to class attributes
        self.df = df
        self.plot_func = plot_func
        self.x = x
        self.y = y
        self.slice_by = slice_by
        self.idx = idx
        self.hover_text = hover_text
        self.kwargs = {k:v for k,v in kwargs.iteritems()}
        
        # build traces
        self.traces = spliced_traces(
            df=self.df,
            plot_func=self.plot_func,
            x=self.x, 
            y=self.y, 
            slice_by=self.slice_by,
            idx=self.idx,
            hover_text=self.hover_text,
            **self.kwargs)
        
        # get slices
        self.slices = None
        if self.slice_by:
            self.slices = list(self._get_slices())
        
        # flat ui colors
        self.colors = get_color_blob()
        self.color_map = make_rgba_color_map(self.slices, seed=111)
        
        # update trace colors with flat ui, group and format legend
        self._update_trace_attrs()
        
        # initialize layout and figure
        self._set_layout() 
        self._set_figure()
        
        
    def _set_layout(self):
        '''creates layout object
        '''
        
        # instantiate layout object
        self.layout = go.Layout()
        
        # remove legend gaps
        self.layout.update({'legend': {'tracegroupgap':0}})
    
    
    def _set_figure(self):
        
        # instantiate figure object
        self.figure = make_figure(self.traces)
        
        # update figure with layout if it has been instantiated
        self.figure.update({'layout': self.layout})
            
    
    def update_layout(self, **kwargs):
        
        self.layout.update(**kwargs)
    
    
    def update_figure(self, **kwargs):
        
        self.figure.update(**kwargs)
    
    
    def subplots(self, cols=None, ordering=None, **kwargs):
        '''makes subplots for each val in traces.keys()
        
        Parameters
        ----------
        cols     : (int) number of columns in the array of subplots
        ordering : (list) complete list of idx values, the order of which determines the 
                   order (left to right, top to bottom) the subplots will be displayed
        **kwargs : plotly.tools.make_subplots keyword arguments
        
        Returns
        -------
        plotly Figure with subplot data, and layout object matched to the state of 
        self.layout at runtime
        '''
        
        fig = make_subplots(
            traces=self.traces, cols=cols, ordering=ordering, **kwargs)
        
        # make sure current layout is
        for k, v in self.layout.items():
            if k not in fig['layout'].keys():
                fig['layout'][k] = v
        return fig


    def buttons(self, **kwargs):
        '''makes a figure with a dropdown menu<commit_msg>default subplots method to pass shared_xaxes=True and shared_yaxes=True to plotly subplots builder<commit_after># parent class of all splice objects in splice_objs.py

# imports
import json
import itertools
import plotly.graph_objs as go
from splicers import * # FIX THIS!
from colors import *

class Splice(object):
    
    def __init__(self, df, plot_func, x, y, slice_by=None, idx=None, hover_text=None, 
                 color=None, group_legend=True, **kwargs):
        
        # instantiate parameters to class attributes
        self.df = df
        self.plot_func = plot_func
        self.x = x
        self.y = y
        self.slice_by = slice_by
        self.idx = idx
        self.hover_text = hover_text
        self.kwargs = {k:v for k,v in kwargs.iteritems()}
        
        # build traces
        self.traces = spliced_traces(
            df=self.df,
            plot_func=self.plot_func,
            x=self.x, 
            y=self.y, 
            slice_by=self.slice_by,
            idx=self.idx,
            hover_text=self.hover_text,
            **self.kwargs)
        
        # get slices
        self.slices = None
        if self.slice_by:
            self.slices = list(self._get_slices())
        
        # flat ui colors
        self.colors = get_color_blob()
        self.color_map = make_rgba_color_map(self.slices, seed=111)
        
        # update trace colors with flat ui, group and format legend
        self._update_trace_attrs()
        
        # initialize layout and figure
        self._set_layout() 
        self._set_figure()
        
        
    def _set_layout(self):
        '''creates layout object
        '''
        
        # instantiate layout object
        self.layout = go.Layout()
        
        # remove legend gaps
        self.layout.update({'legend': {'tracegroupgap':0}})
    
    
    def _set_figure(self):
        
        # instantiate figure object
        self.figure = make_figure(self.traces)
        
        # update figure with layout if it has been instantiated
        self.figure.update({'layout': self.layout})
            
    
    def update_layout(self, **kwargs):
        
        self.layout.update(**kwargs)
    
    
    def update_figure(self, **kwargs):
        
        self.figure.update(**kwargs)
    
    
    def subplots(self, cols=None, ordering=None, **kwargs):
        '''makes subplots for each val in traces.keys()
        
        Parameters
        ----------
        cols     : (int) number of columns in the array of subplots
        ordering : (list) complete list of idx values, the order of which determines the 
                   order (left to right, top to bottom) the subplots will be displayed
        **kwargs : plotly.tools.make_subplots keyword arguments
        
        Returns
        -------
        plotly Figure with subplot data, and layout object matched to the state of 
        self.layout at runtime
        '''
        
        fig = make_subplots(
            traces=self.traces, cols=cols, ordering=ordering, 
            shared_xaxes=True, shared_xaxes=True, **kwargs)
        
        # make sure current layout is
        for k, v in self.layout.items():
            if k not in fig['layout'].keys():
                fig['layout'][k] = v
        return fig


    def buttons(self, **kwargs):
        '''makes a figure with a dropdown menu
{'fraction_non_alphanumeric': 0.08956127080181543, 'fraction_numerical': 0.001210287443267776, 'mean_word_length': 1.7194570135746607, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1599644', 'n_tokens_mistral': 1908, 'n_tokens_neox': 1834, 'n_words': 522}