-
Notifications
You must be signed in to change notification settings - Fork 185
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
geometries and projections #1111
Merged
Merged
Changes from 6 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
bf05165
geometry mark
mbostock 79d4538
pRetTIEr
mbostock 1c2fd49
project x & y; re-fix #1043
mbostock ca62bc2
more projections, and options
mbostock 5945fa3
add missing test
mbostock 8027a85
PretTier
mbostock 587420d
projection + hexbin
mbostock f63a8eb
projection.stream for x and y
mbostock d320bb7
test null projection
mbostock a85bc7a
another comment
mbostock 8191c5a
remove TODO’s
mbostock 8d63435
simplify walmarts
mbostock 854b4ac
Update README
mbostock 7c0711c
sphere, graticule
mbostock 9c8a785
update graticule snapshot
mbostock 119e3e8
Walmart data provenance
Fil 4bc985e
r channel for geometries; sort by R.
Fil 06ac9a9
Use the facets dimensions, and respect margins. Note that this change…
Fil 6b6c05d
clip: "sphere"
mbostock fe09ac7
allow projection configuration function
mbostock 355467a
revert dimensions changes
mbostock 5d0e16c
withDefaultSort
mbostock ce63d6d
Merge branch 'fil/geo' into mbostock/geo
mbostock 2bb4ff0
tweak faceted walmarts test
mbostock d93b812
fix auto height for pre-projected geometry
mbostock 15c6880
more projections
mbostock d973dbb
projection + density
mbostock e2b1691
all marks can clip to sphere
Fil 2e4ddf3
test voronoi clip to sphere
Fil 4b561a4
error if sphere clip lacks projection
mbostock d0e41cb
error if projection and band-requiring channels
mbostock c0cd002
Update README.md
mbostock 1114a5b
Update README.md
mbostock ed1b7e5
pReTTIER
mbostock cf8476e
projection requires x and y channels
mbostock 11a8e83
Update README
mbostock 23d3c83
Update README
mbostock c2c4d49
Update README
mbostock 30b1acd
Update README
mbostock dce3b72
a more interesting voronoi map
Fil 48da147
geo
mbostock 3efd94d
use fitExtent for armadillo
mbostock 4690c5e
more data provenance
mbostock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import {geoPath} from "d3"; | ||
import {create} from "../context.js"; | ||
import {identity} from "../options.js"; | ||
import {Mark} from "../plot.js"; | ||
import {applyChannelStyles, applyDirectStyles, applyIndirectStyles, applyTransform} from "../style.js"; | ||
|
||
const defaults = { | ||
ariaLabel: "geometry", | ||
fill: "none", | ||
stroke: "currentColor", | ||
strokeWidth: 1, | ||
strokeLinecap: "round", | ||
strokeLinejoin: "round", | ||
strokeMiterlimit: 1 | ||
}; | ||
|
||
export class Geometry extends Mark { | ||
constructor(data, options = {}) { | ||
const {geometry = identity} = options; | ||
super( | ||
data, | ||
{ | ||
geometry: {value: geometry} | ||
}, | ||
options, | ||
defaults | ||
); | ||
} | ||
render(index, scales, channels, dimensions, context) { | ||
const {geometry} = channels; | ||
const {projection} = context; | ||
const path = geoPath(projection); | ||
return create("svg:g", context) | ||
.call(applyIndirectStyles, this, scales, dimensions) | ||
.call(applyTransform, this, scales) | ||
.call((g) => | ||
g | ||
.selectAll() | ||
.data(index) | ||
.enter() | ||
.append("path") | ||
.call(applyDirectStyles, this) | ||
.attr("d", (i) => path(geometry[i])) | ||
.call(applyChannelStyles, this, channels) | ||
) | ||
.node(); | ||
} | ||
} | ||
|
||
export function geometry(data, options) { | ||
switch (data?.type) { | ||
case "FeatureCollection": | ||
data = data.features; | ||
break; | ||
case "GeometryCollection": | ||
data = data.geometries; | ||
break; | ||
case "Feature": | ||
case "LineString": | ||
case "MultiLineString": | ||
case "MultiPoint": | ||
case "MultiPolygon": | ||
case "Point": | ||
case "Polygon": | ||
case "Sphere": | ||
data = [data]; | ||
break; | ||
} | ||
return new Geometry(data, options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,13 +82,14 @@ export class Text extends Mark { | |
this.frameAnchor = maybeFrameAnchor(frameAnchor); | ||
} | ||
render(index, scales, channels, dimensions, context) { | ||
const {x, y} = scales; | ||
const {x: X, y: Y, rotate: R, text: T, fontSize: FS} = channels; | ||
const {rotate} = this; | ||
const [cx, cy] = applyFrameAnchor(this, dimensions); | ||
return create("svg:g", context) | ||
.call(applyIndirectStyles, this, scales, dimensions) | ||
.call(applyIndirectTextStyles, this, T, dimensions) | ||
.call(applyTransform, this, scales) | ||
.call(applyTransform, this, {x: X && x, y: Y && y}) | ||
.call((g) => | ||
g | ||
.selectAll() | ||
|
@@ -140,7 +141,7 @@ function applyMultilineText(selection, {monospace, lineAnchor, lineHeight, lineW | |
selection.each(function (i) { | ||
const lines = linesof(formatDefault(T[i])); | ||
const n = lines.length; | ||
const y = lineAnchor === "top" ? 0.71 : lineAnchor === "bottom" ? -0.29 - n : (164 - n * 100) / 200; | ||
const y = lineAnchor === "top" ? 0.71 : lineAnchor === "bottom" ? 1 - n : (164 - n * 100) / 200; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This reverts #1061. |
||
if (n > 1) { | ||
for (let i = 0; i < n; ++i) { | ||
if (!lines[i]) continue; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes #1043.