Skip to content

Commit 807a02c

Browse files
authored
Merge pull request #150 from unipept/fix/colorprovider-call-wrong
Fix `ColorProvider` option is only called for the root level
2 parents ed9e168 + 9170720 commit 807a02c

File tree

14 files changed

+91
-9
lines changed

14 files changed

+91
-9
lines changed

dist/unipept-visualizations.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/visualizations/treeview/TreeviewSettings.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ export default class TreeviewSettings extends Settings {
4848
* Time the animation should last (in milliseconds).
4949
*/
5050
animationDuration: number;
51+
/**
52+
* Amount of levels deep in the true for which the color should be set explicitly. This parameter determines up
53+
* until which point in the tree the colorProvider function will be called. By default only the direct children of
54+
* the root node (at level 1) are distinctly colored.
55+
*/
56+
colorProviderLevels: number;
5157
/**
5258
* Function that returns a color to use as a fill color.
5359
*
@@ -71,7 +77,8 @@ export default class TreeviewSettings extends Settings {
7177
linkStrokeColor: (l: HierarchyPointLink<TreeviewNode>) => string;
7278
/**
7379
* Function that returns the color that should be used for a specific node. This actually corresponds to the
74-
* specific color scale that should be used for this visualization.
80+
* specific color scale that should be used for this visualization. Note that this function will only be called for
81+
* nodes up until the level in the tree specified by the parameter "colorProviderLevels".
7582
*
7683
* @param d A TreeviewNode for which the corresponding color should be computed.
7784
* @return The color associated with the given node.

examples/treeview-taxonomy.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
data,
2121
{
2222
width: 900,
23-
height: 600
23+
height: 600,
24+
colorProviderLevels: 3
2425
}
2526
);
2627
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "unipept-visualizations",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "The Unipept visualisation library",
55
"homepage": "https://github.com/unipept/unipept-visualizations",
66
"bugs": "https://github.com/unipept/unipept-visualizations/issues",

src/visualizations/treeview/Treeview.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,17 @@ export default class Treeview {
110110

111111
this.root.data.setSelected(true);
112112

113-
this.root.children?.forEach((d: HPN<TreeviewNode>, i: number) => {
113+
const updateColor = (d: HPN<TreeviewNode>, level: number) => {
114114
d.data.setColor(this.settings.colorProvider(d.data));
115+
if (level < this.settings.colorProviderLevels && d.children) {
116+
for (const child of d.children) {
117+
updateColor(child, level + 1);
118+
}
119+
}
120+
}
121+
122+
this.root.children?.forEach((d: HPN<TreeviewNode>, i: number) => {
123+
updateColor(d, 1);
115124
});
116125

117126
if (this.settings.enableExpandOnClick) {

src/visualizations/treeview/TreeviewSettings.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ export default class TreeviewSettings extends Settings {
6363
*/
6464
animationDuration: number = 500;
6565

66+
/**
67+
* Amount of levels deep in the true for which the color should be set explicitly. This parameter determines up
68+
* until which point in the tree the colorProvider function will be called. By default only the direct children of
69+
* the root node (at level 1) are distinctly colored.
70+
*/
71+
colorProviderLevels: number = 1;
72+
6673
/**
6774
* Function that returns a color to use as a fill color.
6875
*
@@ -97,7 +104,8 @@ export default class TreeviewSettings extends Settings {
97104

98105
/**
99106
* Function that returns the color that should be used for a specific node. This actually corresponds to the
100-
* specific color scale that should be used for this visualization.
107+
* specific color scale that should be used for this visualization. Note that this function will only be called for
108+
* nodes up until the level in the tree specified by the parameter "colorProviderLevels".
101109
*
102110
* @param d A TreeviewNode for which the corresponding color should be computed.
103111
* @return The color associated with the given node.

types/test/TestConsts.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export declare type ImageSnapshotSettings = {
2+
comparisonMethod: string;
3+
customSnapshotsDir: string;
4+
customDiffDir: string;
5+
failureThreshold: number;
6+
failureThresholdType: string;
7+
};
8+
export default class TestConsts {
9+
static resolveImageSnapshotFolder(path: string): ImageSnapshotSettings;
10+
}

types/test/TestDataGenerator.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default class TestDataGenerator {
2+
generateSmall2DDataset(): number[][];
3+
}

types/test/TestUtils.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export declare function sleep(ms: number): Promise<unknown>;
2+
/**
3+
* This function waits a specified amount of time for promises to be fullfilled before returning.
4+
*
5+
* @param ms How many ms should we wait before continueing test execution?
6+
*/
7+
export declare function waitForPromises(ms: number): Promise<void>;
8+
/**
9+
* This function returns only when the given condition evaluates to true, or when the given timeout has been exceeded.
10+
*
11+
* @param condition
12+
* @param timeout
13+
* @param interval
14+
*/
15+
export declare function waitForCondition(condition: () => boolean, timeout?: number, interval?: number): Promise<void>;

types/utilities/TooltipUtilities.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import * as d3 from "d3";
22
export default class TooltipUtilities {
3-
static initTooltip(elementId: string): d3.Selection<HTMLDivElement, unknown, HTMLElement, any>;
3+
static initTooltip(): d3.Selection<HTMLDivElement, unknown, HTMLElement, any>;
44
}

0 commit comments

Comments
 (0)