From 07598593e10667b464098736de9962f5545cc07b Mon Sep 17 00:00:00 2001 From: David Schnur Date: Fri, 27 Apr 2012 13:11:46 -0400 Subject: [PATCH] Added a grid.margin option --- API.txt | 12 ++++++++++++ NEWS.txt | 5 +++++ jquery.flot.js | 15 ++++++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/API.txt b/API.txt index f25110f..dfad459 100644 --- a/API.txt +++ b/API.txt @@ -667,6 +667,7 @@ Customizing the grid aboveData: boolean color: color backgroundColor: color/gradient or null + margin: number or margin object labelMargin: number axisMargin: number markings: array of markings or (fn: axes -> array of markings) @@ -694,6 +695,17 @@ You can turn off the whole grid including tick labels by setting "show" to false. "aboveData" determines whether the grid is drawn above the data or below (below is default). +"margin" is the space in pixels between the canvas edge and the grid, +which can be either a number or an object with individual margins for +each side, in the form: + + margin: { + top: top margin in pixels + left: left margin in pixels + bottom: bottom margin in pixels + right: right margin in pixels + } + "labelMargin" is the space in pixels between tick labels and axis line, and "axisMargin" is the space in pixels between axes when there are two next to each other. diff --git a/NEWS.txt b/NEWS.txt index 0837919..4b0b655 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -30,6 +30,11 @@ Changes: - Tick generators now get the whole axis rather than just min/max. +- Added processOffset and drawBackground hooks (suggested in issue 639). + +- Added a grid "margin" option to set the space between the canvas edge + and the grid. + Bug fixes - Fix problem with null values and pie plugin (patch by gcruxifix, diff --git a/jquery.flot.js b/jquery.flot.js index e75a9ce..f9f0f00 100644 --- a/jquery.flot.js +++ b/jquery.flot.js @@ -122,6 +122,7 @@ backgroundColor: null, // null for transparent, else color borderColor: null, // set if different from the grid color tickColor: null, // color for the ticks, e.g. "rgba(0,0,0,0.15)" + margin: 0, // distance from the canvas edge to the grid labelMargin: 5, // in pixels axisMargin: 8, // in pixels borderWidth: 2, // in pixels @@ -1023,12 +1024,20 @@ function setupGrid() { var i, axes = allAxes(), showGrid = options.grid.show; - // init plot offset - for (var a in plotOffset) - plotOffset[a] = showGrid ? options.grid.borderWidth : 0; + // Initialize the plot's offset from the edge of the canvas + + for (var a in plotOffset) { + var margin = options.grid.margin || 0; + plotOffset[a] = typeof margin == "number" ? margin : margin[a] || 0; + } executeHooks(hooks.processOffset, [plotOffset]); + // If the grid is visible, add its border width to the offset + + for (var a in plotOffset) + plotOffset[a] += showGrid ? options.grid.borderWidth : 0; + // init axes $.each(axes, function (_, axis) { axis.show = axis.options.show;