Giter Club home page Giter Club logo

d3plus-text's Introduction

d3plus-text

A smart SVG text box with line wrapping and automatic font size scaling.

Installing

If using npm, npm install d3plus-text. Otherwise, you can download the latest release from GitHub or load from a CDN.

import modules from "d3plus-text";

d3plus-text can be loaded as a standalone library or bundled as part of D3plus. ES modules, AMD, CommonJS, and vanilla environments are supported. In vanilla, a d3plus global is exported:

<script src="https://cdn.jsdelivr.net/npm/d3plus-text@1"></script>
<script>
  console.log(d3plus);
</script>

Examples

Live examples can be found on d3plus.org, which includes a collection of example visualizations using d3plus-react. These examples are powered by the d3plus-storybook repo, and PRs are always welcome. 🍻

API Reference

  • fontExists - Given either a single font-family or a list of fonts, returns the name of the first font that can be rendered, or false if none are installed on the user's machine.
  • rtl - Returns true if the or element has either the "dir" HTML attribute or the "direction" CSS property set to "rtl". Accepts an optional DOM element as an argument, whose own inherited state will be evaluated rather than the default html/body logic.
  • stringify - Coerces value into a String.
  • strip - Removes all non ASCII characters from a string.
  • textSplit - Splits a given sentence into an array of words.
  • htmlDecode - Strips HTML and "un-escapes" escape characters.
  • textWidth - Given a text string, returns the predicted pixel width of the string when placed into DOM.
  • textWrap - Based on the defined styles and dimensions, breaks a string into an array of strings for each line of text.
  • titleCase - Capitalizes the first letter of each word in a phrase/sentence.
  • trim - Cross-browser implementation of trim.
  • trimLeft - Cross-browser implementation of trimLeft.
  • trimRight - Cross-browser implementation of trimRight.

TextBox <>

This is a global class, and extends all of the methods and functionality of BaseClass.

# new TextBox()

Creates a wrapped text box for each point in an array of data. See this example for help getting started using the TextBox class.

# TextBox.render([callback]) <>

Renders the text boxes. If a callback is specified, it will be called once the shapes are done drawing.

This is a static method of TextBox.

# TextBox.ariaHidden(value) <>

If value is specified, sets the aria-hidden attribute to the specified function or string and returns the current class instance.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.data([data]) <>

Sets the data array to the specified array. A text box will be drawn for each object in the array.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.delay([value]) <>

Sets the animation delay to the specified number in milliseconds.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.duration([value]) <>

Sets the animation duration to the specified number in milliseconds.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.ellipsis([value]) <>

Sets the function that handles what to do when a line is truncated. It should return the new value for the line, and is passed 2 arguments: the String of text for the line in question, and the number of the line. By default, an ellipsis is added to the end of any line except if it is the first word that cannot fit (in that case, an empty string is returned).

This is a static method of TextBox, and is chainable with other methods of this Class. default accessor

function(text, line) {
  return line ? text.replace(/\.|,$/g, "") + "..." : "";
}

# TextBox.fontColor([value]) <>

Sets the font color to the specified accessor function or static string, which is inferred from the DOM selection by default.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.fontFamily([value]) <>

Defines the font-family to be used. The value passed can be either a String name of a font, a comma-separated list of font-family fallbacks, an Array of fallbacks, or a Function that returns either a String or an Array. If supplying multiple fallback fonts, the fontExists function will be used to determine the first available font on the client's machine.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.fontMax([value]) <>

Sets the maximum font size to the specified accessor function or static number (which corresponds to pixel units), which is used when dynamically resizing fonts.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.fontMin([value]) <>

Sets the minimum font size to the specified accessor function or static number (which corresponds to pixel units), which is used when dynamically resizing fonts.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.fontOpacity([value]) <>

Sets the font opacity to the specified accessor function or static number between 0 and 1.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.fontResize([value]) <>

Toggles font resizing, which can either be defined as a static boolean for all data points, or an accessor function that returns a boolean. See this example for a side-by-side comparison.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.fontSize([value]) <>

Sets the font size to the specified accessor function or static number (which corresponds to pixel units), which is inferred from the DOM selection by default.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.fontStroke([value]) <>

Sets the font stroke color for the rendered text.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.fontStrokeWidth([value]) <>

Sets the font stroke width for the rendered text.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.fontWeight([value]) <>

Sets the font weight to the specified accessor function or static number, which is inferred from the DOM selection by default.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.height([value]) <>

Sets the height for each box to the specified accessor function or static number.

This is a static method of TextBox, and is chainable with other methods of this Class. default accessor

function(d) {
  return d.height || 200;
}

# TextBox.html([value = { i: 'font-style: italic;', em: 'font-style: italic;', b: 'font-weight: bold;', strong: 'font-weight: bold;' }]) <>

Configures the ability to render simple HTML tags. Defaults to supporting <b>, <strong>, <i>, and <em>, set to false to disable or provide a mapping of tags to svg styles

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.id([value]) <>

Defines the unique id for each box to the specified accessor function or static number.

This is a static method of TextBox, and is chainable with other methods of this Class. default accessor

function(d, i) {
  return d.id || i + "";
}

# TextBox.lineHeight([value]) <>

Sets the line height to the specified accessor function or static number, which is 1.2 times the font size by default.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.maxLines([value]) <>

Restricts the maximum number of lines to wrap onto, which is null (unlimited) by default.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.overflow([value]) <>

Sets the text overflow to the specified accessor function or static boolean.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.padding([value]) <>

Sets the padding to the specified accessor function, CSS shorthand string, or static number, which is 0 by default.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.pointerEvents([value]) <>

Sets the pointer-events to the specified accessor function or static string.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.rotate([value]) <>

Sets the rotate percentage for each box to the specified accessor function or static string.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.rotateAnchor(_) <>

Sets the anchor point around which to rotate the text box.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.select([selector]) <>

Sets the SVG container element to the specified d3 selector or DOM element. If not explicitly specified, an SVG element will be added to the page for use.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.split([value]) <>

Sets the word split behavior to the specified function, which when passed a string is expected to return that string split into an array of words.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.text([value]) <>

Sets the text for each box to the specified accessor function or static string.

This is a static method of TextBox, and is chainable with other methods of this Class. default accessor

function(d) {
  return d.text;
}

# TextBox.textAnchor([value]) <>

Sets the horizontal text anchor to the specified accessor function or static string, whose values are analagous to the SVG text-anchor property.

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.verticalAlign([value]) <>

Sets the vertical alignment to the specified accessor function or static string. Accepts "top", "middle", and "bottom".

This is a static method of TextBox, and is chainable with other methods of this Class.

# TextBox.width([value]) <>

Sets the width for each box to the specified accessor function or static number.

This is a static method of TextBox, and is chainable with other methods of this Class. default accessor

function(d) {
  return d.width || 200;
}

# TextBox.x([value]) <>

Sets the x position for each box to the specified accessor function or static number. The number given should correspond to the left side of the textBox.

This is a static method of TextBox, and is chainable with other methods of this Class. default accessor

function(d) {
  return d.x || 0;
}

# TextBox.y([value]) <>

Sets the y position for each box to the specified accessor function or static number. The number given should correspond to the top side of the textBox.

This is a static method of TextBox, and is chainable with other methods of this Class. default accessor

function(d) {
  return d.y || 0;
}

d3plus.fontExists(font) <>

Given either a single font-family or a list of fonts, returns the name of the first font that can be rendered, or false if none are installed on the user's machine.

This is a global function.


d3plus.rtl([elem]) <>

Returns true if the or element has either the "dir" HTML attribute or the "direction" CSS property set to "rtl". Accepts an optional DOM element as an argument, whose own inherited state will be evaluated rather than the default html/body logic.

This is a global function.


d3plus.stringify(value) <>

Coerces value into a String.

This is a global function.


d3plus.strip(value, [spacer]) <>

Removes all non ASCII characters from a string.

This is a global function.

Param Type Default Description
value String
[spacer] String "-" The character(s) to be used in place of spaces.

d3plus.textSplit(sentence) <>

Splits a given sentence into an array of words.

This is a global function.


d3plus.htmlDecode(input) <>

Strips HTML and "un-escapes" escape characters.

This is a global function.


d3plus.textWidth(text, [style]) <>

Given a text string, returns the predicted pixel width of the string when placed into DOM.

This is a global function.

Param Type Description
text String | Array Can be either a single string or an array of strings to analyze.
[style] Object An object of CSS font styles to apply. Accepts any of the valid CSS font property values.

d3plus.textWrap() <>

Based on the defined styles and dimensions, breaks a string into an array of strings for each line of text.

This is a global function.

# d3plus..fontFamily([value]) <>

If value is specified, sets the font family accessor to the specified function or string and returns this generator. If value is not specified, returns the current font family.

This is a static method of textWrap.

# d3plus..fontSize([value]) <>

If value is specified, sets the font size accessor to the specified function or number and returns this generator. If value is not specified, returns the current font size.

This is a static method of textWrap.

# d3plus..fontWeight([value]) <>

If value is specified, sets the font weight accessor to the specified function or number and returns this generator. If value is not specified, returns the current font weight.

This is a static method of textWrap.

# d3plus..height([value]) <>

If value is specified, sets height limit to the specified value and returns this generator. If value is not specified, returns the current value.

This is a static method of textWrap.

# d3plus..lineHeight([value]) <>

If value is specified, sets the line height accessor to the specified function or number and returns this generator. If value is not specified, returns the current line height accessor, which is 1.1 times the font size by default.

This is a static method of textWrap.

# d3plus..maxLines([value]) <>

If value is specified, sets the maximum number of lines allowed when wrapping.

This is a static method of textWrap.

# d3plus..overflow([value]) <>

If value is specified, sets the overflow to the specified boolean and returns this generator. If value is not specified, returns the current overflow value.

This is a static method of textWrap.

# d3plus..split([value]) <>

If value is specified, sets the word split function to the specified function and returns this generator. If value is not specified, returns the current word split function.

This is a static method of textWrap.

# d3plus..width([value]) <>

If value is specified, sets width limit to the specified value and returns this generator. If value is not specified, returns the current value.

This is a static method of textWrap.


d3plus.titleCase(str) <>

Capitalizes the first letter of each word in a phrase/sentence.

This is a global function.


d3plus.trim(str) <>

Cross-browser implementation of trim.

This is a global function.


d3plus.trimLeft(str) <>

Cross-browser implementation of trimLeft.

This is a global function.


d3plus.trimRight(str) <>

Cross-browser implementation of trimRight.

This is a global function.


Documentation generated on Wed, 06 Mar 2024 16:14:10 GMT

d3plus-text's People

Contributors

cnavarreteliz avatar davelandry avatar greenkeeperio-bot avatar nbond211 avatar rbaheti avatar stocksr avatar t-ohtsuki-cognitee avatar vegertar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

d3plus-text's Issues

lineHeight not respected when using fontResize

Expected Behavior

When setting fontResize(true), the line-height should respect the difference between the default fontSize and the lineHeight value.

Current Behavior

Currently, it seems to be statically set.

Steps to Reproduce (for bugs)

https://jsfiddle.net/pemwzcc3/1/

Your Environment

  • Browser Name: Chrome
  • Operating System and Version: macOS High Sierra

TextBox issue? Some text being given wrong font size.

Expected Behavior

It appears that text that does not need to wrap lines is being given the font size of a previous TextBox.

Current Behavior

image

Steps to Reproduce (for bugs)

http://jsfiddle.net/cjk1g1kr/8/ takes a min to load all the data I'm throwing at it.

Your Environment

Chrome, W 7 Pro

It could very possibly be my code. But I'd appreciate any insight and ideas for a workaround.
Thanks

detect wrapping bounds based on a shape

The current version of text wrapping in D3Plus v1 will extract x, y, width, and height from a shape placed adjacent to the text (either a <rect> or a <circle>).

One of our goals with these new modules is to sort of "demystify" a lot of the magic that happens behind the scenes to allow better control over all aspects of the functions. That being said, this is a killer feature that should be migrated over.

My initial thought is to have the .select( ) method also support being passed a shape instead of a container, and in that case, extrapolate the values from that shape and insert the new text element immediately after it in the DOM. Shouldn't be too hard.

I think that this can also be coded in a way so that if the shape's properties change, the text will re-wrap if called again.

Cannot append d3plus-text word wrap inside d3 code.

I am currently using d3plus-text library for text wrapping and dynamic font-size rendering. But somehow it is not getting affected in the chart.

I have the following piece of code:
var paths = markets.append("text")
.text(function(d) { return d.market + ": " + n(d.value);})

              .attr("x",0)
              .attr("y", function(d) { return y(d.offset / d.parent.sum)+20; })
              .each(function(d){
            	  d3plusText.TextBox().select(d3.select(this)).fontsize([8,20])render();
              }) ;

Please suggest how to append a textbox layer using d3plus-text inside d3.js.

Max number of lines

In the same way that text-wraps but could truncate with an ellipsis, it would be good to have a maximum number of lines limit too, because even with wrapping sometimes the content is too long.

Instead of:
image

Producing:
image

I'm thinking of having a truncateLines(n) or similar function on the configuration.

break line at newline escape character

Is this within the scope of the library? something I thought would be useful.

Here is an example use case:

  1. text string to split of string 1\nstring 2
  2. string 1 & string 2 will have separate tspan elements regardless of it they fit on the same line (ellipsis would still show if it overflows too far):

Result:

---------------
string 1
string 2
---------------

NOT

---------------
string 1 string
 2
---------------

Help : Use case with D3

Hello,

I am trying to make d3plus-text work with my circle packing (d3 v4) but I do not understand how to integrate it. Can you please help me understand how it works so that my texts are wrapped in their container.

Thank you

Actually :

  var text = g.selectAll("text")
    .data(nodes)
    .enter().append("text")
      .attr("class", "label")
      .attr('dy', '.35em')
      .style("fill-opacity", function(d) { return d.parent === root ? 1 : 0; })
      .style("display", function(d) { return d.parent === root ? "inline" : "none"; })
      .text(function(d) { 
            return d.data.name; 
        })
    ;

An in-range update of d3-selection is breaking the build 🚨

Version 1.0.5 of d3-selection just got published.

Branch Build failing 🚨
Dependency d3-selection
Current Version 1.0.4
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As d3-selection is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this 💪


Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details
Release Notes v1.0.5
  • Update dependencies.
Commits

The new version differs by 3 commits .

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

verticalAlign breaks with rotation

Expected Behavior

When rotating a TextBox, setting the verticalAlign should respect the rotation.

Current Behavior

Currently, it just moves the label down vertically.

Steps to Reproduce (for bugs)

https://jsfiddle.net/5hafqu6b/

Your Environment

  • Browser Name: Chrome
  • Operating System and Version: macOS High Sierra

add ability to selectively turn off fontExists caching as part of TextBox

Expected Behavior

When you call .font('my custom font') and that font is defined in a @font-face rule in css. Then the font should be downloaded and used.

Current Behavior

When you call .font('my custom font') and that font is defined in a @font-face rule in the css. Then provided some the browser has already finished downloading the font, it works correctly. If however that font is not yet available then the font is blacklisted for the duration of page. (I am writing a SPA so this could be a very long time.)

Steps to Reproduce (for bugs)

  1. Add this css @font-face { font-family: 'X-Custom'; src: url(http://fonts.gstatic.com/s/dancingscript/v9/If2RXTr6YS-zF4S-kcSWSVi_szLgiuQHiC4W.ttf) ; }
  2. Create a text box as usual including .font('X-Custom')
  3. Note that the font is not used.
  4. Now add a

    Sample

    to the page
  5. Create the SVG text on page load and note that the font does not get used.
  6. Delay the SVG text until the font is loaded and note that it does work.

An in-range update of d3plus-dev is breaking the build 🚨

Version 0.4.11 of d3plus-dev just got published.

Branch Build failing 🚨
Dependency d3plus-dev
Current Version 0.4.10
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As d3plus-dev is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes v0.4.11
Commits

The new version differs by 35 commits.

There are 35 commits in total.

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of d3-transition is breaking the build 🚨

Version 1.0.4 of d3-transition just got published.

Branch Build failing 🚨
Dependency d3-transition
Current Version 1.0.3
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As d3-transition is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this 💪


Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details
Release Notes v1.0.4
  • Fix string coercion in transition.style and transition.attr. Thanks, @sghall! (#67)
  • Update dependencies.
Commits

The new version differs by 4 commits .

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

implement tuncateWord method

Expected Behavior

Based on logic previously implemented by @IPWright83 here and the discussion here, users should be able to set .truncateWord(true) to enable truncating a string in the middle of a word.

Current Behavior

The current default behavior is to always show whole words.

long text issue

I got another issue with the long text rendering, the rendering text is: "建立客户信息反馈机制,跟踪解决过程,问题解决率达到80%以上", when run with TextBox().overflow(true), throwing the following error:

d3plus-text.js:210 Uncaught TypeError: Cannot read property 'trimRight' of undefined

if use with .overflow(false), the output only includes '...'
I'm using the version 0.9.8

further test shows the issue is related to Chinese symbols, such as ',' in the above sentance

An in-range update of d3-array is breaking the build 🚨

Version 1.0.3 of d3-array just got published.

Branch Build failing 🚨
Dependency d3-array
Current Version 1.0.2
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As d3-array is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this 💪


Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details
Release Notes v1.0.3
  • Update dependencies.
Commits

The new version differs by 6 commits .

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

no text appearing in subsequent renders on Windows

With the font resizing on, if there isn't enough space instead of adding ellipsis on it simply doesn't add any text.

Expected Behavior

Ellipsis if there isn't space for the text. In this provided example I would expect the last 3 characters that can be rendered to be missed off ABCDEFGHIJKLMNOPQRSTUVWXY...

Current Behavior

No text is added to the DOM

Steps to Reproduce (for bugs)

https://jsfiddle.net/IPWright83/uscw0Lh6/1/

I'm using the following where radius = 150 and I'm using 2 strings:
ABCDEFGHIJKLMNOPQRSTUVWXYZ12 and ABCDEFGHIJKLMNOPQRSTUVWXYZ123

new d3plus.TextBox()
    .data([d])
    .select(elements[i])
    .fontResize(true)
    .height(radius)
    .width(radius)
    .text(d => d.name)
    .x(d => -radius / 2)
    .y(d => -radius / 2)
    .ellipsis((text, line) => line ? text.replace(/\.|,$/g, "") + "..." : "")
    .verticalAlign("middle")
    .textAnchor("middle")
    .render();  
  });

Japanese language should be included in noSpaceRange

Thank you so much for this awesome library!
Without TextBox I would have wasted several days :)
I was a bit confused when I used TextBox with Japanese text,
as the wrapping function seemed to be broken against it.
After looking into the source for a moment, I found the reason:
Japanese too should be included in noSpaceRange variable in src/textSplit.js !

Typical Japanese texts like "日本語は基本的にはスペースを含みません" have no space inside them!
See e.g., Japanese Wikipedia article like https://ja.wikipedia.org/wiki/JavaScript.

An in-range update of d3plus-common is breaking the build 🚨

Version 0.6.15 of d3plus-common just got published.

Branch Build failing 🚨
Dependency d3plus-common
Current Version 0.6.14
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As d3plus-common is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this 💪


Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details
Release Notes v0.6.15
  • updates d3-array to v1.1.1 (6f44c40)
  • fix(package): update i18next to version 7.1.2 (#72) (ef501ca)
  • chore(package): update d3plus-dev to version 0.3.1 (#71) (4ee5c5d)
Commits

The new version differs by 4 commits .

  • 6f44c40 updates d3-array to v1.1.1
  • ef501ca fix(package): update i18next to version 7.1.2 (#72)
  • 4ee5c5d chore(package): update d3plus-dev to version 0.3.1 (#71)
  • e93f795 compiles v0.6.14

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Please provide more usage examples

Hey!

I'm trying to swap my code from using the text-wrapping utility in d3plus to this module, but I'm struggling to understand how I'm supposed to use it. I'd be happy to contribute some docs once I get my head around it.

My current code has some circular nodes which have data associated with them. This is how I insert the labels:

nodeData
    .append('text')
    .text(function(node) {
        return node.name;
    })
    .each(function() {
        d3plus.textwrap()
            .container(d3.select(this))
            .shape('circle')
            .draw();
    });

How would I convert this to using d3plus-text? I have managed to get the box method to insert tspans into the page based on the data I give it (by passing through the full node data array at once), but I want to wrap text that is associated with individual nodes on my page (the nodeData array).

Thanks in advance,

Helen

advanced overflow options

Thank you for making this a standalone module. It took me some time to figure out the new API so perhaps I am missing something.

What I am seeing is that if a word is too long for the bounding box it is omitted completely. I believe this is happening here: https://github.com/d3plus/d3plus-text/blob/master/src/box.js#L189 . If I comment out this line the labels that are too long for the bounding box overflow. Not sure if this is by design, perhaps it should be an option at least.

I'm using the module like this:

      const box = d3plusText.box()
        .textAnchor('middle')
        .fontSize(14)
        .width(d => d.values.length * boxWidth + 5)
        .text(d => d.key.replace(/_/g, ' '))
        .height(45);

      subplot.append('g')
        .attr('class', 'boxLabelText')
        .attr('transform', 'translate(-5,0)')
        .each(function (d) {
          box
            .data([d])
            .select(this)();
        });

text wrapping for double byte languages

Google Group: https://groups.google.com/forum/#!topic/d3plus/Mm0f2JW7asg

Does anyone have experience using the text wrapping functions with double-byte languages like simplified Chinese?

I am told they typically don’t use spaces so the wrapping functions do not know where to break and wrap. I get one long (unwrapped) line of characters.

Is there any way to detect word breaks? How do HTML div containers handle this? Should we just check for breaks between each character?

An in-range update of d3-array is breaking the build 🚨

Version 1.1.1 of d3-array just got published.

Branch Build failing 🚨
Dependency d3-array
Current Version 1.1.0
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As d3-array is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this 💪


Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details
Release Notes v1.1.1
  • Update dependencies.
Commits

The new version differs by 2 commits .

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Replace includes with indexOf in fontExists to make it compatible with IE11

TypeError: Object doesn't support property or method 'includes' at fontExists

Expected Behavior

Replace includes(fam) in src/fontExists.js in l.29 with indexOf(fam) !== -1 as "includes" is not supported by IE11, current core-js polyfills don't seem to solve the issue for Angular 4 and 5.

Current Behavior

IE11 is not able to render the text nodes.

Your Environment

Angular Core: 4.4.6
Angular Compiler CLI: 4.4.6
Node: 8.11.1
Navigator Platform: Win32
Browser: Internet Explorer 11.0.9600

text wrapping doesn't work properly when sentence contains both Chinese and English

Hi, I've read your blog post https://blog.datawheel.us/english-is-not-chinese-69b43959bb47, thanks for the work! But the example does not work when Chinese is combined with English, when putting an English sentence between, spaces between English words does not show up.

Expected Behavior

Spaces of English words show correctly

Current Behavior

Spaces between English words disappears

Steps to Reproduce (for bugs)

http://jsfiddle.net/gest45z9/12/

Your Environment

  • Browser Name: Chrome
  • Operating System and Version: MacOS Sierra v10.12.6

TextBox with auto resize bug

Expected Behavior

When using the TextBox with the fontResize set to true and passing a width and height, I expect the text to be wrapped to that container. In some cases depending on the text length and having a small width and big height, that doesn't happen.

Current Behavior

The text is enlarged way to much and goes out of the container bounds.

Steps to Reproduce (for bugs)

Provided a JSFiddle that reproduced the bug here: https://jsfiddle.net/74pg8we4/10/
Note that the big ok is the wrong behaviour, the small okkkkkk is what should happen.

image

multiple define functions present when uglifying

Hi you are doing a great job creating this module. But I am unable to use this in my project as it always throws up the error box is undefined. Can you please provide us with some usage examples?

Also I am getting an error saying multiple define functions present when i uglifying my project with the help of grunt and require.js, It would be great if you could help me regarding this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.