mirror of
https://github.com/unidoc/unioffice.git
synced 2025-04-25 13:48:53 +08:00
spreadsheet: allow multiple anchor types for charts
This commit is contained in:
parent
558e5ee274
commit
58b6c0700e
@ -28,9 +28,8 @@ func main() {
|
||||
|
||||
// Charts need to reside in a drawing
|
||||
dwng := ss.AddDrawing()
|
||||
chart, anc := dwng.AddChart()
|
||||
// make it a bit wider than the default
|
||||
anc.BottomRight().SetCol(15)
|
||||
chart, anc := dwng.AddChart(spreadsheet.AnchorTypeTwoCell)
|
||||
anc.SetWidthCells(10)
|
||||
|
||||
lc := chart.AddBarChart()
|
||||
priceSeries := lc.AddSeries()
|
||||
|
@ -28,9 +28,8 @@ func main() {
|
||||
|
||||
// Charts need to reside in a drawing
|
||||
dwng := ss.AddDrawing()
|
||||
chart, anc := dwng.AddChart()
|
||||
// make it a bit wider than the default
|
||||
anc.BottomRight().SetCol(15)
|
||||
chart, anc := dwng.AddChart(spreadsheet.AnchorTypeTwoCell)
|
||||
anc.SetWidthCells(10)
|
||||
|
||||
lc := chart.AddBubbleChart()
|
||||
|
||||
|
@ -76,8 +76,8 @@ func main() {
|
||||
|
||||
// Charts need to reside in a drawing
|
||||
dwng := ss.AddDrawing()
|
||||
chrt1, anc1 := dwng.AddChart()
|
||||
chrt2, anc2 := dwng.AddChart()
|
||||
chrt1, anc1 := dwng.AddChart(spreadsheet.AnchorTypeTwoCell)
|
||||
chrt2, anc2 := dwng.AddChart(spreadsheet.AnchorTypeTwoCell)
|
||||
addBar3DChart(chrt1)
|
||||
addLineChart(chrt2)
|
||||
anc1.SetWidth(9)
|
||||
|
@ -28,9 +28,8 @@ func main() {
|
||||
|
||||
// Charts need to reside in a drawing
|
||||
dwng := ss.AddDrawing()
|
||||
crt, anc := dwng.AddChart()
|
||||
// make it a bit wider than the default
|
||||
anc.BottomRight().SetCol(15)
|
||||
crt, anc := dwng.AddChart(spreadsheet.AnchorTypeTwoCell)
|
||||
anc.SetWidthCells(10)
|
||||
|
||||
lc := crt.AddLine3DChart()
|
||||
priceSeries := lc.AddSeries()
|
||||
|
@ -12,7 +12,7 @@ func main() {
|
||||
sheet := ss.AddSheet()
|
||||
|
||||
dwng := ss.AddDrawing()
|
||||
chart, anc := dwng.AddChart()
|
||||
chart, anc := dwng.AddChart(spreadsheet.AnchorTypeTwoCell)
|
||||
anc.MoveTo(0, 0)
|
||||
anc.SetWidth(10)
|
||||
|
||||
|
@ -28,9 +28,9 @@ func main() {
|
||||
|
||||
// Charts need to reside in a drawing
|
||||
dwng := ss.AddDrawing()
|
||||
chart, anc := dwng.AddChart()
|
||||
chart, anc := dwng.AddChart(spreadsheet.AnchorTypeTwoCell)
|
||||
// make it a bit wider than the default
|
||||
anc.BottomRight().SetCol(15)
|
||||
anc.SetWidthCells(10)
|
||||
|
||||
lc := chart.AddLineChart()
|
||||
priceSeries := lc.AddSeries()
|
||||
|
@ -29,8 +29,8 @@ func main() {
|
||||
|
||||
// Charts need to reside in a drawing
|
||||
dwng := ss.AddDrawing()
|
||||
chrt1, anc1 := dwng.AddChart()
|
||||
chrt2, anc2 := dwng.AddChart()
|
||||
chrt1, anc1 := dwng.AddChart(spreadsheet.AnchorTypeTwoCell)
|
||||
chrt2, anc2 := dwng.AddChart(spreadsheet.AnchorTypeTwoCell)
|
||||
addBarChart(chrt1)
|
||||
addLineChart(chrt2)
|
||||
anc1.SetWidth(9)
|
||||
|
@ -38,9 +38,8 @@ func main() {
|
||||
}
|
||||
// Charts need to reside in a drawing
|
||||
dwng := ss.AddDrawing()
|
||||
chart, anc := dwng.AddChart()
|
||||
// make it a bit wider than the default
|
||||
anc.BottomRight().SetCol(15)
|
||||
chart, anc := dwng.AddChart(spreadsheet.AnchorTypeTwoCell)
|
||||
anc.SetWidthCells(10)
|
||||
|
||||
lc := chart.AddLineChart()
|
||||
priceSeries := lc.AddSeries()
|
||||
|
@ -28,9 +28,8 @@ func main() {
|
||||
|
||||
// Charts need to reside in a drawing
|
||||
dwng := ss.AddDrawing()
|
||||
chart, anc := dwng.AddChart()
|
||||
// make it a bit wider than the default
|
||||
anc.BottomRight().SetCol(15)
|
||||
chart, anc := dwng.AddChart(spreadsheet.AnchorTypeTwoCell)
|
||||
anc.SetWidthCells(10)
|
||||
|
||||
lc := chart.AddPieChart()
|
||||
priceSeries := lc.AddSeries()
|
||||
|
@ -28,9 +28,8 @@ func main() {
|
||||
|
||||
// Charts need to reside in a drawing
|
||||
dwng := ss.AddDrawing()
|
||||
chart, anc := dwng.AddChart()
|
||||
// make it a bit wider than the default
|
||||
anc.BottomRight().SetCol(15)
|
||||
chart, anc := dwng.AddChart(spreadsheet.AnchorTypeTwoCell)
|
||||
anc.SetWidthCells(10)
|
||||
|
||||
lc := chart.AddRadarChart()
|
||||
priceSeries := lc.AddSeries()
|
||||
|
@ -28,10 +28,8 @@ func main() {
|
||||
|
||||
// Charts need to reside in a drawing
|
||||
dwng := ss.AddDrawing()
|
||||
chart, anc := dwng.AddChart()
|
||||
// make it a bit wider than the default
|
||||
anc.BottomRight().SetCol(15)
|
||||
|
||||
chart, anc := dwng.AddChart(spreadsheet.AnchorTypeTwoCell)
|
||||
anc.SetWidthCells(10)
|
||||
lc := chart.AddSurfaceChart()
|
||||
priceSeries := lc.AddSeries()
|
||||
priceSeries.SetText("Price")
|
||||
|
@ -37,7 +37,7 @@ func (d Drawing) X() *sd.WsDr {
|
||||
|
||||
// AddChart adds an chart to a drawing, returning the chart and an anchor that
|
||||
// can be used to position the chart within the sheet.
|
||||
func (d Drawing) AddChart() (chart.Chart, Anchor) {
|
||||
func (d Drawing) AddChart(at AnchorType) (chart.Chart, Anchor) {
|
||||
chartSpace := crt.NewChartSpace()
|
||||
d.wb.charts = append(d.wb.charts, chartSpace)
|
||||
|
||||
@ -55,22 +55,42 @@ func (d Drawing) AddChart() (chart.Chart, Anchor) {
|
||||
}
|
||||
}
|
||||
|
||||
tca := defaultTwoCellAnchor()
|
||||
d.x.EG_Anchor = append(d.x.EG_Anchor, &sd.EG_Anchor{TwoCellAnchor: tca})
|
||||
|
||||
tca.Choice = &sd.EG_ObjectChoicesChoice{}
|
||||
tca.Choice.GraphicFrame = sd.NewCT_GraphicalObjectFrame()
|
||||
var anc Anchor
|
||||
var gf *sd.CT_GraphicalObjectFrame
|
||||
switch at {
|
||||
case AnchorTypeAbsolute:
|
||||
aa := defaultAbsoluteAnchor()
|
||||
d.x.EG_Anchor = append(d.x.EG_Anchor, &sd.EG_Anchor{AbsoluteAnchor: aa})
|
||||
aa.Choice = &sd.EG_ObjectChoicesChoice{}
|
||||
aa.Choice.GraphicFrame = sd.NewCT_GraphicalObjectFrame()
|
||||
gf = aa.Choice.GraphicFrame
|
||||
anc = AbsoluteAnchor{aa}
|
||||
case AnchorTypeOneCell:
|
||||
oca := defaultOneCelAnchor()
|
||||
d.x.EG_Anchor = append(d.x.EG_Anchor, &sd.EG_Anchor{OneCellAnchor: oca})
|
||||
oca.Choice = &sd.EG_ObjectChoicesChoice{}
|
||||
oca.Choice.GraphicFrame = sd.NewCT_GraphicalObjectFrame()
|
||||
gf = oca.Choice.GraphicFrame
|
||||
anc = OneCellAnchor{oca}
|
||||
case AnchorTypeTwoCell:
|
||||
tca := defaultTwoCellAnchor()
|
||||
d.x.EG_Anchor = append(d.x.EG_Anchor, &sd.EG_Anchor{TwoCellAnchor: tca})
|
||||
tca.Choice = &sd.EG_ObjectChoicesChoice{}
|
||||
tca.Choice.GraphicFrame = sd.NewCT_GraphicalObjectFrame()
|
||||
gf = tca.Choice.GraphicFrame
|
||||
anc = TwoCellAnchor{tca}
|
||||
}
|
||||
|
||||
// required by Mac Excel
|
||||
tca.Choice.GraphicFrame.NvGraphicFramePr = sd.NewCT_GraphicalObjectFrameNonVisual()
|
||||
tca.Choice.GraphicFrame.NvGraphicFramePr.CNvPr.IdAttr = 2
|
||||
tca.Choice.GraphicFrame.NvGraphicFramePr.CNvPr.NameAttr = "Chart"
|
||||
gf.NvGraphicFramePr = sd.NewCT_GraphicalObjectFrameNonVisual()
|
||||
gf.NvGraphicFramePr.CNvPr.IdAttr = 2
|
||||
gf.NvGraphicFramePr.CNvPr.NameAttr = "Chart"
|
||||
|
||||
tca.Choice.GraphicFrame.Graphic = dml.NewGraphic()
|
||||
tca.Choice.GraphicFrame.Graphic.GraphicData.UriAttr = "http://schemas.openxmlformats.org/drawingml/2006/chart"
|
||||
gf.Graphic = dml.NewGraphic()
|
||||
gf.Graphic.GraphicData.UriAttr = "http://schemas.openxmlformats.org/drawingml/2006/chart"
|
||||
c := c.NewChart()
|
||||
c.IdAttr = chartID
|
||||
tca.Choice.GraphicFrame.Graphic.GraphicData.Any = []gooxml.Any{c}
|
||||
gf.Graphic.GraphicData.Any = []gooxml.Any{c}
|
||||
|
||||
//chart.Chart.PlotVisOnly = crt.NewCT_Boolean()
|
||||
//chart.Chart.PlotVisOnly.ValAttr = gooxml.Bool(true)
|
||||
@ -78,7 +98,7 @@ func (d Drawing) AddChart() (chart.Chart, Anchor) {
|
||||
chrt := chart.MakeChart(chartSpace)
|
||||
chrt.Properties().SetSolidFill(color.White)
|
||||
chrt.SetDisplayBlanksAs(crt.ST_DispBlanksAsGap)
|
||||
return chrt, TwoCellAnchor{tca}
|
||||
return chrt, anc
|
||||
}
|
||||
|
||||
// AddImage adds an image with a paricular anchor type, returning an anchor to
|
||||
|
Loading…
x
Reference in New Issue
Block a user