def features_visualization(features): ''' features - a dictionary of track features prints a bar chart of selected features (on the same scale of 0-1) ''' feature_dict = copy.deepcopy(features) # exclude some features for feature in [ 'time_signature', 'mode', 'loudness', 'key', 'tempo', 'duration_ms', 'analysis_url', 'id', 'track_href', 'type', 'uri' ]: del feature_dict[feature] # customize chart style custom_style = Style(background='rgba(253, 247, 246, 0.4)', plot_background='rgba(249, 228, 225, 1)', foreground='rgba(0, 0, 0, 0.9)', foreground_strong='rgba(0, 0, 0, 0.9)', foreground_subtle='rgba(0, 0, 0, 0.5)', opacity='.6', opacity_hover='.9', colors=('#d94e4c', '#e5884f', '#39929a', lighten('#d94e4c', 10), darken('#39929a', 15), lighten('#e5884f', 17), darken('#d94e4c', 10), '#234547')) # create chart chart = pygal.HorizontalBar(style=custom_style) chart.title = 'Track Features' for feature, value in feature_dict.items(): chart.add(feature, value) chart.render() return chart.render_data_uri()
class DarkGreenStyle(Style): """A dark green style""" background = darken('#251e01', 3) plot_background = darken('#251e01', 1) foreground = 'rgba(255, 255, 255, 0.9)' foreground_strong = 'rgba(255, 255, 255, 0.9)' foreground_subtle = 'rgba(255, 255, 255, 0.6)' opacity = '.6' opacity_hover = '.9' transition = '250ms ease-in' colors = ('#adde09', '#6e8c06', '#4a5e04', '#fcd202', '#C1E34D', lighten('#fcd202', 25))
class TurquoiseStyle(Style): """A turquoise style""" background = darken('#1b8088', 15) plot_background = darken('#1b8088', 17) foreground = 'rgba(255, 255, 255, 0.9)' foreground_strong = 'rgba(255, 255, 255, 0.9)' foreground_subtle = 'rgba(255, 255 , 255, 0.5)' opacity = '.5' opacity_hover = '.9' transition = '250ms ease-in' colors = ('#93d2d9', '#ef940f', '#8C6243', '#fff', darken('#93d2d9', 20), lighten('#ef940f', 15), lighten('#8c6243', 15), '#1b8088')
class RedBlueStyle(Style): """A red and blue theme""" background = lighten('#e6e7e9', 7) plot_background = lighten('#e6e7e9', 10) foreground = 'rgba(0, 0, 0, 0.9)' foreground_strong = 'rgba(0, 0, 0, 0.9)' foreground_subtle = 'rgba(0, 0, 0, 0.5)' opacity = '.6' opacity_hover = '.9' colors = ('#d94e4c', '#e5884f', '#39929a', lighten('#d94e4c', 10), darken('#39929a', 15), lighten('#e5884f', 17), darken('#d94e4c', 10), '#234547')
class DarkGreenBlueStyle(Style): """A dark green and blue style""" background = '#000' plot_background = lighten('#000', 8) foreground = 'rgba(255, 255, 255, 0.9)' foreground_strong = 'rgba(255, 255, 255, 0.9)' foreground_subtle = 'rgba(255, 255, 255, 0.6)' opacity = '.55' opacity_hover = '.9' transition = '250ms ease-in' colors = (lighten('#34B8F7', 15), '#7dcf30', '#247fab', darken('#7dcf30', 10), lighten('#247fab', 10), lighten('#7dcf30', 10), darken('#247fab', 10), '#fff')
class LightGreenStyle(Style): """A light green style""" background = lighten('#f3f3f3', 3) plot_background = '#fff' foreground = '#333333' foreground_strong = '#666' foreground_subtle = '#222222' opacity = '.5' opacity_hover = '.9' transition = '250ms ease-in' colors = ('#7dcf30', '#247fab', lighten('#7dcf30', 10), '#ccc', darken('#7dcf30', 15), '#ddd', lighten('#247fab', 10), darken('#247fab', 15))
class BlueStyle(Style): """A blue style""" background = darken('#f8f8f8', 3) plot_background = '#f8f8f8' foreground = 'rgba(0, 0, 0, 0.9)' foreground_strong = 'rgba(0, 0, 0, 0.9)' foreground_subtle = 'rgba(0, 0, 0, 0.6)' opacity = '.5' opacity_hover = '.9' transition = '250ms ease-in' colors = ('#00b2f0', '#43d9be', '#0662ab', darken('#00b2f0', 20), lighten('#43d9be', 20), lighten('#7dcf30', 10), darken('#0662ab', 15), '#ffd541', '#7dcf30', lighten('#00b2f0', 15), darken('#ffd541', 20))
class DarkColorizedStyle(Style): """A dark colorized style""" background = darken('#3a2d3f', 5) plot_background = lighten('#3a2d3f', 2) foreground = 'rgba(255, 255, 255, 0.9)' foreground_strong = 'rgba(255, 255, 255, 0.9)' foreground_subtle = 'rgba(255, 255 , 255, 0.5)' opacity = '.2' opacity_hover = '.7' transition = '250ms ease-in' colors = ('#c900fe', '#01b8fe', '#59f500', '#ff00e4', '#f9fa00', darken('#c900fe', 20), darken('#01b8fe', 15), darken('#59f500', 20), darken('#ff00e4', 15), lighten('#f9fa00', 20))
def get_colors(self, prefix, len_): """Get the css color list""" def color(tupl): """Make a color css""" return (( '%s.color-{0}, %s.color-{0} a:visited {{\n' ' stroke: {1};\n' ' fill: {1};\n' '}}\n' ) % (prefix, prefix)).format(*tupl) def value_color(tupl): """Make a value color css""" return (( '%s .text-overlay .color-{0} text {{\n' ' fill: {1};\n' '}}\n' ) % (prefix, )).format(*tupl) def ci_color(tupl): """Make a value color css""" if not tupl[1]: return '' return (('%s .color-{0} .ci {{\n' ' stroke: {1};\n' '}}\n') % (prefix, )).format(*tupl) if len(self.colors) < len_: missing = len_ - len(self.colors) cycles = 1 + missing // len(self.colors) colors = [] for i in range(0, cycles + 1): for color_ in self.colors: colors.append(darken(color_, 33 * i / cycles)) if len(colors) >= len_: break else: continue break else: colors = self.colors[:len_] # Auto compute foreground value color when color is missing value_colors = [] for i in range(len_): if i < len(self.value_colors) and self.value_colors[i] is not None: value_colors.append(self.value_colors[i]) else: value_colors.append( 'white' if is_foreground_light(colors[i]) else 'black' ) return '\n'.join( chain( map(color, enumerate(colors)), map(value_color, enumerate(value_colors)), map(ci_color, enumerate(self.ci_colors)) ) )
class LightColorizedStyle(Style): """A light colorized style""" background = '#f8f8f8' plot_background = lighten('#f8f8f8', 3) foreground = '#333' foreground_strong = '#666' foreground_subtle = 'rgba(0, 0 , 0, 0.5)' opacity = '.5' opacity_hover = '.9' transition = '250ms ease-in' colors = ('#fe9592', '#534f4c', '#3ac2c0', '#a2a7a1', darken('#fe9592', 15), lighten('#534f4c', 15), lighten('#3ac2c0', 15), lighten('#a2a7a1', 15), lighten('#fe9592', 15), darken('#3ac2c0', 10))
def test_darken(): assert darken('#800', 20) == '#220000' assert darken('#800', 0) == '#880000' assert darken('#ffffff', 10) == '#e6e6e6' assert darken('#000000', 10) == '#000000' assert darken('#f3148a', 25) == '#810747' assert darken('#121212', 1) == '#0f0f0f' assert darken('#999999', 100) == '#000000' assert darken('#1479ac', 8) == '#105f87'
def __init__(self): mystyle = Style( #background=darken('#f8f8f8', 3), background='white', plot_background='white', foreground='rgba(0, 0, 0, 0.9)', foreground_light='rgba(0, 0, 0, 0.9)', foreground_dark='rgba(0, 0, 0, 0.6)', opacity='.5', opacity_hover='.9', transition='250ms ease-in', colors=('#00b2f0', '#43d9be', '#0662ab', darken('#00b2f0', 20), lighten('#43d9be', 20), lighten('#7dcf30', 10), darken('#0662ab', 15), '#ffd541', '#7dcf30', lighten('#00b2f0', 15), darken('#ffd541', 20))) self.tmpDir = tempfile.mkdtemp() self.config = pygal.Config(style=mystyle, legend_font_size=10, width=500, height=250)
def __init__(self): mystyle = Style( #background=darken('#f8f8f8', 3), background='white', plot_background='white', foreground='rgba(0, 0, 0, 0.9)', foreground_light='rgba(0, 0, 0, 0.9)', foreground_dark='rgba(0, 0, 0, 0.6)', opacity='.5', opacity_hover='.9', transition='250ms ease-in', colors=('#00b2f0', '#43d9be', '#0662ab', darken('#00b2f0', 20),lighten('#43d9be', 20), lighten('#7dcf30', 10), darken('#0662ab', 15), '#ffd541', '#7dcf30', lighten('#00b2f0', 15), darken('#ffd541', 20)) ) self.tmpDir = tempfile.mkdtemp() self.config = pygal.Config(style=mystyle, legend_font_size=10, width=500,height=250)
opacity_hover='.9', transition='500ms ease-in', colors=solarized_colors) RedBlueStyle = Style( background=lighten('#e6e7e9', 7), plot_background=lighten('#e6e7e9', 10), foreground='rgba(0, 0, 0, 0.9)', foreground_light='rgba(0, 0, 0, 0.9)', foreground_dark='rgba(0, 0, 0, 0.5)', opacity='.6', opacity_hover='.9', colors=( '#d94e4c', '#e5884f', '#39929a', lighten('#d94e4c', 10), darken('#39929a', 15), lighten('#e5884f', 17), darken('#d94e4c', 10), '#234547')) LightColorizedStyle = Style( background='#f8f8f8', plot_background=lighten('#f8f8f8', 3), foreground='#333', foreground_light='#666', foreground_dark='rgba(0, 0 , 0, 0.5)', opacity='.5', opacity_hover='.9', transition='250ms ease-in', colors=( '#fe9592', '#534f4c', '#3ac2c0', '#a2a7a1', darken('#fe9592', 15), lighten('#534f4c', 15), lighten('#3ac2c0', 15),
def test_darken(): """Test darken color function""" assert darken('#800', 20) == '#200' assert darken('#800e', 20) == '#200e' assert darken('#800', 0) == '#800' assert darken('#ffffff', 10) == '#e6e6e6' assert darken('#000000', 10) == '#000000' assert darken('#f3148a', 25) == '#810747' assert darken('#f3148aab', 25) == '#810747ab' assert darken('#121212', 1) == '#0f0f0f' assert darken('#999999', 100) == '#000000' assert darken('#99999999', 100) == '#00000099' assert darken('#1479ac', 8) == '#105f87' assert darken('rgb(136, 0, 0)', 20) == 'rgb(34, 0, 0)' assert darken('rgba(20, 121, 172, .13)', 8) == 'rgba(16, 95, 135, 0.13)'
from django.core.servers.basehttp import FileWrapper from django.core.urlresolvers import reverse from elearning.core.errors.views import server_error from .forms import CourseForm from datetime import datetime from pygal.style import Style from pygal.colors import darken from pygal.config import Config import json import pygal import requests import urlparse import tempfile custom_style = Style( background=darken('#f8f8f8', 3), plot_background='#f8f8f8', foreground='rgba(0, 0, 0, 0.9)', foreground_light='rgba(0, 0, 0, 0.9)', foreground_dark='rgba(0, 0, 0, 0.6)', opacity='.5', opacity_hover='.9', transition='250ms ease-in', colors=('#0ACF00','#0E51A7', '#FD0006', '#FF9E00')) question_style = Style( background=darken('#f8f8f8', 3), plot_background='#f8f8f8', foreground='rgba(0, 0, 0, 0.9)', foreground_light='rgba(0, 0, 0, 0.9)', foreground_dark='rgba(0, 0, 0, 0.6)',