Спасибо. Вот несколько моментов:
1) sizeof - это альяс на count . Давайте юзать count?
2) На комментарии тоже есть стандарты в Drupal http://drupal.org/coding-standards/docs
Например, на конце строки знак препинания, начало предложения с заглавной буквы и т.д.
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.
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.
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.
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.
Comments
Comment #1
Niremizov commentedHere is a patch, but it is without smoothing for now.
Comment #2
Niremizov commentedLine endings converted to the UNIX format.
Comment #3
Niremizov commentedAnd again line ending fix.
Comment #4
Niremizov commented!@#$%!
Comment #5
Konstantin Komelin commentedCommited: http://drupalcode.org/project/yandex_metrics.git/commit/2c79f1a
Comment #6
Niremizov commentedAttached patch, fixes "Views, Visitors and new Visitors" chart when using "one day" filter. Results are shown as horizontal lines.
Comment #7
Konstantin Komelin commentedСпасибо. Вот несколько моментов:
1) sizeof - это альяс на count . Давайте юзать count?
2) На комментарии тоже есть стандарты в Drupal http://drupal.org/coding-standards/docs
Например, на конце строки знак препинания, начало предложения с заглавной буквы и т.д.
Comment #8
Niremizov commentedHere it is, with coding-standards fixes...
PS: Still using sizeof, because you have said that it is used inside Drupal core.
Comment #9
kalabroMinor issues:
+ //If there is only one date point, we schould add it's dublicate forsmall typo: should, duplicate
+ } else {new line after first } http://drupal.org/coding-standards (Control Structures)
Thanks!
Comment #10
Konstantin Komelin commentedЕще пробел после //
Comment #11
Niremizov commentedThx for your patience... Okay, so comments have been checked by Coder and fixed. I suppose, it should be fine now.
Comment #12
Konstantin Komelin commentedThere 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?
Comment #13
Konstantin Komelin commentedPorted to 6.x-2.x.
http://drupalcode.org/project/yandex_metrics.git/commit/c381f04
Comment #14
kalabrotagging
Comment #15
kalabroAdded smart grid.
Can be scaled.
~350 max value on 100px chart.

~30 max value on 250px chart.

Comment #16
Konstantin Komelin commentedTested. 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:
It's just automatic refactoring suggestion of my IDE and there are ways to improve it.
Anyway, it's great job. Thanks!
Comment #17
kalabroCommited 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_integerfor dynamic integer grids.Comment #18
Konstantin Komelin commentedWhat do you think about renaming of helper functions? See patch.
Comment #19
kalabroI 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.
Comment #20
Konstantin Komelin commentedI 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.
Comment #21
kalabroLooks good.
Comment #22
Konstantin Komelin commentedOkay, let's use 'fixed' and 'fluid' ) Can I commit it?
Thanks.
Comment #23
kalabroSure!
Я не у штурвала :)
Comment #24
Konstantin Komelin commentedДан ;)
http://drupalcode.org/project/yandex_metrics.git/commit/eb5e460
Comment #25
Konstantin Komelin commented