material_raingular-d3 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/assets/javascripts/material_raingular/d3/.keep +0 -0
- data/lib/assets/javascripts/material_raingular/d3/bar/directive.coffee +8 -0
- data/lib/assets/javascripts/material_raingular/d3/bar/linkmodel.coffee +15 -0
- data/lib/assets/javascripts/material_raingular/d3/bar_chart/controller.coffee +34 -0
- data/lib/assets/javascripts/material_raingular/d3/bar_chart/directive.coffee +21 -0
- data/lib/assets/javascripts/material_raingular/d3/extensions.coffee +8 -0
- data/lib/assets/javascripts/material_raingular/d3/horizontal_bar_chart/controller.coffee +33 -0
- data/lib/assets/javascripts/material_raingular/d3/horizontal_bar_chart/directive.coffee +21 -0
- data/lib/assets/javascripts/material_raingular/d3/pie_chart/directive.coffee +7 -0
- data/lib/assets/javascripts/material_raingular/d3/pie_chart/linkmodel.coffee +39 -0
- data/lib/assets/javascripts/material_raingular/d3/ring_chart/directive.coffee +9 -0
- data/lib/assets/javascripts/material_raingular/d3/ring_chart/linkmodel.coffee +159 -0
- data/lib/assets/javascripts/material_raingular/d3/ring_chart/widget_controller.coffee +14 -0
- data/lib/assets/javascripts/material_raingular/d3/ring_chart/widget_directive.coffee +15 -0
- data/lib/assets/javascripts/material_raingular/d3/stacked_bar/controller.coffee +54 -0
- data/lib/assets/javascripts/material_raingular/d3/stacked_bar/directive.coffee +9 -0
- data/lib/assets/javascripts/material_raingular/d3/x_axis/directive.coffee +7 -0
- data/lib/assets/javascripts/material_raingular/d3/x_axis/linkmodel.coffee +25 -0
- data/lib/assets/javascripts/material_raingular/d3/y_axis/directive.coffee +7 -0
- data/lib/assets/javascripts/material_raingular/d3/y_axis/linkmodel.coffee +26 -0
- data/lib/assets/javascripts/material_raingular-d3.coffee +6 -0
- data/lib/assets/stylesheets/material_raingular/d3/barChart.sass +4 -0
- data/lib/assets/stylesheets/material_raingular/d3/ringWidget.css +51 -0
- data/lib/assets/stylesheets/material_raingular-d3.sass +2 -0
- data/lib/assets/templates/material_raingular/d3/ring_chart/ring.html +7 -0
- data/lib/assets/templates/material_raingular/d3/ring_chart/ringWidget.html +1 -0
- data/lib/material_raingular/d3/version.rb +5 -0
- data/lib/material_raingular/d3.rb +10 -0
- data/material_raingular-d3.gemspec +26 -0
- data/vendor/assets/javascripts/d3.min.js +8 -0
- metadata +124 -0
| @@ -0,0 +1,54 @@ | |
| 1 | 
            +
            class MaterialRaingular.d3.Directives.MrD3StackedBar extends AngularDirectiveModel
         | 
| 2 | 
            +
              @inject('$parse','$element')
         | 
| 3 | 
            +
              initialize: ->
         | 
| 4 | 
            +
                @parent  = @$element.parent().controller('mrD3BarChart')
         | 
| 5 | 
            +
                @direction = if @parent then 'vertical' else 'horizontal'
         | 
| 6 | 
            +
                @parent ?= @$element.parent().controller('mrD3HorizontalBarChart')
         | 
| 7 | 
            +
                @bar     = d3.select(@$element[0])
         | 
| 8 | 
            +
                @label   = @$parse @$element.attr('mr-d3-label')
         | 
| 9 | 
            +
                @$scope.$watch @label.bind(@), @adjustBars.bind(@)
         | 
| 10 | 
            +
                @$scope.$watch @size.bind(@),  @adjustBars.bind(@)
         | 
| 11 | 
            +
                @adjustBars()
         | 
| 12 | 
            +
              bars: -> @bar.selectAll('rect')
         | 
| 13 | 
            +
              size: -> if @direction == 'vertical' then @bar.attr('height') else @bar.attr('width')
         | 
| 14 | 
            +
              rawSize: -> (@bars().nodes().map (rect) => d3.select(rect).attr('raw-size')).sum()
         | 
| 15 | 
            +
              adjustBars: ->
         | 
| 16 | 
            +
                @bar.attr('raw-size',@rawSize() || 0)
         | 
| 17 | 
            +
                @bar.attr('label',   @label(@$scope))
         | 
| 18 | 
            +
                @parent.adjustBars()
         | 
| 19 | 
            +
                width  = @bar.attr('width')
         | 
| 20 | 
            +
                height = @bar.attr('height')
         | 
| 21 | 
            +
                x      = @bar.attr('x')
         | 
| 22 | 
            +
                y      = @bar.attr('y')
         | 
| 23 | 
            +
                usedSpace = 0
         | 
| 24 | 
            +
                key = @bar.node().$$hashKey?.replace(':','_') #TODO: Not Dependable
         | 
| 25 | 
            +
                @parent.holder.selectAll("text.bar.#{key}").remove()
         | 
| 26 | 
            +
                for rect,i in @bars().nodes()
         | 
| 27 | 
            +
                  bar = d3.select(rect)
         | 
| 28 | 
            +
                  bar.attr('class',"#{i} bar")
         | 
| 29 | 
            +
                  bar.attr('fill',"rgba(1,1,1,#{1 - (0.1 * i)})")
         | 
| 30 | 
            +
                  text = @parent.holder.append('text')
         | 
| 31 | 
            +
                  .style("text-anchor","middle")
         | 
| 32 | 
            +
                  .attr('class',"#{i} bar text #{key}")
         | 
| 33 | 
            +
                  .text(bar.attr('label'))
         | 
| 34 | 
            +
                  if @direction == 'vertical'
         | 
| 35 | 
            +
                    ratio = height / @bar.attr('raw-size')
         | 
| 36 | 
            +
                    barHeight = ratio * bar.attr('raw-size')
         | 
| 37 | 
            +
                    usedSpace += barHeight
         | 
| 38 | 
            +
                    bar.attr('x',x)
         | 
| 39 | 
            +
                    bar.attr('width',width)
         | 
| 40 | 
            +
                    bar.attr('y',@parent.height() - usedSpace)
         | 
| 41 | 
            +
                    bar.attr('height',barHeight)
         | 
| 42 | 
            +
                    text.attr('x', -parseFloat(bar.attr('y')) - parseFloat(bar.attr('height'))/2)
         | 
| 43 | 
            +
                    .attr('y',parseFloat(bar.attr('x')) + parseFloat(bar.attr('width')))
         | 
| 44 | 
            +
                    .attr('transform','rotate(-90)')
         | 
| 45 | 
            +
                  else
         | 
| 46 | 
            +
                    ratio = width / @bar.attr('raw-size')
         | 
| 47 | 
            +
                    barWidth = ratio * bar.attr('raw-size')
         | 
| 48 | 
            +
                    bar.attr('y',y)
         | 
| 49 | 
            +
                    bar.attr('height',height)
         | 
| 50 | 
            +
                    bar.attr('x',usedSpace)
         | 
| 51 | 
            +
                    bar.attr('width',barWidth)
         | 
| 52 | 
            +
                    usedSpace += barWidth
         | 
| 53 | 
            +
                    text.attr('x', parseFloat(bar.attr('width'))/2 + parseFloat(bar.attr('x')))
         | 
| 54 | 
            +
                    .attr('y',parseFloat(bar.attr('y')) + parseFloat(bar.attr('height')))
         | 
| @@ -0,0 +1,9 @@ | |
| 1 | 
            +
            # //= require material_raingular/d3/stacked_bar/controller
         | 
| 2 | 
            +
            class MaterialRaingular.d3.Directives.mrD3StackedBar extends AngularDirective
         | 
| 3 | 
            +
              @register(MaterialRaingular.d3.app)
         | 
| 4 | 
            +
              restrict: "E"
         | 
| 5 | 
            +
              require: ['?^^mrD3HorizontalBarChart','?^^mrD3BarChart']
         | 
| 6 | 
            +
              controller: MaterialRaingular.d3.Directives.MrD3StackedBar
         | 
| 7 | 
            +
              transclude: true
         | 
| 8 | 
            +
              replace: true
         | 
| 9 | 
            +
              template: "<g class='stacked bar' ng-transclude></rect>"
         | 
| @@ -0,0 +1,25 @@ | |
| 1 | 
            +
            class XAxisModel extends AngularLinkModel
         | 
| 2 | 
            +
              @inject('$parse')
         | 
| 3 | 
            +
              initialize: ->
         | 
| 4 | 
            +
                @parent = @$controller.compact()[0]
         | 
| 5 | 
            +
                @options = @parent.options
         | 
| 6 | 
            +
                @parent._xAxis = @axis = d3.select(@$element[0])
         | 
| 7 | 
            +
                @axis.attr('transform',"translate(0,#{@parent.height()})")
         | 
| 8 | 
            +
                @label  = @$parse @$attrs.mrD3Label
         | 
| 9 | 
            +
                @domain = @$parse @$attrs.mrD3Domain
         | 
| 10 | 
            +
                @$scope.$watchCollection @domain, @adjustAxis.bind(@)
         | 
| 11 | 
            +
                @$scope.$watch @label,  @adjustAxis.bind(@)
         | 
| 12 | 
            +
                @appendLabel()
         | 
| 13 | 
            +
                @adjustAxis(true)
         | 
| 14 | 
            +
              adjustAxis: (newVal,oldVal) ->
         | 
| 15 | 
            +
                return if newVal == oldVal
         | 
| 16 | 
            +
                @parent.xAxis.domain(@domain(@$scope)) if @domain(@$scope)
         | 
| 17 | 
            +
                @axis.call(d3.axisBottom(@parent.xAxis))
         | 
| 18 | 
            +
                @labelEl.text(@label(@$scope)) if @label(@$scope)
         | 
| 19 | 
            +
                @parent.adjustBars()
         | 
| 20 | 
            +
              appendLabel: ->
         | 
| 21 | 
            +
                @labelEl = @parent.holder.append('text')
         | 
| 22 | 
            +
                .attr('x', @parent.width()/2)
         | 
| 23 | 
            +
                .attr('y', @parent.height() + (@options.margins.bottom + 30) / 2)
         | 
| 24 | 
            +
                .style("text-anchor","middle")
         | 
| 25 | 
            +
              @register(MaterialRaingular.d3.Directives.MrD3XAxis)
         | 
| @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            class YAxisModel extends AngularLinkModel
         | 
| 2 | 
            +
              @inject('$parse')
         | 
| 3 | 
            +
              initialize: ->
         | 
| 4 | 
            +
                @parent = @$controller.compact()[0]
         | 
| 5 | 
            +
                @options = @parent.options
         | 
| 6 | 
            +
                @parent._yAxis = @axis = d3.select(@$element[0])
         | 
| 7 | 
            +
                @label  = @$parse @$attrs.mrD3Label
         | 
| 8 | 
            +
                @domain = @$parse @$attrs.mrD3Domain
         | 
| 9 | 
            +
                @$scope.$watchCollection @domain, @adjustAxis.bind(@)
         | 
| 10 | 
            +
                @$scope.$watch @label,  @adjustAxis.bind(@)
         | 
| 11 | 
            +
                @appendLabel()
         | 
| 12 | 
            +
                @adjustAxis(true)
         | 
| 13 | 
            +
              adjustAxis: (newVal,oldVal) ->
         | 
| 14 | 
            +
                return if newVal == oldVal
         | 
| 15 | 
            +
                @parent.yAxis.domain(@domain(@$scope)) if @domain(@$scope)
         | 
| 16 | 
            +
                @axis.call(d3.axisLeft(@parent.yAxis))
         | 
| 17 | 
            +
                @labelEl.text(@label(@$scope)) if @label(@$scope)
         | 
| 18 | 
            +
                @parent.adjustBars()
         | 
| 19 | 
            +
              appendLabel: ->
         | 
| 20 | 
            +
                @labelEl = @parent.holder.append('text')
         | 
| 21 | 
            +
                .attr("transform", "rotate(-90)")
         | 
| 22 | 
            +
                .attr("y", - (@options.margins.left + 30)/2)
         | 
| 23 | 
            +
                .attr("x",0 - (@parent.height() / 2))
         | 
| 24 | 
            +
                .attr("dy", "1em")
         | 
| 25 | 
            +
                .style("text-anchor", "middle")
         | 
| 26 | 
            +
              @register(MaterialRaingular.d3.Directives.MrD3YAxis)
         | 
| @@ -0,0 +1,51 @@ | |
| 1 | 
            +
            /******************************************************************************
         | 
| 2 | 
            +
              Styling for RingWidgetModule
         | 
| 3 | 
            +
            ******************************************************************************/
         | 
| 4 | 
            +
            mr-d3-ring-widget {
         | 
| 5 | 
            +
              text-align: center;
         | 
| 6 | 
            +
            }
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            mr-d3-ring {
         | 
| 9 | 
            +
              display: block;
         | 
| 10 | 
            +
            }
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            mr-d3-ring svg text {
         | 
| 13 | 
            +
              font-family: sans-serif;
         | 
| 14 | 
            +
              font-size: 12px;
         | 
| 15 | 
            +
              fill: white;
         | 
| 16 | 
            +
            }
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            mr-d3-ring svg text.center {
         | 
| 19 | 
            +
              font-family: sans-serif;
         | 
| 20 | 
            +
              font-size: 60px;
         | 
| 21 | 
            +
              fill: white;
         | 
| 22 | 
            +
              stroke: black;
         | 
| 23 | 
            +
              stroke-width: 2px;
         | 
| 24 | 
            +
              stroke-linecap: round;
         | 
| 25 | 
            +
              stroke-linejoin: round;
         | 
| 26 | 
            +
              text-anchor: middle;
         | 
| 27 | 
            +
              -webkit-touch-callout: none; /* iOS Safari */
         | 
| 28 | 
            +
                -webkit-user-select: none; /* Chrome/Safari/Opera */
         | 
| 29 | 
            +
                 -khtml-user-select: none; /* Konqueror */
         | 
| 30 | 
            +
                   -moz-user-select: none; /* Firefox */
         | 
| 31 | 
            +
                    -ms-user-select: none; /* Internet Explorer/Edge */
         | 
| 32 | 
            +
                        user-select: none;
         | 
| 33 | 
            +
            }
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            /*.mr-d3-ring-scale {
         | 
| 36 | 
            +
              display: inline-block;
         | 
| 37 | 
            +
              width: 200px;
         | 
| 38 | 
            +
              height: 200px;
         | 
| 39 | 
            +
            }*/
         | 
| 40 | 
            +
             | 
| 41 | 
            +
            mr-d3-ring svg g.arc {
         | 
| 42 | 
            +
              opacity: 0.2;
         | 
| 43 | 
            +
            }
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            mr-d3-ring svg g.arc.selected {
         | 
| 46 | 
            +
              opacity: 1;
         | 
| 47 | 
            +
            }
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            mr-d3-ring svg g.arc:hover {
         | 
| 50 | 
            +
              opacity: 1;
         | 
| 51 | 
            +
            }
         | 
| @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            <!-- Note that height and width were defined in here using Angular
         | 
| 2 | 
            +
              interpolation but apparently there is a browser problem with this method
         | 
| 3 | 
            +
              concerning the SVG element. These attributes are now set using D3.js directly
         | 
| 4 | 
            +
            -->
         | 
| 5 | 
            +
            <div class="mr-d3-ring-scale">
         | 
| 6 | 
            +
              <svg viewBox="0 0 200 200"></svg>
         | 
| 7 | 
            +
            </div>
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            <div class="mr-d3-ring-container" ng-transclude></div>
         | 
| @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            +
            require 'material_raingular/d3/version'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |spec|
         | 
| 7 | 
            +
              spec.name          = "material_raingular-d3"
         | 
| 8 | 
            +
              spec.version       = MaterialRaingular::D3::VERSION
         | 
| 9 | 
            +
              spec.authors       = ["Chris Moody"]
         | 
| 10 | 
            +
              spec.email         = ["cmoody@transcon.com"]
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              spec.summary       = %q{D3 integration for material raingular}
         | 
| 13 | 
            +
              spec.homepage      = "https://github.com/cmoodyEIT/material_raingular-d3"
         | 
| 14 | 
            +
              spec.license       = "MIT"
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              spec.files         = `git ls-files -z`.split("\x0").reject do |f|
         | 
| 17 | 
            +
                f.match(%r{^(test|spec|features)/})
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
              spec.bindir        = "exe"
         | 
| 20 | 
            +
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         | 
| 21 | 
            +
              spec.require_paths = ["lib"]
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              spec.add_development_dependency "bundler", "~> 1.13"
         | 
| 24 | 
            +
              spec.add_development_dependency "rake", "~> 10.0"
         | 
| 25 | 
            +
              spec.add_runtime_dependency "material_raingular", "~> 0.6"
         | 
| 26 | 
            +
            end
         |