question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Element Attributes

See original GitHub issue

TLDR; <g class="ct-point" title="Fancy Title, WHEE!"/> is useful, I has!

I know you addressed advanced features such as hover titles and the like some time ago, but I just started looking into chartist and had some features that I felt it could use; specifically custom attributes for series data.

In my use case, I wanted to use the jquery Tooltip library to add fancy hover effects to data. This is a pretty trivial feat via the existing title attribute for DOM elements. However, I felt that using DOM manipulation after-the-fact is a little messy when all I’m needing to do is inject an already-valid attribute onto the generated element.

As such, I’m updating the library to do just this; anything passed in via the series object along side value and className are passed directly through to the DOM, so this adds support for title, data-*, and any other attribute people can think of. If this sounds useful for upstream, just let me know and I’ll see what I can do about making a patch for your upstream version, (aka pull request, silly github terminology).

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
gionkunzcommented, Dec 12, 2015

Well, I guess DOM manipulation within the same call-stack of the chart being drawn isn’t hurting that much. The event pipeline helps a lot in this case. What about a plugin?

var chart = new Chartist.Line('.ct-chart', {
  labels: [1, 2, 3, 4],
  series: [[
    {value: 5, title: 'Five'}, 
    {value: 7, title: 'Seven'}, 
    {value: 3, title: 'Three'}, 
    {value: 9, title: 'Nine'}
  ]]
}, {
  fullWidth: true
});

chart.on('draw', function(data) {
  if(data.type === 'point') {
    data.element.attr({
      title: data.series[data.index].title
    });
  }
});

Also be aware that title is not an officially supported attribute on SVG elements. In SVG there’s a <title> element for this purpose.

If you want to use a tooltip plugin, you can configure therm fairly easy to work with Chartist. I’m using tooltipster frequently with Chartist.

0reactions
gionkunzcommented, Oct 17, 2016

You can use the created event and then use element.querySelectorAll('g') http://gionkunz.github.io/chartist-js/api-documentation.html#chartistsvg-function-queryselectorall

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using custom elements - Web Components | MDN
Customized built-in elements inherit from basic HTML elements. To create one of these, you have to specify which element they extend (as implied ......
Read more >
Using Attributes and Properties in Custom Elements
Attributes are defined in the HTML document and provide additional information about HTML elements. When a browser parses the HTML to create DOM ......
Read more >
Custom elements - The Modern JavaScript Tutorial
We can create custom HTML elements, described by our class, with its own methods and properties, events and so on. Once a custom...
Read more >
Custom Element Best Practices - web.dev
Custom elements let you construct your own HTML tags. This checklist covers best practices to help you build high quality elements.
Read more >
4.13 Custom elements - HTML Standard - WhatWG
A custom element is an element that is custom. Informally, this means that its constructor and prototype are defined by the author, instead...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found