Skip to content

Commit

Permalink
Merge pull request #56 from hkelly93/enhancement/55/Add-a-way-to-over…
Browse files Browse the repository at this point in the history
…ride-value

Added a way to override the 'value' key
  • Loading branch information
hkelly93 committed Jun 10, 2016
2 parents 19cfc67 + edd8e56 commit 3f07c80
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/.idea
/*.iml
/node_modules
.idea/*
*.iml
node_modules/*
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@
* Fixed the way that the width of the parent labels was determined and added a cache.
* Optimized parent labels by storing the keys instead of generating it each time.
* Added a way to add a custom sort function.
* Added a way to set a custom string for the `value` key instead of having it always say 'value' on the tooltip.`
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ config = {
colors: ['red', 'green', 'blue'], // The custom color set to use for the child blocks. These can be color names, HEX values, or RGBA values.
transitionTime: 1000, // The time in milliseconds for the transitions. Set to 0 to disable.
truncate: 25, // The maximum length for the parent labels before they get truncated. Set to 0 to disable.
sortFunction: sortJson // A custom sort function. The parent value must be sorted first.
sortFunction: sortJson, // A custom sort function. The parent value must be sorted first.
valueKeyName: 'Worldwide Gross' // Set a custom key value in the tooltip instead of showing 'value'.
}
```

Expand All @@ -113,7 +114,8 @@ config = {
thresholds: [], // All chiild blocks will be the same color.
transitionTime: 1500,
truncate: 0,
sortFunction: sortJson
sortFunction: sortJson,
valueKeyName: 'value'
}
```

Expand Down
5 changes: 3 additions & 2 deletions dest/d3.relationshipgraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,8 @@
], // Colors to use for blocks.
transitionTime: userConfig.transitionTime || 1500, // Time for a transition to start and complete (in milliseconds).
truncate: userConfig.truncate || 25, // Maximum length of a parent label before it gets truncated. Use 0 to turn off truncation.
sortFunction: userConfig.sortFunction || sortJson // A custom sort function. The parent value must be sorted first.
sortFunction: userConfig.sortFunction || sortJson, // A custom sort function. The parent value must be sorted first.
valueKeyName: userConfig.valueKeyName || 'value' // Set a custom key value in the tooltip instead of showing 'value'.
};

if (this.config.showTooltips === undefined) {
Expand Down Expand Up @@ -595,7 +596,7 @@
value = document.createElement('td');

if (showKeys) {
key.innerHTML = toTitleCase(element);
key.innerHTML = (upperCaseKey == 'VALUE') ? toTitleCase(self.config.valueKeyName) : toTitleCase(element);
row.appendChild(key);
}

Expand Down
2 changes: 1 addition & 1 deletion dest/d3.relationshipgraph.min.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<title>d3.relationshipgraph Example</title>

<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="../dest/d3.relationshipgraph.min.js"></script>
<script src="../src/d3-tip.js"></script>
<script src="../src/index.js"></script>
<link type="text/css" rel="stylesheet" href="../dest/d3.relationshipgraph.min.css">
</head>
<body>
Expand Down Expand Up @@ -585,6 +586,7 @@ <h1 style="text-align: center; font-family: Helvetica, sans-serif; color: #32323

var graph = d3.select('#graph').relationshipGraph({
'maxChildCount': 10,
'valueKeyName': 'Worldwide Gross',
'thresholds': [1000000000, 2000000000, 3000000000]
});

Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
], // Colors to use for blocks.
transitionTime: userConfig.transitionTime || 1500, // Time for a transition to start and complete (in milliseconds).
truncate: userConfig.truncate || 25, // Maximum length of a parent label before it gets truncated. Use 0 to turn off truncation.
sortFunction: userConfig.sortFunction || sortJson // A custom sort function. The parent value must be sorted first.
sortFunction: userConfig.sortFunction || sortJson, // A custom sort function. The parent value must be sorted first.
valueKeyName: userConfig.valueKeyName || 'value' // Set a custom key value in the tooltip instead of showing 'value'.
};

if (this.config.showTooltips === undefined) {
Expand Down Expand Up @@ -191,7 +192,7 @@
value = document.createElement('td');

if (showKeys) {
key.innerHTML = toTitleCase(element);
key.innerHTML = (upperCaseKey == 'VALUE') ? toTitleCase(self.config.valueKeyName) : toTitleCase(element);
row.appendChild(key);
}

Expand Down
10 changes: 10 additions & 0 deletions test/RelationshipGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -845,4 +845,14 @@ describe('RelationshipGraph', function() {
}
});
});

describe('#VerifyValueKeyName', function() {
it('Should be "cool value".', function() {
var graph = d3.select('#test').relationshipGraph({
valueKeyName: 'cool value'
});

chai.expect(graph.config.valueKeyName).to.equal('cool value');
});
});
});

0 comments on commit 3f07c80

Please sign in to comment.