Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to define how tickLines are rendered? #123

Closed
marcus-grant opened this issue Jan 24, 2018 · 12 comments
Closed

How to define how tickLines are rendered? #123

marcus-grant opened this issue Jan 24, 2018 · 12 comments

Comments

@marcus-grant
Copy link

marcus-grant commented Jan 24, 2018

I've been searching all the documentation and issues and can't find anything that specifies how to customize tick lines, as opposed to tick values or scaling or labelling. The only solution I've come up with is to take the classNames you've given tick-line and specifying a style class for that. Is there any way to pass jsx or at the very least to pass your own class name to each tick line for each orientation?

@emeeks
Copy link
Member

emeeks commented Jan 25, 2018

You can style by class, which is traditionally the way to style axes but yes, in keeping with the many new undocumented features, an axis object accepts a tickLineGenerator that takes a function which returns SVG JSX for your tick. For example ,in XYFrame you could pass:

axes={[
            {
              orient: "left",
              tickLineGenerator: ({ xy }) => (
                <path
                  style={{ fill: "lightgrey", strokeDasharray: "5 5", stroke: "grey" }}
                  d={`M${xy.x1},${xy.y1 - 5}L${xy.x2},${xy.y1 - 5}L${
                    xy.x2
                  },${xy.y1 + 5}L${xy.x1},${xy.y1 + 5}Z`}
                />
              )
            },
            {
              orient: "bottom",
              tickLineGenerator: ({ xy }) => (
                <path
                  style={{ fill: "lightgrey", strokeDasharray: "5 5", stroke: "grey" }}
                  d={`M${xy.x1 - 5},${xy.y1}L${xy.x1 - 5},${xy.y2}L${xy.x1 +
                    5},${xy.y2}L${xy.x1 + 5},${xy.y1}Z`}
                />
              )
            }
          ]}

And produce these... things:

screen shot 2018-01-24 at 5 40 38 pm

If you have any issues let me know. And yes, I'm in the middle of a big doc rewrite so hopefully it will be a better experience in the future. The current docs for <Axis> itself have an example, too:

https://emeeks.github.io/semiotic/#/semiotic/axis

@marcus-grant
Copy link
Author

Ok thank you for the detailed response, I'll get back to you when I've tried it out

@dgwyer
Copy link
Contributor

dgwyer commented Jan 25, 2018

Hi Marcus, I'd be interested in seeing some examples of what you come up with. i.e. how you're looking to customize tick lines.

@bengarvey
Copy link

I've been doing it like marcus (with css) and usually end up doing something like this:

axes={[{className: 'slopeTick', orient: 'left', tickFormat: d => d, ticks: 10}]}

And then in css:

.slopeTick .tick-line {
  opacity: 0;
}

@bengarvey
Copy link

What I would love is the ability to set className to a function rather than a string, but that might be a deeper react issue. I'm trying to do conditional colors for tick labels and haven't figured out a solution for XYFrame yet. It isn't too hard with the ORFrame.

@dgwyer
Copy link
Contributor

dgwyer commented Jan 25, 2018

Hi Ben. You can target singular tick labels, or a range of tick labels, directly via CSS using selectors such as nth-child(n) to produce effects like this.

But this assumes you know the tick values and the style(s) you want to apply ahead of time. I'm assuming you want to be able to set a CSS class per tick value because you want to decide in code (dependent on the data etc.) how to exactly style tick values?

Have you any images, mockups, or examples done in other frameworks that show the sort of thing you're trying to achieve? And what is your criteria for conditionally coloring tick labels?

@bengarvey
Copy link

@dgwyer yeah, I want to do it conditionally on the data. I'll make another issue about it instead of hijacking this one :)

@marcus-grant
Copy link
Author

marcus-grant commented Jan 25, 2018

It's for a work project and a higher priority has come up, but I will definitely get to this within a week and document this when I do. And as for my current solution, it is as @bengarvey has said. I just went on my browser's development tools looked at what CSS classNames were given to the svg paths representing the ticklines, they are called tick-lines, I then went and created my own CSS (SASS actually) class called ticklines where I set the stroke property using the rgba(r,g,b,a) function which allows setting an alpha (transparency/opacity) of the stroke to 0, thus making it transparent and not visible as a tick line anymore. For our project we need the gridlines to either be much more subtle or completely transparent, and potentially only have one dimension of ticklines visible. So for now I'm just making them all invisible.

.tick-line {           
  stroke: rgba(0,0,0,0);                                
}

image

@dgwyer
Copy link
Contributor

dgwyer commented Jan 25, 2018

You can use tickSize: 0 to remove tick lines (currently undocumented).

See this pen for an example of specifying several instances of axes to render multiple tick lines of specific sizes.

It works pretty well: https://codepen.io/dgwyer/pen/06ca097f595e2de6d23ac4294f2d4483

@bengarvey
Copy link

@dgwyer Good find! Now all we have to do is add it to the wiki and it will become documented :)

@emeeks
Copy link
Member

emeeks commented Jan 26, 2018

There's an example of using tickSize in the interactive examples, too: https://emeeks.github.io/semiotic/#/semiotic/axis

I seriously need to get the docs in order, guys.

@emeeks emeeks closed this as completed Jan 26, 2018
@niwsa
Copy link

niwsa commented Mar 22, 2019

Hi everyone just found this thread useful, I was struggling to find out a solution and tickSize 0 helped..Just wanted to say thanks :) I guess way to think is that all properties of d3-axis applies as documented in xyframe#axes-array-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants