Skip to content

axis mark #1197

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

Merged
merged 156 commits into from
Feb 1, 2023
Merged
Changes from 1 commit
Commits
Show all changes
156 commits
Select commit Hold shift + click to select a range
d2b54b7
axis mark
mbostock Dec 23, 2022
e36bf48
deferred channels
mbostock Dec 23, 2022
9d029d2
vector tick
mbostock Dec 23, 2022
1aa729c
tickPadding
mbostock Dec 23, 2022
dbbe828
grid
mbostock Dec 23, 2022
1c1b911
grid
mbostock Dec 23, 2022
0811d59
no rounded stroke
mbostock Dec 24, 2022
e71972a
fix half-pixel offset
mbostock Dec 24, 2022
f90bdb0
more conditional axes
mbostock Dec 24, 2022
bb5d976
grid mark
mbostock Dec 24, 2022
c44c29d
DRY tick
mbostock Dec 24, 2022
8d838b4
tick[XY]
mbostock Dec 24, 2022
6fb3f78
explicit ticks
mbostock Dec 24, 2022
b9ac607
axisTick[XY]
mbostock Dec 24, 2022
f67dcc7
axis mark data
mbostock Dec 24, 2022
59239de
axis insets
mbostock Dec 24, 2022
df951b8
tickFormat
mbostock Dec 24, 2022
ec672c5
better default tick format
mbostock Dec 24, 2022
d273968
simpler inferTickFormat
mbostock Dec 24, 2022
8ef29d7
auto ticks; expose scale.interval
mbostock Dec 24, 2022
edb549a
anchor
mbostock Dec 24, 2022
c1046a0
manual axis label, for now
mbostock Dec 24, 2022
50f0d92
tickRotate
mbostock Dec 24, 2022
b204427
fix crash in sparse excludeIndex
mbostock Dec 26, 2022
564970e
facetAnchor; fix mark-level missing facet
mbostock Dec 26, 2022
e0d8ed2
simpler facet sorting
mbostock Dec 27, 2022
2e5663d
fix #522; better facetAnchor
mbostock Dec 27, 2022
a1fb2ac
fix #1198; better empty facets
mbostock Dec 27, 2022
754cd3c
fix for ordinal scales
mbostock Dec 27, 2022
d1b3c75
soft hyphen
mbostock Dec 27, 2022
dc77e25
test label wrapping
mbostock Dec 27, 2022
70e854a
facet grid
mbostock Dec 27, 2022
b03d2a3
better facet grid
mbostock Dec 27, 2022
3347586
better facet grid, again
mbostock Dec 27, 2022
a364e66
better grid
mbostock Dec 27, 2022
4e0e469
better facet axes; fix font variant
mbostock Dec 28, 2022
a041fdf
extract facetSkip
mbostock Dec 28, 2022
7923696
empty facets
mbostock Dec 28, 2022
0ae5493
destructure options
mbostock Dec 29, 2022
74b0840
remove redundant defaults
mbostock Dec 29, 2022
00535df
fix tickPadding, tickRotate
mbostock Dec 29, 2022
b41631d
better grid defaults
mbostock Dec 29, 2022
e22bf59
more empty facets
mbostock Dec 29, 2022
49c32af
simpler facet warning
mbostock Dec 29, 2022
6d892d3
decoration
mbostock Dec 29, 2022
3c651af
better empty facets
mbostock Dec 29, 2022
a2e3725
better facet sort
mbostock Dec 29, 2022
28b7afd
extract facetAnchor
mbostock Dec 29, 2022
4517a5b
extract more facet logic
mbostock Dec 29, 2022
0962cbb
const facets
mbostock Dec 29, 2022
426364a
unify code
mbostock Dec 29, 2022
bc70e1b
more facet anchors
mbostock Dec 29, 2022
68a1bbb
invert facetAnchor
mbostock Dec 30, 2022
2c76baf
checkpoint axis label
mbostock Dec 30, 2022
b854a09
checkpoint axis mark integration
mbostock Jan 1, 2023
9d94b22
fix minimum offset margin
mbostock Jan 1, 2023
319e59e
fix for null marks and scales
mbostock Jan 1, 2023
4fef6a0
better implicit axes
mbostock Jan 1, 2023
0d27b07
denote side-effect
mbostock Jan 1, 2023
7794fce
better axis options
mbostock Jan 1, 2023
93b1a77
implicit facet axes
mbostock Jan 1, 2023
7aad4ac
more implicit axis options
mbostock Jan 1, 2023
4797caf
inferAxes
mbostock Jan 1, 2023
cdda45e
delete old axes
mbostock Jan 1, 2023
5f54f60
minimize diff
mbostock Jan 1, 2023
ebc9394
fix default margins
mbostock Jan 1, 2023
0fc7d7d
remove mark.decoration
mbostock Jan 1, 2023
d3490e7
facet margin options
mbostock Jan 1, 2023
f1b71f2
move side effect
mbostock Jan 1, 2023
938c9d6
inheritScaleLabels
mbostock Jan 1, 2023
1ff510d
Merge branch 'main' into mbostock/axis-mark
mbostock Jan 2, 2023
027b13c
remove comment
mbostock Jan 2, 2023
5492bde
better ARIA labels; restore prior axis order
mbostock Jan 2, 2023
0b1fcb6
regenerate tests; smarter partial implicit axes
mbostock Jan 3, 2023
e58cac6
more smarter partial implicit axes
mbostock Jan 3, 2023
f6c9c38
axis line
mbostock Jan 3, 2023
d4915e4
text stroke options
mbostock Jan 3, 2023
924ec49
don’t inline text elements
mbostock Jan 3, 2023
a54c209
do inline title elements
mbostock Jan 3, 2023
5083551
axis label
mbostock Jan 3, 2023
a65946b
fix axes for interval scales
mbostock Jan 3, 2023
660d9b2
gridDasharray
mbostock Jan 3, 2023
2faf620
better implicit axis
mbostock Jan 3, 2023
c55990c
x-axis label
mbostock Jan 4, 2023
0be9887
another fancy axis example
mbostock Jan 4, 2023
8701c2f
polish example
mbostock Jan 4, 2023
8f21d24
fancy multi-line time ticks
mbostock Jan 4, 2023
a29691e
another fancy axis example
mbostock Jan 4, 2023
4df432e
remove secondary grid shorthand
mbostock Jan 4, 2023
819705c
tweak y-axis label position
mbostock Jan 4, 2023
70ebb1f
first stab at documentation
Fil Jan 5, 2023
c5e0cec
the grid doesn't follow anchor
Fil Jan 5, 2023
db310f1
Merge branch 'main' into mbostock/axis-mark
mbostock Jan 20, 2023
b60d2b8
better deferred channels
mbostock Jan 20, 2023
973aa59
better explicit built-in axes
mbostock Jan 20, 2023
8e69ee2
fix metroUnemploymentRidgeline test
mbostock Jan 20, 2023
773daa9
use insetTop for better semantics
mbostock Jan 20, 2023
3c8f5ec
fix label option inheritance
mbostock Jan 20, 2023
a6d91fe
axis = both
mbostock Jan 20, 2023
3bf205f
Merge branch 'main' into mbostock/axis-mark
mbostock Jan 20, 2023
3106285
fix comment
mbostock Jan 20, 2023
f3ad022
a few fixes to axis label position
mbostock Jan 24, 2023
96065f4
labelAnchor
mbostock Jan 24, 2023
ace8885
smarter default labelAnchor
mbostock Jan 25, 2023
30b3022
fix googleTrendsRidgeline
mbostock Jan 25, 2023
19a3502
fix longLabels
mbostock Jan 25, 2023
27ee28d
non-fix for named time intervals
mbostock Jan 25, 2023
ae038c7
fix projectionHeightGeometry
mbostock Jan 25, 2023
e0fd9f6
non-fix for x-axis label position
mbostock Jan 25, 2023
599ae3a
better axis label position
mbostock Jan 26, 2023
0b75819
inset axis label
mbostock Jan 26, 2023
d7fc5a7
fix #375; respect facet margins
mbostock Jan 26, 2023
5cd87f0
fix industryUnemploymentTrack
mbostock Jan 26, 2023
e4410be
restore grid in penguinCulmen
mbostock Jan 26, 2023
e80954b
facet margin collapse
mbostock Jan 26, 2023
f1a1e1e
better facet margin collapse
mbostock Jan 26, 2023
34afc03
drop comment
mbostock Jan 26, 2023
dfc2e5c
labelOffset
mbostock Jan 27, 2023
5d15a63
fix auto labels and arrows
mbostock Jan 27, 2023
57cde69
named exports for tests
mbostock Jan 27, 2023
366a045
enable facet axis labels
mbostock Jan 27, 2023
7022708
add non-faceted athletesSample test
mbostock Jan 27, 2023
245d7da
better facet axis label position
mbostock Jan 27, 2023
5d7c944
cleaner
mbostock Jan 27, 2023
7f3865a
enforce constant tick options
mbostock Jan 27, 2023
e789969
shorter athletesSportWeight
mbostock Jan 27, 2023
f6b71ff
remove dead code
mbostock Jan 27, 2023
c62d35d
checkpoint cross-facet marks
mbostock Jan 28, 2023
9da51d5
checkpoint supermarks
mbostock Jan 28, 2023
1187cda
super option
mbostock Jan 28, 2023
686fda6
better super marks
mbostock Jan 28, 2023
4c002c0
drop unused mid facet anchors
mbostock Jan 28, 2023
5745309
disallow superposition, for now
mbostock Jan 29, 2023
fdd950b
facet = super
mbostock Jan 29, 2023
9177f3e
minimize diff
mbostock Jan 29, 2023
6b9bd91
fix axis label position, finally?
mbostock Jan 29, 2023
0113c85
better hexbin tests
mbostock Jan 29, 2023
6159142
polish tests
mbostock Jan 29, 2023
2ea8f2c
fix named time intervals for ticks
mbostock Jan 29, 2023
a653e54
grid xy shorthand
mbostock Jan 29, 2023
8150d8f
consistent scale checks
mbostock Jan 29, 2023
3be2f7c
better axis options
mbostock Jan 29, 2023
25d0f29
tickSpacing option
mbostock Jan 30, 2023
b7baa23
propagate tickSpacing option
mbostock Jan 30, 2023
aba84ee
fix off-by-one with interval ticks
mbostock Jan 30, 2023
c071fa4
typo (thanks, @yurivish!)
Fil Jan 30, 2023
c785d93
only one label for both axes
mbostock Jan 30, 2023
9c57820
a bit of documentation for axisX
Fil Jan 31, 2023
61e1145
given data, don’t defer channels
mbostock Jan 31, 2023
6624e7a
reduce aaplCloseDataTicks test
mbostock Jan 31, 2023
2e9544e
implicit grid with explicit axis
mbostock Jan 31, 2023
9a06f17
more grid shorthand
mbostock Jan 31, 2023
cfd47ac
Update README
mbostock Jan 31, 2023
3e095a3
fix default facet axis anchor
mbostock Jan 31, 2023
be246de
axis plot shorthand
mbostock Feb 1, 2023
85e6456
Update README
mbostock Feb 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
simpler facet sorting
  • Loading branch information
mbostock committed Dec 27, 2022
commit e0d8ed2109d0138e99d5e903599eb8cef2cf276e
36 changes: 17 additions & 19 deletions src/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export function plot(options = {}) {
}
if (0 < nonEmpty.size && nonEmpty.size < facets.length) {
facets = facets.filter((_, i) => nonEmpty.has(i));
facets.forEach((f, i) => (f.i = i)); // adjust facet index accordingly
for (const state of facetStateByMark.values()) {
const {facetsIndex} = state;
if (!facetsIndex) continue;
Expand Down Expand Up @@ -297,36 +298,35 @@ export function plot(options = {}) {

// Render facets in the order of the fx-fy domain, which might not be the
// ordering used to build the nested index initially; see domainChannel.
const facetIndex = new Map(facets.map((f, j) => [f, j]));
selection
.selectAll()
.data(facetKeys(facets, fx, fy))
.data(sort(facets, fx ? facetOrder("x", fx) : () => {}, fy ? facetOrder("y", fy) : () => {}))
.enter()
.append("g")
.attr("aria-label", "facet")
.attr("transform", facetTranslate(fx, fy))
.each(function (key) {
.each(function ({x, y, i}) {
for (const [mark, {channels, values, facets}] of stateByMark) {
switch (mark.facetAnchor) {
case "top":
if (fyDomain.indexOf(key.y) !== 0) continue;
if (fyDomain.indexOf(y) !== 0) continue;
break;
case "bottom":
if (fyDomain.indexOf(key.y) !== fyDomain.length - 1) continue;
if (fyDomain.indexOf(y) !== fyDomain.length - 1) continue;
break;
case "left":
if (fxDomain.indexOf(key.x) !== 0) continue;
if (fxDomain.indexOf(x) !== 0) continue;
break;
case "right":
if (fxDomain.indexOf(key.x) !== fxDomain.length - 1) continue;
if (fxDomain.indexOf(x) !== fxDomain.length - 1) continue;
break;
}
let facet;
if (facets) {
if (mark.facet === null) {
facet = facets[0];
} else {
facet = facets[facetIndex.get(key)];
facet = facets[i];
if (facet === undefined) {
if (mark.fx || mark.fy) continue;
facet = facets[0];
Expand Down Expand Up @@ -545,27 +545,25 @@ function nolabel(axis) {
: Object.assign(Object.create(axis), {label: undefined});
}

// Returns an array of {x?, y?} objects representing the facet domain.
// Returns an array of {x?, y?, i} objects representing the facet domain.
function Facets(channelsByScale, options) {
const {fx, fy} = Scales(channelsByScale, options);
const fxDomain = fx?.scale.domain();
const fyDomain = fy?.scale.domain();
return fxDomain && fyDomain
? cross(fxDomain, fyDomain).map(([x, y]) => ({x, y}))
? cross(fxDomain, fyDomain).map(([x, y], i) => ({x, y, i}))
: fxDomain
? fxDomain.map((x) => ({x}))
? fxDomain.map((x, i) => ({x, i}))
: fyDomain
? fyDomain.map((y) => ({y}))
? fyDomain.map((y, i) => ({y, i}))
: undefined;
}

// Returns keys in order of the associated scale’s domains. (We don’t want to
// recompute the keys here because facets may already be filtered, and facets
// isn’t sorted because it’s constructed prior to the other mark channels.)
function facetKeys(facets, fx, fy) {
const fxI = fx && new InternMap(fx.domain().map((x, i) => [x, i]));
const fyI = fy && new InternMap(fy.domain().map((y, i) => [y, i]));
return sort(facets, (a, b) => (fxI && fxI.get(a.x) - fxI.get(b.x)) || (fyI && fyI.get(a.y) - fyI.get(b.y)));
// Returns an accessor function that returns the order of the given facet value
// in the associated facet scale’s domains.
function facetOrder(k, fk) {
const o = new InternMap(fk.domain().map((v, i) => [v, i]));
return ({[k]: v}) => o.get(v);
}

// Returns a (possibly nested) Map of [[key1, index1], [key2, index2], …]
Expand Down