-
Notifications
You must be signed in to change notification settings - Fork 177
Scatterplot/ Add basic chart with points #831
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
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
167346e
Draw Y axis WIP
kzadurska 3873560
Draw x axis WIP
kzadurska 1ce21d2
Adjust axis
kzadurska 4f80454
Display grid lines
kzadurska 39a7239
Display point
kzadurska b3963f7
Draw points
kzadurska 0bf8dba
Rearrange x axis and y axis
kzadurska b75dfbd
Adjust stage
kzadurska 98bc9e0
Color points and add styles to axis
kzadurska 6367cef
Add axis titles
kzadurska 411ade4
Divide into smaller components
kzadurska 518f2f5
Rename class names
kzadurska 1edadce
Add core review remarks
kzadurska cde586b
Clean up constants
kzadurska 9c961db
Remove any from y axis props
kzadurska 51f3b8a
Fix selecting point values and y axis width source
kzadurska 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2017-2022 Allegro.pl | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import * as React from "react"; | ||
|
||
import { Datum } from "plywood"; | ||
import { ConcreteSeries } from "../../../common/models/series/concrete-series"; | ||
import "./scatterplot.scss"; | ||
|
||
import { LinearScale } from "../../utils/linear-scale/linear-scale"; | ||
|
||
interface PointProps { | ||
datum: Datum; | ||
xScale: LinearScale; | ||
yScale: LinearScale; | ||
xSeries: ConcreteSeries; | ||
ySeries: ConcreteSeries; | ||
} | ||
|
||
const POINT_RADIUS = 3; | ||
|
||
export const Point: React.SFC<PointProps> = ({ datum, xScale, yScale, xSeries, ySeries }) => { | ||
const xValue = xSeries.selectValue(datum); | ||
const yValue = ySeries.selectValue(datum); | ||
|
||
return (<circle | ||
cx={xScale(xValue)} | ||
cy={yScale(yValue)} | ||
r={POINT_RADIUS} | ||
className="point" | ||
/> | ||
); | ||
}; |
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,52 @@ | ||
/* | ||
* Copyright 2017-2022 Allegro.pl | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import * as React from "react"; | ||
|
||
import "./scatterplot.scss"; | ||
|
||
import { Stage } from "../../../common/models/stage/stage"; | ||
import { Unary } from "../../../common/utils/functional/functional"; | ||
import { roundToHalfPx } from "../../utils/dom/dom"; | ||
import { LinearScale } from "../../utils/linear-scale/linear-scale"; | ||
|
||
const TEXT_OFFSET_X = 16; | ||
|
||
interface XAxisProps { | ||
stage: Stage; | ||
ticks: number[]; | ||
tickSize: number; | ||
scale: LinearScale; | ||
formatter: Unary<number, string>; | ||
} | ||
|
||
export const XAxis: React.SFC<XAxisProps> = ({ stage, ticks, scale, formatter, tickSize }) => { | ||
const labelY = tickSize + TEXT_OFFSET_X; | ||
const linePositionY = roundToHalfPx(0); | ||
const lines = ticks.map((tick: number) => { | ||
const x = roundToHalfPx(scale(tick)); | ||
return <line className="tick" key={String(tick)} x1={x} y1={0} x2={x} y2={tickSize} />; | ||
}); | ||
const labels = ticks.map((tick: number) => { | ||
const x = scale(tick); | ||
return <text className="label axis-label-x" key={String(tick)} x={x} y={labelY}>{formatter(tick)}</text>; | ||
}); | ||
|
||
return (<g className="axis" transform={stage.getTransform()}> | ||
{lines} | ||
{labels} | ||
<line className="border" y1={linePositionY} y2={linePositionY} x1={0} x2={stage.width}/> | ||
</g>); | ||
}; |
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,54 @@ | ||
/* | ||
* Copyright 2017-2022 Allegro.pl | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import * as React from "react"; | ||
|
||
import "./scatterplot.scss"; | ||
|
||
import { Stage } from "../../../common/models/stage/stage"; | ||
import { Unary } from "../../../common/utils/functional/functional"; | ||
import { roundToHalfPx } from "../../utils/dom/dom"; | ||
import { LinearScale } from "../../utils/linear-scale/linear-scale"; | ||
|
||
const TEXT_OFFSET_Y = 4; | ||
|
||
interface YAxisProps { | ||
stage: Stage; | ||
ticks: number[]; | ||
tickSize: number; | ||
scale: LinearScale; | ||
formatter: Unary<number, string>; | ||
} | ||
|
||
export const YAxis: React.SFC<YAxisProps> = ({ formatter, stage, tickSize, ticks, scale }) => { | ||
const linePositionX = roundToHalfPx(stage.width); | ||
|
||
const lines = ticks.map((tick: number) => { | ||
const y = roundToHalfPx(scale(tick)); | ||
return <line className="tick" key={String(tick)} x1={stage.width - tickSize} y1={y} x2={stage.width} y2={y} />; | ||
}); | ||
|
||
const labels = ticks.map((tick: number) => { | ||
const y = scale(tick); | ||
const labelX = y + TEXT_OFFSET_Y; | ||
return <text className="label" key={String(tick)} x={0} y={labelX}>{formatter(tick)}</text>; | ||
}); | ||
|
||
return <g className="axis" transform={stage.getTransform()}> | ||
<line className="border" x1={linePositionX} y1={0} x2={linePositionX} y2={stage.height} /> | ||
{lines} | ||
{labels} | ||
</g>; | ||
}; |
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.
Uh oh!
There was an error while loading. Please reload this page.