-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9bbe961
commit 6a00122
Showing
3 changed files
with
58 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,25 @@ | ||
# Getting Started | ||
|
||
Without a doubt, the most commonly used aspect of this module is [textBox](https://github.com/d3plus/d3plus-text#textBox), which is used for intelligently wrapping SVG text. At it's core, you can simply pass along data points with "text" values and the generator will add them to the page using a set of defaults. Here is a data array containing 3 different sentences to be wrapped: | ||
|
||
```js | ||
var data = [ | ||
{text: "Here is some sample text that has been wrapped using d3plus.textBox."}, | ||
{text: "...and here is a second sentence!"}, | ||
{text: "这是句3号。这也即使包装没有空格!"} | ||
]; | ||
``` | ||
|
||
And finally, this is how that data array would be passed to the [textBox](https://github.com/d3plus/d3plus-text#textBox) generator. Please note the `()` at the end of the chain of commands. This is what tells the [textBox](https://github.com/d3plus/d3plus-text#textBox) to finally render to the page, and allows setting multiple properties of the [textBox](https://github.com/d3plus/d3plus-text#textBox) without it trying to render after each one is set. | ||
|
||
```js | ||
d3plus.textBox() | ||
.data(data) | ||
.fontFamily("Verdana") | ||
.fontSize(16) | ||
.width(200) | ||
.x(function(d, i) { return i * 250; }) | ||
(); | ||
``` | ||
|
||
While [textBox](https://github.com/d3plus/d3plus-text#textBox) comes with some handy defaults, this example shows how any of the methods can be overridden with static values or accessor functions. For more information on how the [textSplit](#textSplit) function splits strings, specifically in languages that don't use spaces, check out [this blog post](https://blog.datawheel.us/english-is-not-chinese-69b43959bb47). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Automatic Font Resizing to Fit Container | ||
|
||
A useful method when using text to label variable sized shapes (like in a [tree map](https://github.com/d3plus/d3plus-treemap)) is the [fontResize](https://github.com/d3plus/d3plus-text#textBox.fontResize) function. When set to `true`, the [textBox](https://github.com/d3plus/d3plus-text#textBox) will attempt to scale up or down the [fontSize](https://github.com/d3plus/d3plus-text#textBox.fontSize) value to best fit the containing shape. | ||
|
||
```js | ||
var data = [ | ||
{text: "This is a sentence that will not be resized.", resize: false}, | ||
{text: "This is a sentence that will be resized.", resize: true} | ||
]; | ||
``` | ||
|
||
Here, we can compare the output of using [fontResize](https://github.com/d3plus/d3plus-text#textBox.fontResize) against the normal output, given a 200 x 100 rectangle boundary. | ||
|
||
```js | ||
d3plus.textBox() | ||
.data(data) | ||
.fontFamily("Verdana") | ||
.fontResize(function(d) { return d.resize; }) | ||
.height(100) | ||
.width(200) | ||
.x(function(d, i) { return i * 250; }) | ||
(); | ||
``` | ||
|
||
The [fontSize](https://github.com/d3plus/d3plus-text#textBox.fontSize) calculated by this method is constrained by the [fontMin](https://github.com/d3plus/d3plus-text#textBox.fontMin) and [fontMax](https://github.com/d3plus/d3plus-text#textBox.fontMax) values, which default to `8` and `50` respectively. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters