You are here

public function Percentiles::content in Flot 8

Zooming.

1 string reference to 'Percentiles::content'
flot_examples.routing.yml in flot_examples/flot_examples.routing.yml
flot_examples/flot_examples.routing.yml

File

flot_examples/src/Controller/Percentiles.php, line 15

Class

Percentiles
Displays a chart that demonstrates the fillbetween plugin.

Namespace

Drupal\flot_examples\Controller

Code

public function content() {
  $males = $this::readData('PercentileMaleData.txt');
  $females = $this::readData('PercentileFemaleData.txt');
  $dataset = [
    [
      'label' => "Female mean",
      'data' => $females["mean"],
      'lines' => [
        'show' => TRUE,
      ],
      'color' => "rgb(255,50,50)",
    ],
    [
      'id' => "f15%",
      'data' => $females["15%"],
      'lines' => [
        'show' => TRUE,
        'lineWidth' => 0,
        'fill' => FALSE,
      ],
      'color' => "rgb(255,50,50)",
    ],
    [
      'id' => "f25%",
      'data' => $females["25%"],
      'lines' => [
        'show' => TRUE,
        'lineWidth' => 0,
        'fill' => 0.2,
      ],
      'color' => "rgb(255,50,50)",
      'fillBetween' => "f15%",
    ],
    [
      'id' => "f50%",
      'data' => $females["50%"],
      'lines' => [
        'show' => TRUE,
        'lineWidth' => 0.5,
        'fill' => 0.4,
        'shadowSize' => 0,
      ],
      'color' => "rgb(255,50,50)",
      'fillBetween' => "f25%",
    ],
    [
      'id' => "f75%",
      'data' => $females["75%"],
      'lines' => [
        'show' => TRUE,
        'lineWidth' => 0,
        'fill' => 0.4,
      ],
      'color' => "rgb(255,50,50)",
      'fillBetween' => "f50%",
    ],
    [
      'id' => "f85%",
      'data' => $females["85%"],
      'lines' => [
        'show' => TRUE,
        'lineWidth' => 0,
        'fill' => 0.2,
      ],
      'color' => "rgb(255,50,50)",
      'fillBetween' => "f75%",
    ],
    [
      'label' => "Male mean",
      'data' => $males["mean"],
      'lines' => [
        'show' => TRUE,
      ],
      'color' => "rgb(50,50,255)",
    ],
    [
      'id' => "m15%",
      'data' => $males["15%"],
      'lines' => [
        'show' => TRUE,
        'lineWidth' => 0,
        'fill' => FALSE,
      ],
      'color' => "rgb(50,50,255)",
    ],
    [
      'id' => "m25%",
      'data' => $males["25%"],
      'lines' => [
        'show' => TRUE,
        'lineWidth' => 0,
        'fill' => 0.2,
      ],
      'color' => "rgb(50,50,255)",
      'fillBetween' => "m15%",
    ],
    [
      'id' => "m50%",
      'data' => $males["50%"],
      'lines' => [
        'show' => TRUE,
        'lineWidth' => 0.5,
        'fill' => 0.4,
        'shadowSize' => 0,
      ],
      'color' => "rgb(50,50,255)",
      'fillBetween' => "m25%",
    ],
    [
      'id' => "m75%",
      'data' => $males["75%"],
      'lines' => [
        'show' => TRUE,
        'lineWidth' => 0,
        'fill' => 0.4,
      ],
      'color' => "rgb(50,50,255)",
      'fillBetween' => "m50%",
    ],
    [
      'id' => "m85%",
      'data' => $males["85%"],
      'lines' => [
        'show' => TRUE,
        'lineWidth' => 0,
        'fill' => 0.2,
      ],
      'color' => "rgb(50,50,255)",
      'fillBetween' => "m75%",
    ],
  ];
  $options = [
    'xaxis' => [
      'tickDecimals' => 0,
    ],
    'legend' => [
      'position' => "se",
    ],
  ];
  $text = [];
  $text[] = $this
    ->t('Height in centimeters of individuals from the US (2003-2006) as function of age in years (source: <a href=":one">CDC</a>). The 15%-85%, 25%-75% and 50% percentiles are indicated.', [
    ':one' => 'http://www.cdc.gov/nchs/data/nhsr/nhsr010.pdf',
  ]);
  $text[] = $this
    ->t('For each point of a filled curve, you can specify an arbitrary bottom. As this example illustrates, this can be useful for plotting percentiles. If you have the data sets available without appropriate fill bottoms, you can use the fillbetween plugin to compute the data point bottoms automatically.');
  $output[] = [
    '#type' => 'flot',
    '#theme' => 'flot_examples',
    '#text' => $text,
    '#data' => $dataset,
    '#options' => $options,
    '#attached' => [
      'library' => [
        'flot_examples/percentiles',
      ],
    ],
  ];
  return $output;
}