Socket
Socket
Sign inDemoInstall

@visx/text

Package Overview
Dependencies
8
Maintainers
4
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@visx/text


Version published
Maintainers
4
Install size
3.80 MB
Created

Package description

What is @visx/text?

@visx/text is a part of the VisX library, which provides a collection of reusable low-level visualization components for React. The @visx/text package specifically focuses on rendering text elements with various configurations, such as wrapping, truncation, and alignment, making it easier to handle text in SVG elements.

What are @visx/text's main functionalities?

Basic Text Rendering

This feature allows you to render basic text within an SVG element. You can specify the position, font size, and color of the text.

import { Text } from '@visx/text';

function BasicText() {
  return (
    <svg width={500} height={500}>
      <Text x={100} y={100} fontSize={16} fill="black">
        Hello, VisX!
      </Text>
    </svg>
  );
}

Text Wrapping

This feature allows you to wrap text within a specified width. This is useful for ensuring that long text strings fit within a given space.

import { Text } from '@visx/text';

function WrappedText() {
  return (
    <svg width={500} height={500}>
      <Text x={10} y={10} width={200} fontSize={16} fill="black">
        This is a long text that will wrap within the specified width.
      </Text>
    </svg>
  );
}

Text Truncation

This feature allows you to truncate text that exceeds a specified width. This is useful for ensuring that text does not overflow its container.

import { Text } from '@visx/text';

function TruncatedText() {
  return (
    <svg width={500} height={500}>
      <Text x={10} y={10} width={100} fontSize={16} fill="black" verticalAnchor="start" truncate>
        This is a long text that will be truncated.
      </Text>
    </svg>
  );
}

Text Alignment

This feature allows you to align text both horizontally and vertically within an SVG element. This is useful for centering text or aligning it to specific points.

import { Text } from '@visx/text';

function AlignedText() {
  return (
    <svg width={500} height={500}>
      <Text x={250} y={250} fontSize={16} fill="black" textAnchor="middle" verticalAnchor="middle">
        Centered Text
      </Text>
    </svg>
  );
}

Other packages similar to @visx/text

Changelog

Source

v1.3.0

:rocket: Enhancements
  • [responsive] Add ParentSizeModern, withParentSizeModern that don't add ResizeObserver polyfill #925
  • [scale] add scaleRadial #958
  • [text] add useText hook, refactor Text to use it #946
  • [event] support FocusEvents in localPoint #956
  • [xychart] release package #965
  • [xychart] add PointerEvent handlers to XYChart, all Series #947
  • [xychart] add support for FocusEvents #959
  • [xychart] integrate Annotations #938
:bug: Bug Fix
  • [shape] set y0 when it equals zero #955

:memo: Documentation

  • [xychart] add README and /docs/xychart to demo site #963
  • [demo] fix view demo hover pointer style #929
  • [tooltip] fix offsetTop documentation #970

:house: Internal

  • [xychart] add FocusEvent tests #962
  • [xychart] add PointerEvent tests #952
  • [xychart] add Annotations tests #948
:trophy: Contributors
Changes:
 - @visx/annotation: 1.2.0 => 1.3.0
 - @visx/axis: 1.2.0 => 1.3.0
 - @visx/brush: 1.2.0 => 1.3.0
 - @visx/demo: 1.2.0 => 1.3.0
 - @visx/drag: 1.2.0 => 1.3.0
 - @visx/event: 1.0.0 => 1.3.0
 - @visx/grid: 1.2.0 => 1.3.0
 - @visx/legend: 1.1.0 => 1.3.0
 - @visx/marker: 1.2.0 => 1.3.0
 - @visx/react-spring: 1.2.0 => 1.3.0
 - @visx/responsive: 1.1.0 => 1.3.0
 - @visx/scale: 1.1.0 => 1.3.0
 - @visx/shape: 1.2.0 => 1.3.0
 - @visx/stats: 1.1.0 => 1.3.0
 - @visx/text: 1.1.0 => 1.3.0
 - @visx/threshold: 1.2.0 => 1.3.0
 - @visx/tooltip: 1.1.0 => 1.3.0
 - @visx/visx: 1.2.0 => 1.3.0
 - @visx/xychart: 1.2.0 => 1.3.0
 - @visx/zoom: 1.0.0 => 1.3.0

Readme

Source

@visx/text

The @visx/text provides a better SVG <Text> component with the following features

  • Word-wrapping (when width prop is defined)
  • Vertical alignment (verticalAnchor prop)
  • Rotation (angle prop)
  • Scale-to-fit text (scaleToFit prop)

Example

Simple demo to show off a useful feature. Since svg <text> itself does not support verticalAnchor, normally text rendered at 0,0 would be outside the viewport and thus not visible. By using <Text> with the verticalAnchor="start" prop, the text will now be visible as you'd expect.

import React from 'react';
import { render } from 'react-dom';
import { Text } from '@visx/text';

const App = () => (
  <svg>
    <Text verticalAnchor="start">Hello world</Text>
  </svg>
);

render(<App />, document.getElementById('root'));

Installation

npm install --save @visx/text

Keywords

FAQs

Last updated on 15 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc