# -*- coding: utf-8 -*- ########################################################################################## # @author Rodrigo Botafogo # # Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify, # and distribute this software and its documentation, without fee and without a signed # licensing agreement, is hereby granted, provided that the above copyright notice, this # paragraph and the following two paragraphs appear in all copies, modifications, and # distributions. # # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, # OR MODIFICATIONS. ########################################################################################## #========================================================================================== # #========================================================================================== class Sol module BaseChart #------------------------------------------------------------------------------------ # Base Mixin # Set or get the height attribute of a chart. The height is applied to the SVG element # generated by the chart when rendered (or rerendered). If a value is given, then it # will be used to calculate the new height and the chart returned for method chaining. # The value can either be a numeric, a function, or falsy. If no value is specified # then the value of the current height attribute will be returned. # # By default, without an explicit height being given, the chart will select the width # of its anchor element. If that isn't possible it defaults to 200. Setting the value # falsy will return the chart to the default behavior #------------------------------------------------------------------------------------ def height(val = nil) return @properties["height"] if !val @properties["height"] = val return self end #------------------------------------------------------------------------------------ # Base Mixin # Set the data callback or retrieve the chart's data set. The data callback is passed # the chart's group and by default will return group.all(). This behavior may be # modified to, for instance, return only the top 5 groups: #------------------------------------------------------------------------------------ def data end #------------------------------------------------------------------------------------ # Base Mixin # Set or get the dimension attribute of a chart. In dc a dimension can be any valid # crossfilter dimension. # If a value is given, then it will be used as the new dimension. If no value is # specified then the current dimension will be returned. #------------------------------------------------------------------------------------ def dimension(val = nil) return @properties["dimension"] if !val @properties["dimension"] = val return self end #------------------------------------------------------------------------------------ # #------------------------------------------------------------------------------------ def grouped? @group != nil end #------------------------------------------------------------------------------------ # Base Mixin # Set or get the group attribute of a chart. In dc a group is a crossfilter group. # Usually the group should be created from the particular dimension associated with the # same chart. If a value is given, then it will be used as the new group. # # If no value specified then the current group will be returned. If name is specified # then it will be used to generate legend label. #------------------------------------------------------------------------------------ def group(method, name = nil) @group_name = @name.downcase + "Group" @group = "var #{@group_name} = #{@dim}.group().#{Sol.camelcase(method.to_s)}(function(d) {return d[\"#{@y_column}\"];});" @properties["group"] = @group_name return self end #------------------------------------------------------------------------------------ # Base Mixin # Set or get the minimum width attribute of a chart. This only applicable if the width # is calculated by dc. #------------------------------------------------------------------------------------ def min_width end #------------------------------------------------------------------------------------ # Base Mixin # Set or get the minimum height attribute of a chart. This only applicable if the width # is calculated by dc. #------------------------------------------------------------------------------------ def min_height end #------------------------------------------------------------------------------------ # Set or get the animation transition duration(in milliseconds) for this chart instance. # Default duration is 750ms. #------------------------------------------------------------------------------------ def transition_duration(val = nil) return @properties["transitionDuration"] if !val @properties["transitionDuration"] = val return self end #------------------------------------------------------------------------------------ # Base Mixin # Set or get the width attribute of a chart. See .height for further description of # the behavior. #------------------------------------------------------------------------------------ def width(val = nil) return @properties["width"] if !val @properties["width"] = val return self end end end