Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced screen comparison feature #297

Merged
merged 12 commits into from
Aug 29, 2018

Conversation

m-suchorski
Copy link

More advanced way of comparing screen layouts.

Description

This feature gives user a function to compare screen layouts in more advanced way. User can manually start the comparison.

I've tried to make the original code more readable.

Author: @aux-lux

Motivation and Context

Fixes for this PR: #269

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

I hereby agree to the terms of the AET Contributor License Agreement.

'use strict';
angularAMD.directive('aetCompareScreens', compareScreensDirective);


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove empty lines

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for that, they should all be removed by now.


function linkFunc(scope) {

scope.advancedScreenComparison = function () {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a good practice not to keep empty line after function declaration

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

var tab = document.querySelector('.test-tabs > .tab-content > .tab-pane.ng-scope.active');
var wrapper = tab.querySelector('.page-main .layout-compare');
var initedClass = 'screen-comparison-active';
var arrangeTimeout;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please assign initial value for this variable, in order to allocate it properly in memory

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

var group = [];



Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty lines

canvas.canvasWrapper.appendChild(canvas.canvasB);



Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty lines

max-width: 48%;
vertical-align: top;
box-sizing: content-box;
&+canvas {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

& is not needed in this case, simple + will do

@@ -40,19 +40,25 @@
font-size: 11px;
display: inline-block;
padding: 0 20px;
line-height: 30px;
line-height: 31px;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if line-height is declared, you do not need setting height

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I don't know why this value is even modified. Deleted height value anyway.

@@ -29,6 +29,9 @@
</label>
</div>
</div>
<div class="try-new button button-small button-blue">
<a ng-click="advancedScreenComparison()" aet-compare-screens>Advanced Screen Comparison</a>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use data prefix for custom attributes- same goes for all directives, it should be data-ng-click and data-aet-compare-screens

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know that, thanks. Done now.

}

function deselectGroups(label, ruler, wrapper) {
label.labelA.style.display = 'none';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider manipulating styles with class on the parent element- otherwise this code will trigger four sequential repaint events (same goes for adding block display)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed my approach to this one, please take a look and tell me if it's all right now.

var firstGroup = [];
var secondGroup = [];
if (groups[0][0] > 0) {
for (var i = 0; i < groups[0][0]; i++) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you create multiple variable declarations with the same name- in each variable, within the same function scope, they should be unique- think about hoisting ;)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@malaskowski malaskowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update CHANGELOG according to AET Contributing rules

Copy link
Contributor

@malaskowski malaskowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update Layout report documentation with description of this new feature (and maybe one example screenshot?).

@@ -29,6 +29,9 @@
</label>
</div>
</div>
<div class="try-new button button-small button-blue">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please use more descriptive class name here?
E.g. advanced-screen-comparison or smth like that

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

invertedGroupsB: [],
};

var groups = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please make those variables more meaningful?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

imgSizeB: null,
};

var simple = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is simple?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

wrapper.classList.add(initedClass);
}

var button = document.querySelector('.try-new');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please encapsulate logic in the lines below into a function, e.g. markComparisonStarted or smth. similar?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

loadImage(img.imgB, imgSize.imgSizeB, canvas.canvasB, context.contextB, simple.simpleB, function (returnedSimple, returnedImgSize) {
simple.simpleB = returnedSimple;
imgSize.imgSizeB = returnedImgSize;
button.classList.remove('button-disabled');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please encapsulate logic in the lines below into a function, e.g. markComparisonFinished or smth. similar?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've actually left it how it were mainly because I'd need to pass more than 15 parameters to this new function. I might think of something else in the future.

function drawDifferences(difs, imgSize, invertedGroups, simple, context) {
var maxHeight = Math.max(imgSize.imgSizeA.height, imgSize.imgSizeB.height);
var proc = 100 / maxHeight;
var newDiffBLeft = '52%';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this magic number mean?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the left value of second canvas' differences that's being created few lines below. I got no idea how to make it clearer, that second canvas just needs to be pushed by 52% from the left to make both canvases apprear next to each other.

@tkaik tkaik merged commit c8ec6ef into wttech:master Aug 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants