aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/DataVizBox/components/PieChart.tsx
diff options
context:
space:
mode:
authorsrichman333 <sarah_n_richman@brown.edu>2023-08-01 17:41:09 -0400
committersrichman333 <sarah_n_richman@brown.edu>2023-08-01 17:41:09 -0400
commit591533a40c847f84e23428ab757b8822edbc2a61 (patch)
tree516b41328e0b414b40e8a2063e8c40a4374ba848 /src/client/views/nodes/DataVizBox/components/PieChart.tsx
parent710cb3aa93ea30799479ca7c79444f05aeab2209 (diff)
things save: editable title for all 3 + color for histogram
Diffstat (limited to 'src/client/views/nodes/DataVizBox/components/PieChart.tsx')
-rw-r--r--src/client/views/nodes/DataVizBox/components/PieChart.tsx20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/client/views/nodes/DataVizBox/components/PieChart.tsx b/src/client/views/nodes/DataVizBox/components/PieChart.tsx
index 47d4fb23e..f0c27866d 100644
--- a/src/client/views/nodes/DataVizBox/components/PieChart.tsx
+++ b/src/client/views/nodes/DataVizBox/components/PieChart.tsx
@@ -4,7 +4,7 @@ import * as React from 'react';
import * as d3 from 'd3';
import { IReactionDisposer, action, computed, observable, reaction } from "mobx";
import { LinkManager } from "../../../../util/LinkManager";
-import { Cast, DocCast} from "../../../../../fields/Types";
+import { Cast, DocCast, StrCast} from "../../../../../fields/Types";
import { DataPoint, SelectedDataPoint } from "./LineChart";
import { DocumentManager } from "../../../../util/DocumentManager";
import { Id } from "../../../../../fields/FieldSymbols";
@@ -19,6 +19,7 @@ import { FaFillDrip } from "react-icons/fa";
export interface PieChartProps {
rootDoc: Doc;
+ layoutDoc: Doc;
axes: string[];
pairs: { [key: string]: any }[];
width: number;
@@ -42,8 +43,6 @@ export class PieChart extends React.Component<PieChartProps> {
private byCategory: boolean = true; // whether the data is organized by category or by specified number percentages/ratios
@observable _currSelected: any | undefined = undefined;
private curSliceSelected: any = undefined;
- private sliceColors: any = {};
- @observable graphTitle: string = this.defaultGraphTitle;
// TODO: nda - some sort of mapping that keeps track of the annotated points so we can easily remove when annotations list updates
@computed get _piechartData() {
@@ -254,7 +253,7 @@ export class PieChart extends React.Component<PieChartProps> {
var percentField = Object.keys(dataSet[0])[0]
var descriptionField = Object.keys(dataSet[0])[1]!
- var radius = Math.min(width, height) / 2 - Math.max(this.props.margin.top, this.props.margin.bottom, this.props.margin.left, this.props.margin.right)
+ var radius = Math.min(width, height-this.props.margin.top-this.props.margin.bottom) /2
var svg = (this._piechartSvg = d3
.select(this._piechartRef.current)
.append("svg")
@@ -349,7 +348,7 @@ export class PieChart extends React.Component<PieChartProps> {
.enter()
.append("g")
arcs.append("path")
- .attr("fill", (data, i)=>{ return this.sliceColors[data.data.valueOf()]? this.sliceColors[data.data.valueOf()] : d3.schemeSet3[i]? d3.schemeSet3[i]: d3.schemeSet3[i%12] })
+ .attr("fill", (data, i)=>{ return this.props.layoutDoc['pieSliceColors-'+data.data.valueOf()]? StrCast(this.props.layoutDoc['pieSliceColors-'+data.data.valueOf()]) : d3.schemeSet3[i]? d3.schemeSet3[i]: d3.schemeSet3[i%12] })
.attr("class", 'slice')
.attr("d", arc)
.on('click', onPointClick)
@@ -379,11 +378,15 @@ export class PieChart extends React.Component<PieChartProps> {
@action changeSelectedColor = (color: string) => {
this.curSliceSelected.attr("fill", color);
- this.sliceColors[this._currSelected[this.props.axes[0]].replace(/\$/g, '').replace(/\%/g, '').replace(/\</g, '')] = color;
+ var sliceName = this._currSelected[this.props.axes[0]].replace(/\$/g, '').replace(/\%/g, '').replace(/\</g, '')
+ this.props.layoutDoc['pieSliceColors-'+sliceName] = color;
};
render() {
- const title = this.graphTitle;
+ var titleAccessor: any='';
+ if (this.props.axes.length==2) titleAccessor = StrCast(this.props.layoutDoc['pieChart-title-'+this.props.axes[0]+'-'+this.props.axes[1]]);
+ else if (this.props.axes.length>0) titleAccessor = StrCast(this.props.layoutDoc['pieChart-title-'+this.props.axes[0]]);
+ const title = titleAccessor? titleAccessor : this.defaultGraphTitle;
var selected: string;
if (this._currSelected){
selected = '{ ';
@@ -400,7 +403,8 @@ export class PieChart extends React.Component<PieChartProps> {
<div className="graph-title">
<EditableText
val={title}
- setVal={action(val => this.graphTitle = val as string)}
+ setVal={action(val => {this.props.axes.length>1? this.props.layoutDoc['pieChart-title-'+this.props.axes[0]+"-"+this.props.axes[1]] = val as string
+ : this.props.layoutDoc['pieChart-title-'+this.props.axes[0]] = val as string})}
color={"black"}
size={Size.LARGE}
fillWidth