Positioning the label inside the compressed bubble - highcharts

I have a packed bubble chart with the following jsfiddle link: https://jsfiddle.net/ytvcjzx1/

Below is the code snippet:

(function(H) {
  H.addEvent(H.Series, 'afterDrawDataLabels', function(e) {
    const series = this;
    const chart = series.chart;

    if (!series.parentNode.plotX || chart.options.chart.type !== 'packedbubble') {
      return;
    }

    if (!series.customLabel) {
      series.customLabel = series.chart.renderer.label(
          series.name, null, null, 'rect'
        )
        .attr({
          align: 'center',
          fill: 'rgba(255, 255, 255, 0.7)',
          zIndex: 3
        })
        .css({
          color: 'black',
          fontSize: '12px',
          fontWeight: 'bold',
          whiteSpace: 'nowrap', // To prevent text wrapping
          padding: '5px', // Add some padding around the label text
          borderRadius: '5px' // Add rounded corners to the background
        })
        .add();
    }

    series.customLabel.attr({
      x: series.parentNode.plotX + chart.plotLeft,
      y: series.parentNode.plotY + chart.plotTop - 10
    });
  });
}(Highcharts));
...

The issue arises when dealing with the series name

Long word 1234432222 1234432222...
which extends beyond the bubble area. Is there a way to enable text overflow so that all series names are contained within the bubble and truncated with an ellipsis for hover identification and full view via tooltip? Perhaps a CSS solution may be possible?

Answer №1

If you want the personalized label to show up inside the bubble, you might want to consider making this adjustment in your displayed label:

series.customLabel = series.chart.renderer.label(
      series.name, null, null, 'rect'
    )
    .attr({
      align: 'center',
      fill: 'rgba(255, 255, 255, 0.7)',
      zIndex: 3
    })
    .css({
      color: 'black',
      fontSize: '12px',
      fontWeight: 'bold',
      whiteSpace: 'nowrap', // To avoid text wrapping
      padding: '5px', // Include some padding around the label text
      borderRadius: '5px', // Integrate rounded corners to the background
      textOverflow: 'ellipsis',
      width: series.parentNode.graphic.width
    })
    .add();

This includes

textOverflow: 'ellipsis', width: series.parentNode.graphic.width
.

Take a look at this initial JSFiddle demo, or this JSFiddle demo that features padding and manages window resizing.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Showcase -solely one property object- from numerous property objects enclosed within an array

Hello, I am seeking assistance as I have recently begun learning about angularJS. I am working with objects that have keys such as: scope.eventList=[]; for(){ var event = { id : hash, ...

Utilizing the Power of Magicline in Conjunction with Flexslider

Currently, I am implementing Flexslider for a slideshow on my website and I am attempting to integrate Magicline with it. The functionality is working well, but I have encountered an issue where the magicline does not move when clicking on the navigation a ...

Assurances for a function devoid of any output information

Currently, I am in the process of unraveling a complex web of callback-based code for node.js, and it appears that promises may be the solution due to numerous asynchronous database operations. Particularly, my focus is on utilizing Bluebird. I have reach ...

Guide on how to switch a class on the body using React's onClick event

There's a button in my code that triggers the display of a modal-like div element. When this button is clicked, I aim to apply a class to the body element; then when the close button is clicked, I'll remove this class. I'm looking for guid ...

Enhance Data3 Sankey to disperse data efficiently

There are a few instances where the D3 Sankey spread feature is showcased here. However, it seems that this specific function is not included in the official D3 Sankey plugin. Is there anyone who can assist me in obtaining the code for the Spread function ...

JavaScript and jQuery radio button matrix group implementation

I'm feeling completely lost when it comes to solving this problem. My task is to create a matrix of radio buttons with columns labeled 1 to 3 and rows labeled A to C. A B C 1 (o) (o) (o) 2 (o) (o) (o) 3 (o) (o) (o) <tabl ...

Utilizing unique symbols to dynamically add form elements to an HTML page with jQuery's append method

I am facing an issue with creating forms on my HTML page. Here is an example of how I am trying to do it: <form action="/tasks/<%= allTasks.e[0].id %>/delete" method="POST"> <button class="deleteTask">Delete</button> </f ...

Setting a false condition on jQuery's .on('canplaythrough') event

Struggling to implement a custom audio control with jQuery, but encountering some issues. I'm in the process of converting native JavaScript to jQuery for consistency in my code, however, I can't seem to get it working. The original code that is ...

Challenge with dependency cycle arises when utilizing Styled Components in conjunction with compound component design pattern

I have implemented multiple accordion components using the compound component methodology (check out a great talk by Ryan Florence on compound components here). To maintain code quality, I have set up an ESLint rule import/no-cycle to avoid dependency cyc ...

Add elements to a ul element using JavaScript and make the changes permanent

Managing a dashboard website with multiple div elements can be quite tedious, especially when daily updates are required. Manually editing the HTML code is inefficient and time-consuming. Each div contains a ul element where new li items need to be added ...

What is the best way to extract a variable from a MongoDB query when using Node.js?

Is there a way to retrieve a variable from a mongodb query in node.js that counts the number of documents in a collection called students? I attempted to define a global variable just before the query and tried to set its value within the query function: ...

Ways to obtain the coordinates that surround a particular x, y location

I am trying to figure out how to generate an array of coordinates around a specific x, y point. For instance: xxxxx xxoxx xxxxx In this case, "o" is located at coordinates 3, 2. Now I aim to produce: xxx xox xxx as the set of coordinates surrounding "o ...

When attempting to retrieve information, the variable is displaying as undefined, although the console log is indicating that data

Here is the code I am currently using: function get_last_chat_time(steamid){ if(!db_connect) { return 0; } chat_db.aggregate( [ {"$match":{"name":"chat-msg",steamid: steamid}}, { "$sort" : { date : -1 } }, {"$limit" : 1} ...

What is the process for submitting and storing a collection of files in a database as a list?

I am trying to implement a feature in my MVC project where users can upload multiple files and see them listed before submitting the form. However, I am facing some challenges with finding a solution for this. Demo: My goal is to allow users to add multi ...

Halt spread: descend in a bubble?

It seems that the issue at hand may not be related to propagation, but rather a design flaw. I have come across information suggesting that propagation problems tend to bubble up, however, let me explain my situation. I am working with a table edit grid. ...

Opening a Bootstrap Modal in React without relying on npm react-bootstrap

I've been trying to create a Modal in React.js using Bootstrap5, but I'm unable to use npm react-bootstrap for various reasons. I attempted an approach where I utilized state to set Modal classes with a button, which worked well with my NavBar, b ...

Retrieve the parseJSON method using a string identifier

I am trying to serialize a C# const class into name-value pairs, which I need to access by their string names on the client side. For example: return $.parseJSON(constantClass).property; This approach is not working as expected. Is there any alternative ...

The property 'dateClick' is not found in the 'CalendarOptions' type in version 6 of fullcalendar

Below is the Angular code snippet I am currently using: calendarOptions: CalendarOptions = { plugins: [ dayGridPlugin, timeGridPlugin, listPlugin ], initialView: 'dayGridMonth', headerToolbar: { left: 'prev today next' ...

Submitting data using JavaScript's POST method

I am facing a challenge with posting Array data to an HTTP connector. My data is structured as follows: var data = [{ key:'myKey', keyName:'myKeyName', value:'value', valueName:'valueName' }, { ...

Navigating the division between presentational and container components in React/Redux

Here is a basic outline of my current setup: container.js: import Presentation from './Presentation'; import { connect } from 'react-redux'; export default connect( ({ someState}) => ({ ...someState }), (dispatch) => { ...