Skip to content

Commit

Permalink
feat: bar graph entity
Browse files Browse the repository at this point in the history
  • Loading branch information
gitanjli525 committed Sep 24, 2024
1 parent b089409 commit 6490f38
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/screens/NewAnalytics/Graphs/BarGraph/BarGraph.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
external barGraphOptionsToJson: BarGraphTypes.barGraphOptions => JSON.t = "%identity"
@react.component
let make = (~entity, ~data: JSON.t, ~className="") => {
open NewAnalyticsTypes
let object = entity.getObjects(data)
let options = entity.getChatOptions(object)->barGraphOptionsToJson

<div className>
<Highcharts.Chart options highcharts={Highcharts.highcharts} />
</div>
}
82 changes: 82 additions & 0 deletions src/screens/NewAnalytics/Graphs/BarGraph/BarGraphTypes.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
type \"type" = string
type spacingLeft = int
type spacingRight = int

type categories = array<string>
type crosshair = bool
type barWidth = int
type align = string
type color = string
type gridLineWidth = int
type gridLineColor = string
type gridLineDashStyle = string
type tickmarkPlacement = string
type endOnTick = bool
type startOnTick = bool
type min = int
type showInLegend = bool
type name = string

type title = {text: string}
type style = {color: color}
type enabled = {enabled: bool}
type credits = {
...enabled,
}
type exporting = {
...enabled,
}
type marker = {
...enabled,
}
type bar = {marker: marker}
type plotOptions = {bar: bar}
type labels = {
align: align,
style: style,
}
type chart = {
\"type": \"type",
spacingLeft: spacingLeft,
spacingRight: spacingRight,
}

type dataObj = {
showInLegend: showInLegend,
name: name,
data: array<int>,
color: color,
}

type data = array<dataObj>

type yAxis = {
title: title,
gridLineWidth: gridLineWidth,
gridLineColor: gridLineColor,
gridLineDashStyle: gridLineDashStyle,
tickmarkPlacement: tickmarkPlacement,
endOnTick: endOnTick,
startOnTick: startOnTick,
min: min,
}

type xAxis = {
categories: categories,
crosshair: crosshair,
barWidth: barWidth,
labels: labels,
gridLineDashStyle: gridLineDashStyle,
}

type barGraphOptions = {
chart: chart,
title: title,
xAxis: xAxis,
yAxis: yAxis,
plotOptions: plotOptions,
series: data,
credits: credits,
}

type barGraphPayload = {categories: categories, data: data, title: title}
47 changes: 47 additions & 0 deletions src/screens/NewAnalytics/Graphs/BarGraph/BarGraphUtils.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
open BarGraphTypes
let getBarGraphOptions = (barGraphOptions: barGraphPayload) => {
let {categories, data, title} = barGraphOptions
{
chart: {
\"type": "bar",
spacingLeft: 20,
spacingRight: 20,
},
title: {
text: "",
},
xAxis: {
categories,
crosshair: true,
barWidth: 1,
labels: {
align: "center",
style: {
color: "#999",
},
},
gridLineDashStyle: "Dash",
},
yAxis: {
title,
gridLineWidth: 1,
gridLineColor: "#e6e6e6",
gridLineDashStyle: "Solid",
tickmarkPlacement: "on",
endOnTick: false,
startOnTick: false,
min: 0,
},
plotOptions: {
bar: {
marker: {
enabled: false,
},
},
},
series: data,
credits: {
enabled: false,
},
}
}

0 comments on commit 6490f38

Please sign in to comment.