Skip to content
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

adds y-axis scale to the histogram view #4349

Merged
merged 7 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.md).
[Commits](https://github.com/scalableminds/webknossos/compare/19.12.0...HEAD)

### Added
-

- Added scale to y-axis to histograms and smoothing out small values. [#4349](https://github.com/scalableminds/webknossos/pull/4349)
MichaelBuessemeyer marked this conversation as resolved.
Show resolved Hide resolved
### Changed
-

Expand Down
28 changes: 23 additions & 5 deletions frontend/javascripts/oxalis/view/settings/histogram_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,16 @@ class Histogram extends React.PureComponent<HistogramProps> {
const { min, max } = this.props;
const { min: minRange, max: maxRange, elementCounts } = histogram;
const rangeLength = maxRange - minRange;
this.drawYAxis(ctx);
ctx.fillStyle = `rgba(${color.join(",")}, 0.1)`;
ctx.strokeStyle = `rgba(${color.join(",")})`;
const downscaledData = elementCounts.map(value =>
value > 0 ? (Math.log(value) / Math.log(maxValue)) * canvasHeight : 0,
// Here we normalize all values to the interval of 0 - 9 and then add 1
// to gain an interval reaching from 1 - 10.
MichaelBuessemeyer marked this conversation as resolved.
Show resolved Hide resolved
const downscalingFactor = 9 / maxValue;
const downscaledData = elementCounts.map(
value => Math.log10(downscalingFactor * value + 1) * canvasHeight,
);
const activeRegion = new Path2D();
ctx.beginPath();
ctx.moveTo(0, downscaledData[0]);
activeRegion.moveTo(((min - minRange) / rangeLength) * canvasWidth, 0);
for (let i = 0; i < downscaledData.length; i++) {
Expand All @@ -104,6 +107,21 @@ class Histogram extends React.PureComponent<HistogramProps> {
ctx.fill(activeRegion);
};

drawYAxis = (ctx: CanvasRenderingContext2D) => {
// Maximum value of the y axis is always 10. Therefore the axis is independent from any data.
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(0, canvasHeight);
const numberOfScaleLines = 5;
const intervalSize = 2;
for (let interval = 1; interval <= numberOfScaleLines; interval++) {
// We use canvasHeight - 1 because else half of the top line would be cut off.
const lineHeight = Math.round(Math.log10(intervalSize * interval) * (canvasHeight - 1));
ctx.moveTo(0, lineHeight);
ctx.lineTo(8, lineHeight);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe extract the 8 as a lineWidth variable?

}
};

onThresholdChange = ([firstVal, secVal]: [number, number]) => {
const { layerName } = this.props;
if (firstVal < secVal) {
Expand All @@ -122,7 +140,7 @@ class Histogram extends React.PureComponent<HistogramProps> {
ref={ref => {
this.canvasRef = ref;
}}
width={300}
width={canvasWidth}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 ^^

height={canvasHeight}
/>
<Slider
Expand All @@ -133,7 +151,7 @@ class Histogram extends React.PureComponent<HistogramProps> {
defaultValue={[minRange, maxRange]}
onChange={this.onThresholdChange}
onAfterChange={this.onThresholdChange}
style={{ width: 300, margin: 0, marginBottom: 18 }}
style={{ width: canvasWidth, margin: 0, marginBottom: 18 }}
step={(maxRange - minRange) / 255}
tipFormatter={val => roundTo(val, 2).toString()}
/>
Expand Down