Commit 9640bcff authored by Sanjay Yadav's avatar Sanjay Yadav

ENH: Made changes in calendarmap and charts.

parent bd9205c4
Pipeline #32328 passed with stage
in 1 minute and 11 seconds
......@@ -370,18 +370,11 @@ def chart(shape, spec, data):
stacked_or_line = {
'AREA', 'AREA_STACKED', 'AREA_STACKED_100', 'BAR_CLUSTERED',
'BAR_OF_PIE', 'BAR_STACKED', 'BAR_STACKED_100', 'COLUMN_CLUSTERED',
'COLUMN_STACKED', 'COLUMN_STACKED_100', 'CONE_BAR_CLUSTERED',
'CONE_BAR_STACKED', 'CONE_BAR_STACKED_100', 'CONE_COL',
'CONE_COL_CLUSTERED', 'CONE_COL_STACKED', 'CONE_COL_STACKED_100',
'CYLINDER_BAR_CLUSTERED', 'CYLINDER_BAR_STACKED',
'CYLINDER_BAR_STACKED_100', 'CYLINDER_COL', 'CYLINDER_COL_CLUSTERED',
'CYLINDER_COL_STACKED', 'CYLINDER_COL_STACKED_100', 'LINE',
'COLUMN_STACKED', 'COLUMN_STACKED_100', 'LINE',
'LINE_MARKERS', 'LINE_MARKERS_STACKED', 'LINE_MARKERS_STACKED_100',
'LINE_STACKED', 'LINE_STACKED_100', 'PYRAMID_BAR_CLUSTERED',
'PYRAMID_BAR_STACKED', 'PYRAMID_BAR_STACKED_100', 'PYRAMID_COL',
'PYRAMID_COL_CLUSTERED', 'PYRAMID_COL_STACKED', 'RADAR_MARKERS',
'PYRAMID_COL_STACKED_100', 'RADAR', 'RADAR_FILLED', 'PIE',
'PIE_EXPLODED', 'PIE_OF_PIE', 'DOUGHNUT'}
'LINE_STACKED', 'LINE_STACKED_100', 'RADAR_MARKERS',
'RADAR', 'RADAR_FILLED', 'PIE', 'PIE_EXPLODED', 'PIE_OF_PIE',
'DOUGHNUT', 'DOUGHNUT_EXPLODED'}
xy_charts = {
'XY_SCATTER', 'XY_SCATTER_LINES', 'XY_SCATTER_LINES_NO_MARKERS',
......@@ -647,17 +640,27 @@ def calendarmap(shape, spec, data):
default_color = '#ffffff'
default_line_color = '#787C74'
default_txt_color = '#000000'
font_size = spec.get('style', {}).get('font-size', 12)
stroke = spec.get('style', {}).get('stroke', '#ffffff')
fill_rect = spec.get('style', {}).get('fill', '#cccccc')
text_color = spec.get('style', {}).get('color', '#000000')
style = spec.get('style', {})
for key, value in style.items():
if isinstance(value, (dict,)) and 'function' in value:
style[key] = compile_function(style, key, data, handler)
font_size = style.get('font-size', 12)
stroke = style.get('stroke', '#ffffff')
fill_rect = style.get('fill', '#cccccc')
text_color = style.get('color', '#000000')
# Treat infinities as nans when calculating scale
scaledata = pd.Series(data).replace([pd.np.inf, -pd.np.inf], pd.np.nan)
for key in {'lo', 'hi', 'weekstart'}:
if isinstance(spec.get(key), (dict,)) and 'function' in spec.get(key):
spec[key] = compile_function(spec, key, data, handler)
lo_data = spec.get('lo', scaledata.min())
range_data = spec.get('hi', scaledata.max()) - lo_data
gradient = spec.get('gradient', _color.RdYlGn)
color = spec.get('color', lambda v: _color.gradient(
(float(v) - lo_data) / range_data, gradient) if not pd.isnull(v) else default_color)
gradient = matplotlib.cm.get_cmap(spec.get('gradient', 'RdYlGn'))
color = style.get('fill', lambda v: matplotlib.colors.to_hex(
gradient((float(v) - lo_data) / range_data)) if not pd.isnull(v) else default_color)
startweekday = (startdate.weekday() - spec.get('weekstart', 0)) % 7
# Weekday Mean and format
......@@ -680,22 +683,23 @@ def calendarmap(shape, spec, data):
d = startdate + datetime.timedelta(days=i)
fill = '#ffffff'
if not pd.isnull(val):
fill = color(val)
fill = color(val) if callable(color) else color
shp = shapes.add_shape(
MSO_SHAPE.RECTANGLE,
x0 + (width * nx) + (width - sizes[i]) / 2,
y0 + (width * ny) + (width - sizes[i]) / 2,
sizes[i], sizes[i])
rectstyle = {"fill": fill, 'stroke': stroke}
rectstyle = {"fill": fill, 'stroke': stroke(val) if callable(stroke) else stroke}
rect_css(shp, **rectstyle)
text_style = {}
text_style['color'] = _color.contrast(fill)
text_style['font-size'] = font_size
text_style['bold'] = spec.get('style', {}).get('bold')
text_style['italic'] = spec.get('style', {}).get('italic')
text_style['underline'] = spec.get('style', {}).get('underline')
text_style['font-family'] = spec.get('style', {}).get('font-family')
text_style['color'] = style.get('color')(val) if callable(
style.get('color')) else spec.get('color', _color.contrast(fill))
text_style['font-size'] = font_size(val) if callable(font_size) else font_size
text_style['bold'] = style.get('bold')
text_style['italic'] = style.get('italic')
text_style['underline'] = style.get('underline')
text_style['font-family'] = style.get('font-family')
add_text_to_shape(shp, '%02d' % d.day, **text_style)
# Draw the boundary lines between months
......@@ -735,10 +739,11 @@ def calendarmap(shape, spec, data):
px = x0 + (width * nx)
top_bar = shapes.add_shape(
MSO_SHAPE.RECTANGLE, px, shape_top - w, width, w)
rectstyle = {"fill": fill_rect, 'stroke': stroke}
rectstyle = {"fill": fill_rect(val) if callable(fill_rect) else fill_rect,
'stroke': stroke(val) if callable(stroke) else stroke}
rect_css(top_bar, **rectstyle)
top_txt = shapes.add_textbox(px, shape_top - width, width, width)
text_style['color'] = text_color
text_style['color'] = text_color(val) if callable(text_color) else text_color
add_text_to_shape(top_txt, weekly_format.format(weekly_mean[nx]), **text_style)
if label_left:
......@@ -749,10 +754,11 @@ def calendarmap(shape, spec, data):
w = label_left * ((val - lo_weekday) / range_weekday)
bar = shapes.add_shape(
MSO_SHAPE.RECTANGLE, shape_left - w, y0 + (width * ny), w, width)
rectstyle = {"fill": fill_rect, 'stroke': stroke}
rectstyle = {"fill": fill_rect(val) if callable(fill_rect) else fill_rect,
'stroke': stroke(val) if callable(stroke) else stroke}
rect_css(bar, **rectstyle)
left_txt = shapes.add_textbox(shape_left - width, y0 + (width * ny), w, width)
text_style['color'] = text_color
text_style['color'] = text_color(val) if callable(text_color) else text_color
add_text_to_shape(left_txt, weekday_format.format(weekday_mean[ny]), **text_style)
......@@ -778,7 +784,7 @@ def bullet(shape, spec, data):
# if isinstance(spec['data'], (dict,)) and 'function' in spec['data']:
spec['data'] = compile_function(spec, 'data', data, handler)
gradient = spec.get('gradient', 'Greys')
gradient = spec.get('gradient', 'RdYlGn')
# if isinstance(gradient, (dict,)) and 'function' in gradient:
# gradient = compile_function(spec, 'gradient', data, handler)
shapes = shape._parent
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment