Вход Регистрация
Файл: src/public/plugins/metrics-graphics/charts/missing.js
Строк: 149
<?php
(function () {
  
'use strict';

  function 
mg_missing_add_text (svgargs) {
    
svg.selectAll('.mg-missing-text').data([args.missing_text])
      .
enter().append('text')
      .
attr('class''mg-missing-text')
      .
attr('x'args.width 2)
      .
attr('y'args.height 2)
      .
attr('dy''.50em')
      .
attr('text-anchor''middle')
      .
text(args.missing_text);
  }

  function 
mg_missing_x_scale (args) {
    
args.scales.d3.scale.linear()
      .
domain([0args.data.length])
      .
range([mg_get_plot_left(args), mg_get_plot_right(args)]);
    
args.scalefns.yf = function (di) { return args.scales.Y(di.y); };
  }

  function 
mg_missing_y_scale (args) {
    
args.scales.d3.scale.linear()
      .
domain([-22])
      .
range([args.height args.bottom args.buffer 2args.top]);
    
args.scalefns.xf = function (di) { return args.scales.X(di.x); };
  }

  function 
mg_make_fake_data (args) {
    var 
data = [];
    for (var 
1<= 50x++) {
      
data.push({'x'x'y'Math.random() - (0.03)});
    }
    
args.data data;
  }

  function 
mg_add_missing_background_rect (gargs) {
    
g.append('svg:rect')
      .
classed('mg-missing-background'true)
      .
attr('x'args.buffer)
      .
attr('y'args.buffer)
      .
attr('width'args.width args.buffer 2)
      .
attr('height'args.height args.buffer 2)
      .
attr('rx'15)
      .
attr('ry'15);
  }

  function 
mg_missing_add_line (gargs) {
    var 
line d3.svg.line()
      .
x(args.scalefns.xf)
      .
y(args.scalefns.yf)
      .
interpolate(args.interpolate);
    
g.append('path')
      .
attr('class''mg-main-line mg-line1-color')
      .
attr('d'line(args.data));
  }

  function 
mg_missing_add_area (gargs) {
    var 
area d3.svg.area()
      .
x(args.scalefns.xf)
      .
y0(args.scales.Y.range()[0])
      .
y1(args.scalefns.yf)
      .
interpolate(args.interpolate);
    
g.append('path')
      .
attr('class''mg-main-area mg-area1-color')
      .
attr('d'area(args.data));
  }

  function 
mg_remove_all_children (args) {
    
d3.select(args.target).selectAll('svg *').remove();
  }

  function 
mg_missing_remove_legend (args) {
    if (
args.legend_target) {
      
d3.select(args.legend_target).html('');
    }
  }

  function 
missingData (args) {
    
this.init = function (args) {
      
this.args args;

      
mg_init_compute_width(args);
      
mg_init_compute_height(args);

      
chart_title(args);

      
// create svg if one doesn't exist

      
var container d3.select(args.target);
      
mg_raise_container_error(containerargs);
      var 
svg container.selectAll('svg');
      
mg_remove_svg_if_chart_type_has_changed(svgargs);
      
svg mg_add_svg_if_it_doesnt_exist(svgargs);
      
mg_adjust_width_and_height_if_changed(svgargs);
      
mg_set_viewbox_for_scaling(svgargs);
      
mg_remove_all_children(args);

      
svg.classed('mg-missing'true);
      
mg_missing_remove_legend(args);

      
// are we adding a background placeholder
      
if (args.show_missing_background) {
        
mg_make_fake_data(args);
        
mg_missing_x_scale(args);
        
mg_missing_y_scale(args);
        var 
mg_add_g(svg'mg-missing-pane');

        
mg_add_missing_background_rect(gargs);
        
mg_missing_add_line(gargs);
        
mg_missing_add_area(gargs);
      }

      
mg_missing_add_text(svgargs);

      
this.windowListeners();

      return 
this;
    };

    
this.windowListeners = function () {
      
mg_window_listeners(this.args);
      return 
this;
    };

    
this.init(args);
  }

  var 
defaults = {
    
top40// the size of the top margin
    
bottom30// the size of the bottom margin
    
right10// size of the right margin
    
left10// size of the left margin
    
buffer8// the buffer between the actual chart area and the margins
    
legend_target'',
    
width350,
    
height220,
    
missing_text'Data currently missing or unavailable',
    
scalefns: {},
    
scales: {},
    
show_tooltipstrue,
    
show_missing_backgroundtrue,
    
interpolate'cardinal'
  
};

  
MG.register('missing-data'missingDatadefaults);
}).
call(this);
?>
Онлайн: 1
Реклама