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

2.0 port of the sunburst + some cleanup. #33

Closed
wants to merge 72 commits into from
Closed

Conversation

MaybeJustJames
Copy link
Collaborator

Closes #30

Attempting to mimic current style
Transpiled output should not be in git
- Also change parameter name for sunburstNode.createNodes from node to nodes
* Now jquery plugin is not going to be ported
Also remove yarn lock file
Also refactor color manipulation code from util into color
Copy link
Member

@pverscha pverscha left a comment

Choose a reason for hiding this comment

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

Hey @MaybeJustJames ,

Thank you for this PR :) I do have some suggestions / comments that you should take a look at, if possible.

Some general remarks:

  • Try not to prefix interfaces with "I". This is a coding-style that's not commonly used in TypeScript / JavaScript environments and that's even discouraged by Angular / React. (see this for more information: Prohibition against prefixing interfaces with "I" microsoft/TypeScript-Handbook#121 (comment))
  • There's still a tslint.json file present in the repository, although we are using ESLint. Note that TSLint used to be the default linter for TypeScript, but that it is currently deprecated and should be completely replaced by ESLint.
  • Run an automatic ESLint fix afterwards to clean up the indentation.
  • I'm not a big fan of declaring functions as const's throughout the code (it can occasionally be handy, but I think it should be avoided in general). Instead of something like this:
/**
 * Checks that `child` is within the hierarchial depth limit and is within
 * the same (sub-)tree as `ancestor`.
 * @param maxGeneration The (absolute) hierarchial depth limit.
 * @return true iff the above conditions are satisfied.
 */
const displayableFromAncestor: (ancestor: d3.HierarchyNode<Node>,
                                child: d3.HierarchyNode<Node>,
                                maxGeneration: number) => boolean
  = (ancestor: d3.HierarchyNode<Node>,
     child: d3.HierarchyNode<Node>,
     maxGeneration: number): boolean =>
  (child.depth < maxGeneration) &&
  (Data.ancestorOf(ancestor, child)
   .orElse(Infinity) < maxGeneration);

I suggest to reformat this to something clearer:

function displayableFromAncestor(
    ancestor: d3.HierarchyNode<Node>,
    child: d3.HierarchyNode<Node>,
    maxGeneration: number
): boolean {
    return child.depth < maxGeneration && (Data.ancestorOf(ancestor, child).orElse(Infinity) < maxGeneration);
}

This way, we don't have to define the parameters of this function twice (once in the type signature and once in the actual function) and the start and end of the function can easily be spotted.

How should we proceed from here? Do you still have time to look into these things or should we try to update the PR according to my comments and merge it ourselves?

I would like to thank you again for your help in updating our package to TypeScript / D3 v5 :)

super(node);
}

public static new(node: BasicNode = emptyBasicNode()): SunburstNode {
Copy link
Member

Choose a reason for hiding this comment

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

What's the added value of this function? Can't we just use the constructor to create new SunburstNode's since all this function does is call the constructor?

const clr: (node: d3.HierarchyNode<Node>) => string
= (node: d3.HierarchyNode<Node>): string => {
const c = color !== undefined ? color(node) : "black";
console.log(`background color: ${c}`);
Copy link
Member

Choose a reason for hiding this comment

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

This log should be removed.

/**
* Given some settings, bake a function that generates HTML for a breadcrumb.
*/
const createCrumb: (genClassName: (name: string) => string,
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to change this and declare this as a normal function, like so:

function createCrumb(
    genClassName: (name: string) => string,
    text?: (node: d3.HierarchyNode<Node>) => string,
    color?: (node: d3.HierarchyNode<Node> => string
) {
    ...
}

It's quite hard to read this function right now due to all of the nested arrow-functions and inconsistent indentation.

}

/**
* Update the rendered breadcrumbs with `data` as as the node deepest
Copy link
Member

Choose a reason for hiding this comment

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

Something is wrong with this comment, can you take another look and update it? :)

Comment on lines +113 to +115
this.colour !== undefined
? this.colour(d)
: Breadcrumb.DEFAULT_COLOUR)
Copy link
Member

Choose a reason for hiding this comment

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

Also place this on one line, similar to line 110.

@@ -0,0 +1,31 @@
import { scaleOrdinal, ScaleOrdinal } from "d3";
Copy link
Member

Choose a reason for hiding this comment

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

Is there an advantage in using these colour palette's over the built-in D3 palettes?

* Formula: sum(squared components)/# of components
* TODO: Make a weighted average version.
*/
const averageColor: (colours: OptionalColor[]) => OptionalColor
Copy link
Member

Choose a reason for hiding this comment

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

This function is not being used and can maybe be removed?

= (datum: Node, counter: (d: Node) => number): number => {
if (datum.children !== undefined) {
return datum.children.map((v: Node): number => count(v, counter))
.reduce(((a: number, b: number): number => a + b), 0);
Copy link
Member

Choose a reason for hiding this comment

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

Use D3's built-in sum function here.


public readonly abstract className: string; // The visualization class: for styling

public constructor(height?: number, width?: number, enableTooltips?: boolean) {
Copy link
Member

Choose a reason for hiding this comment

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

I think it might be better to change this constructor to:

public constructor(height: number = Settings.DEFAULT_SIZE, width: number = Settings.DEFAULT_SIZE, enableTooltips: boolean = true)


/**
* IStyleConstraints data constructor
* Use with care!
Copy link
Member

Choose a reason for hiding this comment

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

Can you elaborate here and explain why this should be used with care?

@pverscha
Copy link
Member

Hi @MaybeJustJames,

Thank you for your PR :) We've incorporated the work you made in this PR, together with some new changes (since the D3 API changed again) in a new PR #36 that has been merged with the codebase by now.

@pverscha pverscha closed this Jan 26, 2021
@bmesuere bmesuere deleted the 2.0_sunburst branch March 9, 2021 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants