Comments

Niremizov’s picture

Here is a patch, but it is without smoothing for now.

Niremizov’s picture

Line endings converted to the UNIX format.

Niremizov’s picture

And again line ending fix.

Niremizov’s picture

Konstantin Komelin’s picture

Status: Active » Needs review
Niremizov’s picture

Attached patch, fixes "Views, Visitors and new Visitors" chart when using "one day" filter. Results are shown as horizontal lines.

Konstantin Komelin’s picture

Status: Needs review » Needs work

Спасибо. Вот несколько моментов:
1) sizeof - это альяс на count . Давайте юзать count?
2) На комментарии тоже есть стандарты в Drupal http://drupal.org/coding-standards/docs
Например, на конце строки знак препинания, начало предложения с заглавной буквы и т.д.

Niremizov’s picture

Here it is, with coding-standards fixes...
PS: Still using sizeof, because you have said that it is used inside Drupal core.

kalabro’s picture

Minor issues:

+ //If there is only one date point, we schould add it's dublicate for
small typo: should, duplicate

+ } else {

new line after first } http://drupal.org/coding-standards (Control Structures)

Thanks!

Konstantin Komelin’s picture

Еще пробел после //

Niremizov’s picture

Thx for your patience... Okay, so comments have been checked by Coder and fixed. I suppose, it should be fine now.

Konstantin Komelin’s picture

There was a bug in #11:
+ $new_visitors[] = !empty($z_point->new_visitors) ? $value->new_visitors : 0;

I've replaced $value with $z_point and commited:
http://drupalcode.org/project/yandex_metrics.git/commit/cb5f32d

Let's think about grid lines for this chart.
See example http://code.google.com/p/drupal-chart-api/wiki/Examples (Grid lines and chart fill)
Is it possible to implement dashed grid through Chart module?

Konstantin Komelin’s picture

kalabro’s picture

tagging

kalabro’s picture

Status: Needs work » Needs review
StatusFileSize
new3.06 KB
new19.99 KB
new19.75 KB
new13.56 KB

Added smart grid.

Can be scaled.

~350 max value on 100px chart.
2013-04-01_00-55-41.png

~30 max value on 250px chart.
2013-04-01_00-57-36.png

Konstantin Komelin’s picture

Status: Needs review » Needs work

Tested. Looks beautiful!

Can we refactor chart method a bit because it's too long? For example, extract grid param calculation to separate function, smth like:

list($step_x_percent, $step_y, $step_y_percent, $axis_y_count_labels) = _yandex_metrics_reports_calculate_grid_params($dates, $height, $max);
function _yandex_metrics_reports_calculate_grid_params($dates, $height, $max) {
// Calculate grid steps for X.
  $grid_x_count = count($dates);
  $grid_x_count = $grid_x_count > 1 ? $grid_x_count - 1 : $grid_x_count;
  $step_x_percent = 100 / $grid_x_count;

  /**
   * Calculate grid steps for Y.
   *
   * We use manual method to syncronize Y-axis labels and Y grid.
   * First, define min Y step as 25px so grids are not too close to each other.
   * Round $max_grid up to dozens. 8 becomes 10, 141 becomes 150.
   * Calculate min step and round it to nice value as $step_y. 2 becomes 2,
   * 34 becomes 35, 148 becomes 150.
   * Draw Y grid on base of $step_y_percent.
   * Draw Y labels on base of $axis_y_count_labels, $step_y and $step_y_percent.
   */
  $min_step_y_percent = 100 * 25 / $height; // 25px.
  $max_grid = ceil($max / 10) * 10;
  $min_step_y = $max_grid * $min_step_y_percent / 100;
  // Round min step.
  $step_y = round($min_step_y / 5) * 5;
  $step_y = !$step_y ? round($min_step_y) : $step_y;
  // Convert min step back to percents.
  $step_y_percent = $step_y * 100 / $max_grid;
  // Count Y labels.
  $axis_y_count_labels = $max_grid / $step_y;
  return array($step_x_percent, $step_y, $step_y_percent, $axis_y_count_labels);
}

It's just automatic refactoring suggestion of my IDE and there are ways to improve it.

Anyway, it's great job. Thanks!

kalabro’s picture

Status: Needs work » Fixed

Commited and pushed!
http://drupalcode.org/project/yandex_metrics.git/commit/9350bf

Two helper methods (may be useful for other charts in future):
_yandex_metrics_reports_calculate_grid_fixed() for known number of grid lines.
_yandex_metrics_reports_calculate_grid_integer for dynamic integer grids.

Konstantin Komelin’s picture

Status: Fixed » Needs work
StatusFileSize
new2.08 KB

What do you think about renaming of helper functions? See patch.

kalabro’s picture

I personally dislike "static" because it is related for me to "static" PHP keyword.

Can we add @todo comment about these helter functions? I want to draw the attention of developers that with functions are open for further improvement in another use cases.

Konstantin Komelin’s picture

I spent some time to understand the purpose of the functions and then I only decided to rename because it was difficult to understand.

To improve @todo we will have to spend time to understand that again. So let's build good basis (architecture of code) now and improve algorithms later.

I also thought about the misunderstanding of 'static' but it's antonym for 'dynamic'.
So we can use 'fixed' istead of 'static' and 'fluid' or 'flexible' instead of 'dynamic'.

You know, I can improve it by myself without problems but It's important for me to know your opinion and explain mine.

kalabro’s picture

So we can use 'fixed' istead of 'static' and 'fluid' or 'flexible'

Looks good.

Konstantin Komelin’s picture

Okay, let's use 'fixed' and 'fluid' ) Can I commit it?

Thanks.

kalabro’s picture

Sure!
Я не у штурвала :)

Konstantin Komelin’s picture

Status: Needs work » Closed (fixed)