Beispiel #1
0
    def build_html_details(self, xml=None, ):

        if xml is None:
            xml = xmlwitch.Builder(version='1.0', encoding='utf-8')


        with xml.div():
            with xml.h1():
                with xml.a(name=self.short_filename):
                    #xml.write_escaped(self.filename)
                    xml.write_escaped(self.short_filename)

            with xml.image(src=self.full_filename):
                pass

            #for each element type: g, path, text, etc
            for (element,attrs) in sorted(self.svg_data.all_styles.items()):
                with xml.table():

                    # for each style type (color, fill, etc):
                    for (attr,vals) in sorted(attrs.items()):

                        # Print each values
                        for i,val in enumerate(vals):
                            with xml.tr():
                                xml.td( element if i==0 else '' )
                                xml.td( attr )
                                xml.td(val)

            xml.write_escaped( str(','.join(self.svg_data.transforms) ) )

        return  xml
Beispiel #2
0
    def build_summary_table(self, xml):

        all_styles = collections.defaultdict( partial(collections.defaultdict, partial(collections.defaultdict,set ) ) )

        for svgfile in self.svgfiles:
            for (element, data) in svgfile.svg_data.all_styles.items():
                for (prop, values) in data.items():
                    for value in values:
                        all_styles[element][prop][value].add(svgfile)


        xml.h1('Summary')
        with xml.table():

            for element in sorted(all_styles):
                for prop in sorted(all_styles[element]):
                    for value in sorted(all_styles[element][prop]):

                        with xml.tr():

                            kwargs = {}
                            if value.startswith('#'):
                                kwargs['bgcolor'] = value

                            xml.td( element  )
                            xml.td( prop  )
                            xml.td( value, **kwargs )
                            svgfiles= sorted(all_styles[element][prop][value])
                            with xml.td():
                                xml.write( ','.join( ['<a href="#%s">%s</a>' % ( svgfile.short_filename, svgfile.short_filename) for svgfile in  svgfiles]) )


                        #for i,svgfile in enumerate(sorted(all_styles[element][prop][value])):
                        #        with xml.tr():

                        #            kwargs = {}
                        #            if value.startswith('#'):
                        #                kwargs['bgcolor'] = value

                        #            xml.td( element if i==0 else '' )
                        #            xml.td( prop if i==0 else '' )
                        #            xml.td( value if i==0 else '', **kwargs )
                        #            xml.td( svgfile.short_filename )



        #['node']['property'] -> ['file1','file2','file3'...]

        from matplotlib.colors import ColorConverter
        #pass
        #colors = set()

        import numpy as np
        import matplotlib.pyplot as plt
        from mpl_toolkits.mplot3d import Axes3D
        #from mpl_toolkits.mplot3d import Axes3D

        fig = plt.figure()
        ax = fig.add_subplot(111, projection='3d')


        for element in sorted(all_styles):
            for prop in sorted(all_styles[element]):
                for value in sorted(all_styles[element][prop]):
                    if value.startswith('#'):
                        files = all_styles[element][prop][value]
                        s = float(len(files)) * 3

                        colors = np.array( ColorConverter().to_rgb(value) ) 
                        colors = colors.reshape( (1,3))
                        print colors
                        print colors.shape
                        l = ax.scatter(colors[:,0], colors[:,1], colors[:,2], c=colors, s=s, picker=5)
                        l.src_color = value
                        l.src_files = files





        def onpick(event):
            print 'On event', event, event.artist
            l = event.artist
            print l.src_color
            print [ f.filename for f in l.src_files]
        fig.canvas.mpl_connect('pick_event', onpick)

        plt.show()