Package org.wicketstuff.gchart
Class Chart
- java.lang.Object
-
- org.apache.wicket.Component
-
- org.apache.wicket.markup.html.WebComponent
-
- org.wicketstuff.gchart.Chart
-
- All Implemented Interfaces:
Serializable,IEventSink,IEventSource,IFeedbackContributor,IConverterLocator,IMetadataContext<Serializable,Component>,IHeaderContributor,IRequestableComponent,IHierarchical<Component>,IClusterable,JavaScriptable,Jsonable
public class Chart extends WebComponent implements JavaScriptable, Jsonable
Abstraction of Google charts for wicket.OutputMarkupIdis set to true, since id is referenced in generated JavaScript.- Author:
- Dieter Tremel
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringLOADER_URLURL for Google lib loader-
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_INITIALIZED, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER, RFLAG_CONTAINER_DEQUEING
-
-
Constructor Summary
Constructors Constructor Description Chart(String id)Basic Constructor.Chart(String id, IModel<ChartType> typeModel, IModel<ChartOptions> optionModel, IModel<DataTable> dataModel)Complete Constructor.Chart(String id, IModel<ChartType> typeModel, IModel<ChartOptions> optionModel, IModel<DataTable> dataModel, ChartLibLoader loader)Complete Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigureAjaxUpdate(AjaxRequestTarget target)Configure an ajax response to redraw the chart.protected StringBuildercreateJavaScriptBuilder()Create a builder containing the standard javascript without wrapper.JavaScriptHeaderItemcreateLoaderItem()Create the JavaScript for the Google loader.protected StringcreateLoaderStatement()Create the load statement of the chart lib with package, language and Maps API key declaration as defined by the chart and itsChartType.StringcreateRedrawJavaScript()Create a a redraw script for responsive charts.protected StringBuildercreateWrapperJavaScriptBuilder()Create a builder containing the javascript with use of ChartWrapper.StringgetCallbackId()Make a callback identifier from chart id.StringgetChartId()Make a chart identifier from chart id.IModel<DataTable>getDataModel()StringgetDataTableId()Make a data table id from chart id.JavaScriptContentHeaderItemgetJavaScriptHeaderItem()Create the Javascript HeaderItem for the chart without dependencies for ajax.ChartLibLoadergetLoader()StringgetLoaderUrl()Get Google Loader URL.LocalegetLocale()The Locale is used to render alanguage = "de"in the load statement like in the example:StringgetMapsApiKey()Getter for Google Maps API key for geo- and map charts.IModel<ChartOptions>getOptionModel()StringgetOptionsId()Make a options id from chart id.StringgetRedrawScriptId()Make a script id for redraw script from chart id.StringgetScriptId()Make a script id from chart id.IModel<ChartType>getTypeModel()protected StringBuilderinitLoaderBuilder()Create a StringBuilder for generating Javascript.booleanisResponsive()Should some JavaScript be added to make the Chart responsive.protected voidonDetach()voidrenderHead(IHeaderResponse response)voidsetDataModel(IModel<DataTable> dataModel)voidsetLocale(Locale locale)Override default Locale for the chart.voidsetMapsApiKey(String mapsApiKey)Setter for Google Maps API key for geo- and map charts.voidsetOptionModel(IModel<ChartOptions> optionModel)voidsetResponsive(boolean responsive)Set this to true if some JavaScript should be added to make the Chart responsive.voidsetTypeModel(IModel<ChartType> typeModel)StringtoJavaScript()Return the JavaScript part.com.github.openjson.JSONObjecttoJSON()Create the JSON serialization of the instance.-
Methods inherited from class org.apache.wicket.markup.html.WebComponent
getWebApplication, getWebPage, getWebRequest, getWebResponse, getWebSession, onRender
-
Methods inherited from class org.apache.wicket.Component
add, addStateChange, beforeRender, canCallListener, canCallListenerAfterExpiry, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, clearOriginalDestination, configure, continueToOriginalDestination, createConverter, debug, detach, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findMarkupStream, findPage, findParent, findParentWithAssociatedMarkup, get, getAjaxRegionMarkupId, getApplication, getBehaviorById, getBehaviorId, getBehaviors, getBehaviors, getClassRelativePath, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessages, getFlag, getId, getInnermostModel, getInnermostModel, getLocalizer, getMarkup, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdFromMarkup, getMarkupIdImpl, getMarkupSourcingStrategy, getMarkupTag, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getRequestFlag, getResponse, getSession, getSizeInBytes, getStatelessHint, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalInitialize, internalOnModelChanged, internalRenderComponent, internalRenderHead, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isInitialized, isRenderAllowed, isRendering, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, newMarkupSourcingStrategy, onAfterRender, onBeforeRender, onComponentTag, onComponentTagBody, onConfigure, onEvent, onInitialize, onModelChanged, onModelChanging, onReAdd, onRemove, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderPart, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, send, setAuto, setDefaultModel, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setIgnoreAttributeModifier, setMarkup, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setParent, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, success, toString, toString, urlFor, urlFor, urlFor, urlForListener, urlForListener, visitParents, visitParents, warn, wrap
-
-
-
-
Field Detail
-
LOADER_URL
public static final String LOADER_URL
URL for Google lib loader- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Chart
public Chart(String id)
Basic Constructor.- Parameters:
id- Wicket id. Id is used in javascript, but at the moment not escaped to JavaScript identifier rules. So use only characters allowed for JavaScript declarations to avoid problems.
-
Chart
public Chart(String id, IModel<ChartType> typeModel, IModel<ChartOptions> optionModel, IModel<DataTable> dataModel)
Complete Constructor.- Parameters:
id- Wicket id. Id is used in javascript, but at the moment not escaped to JavaScript identifier rules. So use only characters allowed for JavaScript declarations to avoid problems. This constructor is for use withoutChartLibLoader(one chart per page).typeModel- Model of Type of chart.optionModel- Model of optionModel.dataModel- Model of data dataModel.
-
Chart
public Chart(String id, IModel<ChartType> typeModel, IModel<ChartOptions> optionModel, IModel<DataTable> dataModel, ChartLibLoader loader)
Complete Constructor.- Parameters:
id- Wicket id. Id is used in javascript, but at the moment not escaped to JavaScript identifier rules. So use only characters allowed for JavaScript declarations to avoid problems. This constructor is for use withChartLibLoader(multiple charts per page).typeModel- Model of Type of chart.optionModel- Model of optionModel.dataModel- Model of data dataModel.loader- Loader to add the chart to.
-
-
Method Detail
-
getLoaderUrl
public String getLoaderUrl()
Get Google Loader URL. Can be overwritten, if Google changes URL in future.- Returns:
- Returns
LOADER_URL.
-
createLoaderItem
public JavaScriptHeaderItem createLoaderItem()
Create the JavaScript for the Google loader.- Returns:
- HeaderItem for Google loader url.
-
renderHead
public void renderHead(IHeaderResponse response)
- Specified by:
renderHeadin interfaceIHeaderContributor- Overrides:
renderHeadin classComponent
-
configureAjaxUpdate
public void configureAjaxUpdate(AjaxRequestTarget target)
Configure an ajax response to redraw the chart. Use this call for instance inAjaxCheckBox#onUpdateorAjaxLink#onClick. Can be used after data change or options change. See example page for usage example switching StackedPercent option on a bar chart.- Parameters:
target- Request target to configure.
-
getJavaScriptHeaderItem
public JavaScriptContentHeaderItem getJavaScriptHeaderItem()
Create the Javascript HeaderItem for the chart without dependencies for ajax.- Returns:
- Header item for chart draw script.
-
isResponsive
public boolean isResponsive()
Should some JavaScript be added to make the Chart responsive. By default Google charts are not responsive, this is an extension by wicket-gchart.This is set to true by default.
- Returns:
- True if the chart will redraw on window resize, false if not.
-
setResponsive
public void setResponsive(boolean responsive)
Set this to true if some JavaScript should be added to make the Chart responsive. By default Google charts are not responsive, this is an extension by wicket-gchart. If true a script like
will be rendered in head to add this functionality.$(window).resize(function(){ drawChart1(); });- Parameters:
responsive- Set to true to dynamically redraw the chart on resize events. Set to false not to redraw. Default is true.
-
getLocale
public Locale getLocale()
The Locale is used to render alanguage = "de"in the load statement like in the example:
If Locale is not explicitly set and null, the wicket// Load Google Charts for the Japanese locale. google.charts.load('current', {'packages':['corechart'], 'language': 'ja'});Component.getLocale()is returned, which is identical toSession.getLocale(). To override usesetLocale(java.util.Locale).
-
setLocale
public void setLocale(Locale locale)
Override default Locale for the chart. SeegetLocale().- Parameters:
locale- Locale to render chart with.
-
getMapsApiKey
public String getMapsApiKey()
Getter for Google Maps API key for geo- and map charts. In all other charts this value will be null. Getter should never find any usage except tests and logging.- Returns:
- Google Maps API key. Null except for Geo Charts.
-
setMapsApiKey
public void setMapsApiKey(String mapsApiKey)
Setter for Google Maps API key for geo- and map charts. In all other charts this has no use. For geo- and mapcharts add this key to be rendered in package deklaration:google.charts.load('current', { 'packages':['geochart'], // Note: you will need to get a mapsApiKey for your project. // See: https://developers.google.com/chart/interactive/docs/basic_load_libs#load-settings 'mapsApiKey': 'AIzaSyD-9tSrke72PouQMnMX-a7eZSW0jkFMBWY' });- Parameters:
mapsApiKey- Google Maps API key.
-
getOptionModel
public IModel<ChartOptions> getOptionModel()
-
setOptionModel
public void setOptionModel(IModel<ChartOptions> optionModel)
-
createLoaderStatement
protected String createLoaderStatement()
Create the load statement of the chart lib with package, language and Maps API key declaration as defined by the chart and itsChartType.- Returns:
- Onle line load statement to be included in a JavaScript.
-
toJavaScript
public String toJavaScript()
Description copied from interface:JavaScriptableReturn the JavaScript part.- Specified by:
toJavaScriptin interfaceJavaScriptable- Returns:
- JavaScript String for use as part of chart declaration.
-
initLoaderBuilder
protected StringBuilder initLoaderBuilder()
Create a StringBuilder for generating Javascript. If needed the builder contains altready the chart library loader statement.- Returns:
- Builder stub with loader statement.
-
createJavaScriptBuilder
protected StringBuilder createJavaScriptBuilder()
Create a builder containing the standard javascript without wrapper.- Returns:
- Stringbuilder with already defined javascript.
-
createWrapperJavaScriptBuilder
protected StringBuilder createWrapperJavaScriptBuilder()
Create a builder containing the javascript with use of ChartWrapper. See ChartWrapper Class.- Returns:
- Stringbuilder with already defined javascript.
-
toJSON
public com.github.openjson.JSONObject toJSON()
Description copied from interface:JsonableCreate the JSON serialization of the instance.
-
getCallbackId
public String getCallbackId()
Make a callback identifier from chart id.- Returns:
- Identifier for callback.
-
getChartId
public String getChartId()
Make a chart identifier from chart id.- Returns:
- Identifier(js) for chart.
-
getScriptId
public String getScriptId()
Make a script id from chart id.- Returns:
- Identifier(js) for chart creation script.
-
getDataTableId
public String getDataTableId()
Make a data table id from chart id.- Returns:
- Identifier(js) for datatable variable.
-
getOptionsId
public String getOptionsId()
Make a options id from chart id.- Returns:
- Identifier(js) for options variable.
-
getRedrawScriptId
public String getRedrawScriptId()
Make a script id for redraw script from chart id. This is used if chart should be responsive.- Returns:
- Identifier(js) for chart redraw script.
-
createRedrawJavaScript
public String createRedrawJavaScript()
Create a a redraw script for responsive charts. The chart is redrawn on(window).resizeevents.- Returns:
- Complete redraw script.
-
getLoader
public ChartLibLoader getLoader()
- Returns:
- the loader
-
-