-
Notifications
You must be signed in to change notification settings - Fork 219
arealine mark #2407
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
arealine mark #2407
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4568a90
arealine
mbostock a6deb1c
color option shorthand
mbostock 3829e99
fix line offset
mbostock cd44c86
document area line mark
mbostock ac22d70
fix docs:build?
mbostock 9d024cc
restore line option; fillOpacity 0.3
mbostock d72b9a0
simplify z: null check
mbostock 54da7a2
fold color option into AreaOptions
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,40 @@ | ||
| import type {ColorOptions, Data} from "../mark.js"; | ||
| import {MarkerOptions} from "../marker.js"; | ||
| import {Area, AreaXOptions, AreaYOptions} from "./area.js"; | ||
|
|
||
| /** Options for the areaLineX mark. */ | ||
| export interface AreaLineXOptions extends AreaXOptions, ColorOptions, MarkerOptions {} | ||
|
|
||
| /** Options for the areaLineY mark. */ | ||
| export interface AreaLineYOptions extends AreaYOptions, ColorOptions, MarkerOptions {} | ||
|
|
||
| /** | ||
| * Returns a new vertically-oriented arealine mark for the given *data* and | ||
| * *options*, where the baseline and topline share **y** values, as in a | ||
| * time-series area chart where time goes up↑. For example, to plot Apple’s | ||
| * daily stock price: | ||
| * | ||
| * ```js | ||
| * Plot.areaLineX(aapl, {y: "Date", x: "Close"}) | ||
| * ``` | ||
| * | ||
| * See Plot.areaX for more details. | ||
| */ | ||
| export function areaLineX(data?: Data, options?: AreaLineXOptions): AreaLine; | ||
|
|
||
| /** | ||
| * Returns a new horizontally-oriented arealine mark for the given *data* and | ||
| * *options*, where the baseline and topline share **x** values, as in a | ||
| * time-series area chart where time goes right→. For example, to plot Apple’s | ||
| * daily stock price: | ||
| * | ||
| * ```js | ||
| * Plot.areaLineY(aapl, {x: "Date", y: "Close"}) | ||
| * ``` | ||
| * | ||
| * See Plot.areaLineY for more details. | ||
| */ | ||
| export function areaLineY(data?: Data, options?: AreaLineYOptions): AreaLine; | ||
|
|
||
| /** The arealine mark. */ | ||
| export class AreaLine extends Area {} |
This file contains hidden or 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,80 @@ | ||
| import {area as shapeArea, line as shapeLine} from "d3"; | ||
| import {Area} from "./area.js"; | ||
| import {create} from "../context.js"; | ||
| import {applyGroupedMarkers, markers} from "../marker.js"; | ||
| import {applyDirectStyles, applyIndirectStyles, applyTransform, applyGroupedChannelStyles} from "../style.js"; | ||
| import {groupIndex} from "../style.js"; | ||
| import {maybeDenseIntervalX, maybeDenseIntervalY} from "../transforms/bin.js"; | ||
| import {maybeStackX, maybeStackY} from "../transforms/stack.js"; | ||
|
|
||
| const defaults = { | ||
| ariaLabel: "area-line", | ||
| fillOpacity: 0.1, | ||
| stroke: "currentColor", | ||
| strokeWidth: 1.5, | ||
| strokeLinecap: "round", | ||
| strokeLinejoin: "round", | ||
| strokeMiterlimit: 1 | ||
| }; | ||
|
|
||
| export class AreaLine extends Area { | ||
| constructor(data, options = {}) { | ||
| super(data, options, defaults); | ||
| markers(this, options); | ||
| } | ||
| render(index, scales, channels, dimensions, context) { | ||
| const {x1: X1, y1: Y1, x2: X2 = X1, y2: Y2 = Y1} = channels; | ||
| return create("svg:g", context) | ||
| .call(applyIndirectStyles, this, dimensions, context) | ||
| .call(applyTransform, this, scales, 0, 0) | ||
| .call((g) => | ||
| g | ||
| .selectAll() | ||
| .data(groupIndex(index, [X1, Y1, X2, Y2], this, channels)) | ||
| .enter() | ||
| .append("g") | ||
| .call(applyDirectStyles, this) | ||
| .call(applyGroupedChannelStyles, this, channels) | ||
| .call((e) => | ||
| e | ||
| .append("path") | ||
| .attr("stroke", "none") | ||
| .attr( | ||
| "d", | ||
| shapeArea() | ||
| .curve(this.curve) | ||
| .defined((i) => i >= 0) | ||
| .x0((i) => X1[i]) | ||
| .y0((i) => Y1[i]) | ||
| .x1((i) => X2[i]) | ||
| .y1((i) => Y2[i]) | ||
| ) | ||
| ) | ||
| .call((e) => | ||
| e | ||
| .append("path") | ||
| .call(applyGroupedMarkers, this, channels, context) | ||
| .attr("fill", "none") | ||
| .attr( | ||
| "d", | ||
| shapeLine() | ||
| .curve(this.curve) | ||
| .defined((i) => i >= 0) | ||
| .x((i) => X2[i]) | ||
| .y((i) => Y2[i]) | ||
mbostock marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
| ) | ||
| ) | ||
| .node(); | ||
| } | ||
| } | ||
|
|
||
| export function areaLineX(data, options) { | ||
| const {x, y, color, stroke = color, fill = color, z = x === fill || x === stroke ? null : undefined, ...rest} = maybeDenseIntervalY(options); // prettier-ignore | ||
| return new AreaLine(data, maybeStackX({...rest, x, y1: y, y2: undefined, z, fill, stroke})); | ||
| } | ||
|
|
||
| export function areaLineY(data, options) { | ||
| const {x, y, color, stroke = color, fill = color, z = y === fill || y === stroke ? null : undefined, ...rest} = maybeDenseIntervalX(options); // prettier-ignore | ||
| return new AreaLine(data, maybeStackY({...rest, x1: x, x2: undefined, y, z, fill, stroke})); | ||
| } | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 could be supported on all marks…
Uh oh!
There was an error while loading. Please reload this page.
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.
Once we support
color, we'll often want to use this overstrokeorfill, because it's less cognitive work—so it should "just work" everywhere.I feel it can be a bit tricky though, because it might not make sense for all marks to set both
strokeandfill. For instance, I don't think we'd want to set afillon a line (it's rarely a good idea), or a link (it doesn't apply, so better stick withfill: "none"), but maybe on an arrow (it can apply if there is a non-zero bend), although I would rarely do it.In this sense "color" should mean "the base color for the mark" rather than "a shorthand for stroke and fill".
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.
I think the simpler definition of shorthand is easier to understand (and worse is better) and we shouldn’t try to define a “base color” separately for each mark.
I can remove the color shorthand from this PR if you think it’s a bad idea and we can discuss it 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.
Yes, please remove it, I think it might set the wrong expectation
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.
For what it’s worth we already support a color option on the following marks: axis, grid, auto, crosshair, bollinger. The definition I am using here feels consistent with that existing usage.