Comments (1)
I'd like to add to this – trying to figure this out and it's unclear how to do this efficiently with D3.
Key reason why this is important is that color and texture offer two separate dimensions for visualization. As an example, in my current project, fill is defined by the color dimension, which is mapped to the legend in my visualizations, and textures will ideally be defined to correspond to an interactive filter dimension (i.e. we have filters that let the user interact with the data and subset it to get a drilled down view).
For any future folks, one current work around is to duplicate each element – in my case, I first render the color data element and then, using D3's element cloning method, render the textured element on top of it. Any event bindings are then applied to the textured element that's rendered on top of its corresponding colored element. It works, but duplicating each SVG node corresponding to a data element is a pretty DOM heavy and inefficient approach.
Key code below (for a stacked bar graph):
import textures from "textures";
// Setup Texture Scale & Map Object
self.texturescale = D3.scaleOrdinal().domain(self.filters).range(self.textures);
self.texturesMap = Object.fromEntries(
new Map(self.textures.map((texture) => [
texture,
textures
.paths()
.d(texture)
.shapeRendering("geometricPrecision")
.lighter()
.thinner()
.fill("transparent")
]))
);
// ... Other chart code
self.bargroups
.selectAll("rect")
.data((d) => d)
.enter()
.append("rect")
.attr("id", (d) => `bar-${d.id}`)
.attr("class", (d) => `bar`)
.attr("x", (d) => self.x(d.from))
.attr("y", (d) => self.y(d.group))
.attr("width", (d) => self.x(d.to) - self.x(d.from))
.attr("height", self.y.bandwidth())
.attr("fill", (d) => self.texturesMap[self.textureScale(d.filter)]
.attr("opacity", 0.7)
.clone(true) // Clone Rect Element
.attr("class", "bar interactable")
.attr("fill", (d) => self.texturesMap[self.textureScale(d.filter).url()]
.attr("opacity", 1.0)
.on("mouseover", (e, d) => self.mouseOverBar(e, d))
from textures.
Related Issues (20)
- Undefined on svg.call HOT 6
- Browser printing is not the same as I thought
- A tool for drawing textures
- Making textures work in simple context HOT 2
- Have a new texture instance with a copy() method
- Avoid svg.call(t) HOT 4
- Please push a new minor version to npm HOT 2
- Replace header .png with an .svg map of Italy HOT 1
- working with svg crowbar to export? HOT 5
- D3v4 compatibility HOT 3
- create tags? HOT 2
- TypeError: this.append is not a function HOT 1
- Use linear gradient as fill/stroke colour? HOT 1
- Possible to assign fill to custom paths? HOT 2
- Best way to use in Sketch for design? HOT 3
- texture fill for responsive map
- downloading a fill that is done with a url
- Publish to https://cdnjs.com/ HOT 1
- Example chart integrations HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from textures.