-
Notifications
You must be signed in to change notification settings - Fork 41
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
188616847 stroke point plot background color import/export V2 #1802
Merged
+1,827
−28
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b854340
Adds test document for plot format export/import
eireland 90297bd
Adds point color, point size, stroke color, and background color to f…
eireland a85912c
Fixes bug where graph background transparency was not working
eireland 775aae4
Updates test file to include background transparency
eireland 37f47fa
Updates test file to add graphs with cat legends and choropleth legends
eireland b9b80e8
Updates test document for graph formatting export to V2
eireland 7bc04ab
Adds opacity to options to be added when parsing a color string
eireland 881f137
Adds some color utils for getting transparency from color strings
eireland 3a8a270
chore: code review tweaks
kswenson ca7a334
PR Fixes
eireland 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { colord } from "colord" | ||
import { SetRequired } from "type-fest" | ||
import { AttributeType } from "../../models/data/attribute-types" | ||
import { toV2Id } from "../../utilities/codap-utils" | ||
import { removeAlphaFromColor } from "../../utilities/color-utils" | ||
import { V2TileExportFn } from "../../v2/codap-v2-tile-exporters" | ||
import { guidLink, ICodapV2Adornment, ICodapV2GraphStorage, IGuidLink } from "../../v2/codap-v2-types" | ||
import { IAxisModel, isNumericAxisModel } from "../axis/models/axis-model" | ||
|
@@ -230,13 +232,39 @@ function getPlotModels(graph: IGraphContentModel): Partial<ICodapV2GraphStorage> | |
return storage | ||
} | ||
|
||
const getTransparency = (color: string, type: "point" | "stroke") => { | ||
const rgbaColor = colord(color).toRgb() | ||
return rgbaColor.a ?? (type === "point" ? 0.84 : 1) | ||
} | ||
|
||
// v2 uses color names for default stroke colors | ||
const strokeColorStr = (color: string) => { | ||
const colorHex = removeAlphaFromColor(color).toLowerCase() | ||
return colorHex === "#ffffff" ? "white" | ||
: colorHex === "#d3d3d3" ? "lightgrey" | ||
: colorHex | ||
} | ||
|
||
export const v2GraphExporter: V2TileExportFn = ({ tile }) => { | ||
const graph = isGraphContentModel(tile.content) ? tile.content : undefined | ||
if (!graph) return | ||
|
||
const componentStorage: Partial<ICodapV2GraphStorage> = { | ||
_links_: getLinks(graph), | ||
displayOnlySelected: !!graph.dataConfiguration.displayOnlySelectedCases, | ||
pointColor: removeAlphaFromColor(graph.pointDescription.pointColor), | ||
transparency: getTransparency(graph.pointDescription.pointColor, "point"), | ||
strokeColor: graph.pointDescription.pointStrokeSameAsFill | ||
? "white" // v2 uses white for stroke when stroke is same as fill | ||
: strokeColorStr(graph.pointDescription.pointStrokeColor), | ||
strokeTransparency: graph.pointDescription.pointStrokeSameAsFill | ||
? 0.4 : getTransparency(graph.pointDescription.pointStrokeColor, "stroke"), | ||
pointSizeMultiplier: graph.pointDescription.pointSizeMultiplier, | ||
strokeSameAsFill: graph.pointDescription.pointStrokeSameAsFill, | ||
plotBackgroundColor: graph.plotBackgroundColor === "#FFFFFF" | ||
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. Do we need to worry about other variations (e.g. |
||
? null : removeAlphaFromColor(graph.plotBackgroundColor), | ||
plotBackgroundOpacity: getTransparency(graph.plotBackgroundColor, "stroke"), | ||
isTransparent: graph.isTransparent, | ||
// attribute roles and types | ||
...getAttrRoleAndType(graph, "x", "x"), | ||
...getAttrRoleAndType(graph, "y", "y"), | ||
|
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.
I moved this function here because it contains graph-specific logic rather than something appropriate to all clients of
color-utils
. That said, in practice it doesn't matter becausetoRgb()
is documented to always return an alpha, so the?? (type === "point" ? 0.84 : 1)
will never have any effect. If there are some circumstances in which0.84
should be returned, then the logic will need to be clarified.