This repository was archived by the owner on Jun 11, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Result bar chart #10
Merged
Merged
Result bar chart #10
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| import React, { Component } from "react"; | ||
| import ReactDOM from "react-dom"; | ||
| import * as d3 from "d3"; | ||
| import { DirectionalHint } from 'office-ui-fabric-react/lib/Tooltip'; | ||
| import { PrimaryButton, DefaultButton } from 'office-ui-fabric-react/lib/Button'; | ||
|
|
||
|
|
||
| type PerspectiveScoresBarChartState = { | ||
| selectedScore: string | ||
| } | ||
|
|
||
| type PerspectiveScoresBarChartProps = { | ||
| id: number, | ||
| scores: any, | ||
| defaultSelectedScore: string | ||
| } | ||
|
|
||
| class PerspectiveScoresBarChart extends Component<PerspectiveScoresBarChartProps, PerspectiveScoresBarChartState> { | ||
|
|
||
| constructor(props) { | ||
| super(props); | ||
|
|
||
| this.state = { | ||
| selectedScore: props.defaultSelectedScore | ||
| }; | ||
|
|
||
| this.node = React.createRef<HTMLDivElement>(); | ||
| this.domID = `perspectivescoresbarchart-${props.id}`; | ||
| } | ||
|
|
||
| node: React.RefObject<HTMLDivElement> | ||
|
|
||
| domID: string | ||
|
|
||
| componentDidMount() { | ||
| this.createDistributionBarChart(); | ||
| } | ||
|
|
||
| componentDidUpdate() { | ||
| this.createDistributionBarChart(); | ||
| } | ||
|
|
||
| setSelectedScore = (selectedScore: string) => { | ||
| this.setState({ | ||
| selectedScore: selectedScore | ||
| }); | ||
| } | ||
|
|
||
| createDistributionBarChart = () => { | ||
| var _this = this; | ||
| var body = d3.select(this.node.current); | ||
|
|
||
| var margin = { top: 5, right: 15, bottom: 50, left: 55 } | ||
| var h = 111 - margin.top - margin.bottom | ||
| var w = 200; | ||
|
|
||
| // SVG | ||
| d3.select(`#${this.domID}`).remove(); | ||
| var svg = body.append('svg') | ||
| .attr('id', this.domID) | ||
| .attr('height',h + margin.top + margin.bottom) | ||
| .attr('width',w) | ||
| .attr('float', 'left'); | ||
|
|
||
| var xScale = d3.scaleBand().range([0, w]).padding(0.4), | ||
| yScale = d3.scaleLinear().range([h, 0]); | ||
|
|
||
| var g = svg.append("g") | ||
| .attr("transform", "translate(" + 55 + "," + margin.top + ")"); | ||
|
|
||
| xScale.domain(this.props.scores.map(function(d) { return d.score; })); | ||
| yScale.domain([0.0, 1.0]); | ||
|
|
||
| var selectedScoreObj = this.props.scores.filter(scoreObj => (scoreObj.score == this.state.selectedScore))[0]; | ||
| var selectedScoreMessage = `${selectedScoreObj.scoreName}: ${selectedScoreObj.value.toFixed(2)}`; | ||
|
|
||
| g.append("g") | ||
| .attr("transform", "translate(0," + h + ")") | ||
| .append("text") | ||
| .attr("y", 30) | ||
| .attr("x", (w + margin.left)/2) | ||
| .attr("text-anchor", "end") | ||
| .attr("fill", "black") | ||
| .attr("font-size", "14px") | ||
| .text(selectedScoreMessage); | ||
|
|
||
| g.selectAll(".bar") | ||
| .data(this.props.scores) | ||
| .enter().append("rect") | ||
| .attr("class", "bar") | ||
| .attr("x", function(d) { return xScale(d.score); }) | ||
| .attr("y", function(d) { return yScale(d.value); }) | ||
| .attr("width", xScale.bandwidth()) | ||
| .attr("height", function(d) { return h - yScale(d.value); }) | ||
| .classed("highlighted-bar", function(d) { return d.score == _this.state.selectedScore }) | ||
| .on("click", function(d) { | ||
| _this.setSelectedScore(d.score); | ||
| }); | ||
| } | ||
|
|
||
| render() { | ||
| return ( | ||
| <div className="plot plot-distribution"> | ||
| <div ref={this.node}/> | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| export default PerspectiveScoresBarChart; |
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
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.
You might want to revert this when you merge your work with mine
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 took a look at the id generation code. So I think that we should use id's given to us from the backend as these might come from a DB down the line. I modified the constructor of the model you added so that it just takes the server side id.