Skip to content

Commit

Permalink
feat: add addRangeChart method to create charts programmatically
Browse files Browse the repository at this point in the history
  • Loading branch information
hyyan committed Jul 19, 2019
1 parent f25d5ae commit 1ec9008
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 5 deletions.
12 changes: 12 additions & 0 deletions BBjGridExWidget.bbj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use ::BBjGridExWidget/BBjGridExWidgetRenderers.bbj::BBjGridExWidgetRendererImage
use ::BBjGridExWidget/BBjGridExWidgetClientJsonFactory.bbj::BBjGridExWidgetClientJsonFactory
use ::BBjGridExWidget/BBjGridExWidgetClientModels.bbj::BBjGridExWidgetClientRowModel
use ::BBjGridExWidget/BBjGridExWidgetClientModels.bbj::BBjGridExWidgetClientAddRangeSelectionModel
use ::BBjGridExWidget/BBjGridExWidgetClientModels.bbj::BBjGridExWidgetClientAddRangeChartModel
use ::BBjGridExWidget/BBjGridExWidgetClientEvents.bbj::BBjGridExWidgetClientEventsRowSelection
use ::BBjGridExWidget/BBjGridExWidgetClientEvents.bbj::BBjGridExWidgetClientEventsContextMenu
use ::BBjGridExWidget/BBjGridExWidgetClientEvents.bbj::BBjGridExWidgetClientEventsCell
Expand Down Expand Up @@ -3201,6 +3202,17 @@ class public BBjGridExWidget extends BBjWidget implements BBjGridExWidgetColumns
#executeScript("gw_clearRangeSelection('" + #GRIDID$ + "')")
methodend
rem /**
rem * Add new chart range
rem *
rem * <br><b><small>#API</small></b>
rem *
rem * @param BBjGridExWidgetClientAddRangeChartModel model! the add range model
rem */
method public BBjGridExWidgetClientAddRangeChartModel addRangeChart(BBjGridExWidgetClientAddRangeChartModel model!)
#executeScript("gw_addChartRange('" + #GRIDID$ + "'," + model!.getAsJsonObject().toString() + ")")
methodret model!
methodend
rem /**
rem * Show loading overlay
rem *
rem * <br><b><small>#API</small></b>
Expand Down
40 changes: 40 additions & 0 deletions BBjGridExWidgetClientModels.bbj
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,44 @@ class public BBjGridExWidgetClientAddRangeSelectionModel
methodret json!
methodend

classend
rem /**
rem * The model is used to compose a range chart model in order to be applied on the client.
rem *
REM * @author Hyyan Abo Fakher
rem */
class public BBjGridExWidgetClientAddRangeChartModel
rem /**
rem * Defines the range of cells to be charted , A range is normally defined with start and end rows and a list of columns,
rem * If the start and end rows are omitted, the range covers all rows (ie entire columns are selected).
rem */
field public BBjGridExWidgetClientAddRangeSelectionModel RangeSelection! = null()
rem /**
rem * The type of chart to create
rem */
field public BBjString Type! = null()
rem /**
rem * Normally when a chart is displayed using the grid, the grid will highlight the range the chart is charting
rem * when the chart gets focus, to suppress this behaviour, set the field to false
rem */
field public BBjNumber SuppressChartRanges! = null()
rem /**
rem * When set to true, series values will be summed for each category before charting.
rem */
field public BBjNumber Aggregate! = null()
rem /**
rem * Convert the model to JSON object
rem *
rem * @return JsonObject
rem */
method public JsonObject getAsJsonObject()
declare JsonObject json!

json! = new JsonObject()
json!. add("cellRange" , #getRangeSelection().getAsJsonObject() , err=*next)
json!.addProperty("chartType" , #getType(), err=*next)
json!.addProperty("suppressChartRanges" , #getSuppressChartRanges().booleanValue(), err=*next)
json!.addProperty("aggregate" , #getAggregate().booleanValue(), err=*next)
methodret json!
methodend
classend
38 changes: 36 additions & 2 deletions client/dist/bbj-grid-widget.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions client/dist/bbj-grid-widget.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/dist/report.html

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions client/src/api/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
* file that was distributed with this source code.
*/

import { gw_getGrid } from "api/utilities";
import { gw_parseAddCellRange } from "api/cells";

const { deepParseJson } = require("deep-parse-json");

/**
* Return the chart toolbar items defined in the grid's context
*
Expand All @@ -19,4 +24,18 @@ export function gw_getChartToolbarItems(params) {
.gridOptions
.context
.chartToolbarItems || [];
}

/**
* Add new chart range
*
* @param {Number} id grid's id
* @param {Object} range bounded or unbounded range model
*/
export function gw_addChartRange(id, range) {
const pr = deepParseJson(JSON.stringify(range));
const options = gw_getGrid(id).options;

pr.cellRange = gw_parseAddCellRange(options , pr.cellRange);
options.api.chartRange(pr);
}
1 change: 1 addition & 0 deletions client/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export * from './toolpanel.js';
export * from './statusbar.js';
export * from './overlays.js';
export * from './context.js';
export * from './charts.js';
export * from './jss.js';

0 comments on commit 1ec9008

Please sign in to comment.